@hufe921/canvas-editor 0.9.133 → 0.9.135
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 +45 -0
- package/README.md +166 -53
- package/dist/assets/{catalog-Cno2frQt.js.map → catalog-B-cbxN0s.js.map} +1 -1
- package/dist/assets/{group-Bz5rW3In.js.map → group-BZtj1M7o.js.map} +1 -1
- package/dist/assets/value-By4_Dx3W.js.map +1 -0
- package/dist/assets/{wordCount-C2BnvS6l.js.map → wordCount-Osi0e4qK.js.map} +1 -1
- package/dist/canvas-editor.js +1446 -1204
- package/dist/canvas-editor.js.map +1 -1
- package/dist/canvas-editor.umd.cjs +31 -31
- package/dist/canvas-editor.umd.cjs.map +1 -1
- package/dist/src/editor/core/accessibility/Accessibility.d.ts +14 -0
- package/dist/src/editor/core/draw/Draw.d.ts +3 -0
- package/dist/src/editor/core/draw/interactive/Search.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/date/DatePicker.d.ts +25 -0
- package/dist/src/editor/core/position/Position.d.ts +5 -0
- package/dist/src/editor/dataset/constant/Accessibility.d.ts +2 -0
- package/dist/src/editor/dataset/enum/DatePicker.d.ts +5 -0
- package/dist/src/editor/interface/Accessibility.d.ts +3 -0
- package/dist/src/editor/interface/Editor.d.ts +3 -0
- package/dist/src/editor/interface/EventBus.d.ts +2 -1
- package/dist/src/editor/interface/Listener.d.ts +2 -0
- package/dist/src/editor/interface/Position.d.ts +1 -0
- package/dist/src/editor/interface/i18n/Accessibility.d.ts +4 -0
- package/dist/src/editor/interface/i18n/I18n.d.ts +2 -0
- package/package.json +13 -13
- package/dist/assets/value-CEZhhW6y.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,48 @@
|
|
|
1
|
+
## [0.9.135](https://github.com/Hufe921/canvas-editor/compare/v0.9.134...v0.9.135) (2026-06-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* avoid removing last checkbox code when unchecked code is missing ([ffaccae](https://github.com/Hufe921/canvas-editor/commit/ffaccae9cfd804bae3045ebc90b294ffc2518f91))
|
|
7
|
+
* correct delete key behavior when text is selected before control #1421 ([56a713a](https://github.com/Hufe921/canvas-editor/commit/56a713a1f4eb80610c778b9b6c91faaea4c55687)), closes [#1421](https://github.com/Hufe921/canvas-editor/issues/1421)
|
|
8
|
+
* correct regex search navigation match length ([f540dda](https://github.com/Hufe921/canvas-editor/commit/f540dda8bdb3f40791c654e7eb1522a8384b9204))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Chores
|
|
12
|
+
|
|
13
|
+
* add pnpm-workspace.yaml ([078dfb1](https://github.com/Hufe921/canvas-editor/commit/078dfb125197925847b48b4f2489212a26627b30))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* add accessibility support for screen readers #1420 ([ae28324](https://github.com/Hufe921/canvas-editor/commit/ae283249f63962736e758640eb77c5f4a955a0f8)), closes [#1420](https://github.com/Hufe921/canvas-editor/issues/1420)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [0.9.134](https://github.com/Hufe921/canvas-editor/compare/v0.9.133...v0.9.134) (2026-05-22)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Chores
|
|
26
|
+
|
|
27
|
+
* add dependabot config ([4478c59](https://github.com/Hufe921/canvas-editor/commit/4478c59a77bdedf58c655319254be3485a5438b4))
|
|
28
|
+
* lock pnpm version ([c474691](https://github.com/Hufe921/canvas-editor/commit/c47469115dd1ffb5a5251d04e0665547b4022dfc))
|
|
29
|
+
* update workflow config ([0e9aa29](https://github.com/Hufe921/canvas-editor/commit/0e9aa29a16cedbe51bd22130656840797eb02cb9))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Documentation
|
|
33
|
+
|
|
34
|
+
* add CONTRIBUTING.md ([c7b138d](https://github.com/Hufe921/canvas-editor/commit/c7b138d436da7105fb21027fa8cfdba78214f69b))
|
|
35
|
+
* update documentation descriptions ([1322c86](https://github.com/Hufe921/canvas-editor/commit/1322c86a98356110ad3255b8aaf8d209311ce6d4))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Features
|
|
39
|
+
|
|
40
|
+
* 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)
|
|
41
|
+
* 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)
|
|
42
|
+
* 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)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
1
46
|
## [0.9.133](https://github.com/Hufe921/canvas-editor/compare/v0.9.132...v0.9.133) (2026-05-05)
|
|
2
47
|
|
|
3
48
|
|
package/README.md
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
<h1 align="center">
|
|
1
|
+
<h1 align="center">Canvas Editor</h1>
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
|
-
<
|
|
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">
|
|
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"
|
|
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
|
-
|
|
39
|
+
---
|
|
36
40
|
|
|
37
|
-
##
|
|
41
|
+
## Overview
|
|
38
42
|
|
|
39
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
92
|
+
const container = document.querySelector('.canvas-editor')
|
|
93
|
+
|
|
94
|
+
const editor = new Editor(container, {
|
|
59
95
|
main: [
|
|
60
96
|
{
|
|
61
|
-
value: 'Hello
|
|
97
|
+
value: 'Hello, Canvas Editor!'
|
|
62
98
|
}
|
|
63
99
|
]
|
|
64
100
|
})
|
|
65
101
|
```
|
|
66
102
|
|
|
67
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
162
|
+
```bash
|
|
163
|
+
npm run docs:dev # Start VitePress docs locally
|
|
164
|
+
npm run docs:build # Build the documentation site
|
|
165
|
+
```
|
|
84
166
|
|
|
85
|
-
|
|
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
|
-
|
|
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
|
-
|
|
188
|
+
## Contributing
|
|
93
189
|
|
|
94
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
208
|
+
## Community & Support
|
|
99
209
|
|
|
100
|
-
|
|
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
|
-
##
|
|
215
|
+
## Sponsors
|
|
103
216
|
|
|
104
|
-
|
|
217
|
+
If you find this project useful, please consider [sponsoring](https://hufe.club/donate.jpg) to support its continued development.
|
|
105
218
|
|
|
106
|
-
|
|
219
|
+
## License
|
|
107
220
|
|
|
108
|
-
|
|
221
|
+
This project is licensed under the [MIT License](./LICENSE).
|
|
109
222
|
|
|
110
|
-
|
|
223
|
+
Copyright © 2022–present, [Hufe921](https://github.com/Hufe921).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog-
|
|
1
|
+
{"version":3,"file":"catalog-B-cbxN0s.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":"YA2CA,IAAM,EAAsD,OACtC,SACC,QACD,SACC,QACD,QACA,CACtB,EAEM,EAAuC,sEAQ7C,EAIA,SAAS,EAAkB,EAA4B,CACrD,MAAO,CAAC,EAAQ,MAAQ,EAAsB,SAAS,EAAQ,IAAI,CACrE,CAEA,SAAS,EAAW,EAA8C,CAChE,GAAM,CAAE,cAAa,gBAAiB,EAEhC,EAAsC,CAAC,EACzC,EAAI,EACR,KAAO,EAAI,EAAY,QAAQ,CAC7B,IAAM,EAAU,EAAY,GACtB,GACJ,EACA,EACA,IACG,CACH,IAAM,EAAU,EAAQ,QAElB,EAAgC,CACpC,KAAA,QACA,MAAO,GACP,MAJY,EAAQ,MAKpB,UACA,OAAQ,EAAa,GAAG,MAC1B,EACM,EAAwB,CAAC,EAC/B,KAAO,EAAW,EAAY,QAAQ,CACpC,IAAM,EAAS,EAAY,GAC3B,GAAI,IAAY,EAAO,QAAS,CAC9B,IACA,KACF,CACA,EAAU,KAAK,CAAM,EACrB,GACF,CAMA,MALA,GAAa,MAAQ,EAClB,OAAO,GAAM,EAAkB,CAAE,CAAC,EAClC,IAAI,GAAM,EAAG,KAAK,EAClB,KAAK,EAAE,EACP,QAAY,OAAO,IAAM,GAAG,EAAG,EAAE,EAC7B,CAAE,WAAU,cAAa,CAClC,EACA,GAAI,EAAQ,QAAS,CACnB,GAAM,CAAE,WAAU,gBAAiB,EAAe,EAAS,EAAa,CAAC,EACzE,EAAI,EACJ,EAAiB,KAAK,CAAY,CACpC,CACA,GAAI,EAAQ,OAAA,QAA4B,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,CAEzC,IAAM,EADK,EAAG,OAAO,GACJ,MACjB,GAAI,EAAM,OAAS,EAAG,CACpB,IAAI,EAAQ,EACZ,KAAO,EAAQ,EAAM,QAAQ,CAC3B,GAAI,EAAM,IAAQ,QAAS,CACzB,GAAM,CAAE,eAAc,YAAa,EACjC,EAAM,GACN,EACA,CACF,EACA,EAAiB,KAAK,CAAY,EAClC,EAAQ,CACV,CACA,GACF,CACF,CACF,CACF,CACF,CACA,GACF,CACA,GAAI,CAAC,EAAiB,OAAQ,OAAO,KAErC,IAAM,GACJ,EACA,IACG,CACH,IAAM,EACJ,EAAY,WAAW,EAAY,WAAW,OAAS,GACnD,EAAmB,EAAwB,GAAgB,OAC3D,EAAa,EAAwB,EAAM,OAC7C,GAAkB,EAAa,EACjC,EAAgB,EAAO,CAAc,EAErC,EAAY,WAAW,KAAK,CAC1B,GAAI,EAAM,QACV,KAAM,EAAM,MACZ,MAAO,EAAM,MACb,OAAQ,EAAM,OACd,WAAY,CAAC,CACf,CAAC,CAEL,EAIM,EAAoB,CAAC,EAC3B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAiB,OAAQ,IAAK,CAChD,IAAM,EAAQ,EAAiB,GACzB,EAAc,EAAQ,EAAQ,OAAS,GACvC,EAAmB,EAAwB,GAAa,OACxD,EAAa,EAAwB,EAAM,OAC7C,GAAe,EAAa,EAC9B,EAAgB,EAAO,CAAW,EAElC,EAAQ,KAAK,CACX,GAAI,EAAM,QACV,KAAM,EAAM,MACZ,MAAO,EAAM,MACb,OAAQ,EAAM,OACd,WAAY,CAAC,CACf,CAAC,CAEL,CACA,OAAO,CACT,CAEA,UAAY,GAAO,CACjB,IAAM,EAA8B,EAAI,KAClC,EAAU,EAAW,CAAO,EAClC,YAAY,CAAO,CACrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-
|
|
1
|
+
{"version":3,"file":"group-BZtj1M7o.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":"YAMA,SAAS,EAAY,EAAmC,CACtD,IAAM,EAAqB,CAAC,EAC5B,IAAK,IAAM,KAAW,EAAa,CACjC,GAAI,EAAQ,OAAA,QAA4B,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,KAAK,CAAC,CACxC,CACF,CACF,CACK,KAAQ,SACb,IAAK,IAAM,KAAW,EAAQ,SACvB,EAAS,SAAS,CAAO,GAC5B,EAAS,KAAK,CAAO,CAG3B,CACA,OAAO,CACT,CAEA,UAAY,GAAO,CACjB,IAAM,EAA0B,EAAI,KAC9B,EAAW,EAAY,CAAW,EACxC,YAAY,CAAQ,CACtB"}
|