@hufe921/canvas-editor 1.0.1 → 1.0.2
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 +16 -0
- package/dist/canvas-editor.js +1873 -1670
- package/dist/canvas-editor.js.map +1 -1
- package/dist/canvas-editor.umd.cjs +35 -35
- package/dist/canvas-editor.umd.cjs.map +1 -1
- package/dist/src/editor/core/command/Command.d.ts +3 -0
- package/dist/src/editor/core/command/CommandAdapt.d.ts +5 -1
- package/dist/src/editor/core/draw/Draw.d.ts +3 -0
- package/dist/src/editor/core/draw/interactive/Spellcheck.d.ts +20 -0
- package/dist/src/editor/dataset/constant/Spellcheck.d.ts +2 -0
- package/dist/src/editor/index.d.ts +2 -2
- package/dist/src/editor/interface/Editor.d.ts +2 -0
- package/dist/src/editor/interface/EventBus.d.ts +4 -1
- package/dist/src/editor/interface/Listener.d.ts +1 -0
- package/dist/src/editor/interface/Spellcheck.d.ts +27 -0
- package/package.json +6 -6
|
@@ -64,6 +64,7 @@ export declare class Command {
|
|
|
64
64
|
executeAddWatermark: CommandAdapt['addWatermark'];
|
|
65
65
|
executeDeleteWatermark: CommandAdapt['deleteWatermark'];
|
|
66
66
|
executeSearch: CommandAdapt['search'];
|
|
67
|
+
executeSetSpellcheckRangeList: CommandAdapt['setSpellcheckRangeList'];
|
|
67
68
|
executeSearchNavigatePre: CommandAdapt['searchNavigatePre'];
|
|
68
69
|
executeSearchNavigateNext: CommandAdapt['searchNavigateNext'];
|
|
69
70
|
executeReplace: CommandAdapt['replace'];
|
|
@@ -133,6 +134,7 @@ export declare class Command {
|
|
|
133
134
|
getAreaValue: CommandAdapt['getAreaValue'];
|
|
134
135
|
getHTML: CommandAdapt['getHTML'];
|
|
135
136
|
getText: CommandAdapt['getText'];
|
|
137
|
+
getSpellcheckWordList: CommandAdapt['getSpellcheckWordList'];
|
|
136
138
|
getWordCount: CommandAdapt['getWordCount'];
|
|
137
139
|
getCursorPosition: CommandAdapt['getCursorPosition'];
|
|
138
140
|
getRemainingContentHeight: CommandAdapt['getRemainingContentHeight'];
|
|
@@ -148,6 +150,7 @@ export declare class Command {
|
|
|
148
150
|
getSearchNavigateInfo: CommandAdapt['getSearchNavigateInfo'];
|
|
149
151
|
getLocale: CommandAdapt['getLocale'];
|
|
150
152
|
getGroupIds: CommandAdapt['getGroupIds'];
|
|
153
|
+
getGroupRectList: CommandAdapt['getGroupRectList'];
|
|
151
154
|
getControlValue: CommandAdapt['getControlValue'];
|
|
152
155
|
getControlList: CommandAdapt['getControlList'];
|
|
153
156
|
getContainer: CommandAdapt['getContainer'];
|
|
@@ -16,8 +16,9 @@ import { IColumnOption } from '../../interface/Column';
|
|
|
16
16
|
import { IDeleteElementByIdOption, IElement, IElementPosition, IGetElementByIdOption, IImageCaption, IImageCrop, IInsertElementListOption, IUpdateElementByIdOption } from '../../interface/Element';
|
|
17
17
|
import { ICopyOption, IPasteOption, IPositionContextByEventOption, IPositionContextByEventResult } from '../../interface/Event';
|
|
18
18
|
import { IMargin } from '../../interface/Margin';
|
|
19
|
-
import { IRange, RangeContext } from '../../interface/Range';
|
|
19
|
+
import { IRange, RangeContext, RangeRect } from '../../interface/Range';
|
|
20
20
|
import { IReplaceOption, ISearchOption, ISearchResultContext } from '../../interface/Search';
|
|
21
|
+
import type { ISpellcheckRange } from '../../interface/Spellcheck';
|
|
21
22
|
import { ITextDecoration } from '../../interface/Text';
|
|
22
23
|
import { IGetTitleValueOption, IGetTitleValueResult } from '../../interface/Title';
|
|
23
24
|
import { IWatermark } from '../../interface/Watermark';
|
|
@@ -109,6 +110,8 @@ export declare class CommandAdapt {
|
|
|
109
110
|
deleteWatermark(): void;
|
|
110
111
|
image(payload: IDrawImagePayload): string | null;
|
|
111
112
|
search(payload: string | null, options?: ISearchOption): void;
|
|
113
|
+
setSpellcheckRangeList(payload: ISpellcheckRange[] | null): void;
|
|
114
|
+
getSpellcheckWordList(): import("../../interface/Spellcheck").ISpellcheckWord[];
|
|
112
115
|
searchNavigatePre(): void;
|
|
113
116
|
searchNavigateNext(): void;
|
|
114
117
|
getSearchNavigateInfo(): null | INavigateInfo;
|
|
@@ -168,6 +171,7 @@ export declare class CommandAdapt {
|
|
|
168
171
|
setGroup(): string | null;
|
|
169
172
|
deleteGroup(groupId: string): void;
|
|
170
173
|
getGroupIds(): Promise<string[]>;
|
|
174
|
+
getGroupRectList(groupId: string): RangeRect[] | null;
|
|
171
175
|
locationGroup(groupId: string): void;
|
|
172
176
|
setZone(zone: EditorZone): void;
|
|
173
177
|
getControlValue(payload: IGetControlValueOption): IGetControlValueResult | null;
|
|
@@ -13,6 +13,7 @@ import { Listener } from '../listener/Listener';
|
|
|
13
13
|
import { Position } from '../position/Position';
|
|
14
14
|
import { RangeManager } from '../range/RangeManager';
|
|
15
15
|
import { Search } from './interactive/Search';
|
|
16
|
+
import { Spellcheck } from './interactive/Spellcheck';
|
|
16
17
|
import { Strikeout } from './richtext/Strikeout';
|
|
17
18
|
import { Underline } from './richtext/Underline';
|
|
18
19
|
import { ImageParticle } from './particle/ImageParticle';
|
|
@@ -81,6 +82,7 @@ export declare class Draw {
|
|
|
81
82
|
private badge;
|
|
82
83
|
private magnifier;
|
|
83
84
|
private search;
|
|
85
|
+
private spellcheck;
|
|
84
86
|
private group;
|
|
85
87
|
private area;
|
|
86
88
|
private underline;
|
|
@@ -210,6 +212,7 @@ export declare class Draw {
|
|
|
210
212
|
getCtx(): CanvasRenderingContext2D;
|
|
211
213
|
getOptions(): DeepRequired<IEditorOption>;
|
|
212
214
|
getSearch(): Search;
|
|
215
|
+
getSpellcheck(): Spellcheck;
|
|
213
216
|
getGroup(): Group;
|
|
214
217
|
getArea(): Area;
|
|
215
218
|
getBadge(): Badge;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ISpellcheckContext, ISpellcheckRange, ISpellcheckWord } from '../../../interface/Spellcheck';
|
|
2
|
+
import type { Draw } from '../Draw';
|
|
3
|
+
export declare class Spellcheck {
|
|
4
|
+
private options;
|
|
5
|
+
private draw;
|
|
6
|
+
private position;
|
|
7
|
+
private segmenter;
|
|
8
|
+
private spellcheckRangeList;
|
|
9
|
+
constructor(draw: Draw);
|
|
10
|
+
private _isElementHidden;
|
|
11
|
+
getSpellcheckRangeList(): ISpellcheckRange[];
|
|
12
|
+
private _appendWordList;
|
|
13
|
+
private _collectWordList;
|
|
14
|
+
getSpellcheckWordList(): ISpellcheckWord[];
|
|
15
|
+
setSpellcheckRangeList(payload: ISpellcheckRange[] | null): boolean;
|
|
16
|
+
private _isSameTablePath;
|
|
17
|
+
getRangeByIndex(index: number, context?: ISpellcheckContext): ISpellcheckRange | null;
|
|
18
|
+
private _drawWave;
|
|
19
|
+
render(ctx: CanvasRenderingContext2D, pageIndex: number): void;
|
|
20
|
+
}
|
|
@@ -32,7 +32,7 @@ import { IRangeStyle } from './interface/Listener';
|
|
|
32
32
|
import { Override } from './core/override/Override';
|
|
33
33
|
import { LETTER_CLASS } from './dataset/constant/Common';
|
|
34
34
|
import { INTERNAL_CONTEXT_MENU_KEY } from './dataset/constant/ContextMenu';
|
|
35
|
-
import { IRange } from './interface/Range';
|
|
35
|
+
import { IRange, RangeRect } from './interface/Range';
|
|
36
36
|
import { splitText } from './utils';
|
|
37
37
|
import { createDomFromElementList, getElementListByHTML, getTextFromElementList, type IGetElementListByHTMLOption } from './utils/element';
|
|
38
38
|
import { BackgroundRepeat, BackgroundSize } from './dataset/enum/Background';
|
|
@@ -57,4 +57,4 @@ export default class Editor {
|
|
|
57
57
|
export { splitText, createDomFromElementList, getElementListByHTML, getTextFromElementList };
|
|
58
58
|
export { EDITOR_COMPONENT, LETTER_CLASS, INTERNAL_CONTEXT_MENU_KEY, INTERNAL_SHORTCUT_KEY, EDITOR_CLIPBOARD };
|
|
59
59
|
export { Editor, RowFlex, VerticalAlign, EditorZone, EditorMode, ElementType, ControlType, EditorComponent, PageMode, RenderMode, ImageDisplay, Command, KeyMap, BlockType, MacroType, PaperDirection, TableBorder, TdBorder, TdSlash, MaxHeightRatio, NumberType, TitleLevel, ListType, ListStyle, WordBreak, ControlIndentation, ControlComponent, BackgroundRepeat, BackgroundSize, TextDecorationStyle, LineNumberType, LocationPosition, AreaMode, ControlState, FlexDirection, WatermarkType, WatermarkLayer };
|
|
60
|
-
export type { IElement, IEditorData, IEditorOption, IEditorResult, IContextMenuContext, IRegisterContextMenu, IWatermark, INavigateInfo, IBlock, ILang, ICatalog, ICatalogItem, IRange, IRangeStyle, IBadge, IGetElementListByHTMLOption };
|
|
60
|
+
export type { IElement, IEditorData, IEditorOption, IEditorResult, IContextMenuContext, IRegisterContextMenu, IWatermark, INavigateInfo, IBlock, ILang, ICatalog, ICatalogItem, IRange, IRangeStyle, RangeRect, IBadge, IGetElementListByHTMLOption };
|
|
@@ -33,6 +33,7 @@ import { IAccessibilityOption } from './Accessibility';
|
|
|
33
33
|
import { ITraceOption } from './Trace';
|
|
34
34
|
import { IRulerOption } from './Ruler';
|
|
35
35
|
import { IHintOption } from './Hint';
|
|
36
|
+
import type { ISpellcheckOption } from './Spellcheck';
|
|
36
37
|
export interface IEditorData {
|
|
37
38
|
header?: IElement[];
|
|
38
39
|
main: IElement[];
|
|
@@ -63,6 +64,7 @@ export interface IEditorOption {
|
|
|
63
64
|
searchMatchColor?: string;
|
|
64
65
|
searchNavigateMatchColor?: string;
|
|
65
66
|
searchMatchAlpha?: number;
|
|
67
|
+
spellcheck?: ISpellcheckOption;
|
|
66
68
|
highlightAlpha?: number;
|
|
67
69
|
highlightMarginHeight?: number;
|
|
68
70
|
resizerColor?: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { IContentChange, IControlChange, IControlContentChange, IImageDblclick, IImageMousedown, IImageSizeChange, IInputEventChange, IIntersectionPageNoChange, ILabelMousedown, IMouseEventChange, IPageModeChange, IPageScaleChange, IPageSizeChange, IPositionContextChange, IRangeChange, IRangeStyleChange, ISaved, IVisiblePageNoListChange, IZoneChange } from './Listener';
|
|
1
|
+
import { IContentChange, IControlChange, IControlContentChange, IImageDblclick, IImageMousedown, IImageSizeChange, IInputEventChange, IIntersectionPageNoChange, ILabelMousedown, IMouseEventChange, IPageModeChange, IPageScaleChange, IPageSizeChange, IPositionContextChange, IRangeChange, IRenderChange, IRangeStyleChange, ISaved, IVisiblePageNoListChange, IZoneChange } from './Listener';
|
|
2
|
+
import type { ISpellcheckClick } from './Spellcheck';
|
|
2
3
|
export interface EventBusMap {
|
|
3
4
|
rangeStyleChange: IRangeStyleChange;
|
|
4
5
|
visiblePageNoListChange: IVisiblePageNoListChange;
|
|
@@ -24,4 +25,6 @@ export interface EventBusMap {
|
|
|
24
25
|
imageDblclick: IImageDblclick;
|
|
25
26
|
labelMousedown: ILabelMousedown;
|
|
26
27
|
rangeChange: IRangeChange;
|
|
28
|
+
renderChange: IRenderChange;
|
|
29
|
+
spellcheckClick: ISpellcheckClick;
|
|
27
30
|
}
|
|
@@ -39,6 +39,7 @@ export type IPageSizeChange = (payload: number) => void;
|
|
|
39
39
|
export type IPageScaleChange = (payload: number) => void;
|
|
40
40
|
export type ISaved = (payload: IEditorResult) => void;
|
|
41
41
|
export type IContentChange = () => void;
|
|
42
|
+
export type IRenderChange = () => void;
|
|
42
43
|
export type IControlChange = (payload: IControlChangeResult) => void;
|
|
43
44
|
export type IControlContentChange = (payload: IControlContentChangeResult) => void;
|
|
44
45
|
export type IPageModeChange = (payload: PageMode) => void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ITablePositionContext } from './Position';
|
|
2
|
+
export interface ISpellcheckOption {
|
|
3
|
+
disabled?: boolean;
|
|
4
|
+
color?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ISpellcheckContext {
|
|
7
|
+
tableId?: string;
|
|
8
|
+
tableIndex?: number;
|
|
9
|
+
trIndex?: number;
|
|
10
|
+
tdIndex?: number;
|
|
11
|
+
tablePath?: ITablePositionContext[];
|
|
12
|
+
}
|
|
13
|
+
export interface ISpellcheckWord extends ISpellcheckContext {
|
|
14
|
+
word: string;
|
|
15
|
+
startIndex: number;
|
|
16
|
+
endIndex: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ISpellcheckRange extends ISpellcheckContext {
|
|
19
|
+
startIndex: number;
|
|
20
|
+
endIndex: number;
|
|
21
|
+
data?: unknown;
|
|
22
|
+
}
|
|
23
|
+
export interface ISpellcheckClickPayload {
|
|
24
|
+
evt: MouseEvent;
|
|
25
|
+
range: ISpellcheckRange;
|
|
26
|
+
}
|
|
27
|
+
export type ISpellcheckClick = (payload: ISpellcheckClickPayload) => void;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@hufe921/canvas-editor",
|
|
3
3
|
"author": "Hufe",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.2",
|
|
6
6
|
"description": "A Canvas/SVG-based rich text editor",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
"@types/prismjs": "^1.26.6",
|
|
56
56
|
"@typescript-eslint/eslint-plugin": "^8.67.0",
|
|
57
57
|
"@typescript-eslint/parser": "^8.67.0",
|
|
58
|
-
"@vitest/coverage-v8": "^4.1.
|
|
59
|
-
"cypress": "^15.
|
|
58
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
59
|
+
"cypress": "^15.21.0",
|
|
60
60
|
"cypress-file-upload": "^5.0.8",
|
|
61
61
|
"eslint": "^10.8.1",
|
|
62
|
-
"globals": "^17.
|
|
62
|
+
"globals": "^17.11.0",
|
|
63
63
|
"jsdom": "^29.1.1",
|
|
64
64
|
"simple-git-hooks": "^2.13.1",
|
|
65
65
|
"tslib": "^2.8.1",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"vite": "^8.2.1",
|
|
69
69
|
"vite-plugin-css-injected-by-js": "^5.0.1",
|
|
70
70
|
"vitepress": "^1.6.4",
|
|
71
|
-
"vitest": "^4.1.
|
|
72
|
-
"vitest-canvas-mock": "^1.1.
|
|
71
|
+
"vitest": "^4.1.11",
|
|
72
|
+
"vitest-canvas-mock": "^1.1.5",
|
|
73
73
|
"vue": "^3.5.41"
|
|
74
74
|
},
|
|
75
75
|
"simple-git-hooks": {
|