@coding01/docsjs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +172 -0
- package/dist/index.cjs +1609 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +49 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +1569 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 fanly
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# @coding01/docsjs
|
|
2
|
+
|
|
3
|
+
`@coding01/docsjs` 是一个 Render-first 的 Word 高保真组件,目标是把 Word/WPS/Google Docs 内容以“先渲染、后编辑”的方式无损导入到 Web 端。
|
|
4
|
+
|
|
5
|
+
当前提供:
|
|
6
|
+
- Web Component 内核:`docs-word-editor`
|
|
7
|
+
- React 适配组件:`WordFidelityEditorReact`
|
|
8
|
+
- Vue 适配组件:`WordFidelityEditorVue`
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm i @coding01/docsjs
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
### React
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { WordFidelityEditorReact } from "@coding01/docsjs";
|
|
22
|
+
|
|
23
|
+
export default function Page() {
|
|
24
|
+
return (
|
|
25
|
+
<WordFidelityEditorReact
|
|
26
|
+
onChange={(payload) => {
|
|
27
|
+
console.log(payload.htmlSnapshot);
|
|
28
|
+
}}
|
|
29
|
+
onError={(payload) => {
|
|
30
|
+
console.error(payload.message);
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Vue
|
|
38
|
+
|
|
39
|
+
```vue
|
|
40
|
+
<template>
|
|
41
|
+
<WordFidelityEditorVue @change="onChange" @error="onError" />
|
|
42
|
+
</template>
|
|
43
|
+
|
|
44
|
+
<script setup lang="ts">
|
|
45
|
+
import { WordFidelityEditorVue } from "@coding01/docsjs";
|
|
46
|
+
|
|
47
|
+
const onChange = (payload: { htmlSnapshot: string }) => {
|
|
48
|
+
console.log(payload.htmlSnapshot);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const onError = (payload: { message: string }) => {
|
|
52
|
+
console.error(payload.message);
|
|
53
|
+
};
|
|
54
|
+
</script>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Web Component (Vanilla)
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { defineDocsWordElement } from "@coding01/docsjs";
|
|
61
|
+
|
|
62
|
+
defineDocsWordElement();
|
|
63
|
+
const el = document.createElement("docs-word-editor");
|
|
64
|
+
document.body.appendChild(el);
|
|
65
|
+
|
|
66
|
+
el.addEventListener("docsjs-change", (e) => {
|
|
67
|
+
const detail = (e as CustomEvent<{ htmlSnapshot: string }>).detail;
|
|
68
|
+
console.log(detail.htmlSnapshot);
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## API
|
|
73
|
+
|
|
74
|
+
### Component Events
|
|
75
|
+
|
|
76
|
+
- `docsjs-change`
|
|
77
|
+
- payload: `{ htmlSnapshot: string }`
|
|
78
|
+
- 触发时机:粘贴、上传 Word、手动 `setSnapshot`、`clear`
|
|
79
|
+
- `docsjs-error`
|
|
80
|
+
- payload: `{ message: string }`
|
|
81
|
+
- 触发时机:剪贴板读取失败、DOCX 解析失败等
|
|
82
|
+
|
|
83
|
+
### Web Component Methods
|
|
84
|
+
|
|
85
|
+
- `setSnapshot(rawHtml: string): void`
|
|
86
|
+
- 将外部 HTML 快照注入渲染层
|
|
87
|
+
- `clear(): void`
|
|
88
|
+
- 清空当前文档
|
|
89
|
+
|
|
90
|
+
## Semantic Coverage
|
|
91
|
+
|
|
92
|
+
下表描述“语义与格式覆盖”当前状态。
|
|
93
|
+
|
|
94
|
+
### Completed
|
|
95
|
+
|
|
96
|
+
- 输入链路
|
|
97
|
+
- 粘贴:Word / WPS / Google Docs HTML
|
|
98
|
+
- 上传:`.docx` 文件解析并渲染
|
|
99
|
+
- 页面模型
|
|
100
|
+
- A4 页高/页边距/版心宽度映射
|
|
101
|
+
- 段落语义
|
|
102
|
+
- 对齐、段前段后、行距(`auto` / `exact` / `atLeast`)
|
|
103
|
+
- 缩进(left/right/firstLine/hanging)
|
|
104
|
+
- keep 规则(`keepNext` / `keepLines` / `pageBreakBefore` / `lastRenderedPageBreak`)
|
|
105
|
+
- Run 语义
|
|
106
|
+
- 字号、字体、颜色、粗体、斜体、下划线、删除线
|
|
107
|
+
- 高亮、底纹、上下标、字距、阴影
|
|
108
|
+
- 列表语义
|
|
109
|
+
- 多级编号(`numId` + `ilvl`)
|
|
110
|
+
- `numFmt` 和 `lvlText` 模板(如 `%1.%2.`)
|
|
111
|
+
- section break 计数重置
|
|
112
|
+
- 表格语义
|
|
113
|
+
- `table/tr/td` 结构保留
|
|
114
|
+
- 单元格段落保留与边框/基础 padding 映射
|
|
115
|
+
- 图片语义
|
|
116
|
+
- 提取关系映射(`rId -> media`)
|
|
117
|
+
- `wp:extent` 尺寸映射为像素(稳定布局)
|
|
118
|
+
|
|
119
|
+
### In Progress / Not Completed
|
|
120
|
+
|
|
121
|
+
- 复杂 Word 对象
|
|
122
|
+
- 浮动锚点对象(复杂 `wp:anchor`)
|
|
123
|
+
- 图表、SmartArt、公式(OMML)深层渲染
|
|
124
|
+
- 文档语义高级能力
|
|
125
|
+
- Track Changes / Comments / Footnotes / Endnotes
|
|
126
|
+
- 域代码(目录、页码域)刷新
|
|
127
|
+
- 分页精度
|
|
128
|
+
- widow/orphan 规则完整覆盖
|
|
129
|
+
- 跨页表格与复杂 keep 组合场景
|
|
130
|
+
- 编辑能力
|
|
131
|
+
- 当前提供的是渲染导入组件,完整富文本编辑工具栏与协同编辑仍在规划中
|
|
132
|
+
|
|
133
|
+
## Build & Local Develop
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npm install
|
|
137
|
+
npm run typecheck
|
|
138
|
+
npm run build
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Publish to npm
|
|
142
|
+
|
|
143
|
+
### Manual publish
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
npm login
|
|
147
|
+
npm version patch
|
|
148
|
+
git push origin main --tags
|
|
149
|
+
npm publish --access public
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### GitHub Actions auto publish
|
|
153
|
+
|
|
154
|
+
This repo includes `.github/workflows/publish.yml`:
|
|
155
|
+
- Trigger: push tag `v*.*.*`
|
|
156
|
+
- Steps: `npm ci` -> `typecheck` -> `build` -> `npm publish`
|
|
157
|
+
|
|
158
|
+
Trusted Publishing (recommended):
|
|
159
|
+
- No long-lived `NPM_TOKEN` secret required
|
|
160
|
+
- Uses GitHub OIDC (`id-token: write`) to publish
|
|
161
|
+
|
|
162
|
+
Release flow:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
npm version patch
|
|
166
|
+
git push origin main --follow-tags
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Security Notes
|
|
170
|
+
|
|
171
|
+
- 本组件默认不清洗 Word 内联样式(保真优先)。
|
|
172
|
+
- 生产环境请在宿主应用侧配置 CSP、iframe sandbox 和上传白名单策略。
|