@coding01/docsjs 0.1.2 → 0.1.5

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 CHANGED
@@ -1,11 +1,21 @@
1
1
  # @coding01/docsjs
2
2
 
3
- `@coding01/docsjs` 是一个 Render-first Word 高保真组件,目标是把 Word/WPS/Google Docs 内容以“先渲染、后编辑”的方式无损导入到 Web 端。
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
- - Web Component 内核:`docs-word-editor`
7
- - React 适配组件:`WordFidelityEditorReact`
8
- - Vue 适配组件:`WordFidelityEditorVue`
6
+ [![npm version](https://img.shields.io/npm/v/@coding01/docsjs)](https://www.npmjs.com/package/@coding01/docsjs)
7
+ [![npm downloads](https://img.shields.io/npm/dm/@coding01/docsjs)](https://www.npmjs.com/package/@coding01/docsjs)
8
+ [![CI](https://github.com/fanly/docsjs/actions/workflows/ci.yml/badge.svg)](https://github.com/fanly/docsjs/actions/workflows/ci.yml)
9
+
10
+ [中文文档](./README.zh-CN.md)
11
+
12
+ ## What You Get
13
+
14
+ - Web Component core: `docs-word-editor`
15
+ - React adapter: `WordFidelityEditorReact`
16
+ - Vue adapter: `WordFidelityEditorVue`
17
+ - Import pipeline: clipboard paste + `.docx` upload
18
+ - HTML snapshot output for downstream rendering/storage
9
19
 
10
20
  ## Installation
11
21
 
@@ -18,17 +28,13 @@ npm i @coding01/docsjs
18
28
  ### React
19
29
 
20
30
  ```tsx
21
- import { WordFidelityEditorReact } from "@coding01/docsjs";
31
+ import { WordFidelityEditorReact } from "@coding01/docsjs/react";
22
32
 
23
33
  export default function Page() {
24
34
  return (
25
35
  <WordFidelityEditorReact
26
- onChange={(payload) => {
27
- console.log(payload.htmlSnapshot);
28
- }}
29
- onError={(payload) => {
30
- console.error(payload.message);
31
- }}
36
+ onChange={(payload) => console.log(payload.htmlSnapshot)}
37
+ onError={(payload) => console.error(payload.message)}
32
38
  />
33
39
  );
34
40
  }
@@ -42,19 +48,13 @@ export default function Page() {
42
48
  </template>
43
49
 
44
50
  <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
- };
51
+ import { WordFidelityEditorVue } from "@coding01/docsjs/vue";
52
+ const onChange = (payload: { htmlSnapshot: string }) => console.log(payload.htmlSnapshot);
53
+ const onError = (payload: { message: string }) => console.error(payload.message);
54
54
  </script>
55
55
  ```
56
56
 
57
- ### Web Component (Vanilla)
57
+ ### Web Component
58
58
 
59
59
  ```ts
60
60
  import { defineDocsWordElement } from "@coding01/docsjs";
@@ -71,102 +71,159 @@ el.addEventListener("docsjs-change", (e) => {
71
71
 
72
72
  ## API
73
73
 
74
- ### Component Events
74
+ ### Events
75
75
 
76
76
  - `docsjs-change`
77
- - payload: `{ htmlSnapshot: string }`
78
- - 触发时机:粘贴、上传 Word、手动 `setSnapshot`、`clear`
77
+ - payload: `{ htmlSnapshot: string; source: "paste" | "upload" | "api" | "clear"; fileName?: string }`
79
78
  - `docsjs-error`
80
79
  - payload: `{ message: string }`
81
- - 触发时机:剪贴板读取失败、DOCX 解析失败等
80
+ - `docsjs-ready`
81
+ - payload: `{ version: string }`
82
82
 
83
- ### Web Component Methods
83
+ ### Methods
84
84
 
85
- - `setSnapshot(rawHtml: string): void`
86
- - 将外部 HTML 快照注入渲染层
85
+ - `loadHtml(rawHtml: string): void`
86
+ - `loadDocx(file: File): Promise<void>`
87
+ - `loadClipboard(): Promise<void>`
88
+ - `getSnapshot(): string`
87
89
  - `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
90
+
91
+ ### Attributes
92
+
93
+ - `lang="zh|en"`
94
+ - `show-toolbar="true|false|1|0"`
95
+
96
+ ## Feature Checklist
97
+
98
+ - ✅ Web Component core (`docs-word-editor`)
99
+ - React adapter (`@coding01/docsjs/react`)
100
+ - ✅ Vue adapter (`@coding01/docsjs/vue`)
101
+ - ✅ Paste import (`text/html`, `text/plain`)
102
+ - Clipboard image hydration (`file:/blob:/cid:/mhtml:` to data URL)
103
+ - ✅ `.docx` upload and parse
104
+ - Basic paragraph semantics (alignment, headings, line break)
105
+ - ✅ Basic run styles (bold/italic/underline/strike/color/highlight/super/sub)
106
+ - List reconstruction (`numId` + `ilvl` + `lvlText`)
107
+ - Basic table structure (`table/tr/td`)
108
+ - ✅ Table merge + nested table read-only fidelity (`vMerge/gridSpan`)
109
+ - ✅ Table width mapping (`tblGrid/gridCol`, `tcW`)
110
+ - ✅ Embedded image relationship mapping (`rId -> media`)
111
+ - Page geometry mapping (page height, margins, content width)
112
+ - Runtime render fixes (`mso-*` compatibility, pagination spacer, empty paragraph normalization)
113
+ - Events and public methods
114
+ - ✅ React and Vue runnable demos
115
+ - npm publish workflow with OIDC trusted publishing
116
+ - Footnotes / endnotes / comments / track changes read-only semantics
117
+ - ✅ Comment range markers (`commentRangeStart/commentRangeEnd`)
118
+ - Revision metadata markers (`id/author/date`)
119
+ - ✅ Floating anchors (`wp:anchor`) v1 fidelity (position ref / overlap / layer / wrap distance markers)
120
+ - ✅ Word table v1 fidelity (border model / cell spacing / table-layout mapping)
121
+ - OMML / charts / SmartArt semantic fallback rendering (v1)
122
+ - ✅ Automated fidelity benchmark v1 (golden corpus + CI trend artifacts)
123
+ - Floating anchor text-wrap collision fidelity (pixel-level)
124
+ - Word table auto layout parity with desktop Word
125
+ - OMML high-fidelity renderer (MathML/KaTeX pipeline)
126
+
127
+ ## What's New in v0.1.3
128
+
129
+ - Added deep DOCX semantics:
130
+ - numbering overrides (`lvlOverride/startOverride`)
131
+ - merged cells (`vMerge/gridSpan`) and nested tables
132
+ - footnotes and endnotes (read-only rendering)
133
+ - comments (read-only rendering)
134
+ - revisions insert/delete markers (read-only rendering)
135
+ - comment range markers and revision metadata attributes
136
+ - page break semantic markers (`w:br type=page`, `lastRenderedPageBreak`)
137
+ - table width mapping (`tblGrid/gridCol`, `tcW`)
138
+ - table border model / cell spacing / table-layout mapping
139
+ - OMML formula fallback rendering and chart/SmartArt semantic fallback
140
+ - Added floating image MVP:
141
+ - anchor position mapping (`wp:anchor`)
142
+ - wrap mode markers (`square`, `tight`, `topAndBottom`, `none`)
143
+ - anchor layout metadata (`relativeFrom`, `behindDoc`, `allowOverlap`, `layoutInCell`, `relativeHeight`, `dist*`)
144
+ - Added fidelity tooling:
145
+ - semantic stats collector
146
+ - fidelity score calculator
147
+ - baseline regression framework (config-driven)
148
+ - visual regression workflow scaffold (Playwright + diff artifacts)
149
+ - golden corpus benchmark + trend report workflow (`fidelity-benchmark.yml`)
150
+ - Added engineering quality gates:
151
+ - ESLint + strict verify pipeline (`lint`, `typecheck`, `test`, `build`, `sizecheck`)
152
+ - CI workflow for mandatory quality checks
153
+ - contribution/rules/deep-plan docs
154
+ - Demo upgrades:
155
+ - React and Vue demos now include bilingual toggle (`zh` / `en`)
156
+ - component inner toolbar language follows selected locale
157
+ - semantic dashboard expanded with new indicators (anchor/wrap/comments/revisions/page-break)
158
+
159
+ ## Development
134
160
 
135
161
  ```bash
136
162
  npm install
137
163
  npm run typecheck
164
+ npm run test
138
165
  npm run build
166
+ npm run benchmark:fidelity
139
167
  ```
140
168
 
141
- ## Publish to npm
169
+ ## Demos
142
170
 
143
- ### Manual publish
171
+ ### React demo
144
172
 
145
173
  ```bash
146
- npm login
147
- npm version patch
148
- git push origin main --tags
149
- npm publish --access public
174
+ cd demos/react-demo
175
+ npm install
176
+ npm run dev
150
177
  ```
151
178
 
152
- ### GitHub Actions auto publish
179
+ ### Vue demo
153
180
 
154
- This repo includes `.github/workflows/publish.yml`:
155
- - Trigger: push tag `v*.*.*`
156
- - Steps: `npm ci` -> `typecheck` -> `build` -> `npm publish`
181
+ ```bash
182
+ cd demos/vue-demo
183
+ npm install
184
+ npm run dev
185
+ ```
157
186
 
158
- Trusted Publishing (recommended):
159
- - No long-lived `NPM_TOKEN` secret required
160
- - Uses GitHub OIDC (`id-token: write`) to publish
187
+ ## Publishing
161
188
 
162
- Release flow:
189
+ ### Manual
163
190
 
164
191
  ```bash
192
+ npm login
165
193
  npm version patch
166
194
  git push origin main --follow-tags
195
+ npm publish --access public
167
196
  ```
168
197
 
198
+ ### GitHub Actions
199
+
200
+ Workflow: `.github/workflows/publish.yml`
201
+
202
+ - Trigger: push tag `v*.*.*`
203
+ - Steps: `npm ci` -> `npm run typecheck` -> `npm run build` -> `npm publish --provenance`
204
+
205
+ ### GitHub Packages (repo sidebar "Packages")
206
+
207
+ Workflow: `.github/workflows/publish-github-packages.yml`
208
+
209
+ - Trigger: push tag `v*.*.*` or manual run
210
+ - Target registry: `https://npm.pkg.github.com`
211
+ - Package name in GitHub Packages: `@fanly/docsjs`
212
+ - Note: GitHub sidebar "Packages" only shows packages published to GitHub Packages, not npmjs
213
+
214
+ ## Roadmap
215
+
216
+ See [ROADMAP.md](./ROADMAP.md) for prioritized execution plan (P0/P1/P2) and acceptance criteria.
217
+
169
218
  ## Security Notes
170
219
 
171
- - 本组件默认不清洗 Word 内联样式(保真优先)。
172
- - 生产环境请在宿主应用侧配置 CSPiframe sandbox 和上传白名单策略。
220
+ - Default mode is fidelity-first and keeps Word inline styles.
221
+ - In production, configure CSP, iframe sandbox, file upload allowlist, and optional host-side sanitization.
222
+
223
+ ## Support This Project
224
+
225
+ If this project saves your time, a small tip is appreciated.
226
+
227
+ ![Support docsjs](https://image.coding01.cn/Coding01%20%E8%B5%9E%E8%B5%8F%E7%A0%81.png)
228
+
229
+ `“加个鸡腿💪(゚ω゚💪)”`
@@ -0,0 +1,204 @@
1
+ # @coding01/docsjs
2
+
3
+ 面向 Web 的 Render-first Word 高保真导入组件。
4
+ 目标是在粘贴或上传 `.docx` 时,尽可能无损保留 Word/WPS/Google Docs 的结构和版式。
5
+
6
+ [![npm version](https://img.shields.io/npm/v/@coding01/docsjs)](https://www.npmjs.com/package/@coding01/docsjs)
7
+ [![npm downloads](https://img.shields.io/npm/dm/@coding01/docsjs)](https://www.npmjs.com/package/@coding01/docsjs)
8
+ [![CI](https://github.com/fanly/docsjs/actions/workflows/ci.yml/badge.svg)](https://github.com/fanly/docsjs/actions/workflows/ci.yml)
9
+
10
+ [English README](./README.md)
11
+
12
+ ## 核心能力
13
+
14
+ - Web Component 内核:`docs-word-editor`
15
+ - React 适配:`WordFidelityEditorReact`
16
+ - Vue 适配:`WordFidelityEditorVue`
17
+ - 导入链路:剪贴板粘贴 + `.docx` 上传
18
+ - 输出:完整 HTML Snapshot,便于后续渲染与存储
19
+
20
+ ## 安装
21
+
22
+ ```bash
23
+ npm i @coding01/docsjs
24
+ ```
25
+
26
+ ## 快速开始
27
+
28
+ ### React
29
+
30
+ ```tsx
31
+ import { WordFidelityEditorReact } from "@coding01/docsjs/react";
32
+
33
+ export default function Page() {
34
+ return (
35
+ <WordFidelityEditorReact
36
+ onChange={(payload) => console.log(payload.htmlSnapshot)}
37
+ onError={(payload) => console.error(payload.message)}
38
+ />
39
+ );
40
+ }
41
+ ```
42
+
43
+ ### Vue
44
+
45
+ ```vue
46
+ <template>
47
+ <WordFidelityEditorVue @change="onChange" @error="onError" />
48
+ </template>
49
+
50
+ <script setup lang="ts">
51
+ import { WordFidelityEditorVue } from "@coding01/docsjs/vue";
52
+ const onChange = (payload: { htmlSnapshot: string }) => console.log(payload.htmlSnapshot);
53
+ const onError = (payload: { message: string }) => console.error(payload.message);
54
+ </script>
55
+ ```
56
+
57
+ ### Web Component
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
+
67
+ ## API
68
+
69
+ ### 事件
70
+
71
+ - `docsjs-change`
72
+ - payload: `{ htmlSnapshot: string; source: "paste" | "upload" | "api" | "clear"; fileName?: string }`
73
+ - `docsjs-error`
74
+ - payload: `{ message: string }`
75
+ - `docsjs-ready`
76
+ - payload: `{ version: string }`
77
+
78
+ ### 方法
79
+
80
+ - `loadHtml(rawHtml: string): void`
81
+ - `loadDocx(file: File): Promise<void>`
82
+ - `loadClipboard(): Promise<void>`
83
+ - `getSnapshot(): string`
84
+ - `clear(): void`
85
+
86
+ ### 属性
87
+
88
+ - `lang="zh|en"`
89
+ - `show-toolbar="true|false|1|0"`
90
+
91
+ ## 功能清单
92
+
93
+ - ✅ Web Component 内核(`docs-word-editor`)
94
+ - ✅ React 适配(`@coding01/docsjs/react`)
95
+ - ✅ Vue 适配(`@coding01/docsjs/vue`)
96
+ - ✅ 粘贴导入(`text/html`、`text/plain`)
97
+ - ✅ 剪贴板不稳定图片源替换(`file:/blob:/cid:/mhtml:` -> data URL)
98
+ - ✅ `.docx` 上传解析
99
+ - ✅ 段落基础语义(对齐、标题映射、换行)
100
+ - ✅ Run 基础样式(粗斜体、下划线、删除线、颜色、高亮、上下标)
101
+ - ✅ 列表基础恢复(`numId` + `ilvl` + `lvlText`)
102
+ - ✅ 表格基础结构(`table/tr/td`)
103
+ - ✅ 表格合并与嵌套表格只读保真(`vMerge/gridSpan`)
104
+ - ✅ 表格宽度映射(`tblGrid/gridCol`、`tcW`)
105
+ - ✅ 图片关系映射(`rId -> media`)
106
+ - ✅ 页面几何映射(页高、页边距、版心宽)
107
+ - ✅ 运行时渲染修正(`mso-*` 兼容、分页 spacer、空段落修正)
108
+ - ✅ 事件与公共 API
109
+ - ✅ React/Vue 可运行示例
110
+ - ✅ npm OIDC 自动发布流水线
111
+ - ✅ 批注/脚注/修订只读语义支持
112
+ - ✅ 批注区间标记(`commentRangeStart/commentRangeEnd`)
113
+ - ✅ 修订元数据标记(`id/author/date`)
114
+ - ✅ 浮动锚点对象 v1 保真(定位参照/层级/避让距离/重叠策略标记)
115
+ - ✅ Word 表格 v1 保真(边框模型/单元格间距/布局类型映射)
116
+ - ✅ OMML/图表/SmartArt 语义降级渲染(v1)
117
+ - ✅ 自动化保真评分 v1(golden corpus + CI 趋势产物)
118
+ - ⏳ 浮动对象文字绕排碰撞的像素级还原
119
+ - ⏳ Word 表格自动布局与桌面 Word 深度一致
120
+ - ⏳ OMML 高保真渲染(MathML/KaTeX 渲染链)
121
+
122
+ ## v0.1.3 更新内容
123
+
124
+ - 深度 DOCX 语义增强:
125
+ - 编号覆盖(`lvlOverride/startOverride`)
126
+ - 合并单元格(`vMerge/gridSpan`)和嵌套表格
127
+ - 脚注与尾注(只读渲染)
128
+ - 批注(只读渲染)
129
+ - 修订新增/删除标记(只读渲染)
130
+ - 批注区间标记与修订元数据属性
131
+ - 分页语义标记(`w:br type=page`、`lastRenderedPageBreak`)
132
+ - 表格宽度映射(`tblGrid/gridCol`、`tcW`)
133
+ - 表格边框模型/单元格间距/布局类型映射
134
+ - OMML 公式降级渲染、图表/SmartArt 语义降级渲染
135
+ - 浮动图片 MVP:
136
+ - 锚点定位(`wp:anchor`)
137
+ - 绕排模式标记(`square`、`tight`、`topAndBottom`、`none`)
138
+ - 锚点布局元数据(`relativeFrom`、`behindDoc`、`allowOverlap`、`layoutInCell`、`relativeHeight`、`dist*`)
139
+ - 保真工具链增强:
140
+ - 语义统计器
141
+ - 保真评分器
142
+ - 配置驱动的基准回归测试框架
143
+ - 视觉回归工作流骨架(Playwright + diff artifacts)
144
+ - golden corpus 基准评分 + 趋势报告工作流(`fidelity-benchmark.yml`)
145
+ - 工程质量门增强:
146
+ - ESLint + 严格 `verify`(`lint/typecheck/test/build/sizecheck`)
147
+ - CI 必过质量门
148
+ - 贡献规范 / 规则 / 深度开发计划文档
149
+ - Demo 升级:
150
+ - React/Vue demo 支持中英文切换
151
+ - 组件内置工具栏文案随语言切换
152
+ - 语义统计面板新增浮动图/绕排图/批注/修订/分页断点等指标
153
+
154
+ ## 本地开发
155
+
156
+ ```bash
157
+ npm install
158
+ npm run typecheck
159
+ npm run test
160
+ npm run build
161
+ npm run benchmark:fidelity
162
+ ```
163
+
164
+ ## 演示
165
+
166
+ ### React demo
167
+
168
+ ```bash
169
+ cd demos/react-demo
170
+ npm install
171
+ npm run dev
172
+ ```
173
+
174
+ ### Vue demo
175
+
176
+ ```bash
177
+ cd demos/vue-demo
178
+ npm install
179
+ npm run dev
180
+ ```
181
+
182
+ ## 路线图
183
+
184
+ 执行优先级与验收标准见 [ROADMAP.md](./ROADMAP.md)。
185
+
186
+ ## 发布与关联
187
+
188
+ - npmjs 发布工作流:`.github/workflows/publish.yml`
189
+ - GitHub Packages 发布工作流:`.github/workflows/publish-github-packages.yml`
190
+ - GitHub 侧栏 `Packages` 只显示发布到 GitHub Packages 的包,不显示 npmjs 包
191
+ - 当前 GitHub Packages 包名:`@fanly/docsjs`
192
+
193
+ ## 安全说明
194
+
195
+ - 默认策略是保真优先,不主动清洗 Word 内联样式。
196
+ - 生产环境建议宿主侧配置 CSP、iframe sandbox、上传白名单及可选清洗策略。
197
+
198
+ ## 打赏支持
199
+
200
+ 如果这个项目帮你节省了时间,欢迎打赏支持。
201
+
202
+ ![支持 docsjs](https://image.coding01.cn/Coding01%20%E8%B5%9E%E8%B5%8F%E7%A0%81.png)
203
+
204
+ `“加个鸡腿💪(゚ω゚💪)”`