@coding01/docsjs 0.1.2 → 0.1.3
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 +121 -91
- package/README.zh-CN.md +179 -0
- package/dist/chunk-PRPDJOB7.js +1921 -0
- package/dist/chunk-PRPDJOB7.js.map +1 -0
- package/dist/index.cjs +528 -113
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +41 -20
- package/dist/index.d.ts +41 -20
- package/dist/index.js +56 -1553
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +1992 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +16 -0
- package/dist/react.d.ts +16 -0
- package/dist/react.js +41 -0
- package/dist/react.js.map +1 -0
- package/dist/types-DF14w1ol.d.cts +20 -0
- package/dist/types-DF14w1ol.d.ts +20 -0
- package/dist/vue.cjs +1995 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +24 -0
- package/dist/vue.d.ts +24 -0
- package/dist/vue.js +44 -0
- package/dist/vue.js.map +1 -0
- package/package.json +29 -2
package/README.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
# @coding01/docsjs
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Render-first Word fidelity component for the web.
|
|
4
|
+
Import Word/WPS/Google Docs content from paste or `.docx` while preserving structure and layout as much as possible.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
[中文文档](./README.zh-CN.md)
|
|
7
|
+
|
|
8
|
+
## What You Get
|
|
9
|
+
|
|
10
|
+
- Web Component core: `docs-word-editor`
|
|
11
|
+
- React adapter: `WordFidelityEditorReact`
|
|
12
|
+
- Vue adapter: `WordFidelityEditorVue`
|
|
13
|
+
- Import pipeline: clipboard paste + `.docx` upload
|
|
14
|
+
- HTML snapshot output for downstream rendering/storage
|
|
9
15
|
|
|
10
16
|
## Installation
|
|
11
17
|
|
|
@@ -18,17 +24,13 @@ npm i @coding01/docsjs
|
|
|
18
24
|
### React
|
|
19
25
|
|
|
20
26
|
```tsx
|
|
21
|
-
import { WordFidelityEditorReact } from "@coding01/docsjs";
|
|
27
|
+
import { WordFidelityEditorReact } from "@coding01/docsjs/react";
|
|
22
28
|
|
|
23
29
|
export default function Page() {
|
|
24
30
|
return (
|
|
25
31
|
<WordFidelityEditorReact
|
|
26
|
-
onChange={(payload) =>
|
|
27
|
-
|
|
28
|
-
}}
|
|
29
|
-
onError={(payload) => {
|
|
30
|
-
console.error(payload.message);
|
|
31
|
-
}}
|
|
32
|
+
onChange={(payload) => console.log(payload.htmlSnapshot)}
|
|
33
|
+
onError={(payload) => console.error(payload.message)}
|
|
32
34
|
/>
|
|
33
35
|
);
|
|
34
36
|
}
|
|
@@ -42,19 +44,13 @@ export default function Page() {
|
|
|
42
44
|
</template>
|
|
43
45
|
|
|
44
46
|
<script setup lang="ts">
|
|
45
|
-
import { WordFidelityEditorVue } from "@coding01/docsjs";
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
console.log(payload.htmlSnapshot);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const onError = (payload: { message: string }) => {
|
|
52
|
-
console.error(payload.message);
|
|
53
|
-
};
|
|
47
|
+
import { WordFidelityEditorVue } from "@coding01/docsjs/vue";
|
|
48
|
+
const onChange = (payload: { htmlSnapshot: string }) => console.log(payload.htmlSnapshot);
|
|
49
|
+
const onError = (payload: { message: string }) => console.error(payload.message);
|
|
54
50
|
</script>
|
|
55
51
|
```
|
|
56
52
|
|
|
57
|
-
### Web Component
|
|
53
|
+
### Web Component
|
|
58
54
|
|
|
59
55
|
```ts
|
|
60
56
|
import { defineDocsWordElement } from "@coding01/docsjs";
|
|
@@ -71,102 +67,136 @@ el.addEventListener("docsjs-change", (e) => {
|
|
|
71
67
|
|
|
72
68
|
## API
|
|
73
69
|
|
|
74
|
-
###
|
|
70
|
+
### Events
|
|
75
71
|
|
|
76
72
|
- `docsjs-change`
|
|
77
|
-
- payload: `{ htmlSnapshot: string }`
|
|
78
|
-
- 触发时机:粘贴、上传 Word、手动 `setSnapshot`、`clear`
|
|
73
|
+
- payload: `{ htmlSnapshot: string; source: "paste" | "upload" | "api" | "clear"; fileName?: string }`
|
|
79
74
|
- `docsjs-error`
|
|
80
75
|
- payload: `{ message: string }`
|
|
81
|
-
|
|
76
|
+
- `docsjs-ready`
|
|
77
|
+
- payload: `{ version: string }`
|
|
82
78
|
|
|
83
|
-
###
|
|
79
|
+
### Methods
|
|
84
80
|
|
|
85
|
-
- `
|
|
86
|
-
|
|
81
|
+
- `loadHtml(rawHtml: string): void`
|
|
82
|
+
- `loadDocx(file: File): Promise<void>`
|
|
83
|
+
- `loadClipboard(): Promise<void>`
|
|
84
|
+
- `getSnapshot(): string`
|
|
87
85
|
- `clear(): void`
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
-
|
|
100
|
-
|
|
101
|
-
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
-
|
|
122
|
-
-
|
|
123
|
-
-
|
|
124
|
-
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
-
|
|
129
|
-
-
|
|
130
|
-
-
|
|
131
|
-
-
|
|
132
|
-
|
|
133
|
-
|
|
86
|
+
|
|
87
|
+
### Attributes
|
|
88
|
+
|
|
89
|
+
- `lang="zh|en"`
|
|
90
|
+
- `show-toolbar="true|false|1|0"`
|
|
91
|
+
|
|
92
|
+
## Feature Checklist
|
|
93
|
+
|
|
94
|
+
- ✅ Web Component core (`docs-word-editor`)
|
|
95
|
+
- ✅ React adapter (`@coding01/docsjs/react`)
|
|
96
|
+
- ✅ Vue adapter (`@coding01/docsjs/vue`)
|
|
97
|
+
- ✅ Paste import (`text/html`, `text/plain`)
|
|
98
|
+
- ✅ Clipboard image hydration (`file:/blob:/cid:/mhtml:` to data URL)
|
|
99
|
+
- ✅ `.docx` upload and parse
|
|
100
|
+
- ✅ Basic paragraph semantics (alignment, headings, line break)
|
|
101
|
+
- ✅ Basic run styles (bold/italic/underline/strike/color/highlight/super/sub)
|
|
102
|
+
- ✅ List reconstruction (`numId` + `ilvl` + `lvlText`)
|
|
103
|
+
- ✅ Basic table structure (`table/tr/td`)
|
|
104
|
+
- ✅ Embedded image relationship mapping (`rId -> media`)
|
|
105
|
+
- ✅ Page geometry mapping (page height, margins, content width)
|
|
106
|
+
- ✅ Runtime render fixes (`mso-*` compatibility, pagination spacer, empty paragraph normalization)
|
|
107
|
+
- ✅ Events and public methods
|
|
108
|
+
- ✅ React and Vue runnable demos
|
|
109
|
+
- ✅ npm publish workflow with OIDC trusted publishing
|
|
110
|
+
- ⏳ Floating anchors (`wp:anchor`) full layout fidelity
|
|
111
|
+
- ⏳ Merged cells / nested tables full fidelity
|
|
112
|
+
- ⏳ Footnotes / endnotes / comments / track changes
|
|
113
|
+
- ⏳ OMML / charts / SmartArt
|
|
114
|
+
- ⏳ Automated fidelity benchmark scorecard
|
|
115
|
+
|
|
116
|
+
## What's New in v0.1.3
|
|
117
|
+
|
|
118
|
+
- Added deep DOCX semantics:
|
|
119
|
+
- numbering overrides (`lvlOverride/startOverride`)
|
|
120
|
+
- merged cells (`vMerge/gridSpan`) and nested tables
|
|
121
|
+
- footnotes and endnotes (read-only rendering)
|
|
122
|
+
- comments (read-only rendering)
|
|
123
|
+
- revisions insert/delete markers (read-only rendering)
|
|
124
|
+
- page break semantic markers (`w:br type=page`, `lastRenderedPageBreak`)
|
|
125
|
+
- Added floating image MVP:
|
|
126
|
+
- anchor position mapping (`wp:anchor`)
|
|
127
|
+
- wrap mode markers (`square`, `tight`, `topAndBottom`, `none`)
|
|
128
|
+
- Added fidelity tooling:
|
|
129
|
+
- semantic stats collector
|
|
130
|
+
- fidelity score calculator
|
|
131
|
+
- baseline regression framework (config-driven)
|
|
132
|
+
- visual regression workflow scaffold (Playwright + diff artifacts)
|
|
133
|
+
- Added engineering quality gates:
|
|
134
|
+
- ESLint + strict verify pipeline (`lint`, `typecheck`, `test`, `build`, `sizecheck`)
|
|
135
|
+
- CI workflow for mandatory quality checks
|
|
136
|
+
- contribution/rules/deep-plan docs
|
|
137
|
+
- Demo upgrades:
|
|
138
|
+
- React and Vue demos now include bilingual toggle (`zh` / `en`)
|
|
139
|
+
- component inner toolbar language follows selected locale
|
|
140
|
+
- semantic dashboard expanded with new indicators (anchor/wrap/comments/revisions/page-break)
|
|
141
|
+
|
|
142
|
+
## Development
|
|
134
143
|
|
|
135
144
|
```bash
|
|
136
145
|
npm install
|
|
137
146
|
npm run typecheck
|
|
147
|
+
npm run test
|
|
138
148
|
npm run build
|
|
139
149
|
```
|
|
140
150
|
|
|
141
|
-
##
|
|
151
|
+
## Demos
|
|
142
152
|
|
|
143
|
-
###
|
|
153
|
+
### React demo
|
|
144
154
|
|
|
145
155
|
```bash
|
|
146
|
-
|
|
147
|
-
npm
|
|
148
|
-
|
|
149
|
-
npm publish --access public
|
|
156
|
+
cd demos/react-demo
|
|
157
|
+
npm install
|
|
158
|
+
npm run dev
|
|
150
159
|
```
|
|
151
160
|
|
|
152
|
-
###
|
|
161
|
+
### Vue demo
|
|
153
162
|
|
|
154
|
-
|
|
155
|
-
-
|
|
156
|
-
|
|
163
|
+
```bash
|
|
164
|
+
cd demos/vue-demo
|
|
165
|
+
npm install
|
|
166
|
+
npm run dev
|
|
167
|
+
```
|
|
157
168
|
|
|
158
|
-
|
|
159
|
-
- No long-lived `NPM_TOKEN` secret required
|
|
160
|
-
- Uses GitHub OIDC (`id-token: write`) to publish
|
|
169
|
+
## Publishing
|
|
161
170
|
|
|
162
|
-
|
|
171
|
+
### Manual
|
|
163
172
|
|
|
164
173
|
```bash
|
|
174
|
+
npm login
|
|
165
175
|
npm version patch
|
|
166
176
|
git push origin main --follow-tags
|
|
177
|
+
npm publish --access public
|
|
167
178
|
```
|
|
168
179
|
|
|
180
|
+
### GitHub Actions
|
|
181
|
+
|
|
182
|
+
Workflow: `.github/workflows/publish.yml`
|
|
183
|
+
|
|
184
|
+
- Trigger: push tag `v*.*.*`
|
|
185
|
+
- Steps: `npm ci` -> `npm run typecheck` -> `npm run build` -> `npm publish --provenance`
|
|
186
|
+
|
|
187
|
+
## Roadmap
|
|
188
|
+
|
|
189
|
+
See [ROADMAP.md](./ROADMAP.md) for prioritized execution plan (P0/P1/P2) and acceptance criteria.
|
|
190
|
+
|
|
169
191
|
## Security Notes
|
|
170
192
|
|
|
171
|
-
-
|
|
172
|
-
-
|
|
193
|
+
- Default mode is fidelity-first and keeps Word inline styles.
|
|
194
|
+
- In production, configure CSP, iframe sandbox, file upload allowlist, and optional host-side sanitization.
|
|
195
|
+
|
|
196
|
+
## Support This Project
|
|
197
|
+
|
|
198
|
+
If this project saves your time, a small tip is appreciated.
|
|
199
|
+
|
|
200
|
+

|
|
201
|
+
|
|
202
|
+
`“加个鸡腿💪(゚ω゚💪)”`
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# @coding01/docsjs
|
|
2
|
+
|
|
3
|
+
面向 Web 的 Render-first Word 高保真导入组件。
|
|
4
|
+
目标是在粘贴或上传 `.docx` 时,尽可能无损保留 Word/WPS/Google Docs 的结构和版式。
|
|
5
|
+
|
|
6
|
+
[English README](./README.md)
|
|
7
|
+
|
|
8
|
+
## 核心能力
|
|
9
|
+
|
|
10
|
+
- Web Component 内核:`docs-word-editor`
|
|
11
|
+
- React 适配:`WordFidelityEditorReact`
|
|
12
|
+
- Vue 适配:`WordFidelityEditorVue`
|
|
13
|
+
- 导入链路:剪贴板粘贴 + `.docx` 上传
|
|
14
|
+
- 输出:完整 HTML Snapshot,便于后续渲染与存储
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm i @coding01/docsjs
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 快速开始
|
|
23
|
+
|
|
24
|
+
### React
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { WordFidelityEditorReact } from "@coding01/docsjs/react";
|
|
28
|
+
|
|
29
|
+
export default function Page() {
|
|
30
|
+
return (
|
|
31
|
+
<WordFidelityEditorReact
|
|
32
|
+
onChange={(payload) => console.log(payload.htmlSnapshot)}
|
|
33
|
+
onError={(payload) => console.error(payload.message)}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Vue
|
|
40
|
+
|
|
41
|
+
```vue
|
|
42
|
+
<template>
|
|
43
|
+
<WordFidelityEditorVue @change="onChange" @error="onError" />
|
|
44
|
+
</template>
|
|
45
|
+
|
|
46
|
+
<script setup lang="ts">
|
|
47
|
+
import { WordFidelityEditorVue } from "@coding01/docsjs/vue";
|
|
48
|
+
const onChange = (payload: { htmlSnapshot: string }) => console.log(payload.htmlSnapshot);
|
|
49
|
+
const onError = (payload: { message: string }) => console.error(payload.message);
|
|
50
|
+
</script>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Web Component
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { defineDocsWordElement } from "@coding01/docsjs";
|
|
57
|
+
|
|
58
|
+
defineDocsWordElement();
|
|
59
|
+
const el = document.createElement("docs-word-editor");
|
|
60
|
+
document.body.appendChild(el);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## API
|
|
64
|
+
|
|
65
|
+
### 事件
|
|
66
|
+
|
|
67
|
+
- `docsjs-change`
|
|
68
|
+
- payload: `{ htmlSnapshot: string; source: "paste" | "upload" | "api" | "clear"; fileName?: string }`
|
|
69
|
+
- `docsjs-error`
|
|
70
|
+
- payload: `{ message: string }`
|
|
71
|
+
- `docsjs-ready`
|
|
72
|
+
- payload: `{ version: string }`
|
|
73
|
+
|
|
74
|
+
### 方法
|
|
75
|
+
|
|
76
|
+
- `loadHtml(rawHtml: string): void`
|
|
77
|
+
- `loadDocx(file: File): Promise<void>`
|
|
78
|
+
- `loadClipboard(): Promise<void>`
|
|
79
|
+
- `getSnapshot(): string`
|
|
80
|
+
- `clear(): void`
|
|
81
|
+
|
|
82
|
+
### 属性
|
|
83
|
+
|
|
84
|
+
- `lang="zh|en"`
|
|
85
|
+
- `show-toolbar="true|false|1|0"`
|
|
86
|
+
|
|
87
|
+
## 功能清单
|
|
88
|
+
|
|
89
|
+
- ✅ Web Component 内核(`docs-word-editor`)
|
|
90
|
+
- ✅ React 适配(`@coding01/docsjs/react`)
|
|
91
|
+
- ✅ Vue 适配(`@coding01/docsjs/vue`)
|
|
92
|
+
- ✅ 粘贴导入(`text/html`、`text/plain`)
|
|
93
|
+
- ✅ 剪贴板不稳定图片源替换(`file:/blob:/cid:/mhtml:` -> data URL)
|
|
94
|
+
- ✅ `.docx` 上传解析
|
|
95
|
+
- ✅ 段落基础语义(对齐、标题映射、换行)
|
|
96
|
+
- ✅ Run 基础样式(粗斜体、下划线、删除线、颜色、高亮、上下标)
|
|
97
|
+
- ✅ 列表基础恢复(`numId` + `ilvl` + `lvlText`)
|
|
98
|
+
- ✅ 表格基础结构(`table/tr/td`)
|
|
99
|
+
- ✅ 图片关系映射(`rId -> media`)
|
|
100
|
+
- ✅ 页面几何映射(页高、页边距、版心宽)
|
|
101
|
+
- ✅ 运行时渲染修正(`mso-*` 兼容、分页 spacer、空段落修正)
|
|
102
|
+
- ✅ 事件与公共 API
|
|
103
|
+
- ✅ React/Vue 可运行示例
|
|
104
|
+
- ✅ npm OIDC 自动发布流水线
|
|
105
|
+
- ⏳ 浮动锚点对象(`wp:anchor`)完整还原
|
|
106
|
+
- ⏳ 合并单元格/嵌套表格完整还原
|
|
107
|
+
- ⏳ 批注/脚注/修订等高级语义
|
|
108
|
+
- ⏳ OMML/图表/SmartArt
|
|
109
|
+
- ⏳ 自动化保真评分体系
|
|
110
|
+
|
|
111
|
+
## v0.1.3 更新内容
|
|
112
|
+
|
|
113
|
+
- 深度 DOCX 语义增强:
|
|
114
|
+
- 编号覆盖(`lvlOverride/startOverride`)
|
|
115
|
+
- 合并单元格(`vMerge/gridSpan`)和嵌套表格
|
|
116
|
+
- 脚注与尾注(只读渲染)
|
|
117
|
+
- 批注(只读渲染)
|
|
118
|
+
- 修订新增/删除标记(只读渲染)
|
|
119
|
+
- 分页语义标记(`w:br type=page`、`lastRenderedPageBreak`)
|
|
120
|
+
- 浮动图片 MVP:
|
|
121
|
+
- 锚点定位(`wp:anchor`)
|
|
122
|
+
- 绕排模式标记(`square`、`tight`、`topAndBottom`、`none`)
|
|
123
|
+
- 保真工具链增强:
|
|
124
|
+
- 语义统计器
|
|
125
|
+
- 保真评分器
|
|
126
|
+
- 配置驱动的基准回归测试框架
|
|
127
|
+
- 视觉回归工作流骨架(Playwright + diff artifacts)
|
|
128
|
+
- 工程质量门增强:
|
|
129
|
+
- ESLint + 严格 `verify`(`lint/typecheck/test/build/sizecheck`)
|
|
130
|
+
- CI 必过质量门
|
|
131
|
+
- 贡献规范 / 规则 / 深度开发计划文档
|
|
132
|
+
- Demo 升级:
|
|
133
|
+
- React/Vue demo 支持中英文切换
|
|
134
|
+
- 组件内置工具栏文案随语言切换
|
|
135
|
+
- 语义统计面板新增浮动图/绕排图/批注/修订/分页断点等指标
|
|
136
|
+
|
|
137
|
+
## 本地开发
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npm install
|
|
141
|
+
npm run typecheck
|
|
142
|
+
npm run test
|
|
143
|
+
npm run build
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## 演示
|
|
147
|
+
|
|
148
|
+
### React demo
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
cd demos/react-demo
|
|
152
|
+
npm install
|
|
153
|
+
npm run dev
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Vue demo
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
cd demos/vue-demo
|
|
160
|
+
npm install
|
|
161
|
+
npm run dev
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 路线图
|
|
165
|
+
|
|
166
|
+
执行优先级与验收标准见 [ROADMAP.md](./ROADMAP.md)。
|
|
167
|
+
|
|
168
|
+
## 安全说明
|
|
169
|
+
|
|
170
|
+
- 默认策略是保真优先,不主动清洗 Word 内联样式。
|
|
171
|
+
- 生产环境建议宿主侧配置 CSP、iframe sandbox、上传白名单及可选清洗策略。
|
|
172
|
+
|
|
173
|
+
## 打赏支持
|
|
174
|
+
|
|
175
|
+
如果这个项目帮你节省了时间,欢迎打赏支持。
|
|
176
|
+
|
|
177
|
+

|
|
178
|
+
|
|
179
|
+
`“加个鸡腿💪(゚ω゚💪)”`
|