@coding01/docsjs 0.1.0 → 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 CHANGED
@@ -1,11 +1,17 @@
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
+ [中文文档](./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
- console.log(payload.htmlSnapshot);
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 onChange = (payload: { htmlSnapshot: string }) => {
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 (Vanilla)
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
- ### Component Events
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
- - 触发时机:剪贴板读取失败、DOCX 解析失败等
76
+ - `docsjs-ready`
77
+ - payload: `{ version: string }`
82
78
 
83
- ### Web Component Methods
79
+ ### Methods
84
80
 
85
- - `setSnapshot(rawHtml: string): void`
86
- - 将外部 HTML 快照注入渲染层
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
- ## 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
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
- ## Publish to npm
151
+ ## Demos
142
152
 
143
- ### Manual publish
153
+ ### React demo
144
154
 
145
155
  ```bash
146
- npm login
147
- npm version patch
148
- git push origin main --tags
149
- npm publish --access public
156
+ cd demos/react-demo
157
+ npm install
158
+ npm run dev
150
159
  ```
151
160
 
152
- ### GitHub Actions auto publish
161
+ ### Vue demo
153
162
 
154
- This repo includes `.github/workflows/publish.yml`:
155
- - Trigger: push tag `v*.*.*`
156
- - Steps: `npm ci` -> `typecheck` -> `build` -> `npm publish`
163
+ ```bash
164
+ cd demos/vue-demo
165
+ npm install
166
+ npm run dev
167
+ ```
157
168
 
158
- Trusted Publishing (recommended):
159
- - No long-lived `NPM_TOKEN` secret required
160
- - Uses GitHub OIDC (`id-token: write`) to publish
169
+ ## Publishing
161
170
 
162
- Release flow:
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
- - 本组件默认不清洗 Word 内联样式(保真优先)。
172
- - 生产环境请在宿主应用侧配置 CSPiframe sandbox 和上传白名单策略。
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
+ ![Support docsjs](https://image.coding01.cn/Coding01%20%E8%B5%9E%E8%B5%8F%E7%A0%81.png)
201
+
202
+ `“加个鸡腿💪(゚ω゚💪)”`
@@ -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
+ ![支持 docsjs](https://image.coding01.cn/Coding01%20%E8%B5%9E%E8%B5%8F%E7%A0%81.png)
178
+
179
+ `“加个鸡腿💪(゚ω゚💪)”`