@hufe921/canvas-editor 0.9.132 → 0.9.134

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/CHANGELOG.md CHANGED
@@ -1,3 +1,55 @@
1
+ ## [0.9.134](https://github.com/Hufe921/canvas-editor/compare/v0.9.133...v0.9.134) (2026-05-22)
2
+
3
+
4
+ ### Chores
5
+
6
+ * add dependabot config ([4478c59](https://github.com/Hufe921/canvas-editor/commit/4478c59a77bdedf58c655319254be3485a5438b4))
7
+ * lock pnpm version ([c474691](https://github.com/Hufe921/canvas-editor/commit/c47469115dd1ffb5a5251d04e0665547b4022dfc))
8
+ * update workflow config ([0e9aa29](https://github.com/Hufe921/canvas-editor/commit/0e9aa29a16cedbe51bd22130656840797eb02cb9))
9
+
10
+
11
+ ### Documentation
12
+
13
+ * add CONTRIBUTING.md ([c7b138d](https://github.com/Hufe921/canvas-editor/commit/c7b138d436da7105fb21027fa8cfdba78214f69b))
14
+ * update documentation descriptions ([1322c86](https://github.com/Hufe921/canvas-editor/commit/1322c86a98356110ad3255b8aaf8d209311ce6d4))
15
+
16
+
17
+ ### Features
18
+
19
+ * add filterHideElementRow option for print mode #1410 ([67ca33a](https://github.com/Hufe921/canvas-editor/commit/67ca33a1f2002c1e70eee6f04882e55b65fed8ee)), closes [#1410](https://github.com/Hufe921/canvas-editor/issues/1410)
20
+ * add year and month picker for date control #1256 ([fb45ee1](https://github.com/Hufe921/canvas-editor/commit/fb45ee18811f23b733b8fa2c6e7529d31b83691b)), closes [#1256](https://github.com/Hufe921/canvas-editor/issues/1256)
21
+ * use table-relative coordinates for float images #1372 ([1d403ea](https://github.com/Hufe921/canvas-editor/commit/1d403ea6f344217791de151c8606e93788bce533)), closes [#1372](https://github.com/Hufe921/canvas-editor/issues/1372)
22
+
23
+
24
+
25
+ ## [0.9.133](https://github.com/Hufe921/canvas-editor/compare/v0.9.132...v0.9.133) (2026-05-05)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * prevent prototype pollution in mergeObject #1405 ([e18abe4](https://github.com/Hufe921/canvas-editor/commit/e18abe497ea3ef37aff8e0611879e53fac069272)), closes [#1405](https://github.com/Hufe921/canvas-editor/issues/1405)
31
+
32
+
33
+ ### Chores
34
+
35
+ * migrate package manager from yarn to pnpm ([8a03995](https://github.com/Hufe921/canvas-editor/commit/8a039952151c7590292e9961329f94ce6851ad2b))
36
+ * update release script ([06172a3](https://github.com/Hufe921/canvas-editor/commit/06172a366f3ed875c3f30e66c54f89769683070a))
37
+ * upgrade dependency version #1407 ([1125ae4](https://github.com/Hufe921/canvas-editor/commit/1125ae448479f0feb56174d85fe4996a61d65629)), closes [#1407](https://github.com/Hufe921/canvas-editor/issues/1407)
38
+
39
+
40
+ ### Features
41
+
42
+ * allow setGroup and deleteGroup in readonly/form mode #1406 ([bd6e903](https://github.com/Hufe921/canvas-editor/commit/bd6e9039e76114c3af2c29b37481462e52244633)), closes [#1406](https://github.com/Hufe921/canvas-editor/issues/1406)
43
+ * auto-generate colgroup for table when not provided #1404 ([636a786](https://github.com/Hufe921/canvas-editor/commit/636a7868fbace75d35cff2e18c01d9caed01d30c)), closes [#1404](https://github.com/Hufe921/canvas-editor/issues/1404)
44
+
45
+
46
+ ### Tests
47
+
48
+ * add unit tests for core modules ([a12c679](https://github.com/Hufe921/canvas-editor/commit/a12c67988b2eea07f4ec926038f120bb85c4f746))
49
+ * improve test coverage with new test cases ([10357f6](https://github.com/Hufe921/canvas-editor/commit/10357f6b6f92e561b043061fc0b6d159f155c1ba))
50
+
51
+
52
+
1
53
  ## [0.9.132](https://github.com/Hufe921/canvas-editor/compare/v0.9.131...v0.9.132) (2026-04-24)
2
54
 
3
55
 
package/README.md CHANGED
@@ -1,7 +1,13 @@
1
- <h1 align="center">canvas-editor</h1>
1
+ <h1 align="center">Canvas Editor</h1>
2
2
 
3
3
  <p align="center">
4
- <a href="https://trendshift.io/repositories/8401" target="_blank"><img src="https://trendshift.io/api/badge/repositories/8401" alt="Hufe921%2Fcanvas-editor | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
4
+ <strong>A Canvas/SVG-based rich text editor.</strong>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <a href="https://trendshift.io/repositories/8401" target="_blank">
9
+ <img src="https://trendshift.io/api/badge/repositories/8401" alt="Hufe921%2Fcanvas-editor | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/>
10
+ </a>
5
11
  </p>
6
12
 
7
13
  <p align="center">
@@ -18,36 +24,64 @@
18
24
  <a href="https://deepwiki.com/Hufe921/canvas-editor" target="_blank"><img src="https://img.shields.io/badge/Ask_DeepWiki-_.svg?style=flat&color=0094de&labelColor=000000&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGNsYXNzPSJzaXplLTQgdHJhbnNmb3JtIHRyYW5zaXRpb24tdHJhbnNmb3JtIGR1cmF0aW9uLTcwMCBncm91cC1ob3Zlcjpyb3RhdGUtMTgwIFsmYW1wO19wYXRoXTpzdHJva2UtMCIgdmlld0JveD0iMTEwIDExMCA0NjAgNTAwIj48cGF0aCBkPSJNNDE5IDMzMnExNi03IDMyIDBsMjUgMTUgMyAxIDMgMSAzLTEgMy0xIDUxLTI5cTYtMyA2LTExdi01OHEwLTgtNi0xMWwtNTEtMjlxLTYtMy0xMiAwbC01MSAyOXYxbC0yIDEtMiAydjFsLTEgMnYxbC0xIDN2MjlhMzIgMzIgMCAwIDEtNDggMjhsLTI1LTE1LTMtMS0zLTEtMyAxLTMgMS01MSAyOXEtNSAzLTYgMTF2NThxMSA4IDYgMTFsNTEgMjkgMyAxIDMgMSAzLTEgMy0xIDI1LTE1YTMyIDMyIDAgMCAxIDQ4IDI4djI5bDEgM3YxbDEgMnYxbDIgMiAyIDIgNTEgMjkgNiAyIDYtMiA1MS0yOXE2LTMgNi0xMXYtNThxMC04LTYtMTFsLTUxLTI5LTMtMS0zLTEtMyAxLTMgMS0yNSAxNWEzMiAzMiAwIDAgMS00OC0yOHExLTE4IDE2LTI4IiBzdHlsZT0iZmlsbDojMjFjMTlhIi8+PHBhdGggZD0ibTE0MSAzMTggNTEgMjkgNiAyIDYtMiA1MS0yOXYtMWwyLTEgMi0ydi0xbDEtMnYtMWwxLTN2LTI5YTMyIDMyIDAgMCAxIDQ4LTI4bDI1IDE1IDMgMSAzIDEgMy0xIDMtMSA1MS0yOXE2LTMgNi0xMXYtNThxMC04LTYtMTFsLTUxLTI5cS02LTMtMTIgMGwtNTEgMjktMiAyaC0xbC0xIDJ2MWwtMSAydjFsLTEgM3YyOWEzMiAzMiAwIDAgMS00OCAyOGwtMjUtMTUtMy0xLTMtMS0zIDEtMyAxLTUxIDI5cS02IDMtNiAxMXY1OHEwIDggNiAxMSIgc3R5bGU9ImZpbGw6IzM5NjljYSIvPjxwYXRoIGQ9Im0zOTcgNDg0LTUxLTI5LTMtMS0zLTEtMyAxLTMgMS0yNSAxNWEzMiAzMiAwIDAgMS00OC0yOHYtMjlsLTEtM3YtMWwtMS0ydi0xbC0yLTItMi0xdi0xbC01MS0yOXEtNi0zLTEyIDBsLTUxIDI5cS02IDMtNiAxMXY1OHEwIDggNiAxMWw1MSAyOSAzIDEgMyAxIDMtMSAzLTEgMjUtMTVhMzIgMzIgMCAwIDEgNDggMjh2MjlsMSAzdjFsMSAydjFsMiAyIDIgMiA1MSAyOSA2IDIgNi0yIDUxLTI5cTYtMyA2LTExdi01OHEwLTgtNi0xMSIgc3R5bGU9ImZpbGw6IzAyOTRkZSIvPjwvc3ZnPg==&logoColor=ffffff" alt="DeepWiki"/></a>
19
25
  </p>
20
26
 
21
- <p align="center"> a rich text editor by canvas/svg</p>
27
+ <p align="center">
28
+ <a href="https://hufe.club/canvas-editor" target="_blank"><strong>Live Demo</strong></a> ·
29
+ <a href="https://hufe.club/canvas-editor-docs" target="_blank"><strong>Documentation</strong></a> ·
30
+ <a href="https://github.com/Hufe921/canvas-editor/issues/new?assignees=&labels=&projects=&template=bug_report.yml" target="_blank">Report Bug</a> ·
31
+ <a href="https://github.com/Hufe921/canvas-editor/issues/new?assignees=&labels=%3Asparkles%3A+feature+request&projects=&template=feature_request.yml" target="_blank">Request Feature</a> ·
32
+ <a href="https://github.com/Hufe921/canvas-editor/discussions" target="_blank">Discussions</a>
33
+ </p>
22
34
 
23
35
  <p align="center">
24
- <a href="https://hufe.club/canvas-editor" target="_blank">View Demo</a>
25
- ·
26
- <a href="https://hufe.club/canvas-editor-docs" target="_blank">View Docs</a>
27
- ·
28
- <a href="https://github.com/Hufe921/canvas-editor/issues/new?assignees=&labels=&projects=&template=bug_report.yml" target="_blank">Report Bug</a>
29
- ·
30
- <a href="https://github.com/Hufe921/canvas-editor/issues/new?assignees=&labels=%3Asparkles%3A+feature+request&projects=&template=feature_request.yml" target="_blank">Request Feature</a>
31
- ·
32
- <a href="https://github.com/Hufe921/canvas-editor/discussions" target="_blank">FAQ</a>
36
+ English · <a href="https://hufe.club/canvas-editor-docs">中文文档</a>
33
37
  </p>
34
38
 
35
- <p align="center">Love the project? Please consider <a href="https://hufe.club/donate.jpg" target="_blank">donating(赞助)</a> to help it improve!</p>
39
+ ---
36
40
 
37
- ## Tips
41
+ ## Overview
38
42
 
39
- 1. Official plugin: [canvas-editor-plugin](https://github.com/Hufe921/canvas-editor-plugin)
40
- 2. The render layer by svg is under development, see [feature/svg](https://github.com/Hufe921/canvas-editor/tree/feature/svg)
41
- 3. The export pdf feature is available now, see [feature/pdf](https://github.com/Hufe921/canvas-editor/tree/feature/pdf)
42
- 4. The AI-powered text processing demo, see [feature/ai](https://github.com/Hufe921/canvas-editor/tree/feature/ai)
43
- 5. Table pagination [#41](https://github.com/Hufe921/canvas-editor/issues/41) is under active development, see: [poc/table-paging](https://github.com/Hufe921/canvas-editor/tree/poc/table-paging) · [demo](https://hufe.club/canvas-editor-table/)
43
+ **Canvas Editor** is a feature-rich, WYSIWYG document editor built on top of the HTML `<canvas>` API. It is designed for use cases that demand pixel-perfect rendering, advanced typography, complex layouts, and Word-like document experiences in the browser — including EMR (Electronic Medical Records), legal contracts, reports, and other document-centric applications.
44
44
 
45
- ## Basic usage
45
+ Unlike traditional `contenteditable`-based editors, Canvas Editor takes full control of the rendering pipeline, providing consistent typography across browsers, precise pagination, and a uniform export experience.
46
+
47
+ ## Features
48
+
49
+ - **Rich Text** — Undo / Redo, Font, Size, Bold, Italic, Underline, Strikeout, Superscript, Alignment, Headings, Lists, and more
50
+ - **Insertable Elements** — Tables, Images, Hyperlinks, Code Blocks, Page Breaks, Math Formulas (LaTeX), Date Pickers, Block elements
51
+ - **Form Controls** — Select, Text, Date, Radio, Checkbox controls
52
+ - **Pagination** — Native pagination with headers, footers, and page numbers
53
+ - **Page Layout** — Configurable page margins, watermarks, backgrounds
54
+ - **Document Structure** — Catalog (TOC) generation, comments, group annotations
55
+ - **Print & Export** — Print-ready output via canvas-to-image / PDF rendering
56
+ - **Interaction** — Custom context menus, customizable shortcut keys, drag-and-drop for text, elements, and controls
57
+ - **Extensibility** — Plugin system for adding custom functionality
58
+ - **Performance** — Web Workers for word counting, catalog generation, and async value retrieval
59
+
60
+ ## Why Canvas Editor?
61
+
62
+ | | Canvas Editor | contenteditable Editors |
63
+ | ----------------------- | -------------------------------- | --------------------------- |
64
+ | Cross-browser rendering | Pixel-perfect, identical | Varies by browser |
65
+ | Pagination | Native, document-style | Manual / unsupported |
66
+ | Print fidelity | Matches on-screen output | Often diverges |
67
+ | Typography control | Full control | Limited by the browser |
68
+ | Document features | TOC, headers/footers, watermarks | Requires heavy custom logic |
69
+
70
+ ## Installation
46
71
 
47
72
  ```bash
48
- npm i @hufe921/canvas-editor --save
73
+ # npm
74
+ npm install @hufe921/canvas-editor
75
+
76
+ # pnpm
77
+ pnpm add @hufe921/canvas-editor
78
+
79
+ # yarn
80
+ yarn add @hufe921/canvas-editor
49
81
  ```
50
82
 
83
+ ## Quick Start
84
+
51
85
  ```html
52
86
  <div class="canvas-editor"></div>
53
87
  ```
@@ -55,56 +89,135 @@ npm i @hufe921/canvas-editor --save
55
89
  ```javascript
56
90
  import Editor from '@hufe921/canvas-editor'
57
91
 
58
- new Editor(document.querySelector('.canvas-editor'), {
92
+ const container = document.querySelector('.canvas-editor')
93
+
94
+ const editor = new Editor(container, {
59
95
  main: [
60
96
  {
61
- value: 'Hello World'
97
+ value: 'Hello, Canvas Editor!'
62
98
  }
63
99
  ]
64
100
  })
65
101
  ```
66
102
 
67
- ## Features
103
+ For complete API documentation, see the [official docs](https://hufe.club/canvas-editor-docs).
104
+
105
+ ## Ecosystem
106
+
107
+ | Project | Description |
108
+ | ---------------------------------------------------------------------------------- | --------------------------------------------------------------------- |
109
+ | [canvas-editor-plugin](https://github.com/Hufe921/canvas-editor-plugin) | Official plugin collection |
110
+ | [feature/svg](https://github.com/Hufe921/canvas-editor/tree/feature/svg) | SVG render layer (in development) |
111
+ | [feature/pdf](https://github.com/Hufe921/canvas-editor/tree/feature/pdf) | PDF export feature |
112
+ | [feature/ai](https://github.com/Hufe921/canvas-editor/tree/feature/ai) | AI-powered text processing demo |
113
+ | [poc/table-paging](https://github.com/Hufe921/canvas-editor/tree/poc/table-paging) | Table pagination POC ([demo](https://hufe.club/canvas-editor-table/)) |
114
+ | [feature/CRDT](https://github.com/Hufe921/canvas-editor/tree/feature/CRDT) | CRDT-based collaboration (experimental) |
115
+
116
+ ## Development
117
+
118
+ ### Prerequisites
119
+
120
+ - Node.js `>= 24.13.1`
121
+ - pnpm (recommended)
122
+
123
+ ### Setup
124
+
125
+ ```bash
126
+ # Install dependencies
127
+ pnpm install
128
+
129
+ # Start the development server
130
+ npm run dev
131
+ ```
132
+
133
+ ### Build
134
+
135
+ ```bash
136
+ # Build the application (demo)
137
+ npm run build
138
+
139
+ # Build the library (publishable package)
140
+ npm run lib
141
+ ```
142
+
143
+ ### Quality Checks
144
+
145
+ ```bash
146
+ # Lint
147
+ npm run lint
148
+
149
+ # Type check
150
+ npm run type:check
151
+
152
+ # Unit tests (Vitest)
153
+ npm run test:unit
68
154
 
69
- - Rich text operations (Undo, Redo, Font, Size, Bold, Italic, Underline, Strikeout, Superscript, Alignment, Title, List, ...)
70
- - Insert elements (Table, Image, Link, Code Block, Page Break, Math Formula, Date Picker, Block, ...)
71
- - Print (Based on canvas to picture, pdf drawing)
72
- - Controls (Select, Text, Date, Radio, Checkbox)
73
- - Contextmenu (Internal, Custom)
74
- - Shortcut keys (Internal, Custom)
75
- - Drag and Drop(Text, Element, Control)
76
- - Header, Footer, Page Number
77
- - Page Margin
78
- - Watermark
79
- - Pagination
80
- - Comment
81
- - Catalog
155
+ # E2E tests (Cypress)
156
+ npm run cypress:open # interactive
157
+ npm run cypress:run # headless
158
+ ```
159
+
160
+ ### Documentation
82
161
 
83
- ## Roadmap
162
+ ```bash
163
+ npm run docs:dev # Start VitePress docs locally
164
+ npm run docs:build # Build the documentation site
165
+ ```
84
166
 
85
- 1. Table paging
86
- 2. Control rules
87
- 3. Improve performance
88
- 4. [CRDT](https://github.com/Hufe921/canvas-editor/tree/feature/CRDT)
167
+ ## Project Structure
89
168
 
90
- ## Snapshot
169
+ ```
170
+ src/editor/
171
+ ├── core/
172
+ │ ├── draw/ # Rendering engine (canvas drawing)
173
+ │ │ ├── particle/ # Element renderers (text, image, table, latex, ...)
174
+ │ │ ├── control/ # Form control rendering
175
+ │ │ ├── frame/ # Frame elements (margin, background, borders)
176
+ │ │ ├── richtext/ # Decorations (underline, highlight)
177
+ │ │ └── interactive/# Interactive features (search, graffiti)
178
+ │ ├── command/ # Command pattern (executeBold, executeUndo, ...)
179
+ │ ├── event/ # Canvas and global event handling
180
+ │ ├── observer/ # Mouse, selection, image observers
181
+ │ ├── worker/ # Web Workers for async operations
182
+ │ └── plugin/ # Plugin system
183
+ ├── interface/ # TypeScript interfaces
184
+ ├── dataset/ # Enums and constants
185
+ └── utils/ # Utility helpers
186
+ ```
91
187
 
92
- ![image](https://github.com/Hufe921/canvas-editor/blob/main/src/assets/snapshots/main_v0.9.35.png)
188
+ ## Contributing
93
189
 
94
- ## Install
190
+ Contributions are what make the open-source community such an amazing place. **Any contributions you make are greatly appreciated** — bug reports, feature requests, documentation improvements, or pull requests.
95
191
 
96
- `yarn`
192
+ 1. Fork the repository
193
+ 2. Create your feature branch (`git checkout -b feat/amazing-feature`)
194
+ 3. Commit your changes following [Conventional Commits](https://www.conventionalcommits.org/) (`git commit -m 'feat: add amazing feature'`)
195
+ 4. Push to the branch (`git push origin feat/amazing-feature`)
196
+ 5. Open a Pull Request
197
+
198
+ > Pre-commit hooks automatically run `lint` and `type:check`. Commit messages must follow Conventional Commits format (`feat:`, `fix:`, `docs:`, `refactor:`, ...).
199
+
200
+ ### Contributors
201
+
202
+ Thanks to all the people who have contributed to Canvas Editor!
203
+
204
+ <a href="https://github.com/Hufe921/canvas-editor/graphs/contributors">
205
+ <img src="https://contrib.rocks/image?repo=Hufe921/canvas-editor" />
206
+ </a>
97
207
 
98
- ## Dev
208
+ ## Community & Support
99
209
 
100
- `npm run dev`
210
+ - **Documentation** — [hufe.club/canvas-editor-docs](https://hufe.club/canvas-editor-docs)
211
+ - **Discussions** — [GitHub Discussions](https://github.com/Hufe921/canvas-editor/discussions)
212
+ - **Bug Reports** — [GitHub Issues](https://github.com/Hufe921/canvas-editor/issues)
213
+ - **AI-Assisted Q&A** — [Zread](https://zread.ai/Hufe921/canvas-editor) · [DeepWiki](https://deepwiki.com/Hufe921/canvas-editor)
101
214
 
102
- ## Build
215
+ ## Sponsors
103
216
 
104
- #### app
217
+ If you find this project useful, please consider [sponsoring](https://hufe.club/donate.jpg) to support its continued development.
105
218
 
106
- `npm run build`
219
+ ## License
107
220
 
108
- #### lib
221
+ This project is licensed under the [MIT License](./LICENSE).
109
222
 
110
- `npm run lib`
223
+ Copyright © 2022–present, [Hufe921](https://github.com/Hufe921).
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalog-Cno2frQt.js","names":[],"sources":["../../src/editor/core/worker/works/catalog.ts"],"sourcesContent":["import { ICatalog, ICatalogItem } from '../../../interface/Catalog'\nimport { IElement, IElementPosition } from '../../../interface/Element'\n\ninterface IGetCatalogPayload {\n elementList: IElement[]\n positionList: IElementPosition[]\n}\n\ntype ICatalogElement = IElement & {\n pageNo: number\n}\n\nenum ElementType {\n TEXT = 'text',\n IMAGE = 'image',\n TABLE = 'table',\n HYPERLINK = 'hyperlink',\n SUPERSCRIPT = 'superscript',\n SUBSCRIPT = 'subscript',\n SEPARATOR = 'separator',\n PAGE_BREAK = 'pageBreak',\n CONTROL = 'control',\n CHECKBOX = 'checkbox',\n RADIO = 'radio',\n LATEX = 'latex',\n TAB = 'tab',\n DATE = 'date',\n BLOCK = 'block',\n TITLE = 'title',\n AREA = 'area',\n LIST = 'list',\n LABEL = 'label'\n}\n\nenum TitleLevel {\n FIRST = 'first',\n SECOND = 'second',\n THIRD = 'third',\n FOURTH = 'fourth',\n FIFTH = 'fifth',\n SIXTH = 'sixth'\n}\n\nconst titleOrderNumberMapping: Record<TitleLevel, number> = {\n [TitleLevel.FIRST]: 1,\n [TitleLevel.SECOND]: 2,\n [TitleLevel.THIRD]: 3,\n [TitleLevel.FOURTH]: 4,\n [TitleLevel.FIFTH]: 5,\n [TitleLevel.SIXTH]: 6\n}\n\nconst TEXTLIKE_ELEMENT_TYPE: ElementType[] = [\n ElementType.TEXT,\n ElementType.HYPERLINK,\n ElementType.SUBSCRIPT,\n ElementType.SUPERSCRIPT,\n ElementType.CONTROL,\n ElementType.DATE,\n ElementType.LABEL\n]\n\nconst ZERO = '\\u200B'\n\nfunction isTextLikeElement(element: IElement): boolean {\n return !element.type || TEXTLIKE_ELEMENT_TYPE.includes(element.type)\n}\n\nfunction getCatalog(payload: IGetCatalogPayload): ICatalog | null {\n const { elementList, positionList } = payload\n // 筛选标题\n const titleElementList: ICatalogElement[] = []\n let t = 0\n while (t < elementList.length) {\n const element = elementList[t]\n const getElementInfo = (\n element: IElement,\n elementList: IElement[],\n position: number\n ) => {\n const titleId = element.titleId\n const level = element.level\n const titleElement: ICatalogElement = {\n type: ElementType.TITLE,\n value: '',\n level,\n titleId,\n pageNo: positionList[t].pageNo\n }\n const valueList: IElement[] = []\n while (position < elementList.length) {\n const titleE = elementList[position]\n if (titleId !== titleE.titleId) {\n position--\n break\n }\n valueList.push(titleE)\n position++\n }\n titleElement.value = valueList\n .filter(el => isTextLikeElement(el))\n .map(el => el.value)\n .join('')\n .replace(new RegExp(ZERO, 'g'), '')\n return { position, titleElement }\n }\n if (element.titleId) {\n const { position, titleElement } = getElementInfo(element, elementList, t)\n t = position\n titleElementList.push(titleElement)\n }\n if (element.type === ElementType.TABLE) {\n const trList = element.trList!\n for (let r = 0; r < trList.length; r++) {\n const tr = trList[r]\n for (let d = 0; d < tr.tdList.length; d++) {\n const td = tr.tdList[d]\n const value = td.value\n if (value.length > 1) {\n let index = 1\n while (index < value.length) {\n if (value[index]?.titleId) {\n const { titleElement, position } = getElementInfo(\n value[index],\n value,\n index\n )\n titleElementList.push(titleElement)\n index = position\n }\n index++\n }\n }\n }\n }\n }\n t++\n }\n if (!titleElementList.length) return null\n // 查找到比最新元素大的标题时终止\n const recursiveInsert = (\n title: ICatalogElement,\n catalogItem: ICatalogItem\n ) => {\n const subCatalogItem =\n catalogItem.subCatalog[catalogItem.subCatalog.length - 1]\n const catalogItemLevel = titleOrderNumberMapping[subCatalogItem?.level]\n const titleLevel = titleOrderNumberMapping[title.level!]\n if (subCatalogItem && titleLevel > catalogItemLevel) {\n recursiveInsert(title, subCatalogItem)\n } else {\n catalogItem.subCatalog.push({\n id: title.titleId!,\n name: title.value,\n level: title.level!,\n pageNo: title.pageNo,\n subCatalog: []\n })\n }\n }\n // 循环标题组\n // 如果当前列表级别小于标题组最新标题级别:则递归查找最小级别并追加\n // 如果大于:则直接追加至当前标题组\n const catalog: ICatalog = []\n for (let e = 0; e < titleElementList.length; e++) {\n const title = titleElementList[e]\n const catalogItem = catalog[catalog.length - 1]\n const catalogItemLevel = titleOrderNumberMapping[catalogItem?.level]\n const titleLevel = titleOrderNumberMapping[title.level!]\n if (catalogItem && titleLevel > catalogItemLevel) {\n recursiveInsert(title, catalogItem)\n } else {\n catalog.push({\n id: title.titleId!,\n name: title.value,\n level: title.level!,\n pageNo: title.pageNo,\n subCatalog: []\n })\n }\n }\n return catalog\n}\n\nonmessage = evt => {\n const payload = <IGetCatalogPayload>evt.data\n const catalog = getCatalog(payload)\n postMessage(catalog)\n}\n"],"mappings":"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"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group-Bz5rW3In.js","names":[],"sources":["../../src/editor/core/worker/works/group.ts"],"sourcesContent":["import { IElement } from '../../../interface/Element'\n\nenum ElementType {\n TABLE = 'table'\n}\n\nfunction getGroupIds(elementList: IElement[]): string[] {\n const groupIds: string[] = []\n for (const element of elementList) {\n if (element.type === ElementType.TABLE) {\n const trList = element.trList!\n for (let r = 0; r < trList.length; r++) {\n const tr = trList[r]\n for (let d = 0; d < tr.tdList.length; d++) {\n const td = tr.tdList[d]\n groupIds.push(...getGroupIds(td.value))\n }\n }\n }\n if (!element.groupIds) continue\n for (const groupId of element.groupIds) {\n if (!groupIds.includes(groupId)) {\n groupIds.push(groupId)\n }\n }\n }\n return groupIds\n}\n\nonmessage = evt => {\n const elementList = <IElement[]>evt.data\n const groupIds = getGroupIds(elementList)\n postMessage(groupIds)\n}\n"],"mappings":"YAEA,IAAK,EAAL,SAAA,EAAA,OACE,GAAA,MAAQ,WADL,GAAA,EAAA,CAEJ,CAED,SAAS,EAAY,EAAmC,CACtD,IAAM,EAAqB,EAAE,CAC7B,IAAK,IAAM,KAAW,EAAa,CACjC,GAAI,EAAQ,OAAS,EAAY,MAAO,CACtC,IAAM,EAAS,EAAQ,OACvB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAO,OAAQ,IAAK,CACtC,IAAM,EAAK,EAAO,GAClB,IAAK,IAAI,EAAI,EAAG,EAAI,EAAG,OAAO,OAAQ,IAAK,CACzC,IAAM,EAAK,EAAG,OAAO,GACrB,EAAS,KAAK,GAAG,EAAY,EAAG,MAAM,CAAC,GAIxC,KAAQ,SACb,IAAK,IAAM,KAAW,EAAQ,SACvB,EAAS,SAAS,EAAQ,EAC7B,EAAS,KAAK,EAAQ,CAI5B,OAAO,EAGT,UAAY,GAAO,CACjB,IAAM,EAA0B,EAAI,KAC9B,EAAW,EAAY,EAAY,CACzC,YAAY,EAAS"}