belobog-stellar-grid 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE_APACHE +176 -0
- package/LICENSE_MIT +25 -0
- package/README.md +413 -0
- package/belobog_stellar_grid.d.ts +126 -0
- package/belobog_stellar_grid.js +690 -0
- package/belobog_stellar_grid_bg.wasm +0 -0
- package/package.json +33 -0
package/LICENSE_APACHE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/LICENSE_MIT
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Copyright (c) 2018 Kurisu <makise_kurisuu@outlook.jp>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any
|
|
4
|
+
person obtaining a copy of this software and associated
|
|
5
|
+
documentation files (the "Software"), to deal in the
|
|
6
|
+
Software without restriction, including without
|
|
7
|
+
limitation the rights to use, copy, modify, merge,
|
|
8
|
+
publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software
|
|
10
|
+
is furnished to do so, subject to the following
|
|
11
|
+
conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice
|
|
14
|
+
shall be included in all copies or substantial portions
|
|
15
|
+
of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
18
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
19
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
20
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
21
|
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
24
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
25
|
+
DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<h1><code>belobog-stellar-grid</code></h1>
|
|
4
|
+
|
|
5
|
+
<p><strong>🦀 现代化的 WebAssembly 表格导出库</strong></p>
|
|
6
|
+
|
|
7
|
+
<p>一个安全、高效、易用的 Rust WebAssembly 库,用于将 HTML 表格导出为 CSV 和 XLSX 文件</p>
|
|
8
|
+
|
|
9
|
+
<p>
|
|
10
|
+
<img src="https://img.shields.io/badge/version-1.0.0-blue.svg" alt="Version" />
|
|
11
|
+
<img src="https://img.shields.io/badge/rust-edition%202024-orange.svg" alt="Rust Edition" />
|
|
12
|
+
<img src="https://img.shields.io/badge/test_coverage-100%25-brightgreen.svg" alt="Test Coverage" />
|
|
13
|
+
<img src="https://img.shields.io/badge/license-MIT%2FApache--2.0-green.svg" alt="License" />
|
|
14
|
+
<a href="https://github.com/kurisu994/belobog-stellar-grid"><img src="https://img.shields.io/badge/github-belobog--stellar--grid-181717.svg?logo=github" alt="GitHub" /></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">Rust and WebAssembly</a></sub>
|
|
18
|
+
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 📋 项目简介
|
|
24
|
+
|
|
25
|
+
`belobog-stellar-grid` 是一个高性能的 WebAssembly 库,让你可以轻松地在浏览器中将 HTML 表格导出为 CSV/XLSX 文件。项目采用模块化架构设计,包含完善的文件名验证、RAII 资源管理和分批异步处理机制。
|
|
26
|
+
|
|
27
|
+
### 为什么选择这个库?
|
|
28
|
+
|
|
29
|
+
- **🎯 零配置**:开箱即用,无需复杂的设置
|
|
30
|
+
- **🚀 极致性能**:Rust 原生速度 + WebAssembly 优化
|
|
31
|
+
- **🔒 企业级安全**:内置文件名验证,防止路径遍历攻击
|
|
32
|
+
- **📦 轻量级**:约 117KB 的 WASM 文件(gzip 后约 40KB)
|
|
33
|
+
- **✅ 100% 测试覆盖**:47 个单元测试确保代码质量
|
|
34
|
+
- **🏗️ 模块化架构**:清晰的模块设计,易于维护和扩展
|
|
35
|
+
- **🌍 国际化支持**:完美支持中文、日文、韩文等 Unicode 字符
|
|
36
|
+
- **💾 多格式导出**:支持 CSV 和 XLSX (Excel) 两种格式
|
|
37
|
+
|
|
38
|
+
### ✨ 核心特性
|
|
39
|
+
|
|
40
|
+
#### 🛡️ 安全性
|
|
41
|
+
|
|
42
|
+
- **RAII 资源管理**:`UrlGuard` 自动清理 Blob URL
|
|
43
|
+
- **文件名安全验证**:阻止路径遍历、危险字符等 10+ 种威胁
|
|
44
|
+
- **全面错误处理**:所有函数返回 `Result<T, JsValue>`
|
|
45
|
+
- **内存安全保证**:得益于 Rust 的所有权系统
|
|
46
|
+
- **中文错误消息**:用户友好的错误提示
|
|
47
|
+
|
|
48
|
+
#### 🚀 性能优化
|
|
49
|
+
|
|
50
|
+
- **零拷贝操作**:直接操作 DOM,参数使用 `&str` 引用
|
|
51
|
+
- **分批异步处理**:支持百万级数据导出,避免页面卡死
|
|
52
|
+
- **wee_alloc 优化**:使用轻量级分配器减小文件体积
|
|
53
|
+
- **LTO 优化**:链接时优化减少最终 WASM 大小
|
|
54
|
+
- **实时进度反馈**:支持大型表格的进度回调
|
|
55
|
+
|
|
56
|
+
## 🚀 快速开始
|
|
57
|
+
|
|
58
|
+
### 30 秒上手
|
|
59
|
+
|
|
60
|
+
```html
|
|
61
|
+
<!DOCTYPE html>
|
|
62
|
+
<html>
|
|
63
|
+
<head>
|
|
64
|
+
<script type="module">
|
|
65
|
+
import init, { export_table, ExportFormat } from "./pkg/belobog_stellar_grid.js";
|
|
66
|
+
|
|
67
|
+
// 1. 初始化(只需一次)
|
|
68
|
+
await init();
|
|
69
|
+
|
|
70
|
+
// 2. 导出为 CSV(默认)
|
|
71
|
+
document.getElementById("csv-btn").onclick = () => {
|
|
72
|
+
export_table("my-table", "数据.csv");
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// 3. 导出为 Excel
|
|
76
|
+
document.getElementById("xlsx-btn").onclick = () => {
|
|
77
|
+
export_table("my-table", "数据.xlsx", ExportFormat.Xlsx);
|
|
78
|
+
};
|
|
79
|
+
</script>
|
|
80
|
+
</head>
|
|
81
|
+
<body>
|
|
82
|
+
<table id="my-table">
|
|
83
|
+
<tr>
|
|
84
|
+
<th>姓名</th>
|
|
85
|
+
<th>年龄</th>
|
|
86
|
+
</tr>
|
|
87
|
+
<tr>
|
|
88
|
+
<td>张三</td>
|
|
89
|
+
<td>25</td>
|
|
90
|
+
</tr>
|
|
91
|
+
</table>
|
|
92
|
+
<button id="csv-btn">导出 CSV</button>
|
|
93
|
+
<button id="xlsx-btn">导出 Excel</button>
|
|
94
|
+
</body>
|
|
95
|
+
</html>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
就是这么简单! 🎉
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
### 📦 安装方式
|
|
103
|
+
|
|
104
|
+
#### NPM 安装(推荐)
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# pnpm(推荐)
|
|
108
|
+
pnpm add belobog-stellar-grid
|
|
109
|
+
|
|
110
|
+
# NPM
|
|
111
|
+
npm install belobog-stellar-grid
|
|
112
|
+
|
|
113
|
+
# Yarn
|
|
114
|
+
yarn add belobog-stellar-grid
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### 从源码构建
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
git clone https://github.com/kurisu994/belobog-stellar-grid.git
|
|
121
|
+
cd belobog-stellar-grid
|
|
122
|
+
wasm-pack build --target web
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
### 💻 基本用法
|
|
128
|
+
|
|
129
|
+
#### 统一导出 API(推荐)
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
import init, { export_table, ExportFormat } from "belobog-stellar-grid";
|
|
133
|
+
|
|
134
|
+
// 初始化模块(只需执行一次)
|
|
135
|
+
await init();
|
|
136
|
+
|
|
137
|
+
// 导出为 CSV(默认)
|
|
138
|
+
export_table("table-id");
|
|
139
|
+
export_table("table-id", "销售报表_2024.csv");
|
|
140
|
+
|
|
141
|
+
// 导出为 Excel
|
|
142
|
+
export_table("table-id", "销售报表_2024.xlsx", ExportFormat.Xlsx);
|
|
143
|
+
export_table("table-id", "销售报表_2024", ExportFormat.Xlsx); // 自动添加扩展名
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
#### 带进度条的导出
|
|
147
|
+
|
|
148
|
+
```javascript
|
|
149
|
+
import { export_table, ExportFormat } from "belobog-stellar-grid";
|
|
150
|
+
|
|
151
|
+
// CSV 格式带进度
|
|
152
|
+
export_table("large-table", "大数据.csv", ExportFormat.Csv, (progress) => {
|
|
153
|
+
console.log(`进度: ${Math.round(progress)}%`);
|
|
154
|
+
progressBar.style.width = `${progress}%`;
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### 分批异步导出(大数据量)
|
|
159
|
+
|
|
160
|
+
```javascript
|
|
161
|
+
import { export_table_to_csv_batch } from "belobog-stellar-grid";
|
|
162
|
+
|
|
163
|
+
// 基本用法 - 处理 10,000+ 行数据
|
|
164
|
+
await export_table_to_csv_batch("huge-table", "大数据.csv");
|
|
165
|
+
|
|
166
|
+
// 高级用法 - 自定义配置
|
|
167
|
+
await export_table_to_csv_batch(
|
|
168
|
+
"huge-table",
|
|
169
|
+
"百万数据.csv",
|
|
170
|
+
1000, // 每批处理 1000 行
|
|
171
|
+
(progress) => {
|
|
172
|
+
console.log(`进度: ${Math.round(progress)}%`);
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### 错误处理
|
|
178
|
+
|
|
179
|
+
```javascript
|
|
180
|
+
import { export_table, ExportFormat } from "belobog-stellar-grid";
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
export_table("table-id", "报表", ExportFormat.Xlsx);
|
|
184
|
+
alert("✅ 导出成功!");
|
|
185
|
+
} catch (error) {
|
|
186
|
+
console.error("导出失败:", error);
|
|
187
|
+
alert("❌ 导出失败: " + error);
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
### 🎨 完整示例
|
|
194
|
+
|
|
195
|
+
查看 [examples/](./examples/) 目录获取完整示例:
|
|
196
|
+
|
|
197
|
+
| 示例 | 难度 | 描述 |
|
|
198
|
+
| ---------------------- | ------------------------------------------------------ | ------------ |
|
|
199
|
+
| basic-export.html |  | 基础导出示例 |
|
|
200
|
+
| progress-export.html |  | 进度显示示例 |
|
|
201
|
+
| advanced-features.html |  | 高级特性示例 |
|
|
202
|
+
|
|
203
|
+
**运行示例**:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
# 1. 构建项目
|
|
207
|
+
wasm-pack build --target web
|
|
208
|
+
|
|
209
|
+
# 2. 启动本地服务器
|
|
210
|
+
cargo install basic-http-server
|
|
211
|
+
basic-http-server .
|
|
212
|
+
|
|
213
|
+
# 3. 访问 http://localhost:4000/examples/
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## 📚 API 参考
|
|
219
|
+
|
|
220
|
+
### 核心函数
|
|
221
|
+
|
|
222
|
+
#### `export_table(table_id, filename?, format?, progress_callback?)` ✅ 推荐
|
|
223
|
+
|
|
224
|
+
统一的表格导出函数,支持 CSV 和 XLSX 格式。
|
|
225
|
+
|
|
226
|
+
**参数**:
|
|
227
|
+
|
|
228
|
+
- `table_id`: 表格元素的 ID
|
|
229
|
+
- `filename`: 导出文件名(可选)
|
|
230
|
+
- `format`: 导出格式(可选,默认 CSV)
|
|
231
|
+
- `progress_callback`: 进度回调函数(可选)
|
|
232
|
+
|
|
233
|
+
**示例**:
|
|
234
|
+
|
|
235
|
+
```javascript
|
|
236
|
+
import { export_table, ExportFormat } from "belobog-stellar-grid";
|
|
237
|
+
|
|
238
|
+
// 最简单的用法
|
|
239
|
+
export_table("my-table");
|
|
240
|
+
|
|
241
|
+
// 指定文件名和格式
|
|
242
|
+
export_table("my-table", "报表.xlsx", ExportFormat.Xlsx);
|
|
243
|
+
|
|
244
|
+
// 带进度回调
|
|
245
|
+
export_table("large-table", "大数据", ExportFormat.Csv, (progress) => {
|
|
246
|
+
console.log(`进度: ${progress.toFixed(1)}%`);
|
|
247
|
+
});
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
#### `export_table_to_csv_batch(table_id, tbody_id?, filename?, batch_size?, callback?)` 🔧 向后兼容
|
|
253
|
+
|
|
254
|
+
分批异步导出函数,专为大数据量设计。
|
|
255
|
+
|
|
256
|
+
**适用场景**:10,000+ 行数据
|
|
257
|
+
|
|
258
|
+
**参数**:
|
|
259
|
+
|
|
260
|
+
- `table_id`: 表格元素的 ID
|
|
261
|
+
- `tbody_id`: 可选的数据表格体 ID
|
|
262
|
+
- `filename`: 导出文件名(可选)
|
|
263
|
+
- `batch_size`: 每批处理的行数(可选,默认 1000)
|
|
264
|
+
- `callback`: 进度回调函数(可选)
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
### 文件名安全验证
|
|
269
|
+
|
|
270
|
+
所有导出函数都会自动验证文件名安全性:
|
|
271
|
+
|
|
272
|
+
| ✅ 允许 | ❌ 禁止 |
|
|
273
|
+
| -------------------- | ---------------- |
|
|
274
|
+
| `report_2024-12.csv` | `../etc/passwd` |
|
|
275
|
+
| `数据导出.csv` | `file<name>.csv` |
|
|
276
|
+
| `sales.data.csv` | `CON.csv` |
|
|
277
|
+
| `测试-文件.xlsx` | `.hidden` |
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## 🔧 开发指南
|
|
282
|
+
|
|
283
|
+
### 环境要求
|
|
284
|
+
|
|
285
|
+
| 工具 | 版本要求 |
|
|
286
|
+
| --------- | ----------- |
|
|
287
|
+
| Rust | 1.82+ |
|
|
288
|
+
| wasm-pack | latest |
|
|
289
|
+
| Node.js | 16+(可选) |
|
|
290
|
+
|
|
291
|
+
**安装工具**:
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
# 安装 Rust
|
|
295
|
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
296
|
+
|
|
297
|
+
# 安装 wasm-pack
|
|
298
|
+
cargo install wasm-pack
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
### 常用命令
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
# 构建项目
|
|
307
|
+
wasm-pack build --target web
|
|
308
|
+
|
|
309
|
+
# 运行测试
|
|
310
|
+
cargo test
|
|
311
|
+
|
|
312
|
+
# 代码检查
|
|
313
|
+
cargo check
|
|
314
|
+
cargo fmt
|
|
315
|
+
cargo clippy
|
|
316
|
+
|
|
317
|
+
# 运行示例
|
|
318
|
+
basic-http-server .
|
|
319
|
+
# 访问: http://localhost:4000/examples/
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
### 项目结构
|
|
323
|
+
|
|
324
|
+
```
|
|
325
|
+
belobog-stellar-grid/
|
|
326
|
+
├── src/ # 源代码
|
|
327
|
+
│ ├── lib.rs # 主入口
|
|
328
|
+
│ ├── validation.rs # 文件名验证
|
|
329
|
+
│ ├── resource.rs # RAII 资源管理
|
|
330
|
+
│ ├── core/ # 核心导出模块组
|
|
331
|
+
│ │ ├── mod.rs # 统一 API 和协调
|
|
332
|
+
│ │ ├── table_extractor.rs # 表格数据提取
|
|
333
|
+
│ │ ├── export_csv.rs # CSV 导出
|
|
334
|
+
│ │ └── export_xlsx.rs # XLSX 导出
|
|
335
|
+
│ ├── batch_export.rs # 异步分批导出
|
|
336
|
+
│ └── utils.rs # 调试工具
|
|
337
|
+
├── tests/ # 测试目录(47 个测试)
|
|
338
|
+
│ ├── lib_tests.rs # 基础功能测试(35 个)
|
|
339
|
+
│ ├── test_resource.rs # RAII 资源测试(8 个)
|
|
340
|
+
│ └── test_unified_api.rs # 统一 API 测试(4 个)
|
|
341
|
+
├── examples/ # 示例目录
|
|
342
|
+
├── pkg/ # WASM 包输出
|
|
343
|
+
└── README.md # 项目文档
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## 🚀 性能指标
|
|
349
|
+
|
|
350
|
+
### 运行时性能
|
|
351
|
+
|
|
352
|
+
| 数据量 | 同步导出 | 分批异步导出 | 页面响应性 |
|
|
353
|
+
| ------------ | ------------ | ------------- | ---------------- |
|
|
354
|
+
| 1,000 行 | <10ms | <10ms | 无明显差异 |
|
|
355
|
+
| 10,000 行 | ~1s(卡顿) | ~1.2s(流畅) | **大幅改善** |
|
|
356
|
+
| 100,000 行 | ~10s(卡死) | ~12s(流畅) | **从卡死到可用** |
|
|
357
|
+
| 1,000,000 行 | 崩溃 | ~120s(流畅) | **完全解决** |
|
|
358
|
+
|
|
359
|
+
### 文件大小
|
|
360
|
+
|
|
361
|
+
- WASM 原始大小:约 117KB(优化后)
|
|
362
|
+
- Gzip 压缩后:约 40KB
|
|
363
|
+
- Brotli 压缩后:约 35KB
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
## 🤝 社区与支持
|
|
368
|
+
|
|
369
|
+
### 获取帮助
|
|
370
|
+
|
|
371
|
+
1. 📖 查看文档和示例
|
|
372
|
+
2. 🔍 搜索 [Issues](https://github.com/kurisu994/belobog-stellar-grid/issues)
|
|
373
|
+
3. 💬 加入 [讨论区](https://github.com/kurisu994/belobog-stellar-grid/discussions)
|
|
374
|
+
4. 🐛 报告 [Bug](https://github.com/kurisu994/belobog-stellar-grid/issues/new)
|
|
375
|
+
|
|
376
|
+
### 贡献方式
|
|
377
|
+
|
|
378
|
+
我们欢迎各种形式的贡献:
|
|
379
|
+
|
|
380
|
+
- 🐛 报告 Bug
|
|
381
|
+
- 💡 提出新功能
|
|
382
|
+
- 📖 改进文档
|
|
383
|
+
- 🔧 提交代码
|
|
384
|
+
- ⭐ Star 项目
|
|
385
|
+
|
|
386
|
+
**代码规范**:
|
|
387
|
+
|
|
388
|
+
- 遵循 Rust 编码规范(`cargo fmt`)
|
|
389
|
+
- 通过 Clippy 检查(`cargo clippy`)
|
|
390
|
+
- 为新功能添加测试
|
|
391
|
+
|
|
392
|
+
---
|
|
393
|
+
|
|
394
|
+
## 📄 许可证
|
|
395
|
+
|
|
396
|
+
本项目采用双重许可证:
|
|
397
|
+
|
|
398
|
+
- **[MIT License](LICENSE-MIT)** - 简单宽松
|
|
399
|
+
- **[Apache License 2.0](LICENSE-APACHE)** - 更多法律保护
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
## 🙏 致谢
|
|
404
|
+
|
|
405
|
+
感谢以下项目和社区:
|
|
406
|
+
|
|
407
|
+
- [Rust](https://www.rust-lang.org/) - 强大的系统编程语言
|
|
408
|
+
- [WebAssembly](https://webassembly.org/) - 革命性的 Web 技术
|
|
409
|
+
- [wasm-bindgen](https://github.com/rustwasm/wasm-bindgen) - Rust 与 JS 的桥梁
|
|
410
|
+
- [csv](https://github.com/BurntSushi/rust-csv) - 优秀的 CSV 处理库
|
|
411
|
+
- 所有贡献者和使用者 ❤️
|
|
412
|
+
|
|
413
|
+
---
|