@hufe921/canvas-editor 1.0.1 → 1.0.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/CHANGELOG.md +39 -0
- package/dist/assets/value-CLcLo2uw.js.map +1 -1
- package/dist/canvas-editor.js +1993 -1760
- 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 +4 -0
- package/dist/src/editor/core/command/CommandAdapt.d.ts +6 -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/dataset/enum/Common.d.ts +4 -0
- package/dist/src/editor/index.d.ts +4 -4
- package/dist/src/editor/interface/Control.d.ts +1 -0
- 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/Range.d.ts +5 -0
- package/dist/src/editor/interface/Spellcheck.d.ts +27 -0
- package/package.json +13 -13
|
@@ -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'];
|
|
@@ -141,6 +143,7 @@ export declare class Command {
|
|
|
141
143
|
getRangeContext: CommandAdapt['getRangeContext'];
|
|
142
144
|
getRangeRow: CommandAdapt['getRangeRow'];
|
|
143
145
|
getRangeParagraph: CommandAdapt['getRangeParagraph'];
|
|
146
|
+
getSurroundElementList: CommandAdapt['getSurroundElementList'];
|
|
144
147
|
getKeywordRangeList: CommandAdapt['getKeywordRangeList'];
|
|
145
148
|
getKeywordContext: CommandAdapt['getKeywordContext'];
|
|
146
149
|
getPaperMargin: CommandAdapt['getPaperMargin'];
|
|
@@ -148,6 +151,7 @@ export declare class Command {
|
|
|
148
151
|
getSearchNavigateInfo: CommandAdapt['getSearchNavigateInfo'];
|
|
149
152
|
getLocale: CommandAdapt['getLocale'];
|
|
150
153
|
getGroupIds: CommandAdapt['getGroupIds'];
|
|
154
|
+
getGroupRectList: CommandAdapt['getGroupRectList'];
|
|
151
155
|
getControlValue: CommandAdapt['getControlValue'];
|
|
152
156
|
getControlList: CommandAdapt['getControlList'];
|
|
153
157
|
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 { IGetSurroundElementListOption, 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;
|
|
@@ -135,6 +138,7 @@ export declare class CommandAdapt {
|
|
|
135
138
|
getRangeContext(): RangeContext | null;
|
|
136
139
|
getRangeRow(): IElement[] | null;
|
|
137
140
|
getRangeParagraph(): IElement[] | null;
|
|
141
|
+
getSurroundElementList(option?: IGetSurroundElementListOption): IElement[] | null;
|
|
138
142
|
getKeywordRangeList(payload: string): IRange[];
|
|
139
143
|
getKeywordContext(payload: string): ISearchResultContext[] | null;
|
|
140
144
|
pageMode(payload: PageMode): void;
|
|
@@ -168,6 +172,7 @@ export declare class CommandAdapt {
|
|
|
168
172
|
setGroup(): string | null;
|
|
169
173
|
deleteGroup(groupId: string): void;
|
|
170
174
|
getGroupIds(): Promise<string[]>;
|
|
175
|
+
getGroupRectList(groupId: string): RangeRect[] | null;
|
|
171
176
|
locationGroup(groupId: string): void;
|
|
172
177
|
setZone(zone: EditorZone): void;
|
|
173
178
|
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
|
+
}
|
|
@@ -20,6 +20,10 @@ export declare enum LocationPosition {
|
|
|
20
20
|
OUTER_BEFORE = "outer-before",
|
|
21
21
|
OUTER_AFTER = "outer-after"
|
|
22
22
|
}
|
|
23
|
+
export declare enum SurroundPosition {
|
|
24
|
+
BEFORE = "before",
|
|
25
|
+
AFTER = "after"
|
|
26
|
+
}
|
|
23
27
|
export declare enum FlexDirection {
|
|
24
28
|
ROW = "row",
|
|
25
29
|
COLUMN = "column"
|
|
@@ -4,7 +4,7 @@ import { IElement } from './interface/Element';
|
|
|
4
4
|
import { Command } from './core/command/Command';
|
|
5
5
|
import { Listener } from './core/listener/Listener';
|
|
6
6
|
import { RowFlex } from './dataset/enum/Row';
|
|
7
|
-
import { FlexDirection, ImageDisplay, LocationPosition } from './dataset/enum/Common';
|
|
7
|
+
import { FlexDirection, ImageDisplay, LocationPosition, SurroundPosition } from './dataset/enum/Common';
|
|
8
8
|
import { ElementType } from './dataset/enum/Element';
|
|
9
9
|
import { Register } from './core/register/Register';
|
|
10
10
|
import { IContextMenuContext, IRegisterContextMenu } from './interface/contextmenu/ContextMenu';
|
|
@@ -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';
|
|
@@ -56,5 +56,5 @@ export default class Editor {
|
|
|
56
56
|
}
|
|
57
57
|
export { splitText, createDomFromElementList, getElementListByHTML, getTextFromElementList };
|
|
58
58
|
export { EDITOR_COMPONENT, LETTER_CLASS, INTERNAL_CONTEXT_MENU_KEY, INTERNAL_SHORTCUT_KEY, EDITOR_CLIPBOARD };
|
|
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 };
|
|
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, SurroundPosition, AreaMode, ControlState, FlexDirection, WatermarkType, WatermarkLayer };
|
|
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;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EditorZone } from '../dataset/enum/Editor';
|
|
2
|
+
import { SurroundPosition } from '../dataset/enum/Common';
|
|
2
3
|
import { IElement, IElementFillRect, IElementStyle } from './Element';
|
|
3
4
|
export interface IRange {
|
|
4
5
|
startIndex: number;
|
|
@@ -42,3 +43,7 @@ export interface IRangeParagraphInfo {
|
|
|
42
43
|
startIndex: number;
|
|
43
44
|
}
|
|
44
45
|
export type IRangeElementStyle = Pick<IElementStyle, 'bold' | 'color' | 'highlight' | 'font' | 'size' | 'italic' | 'underline' | 'strikeout'>;
|
|
46
|
+
export interface IGetSurroundElementListOption {
|
|
47
|
+
direction?: SurroundPosition;
|
|
48
|
+
length?: number;
|
|
49
|
+
}
|
|
@@ -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.3",
|
|
6
6
|
"description": "A Canvas/SVG-based rich text editor",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -53,24 +53,24 @@
|
|
|
53
53
|
"@types/jsdom": "^28.0.3",
|
|
54
54
|
"@types/node": "^24.12.4",
|
|
55
55
|
"@types/prismjs": "^1.26.6",
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
57
|
-
"@typescript-eslint/parser": "^8.
|
|
58
|
-
"@vitest/coverage-v8": "^4.1.
|
|
59
|
-
"cypress": "^15.
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^8.69.0",
|
|
57
|
+
"@typescript-eslint/parser": "^8.69.0",
|
|
58
|
+
"@vitest/coverage-v8": "^4.1.11",
|
|
59
|
+
"cypress": "^15.21.1",
|
|
60
60
|
"cypress-file-upload": "^5.0.8",
|
|
61
|
-
"eslint": "^10.
|
|
62
|
-
"globals": "^17.
|
|
61
|
+
"eslint": "^10.9.1",
|
|
62
|
+
"globals": "^17.12.0",
|
|
63
63
|
"jsdom": "^29.1.1",
|
|
64
|
-
"simple-git-hooks": "^2.
|
|
64
|
+
"simple-git-hooks": "^2.14.0",
|
|
65
65
|
"tslib": "^2.8.1",
|
|
66
66
|
"typescript": "^6.0.3",
|
|
67
|
-
"typescript-eslint": "^8.
|
|
68
|
-
"vite": "^8.2.
|
|
67
|
+
"typescript-eslint": "^8.69.0",
|
|
68
|
+
"vite": "^8.2.2",
|
|
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.
|
|
73
|
-
"vue": "^3.5.
|
|
71
|
+
"vitest": "^4.1.11",
|
|
72
|
+
"vitest-canvas-mock": "^1.1.5",
|
|
73
|
+
"vue": "^3.5.42"
|
|
74
74
|
},
|
|
75
75
|
"simple-git-hooks": {
|
|
76
76
|
"pre-commit": "npm run lint && npm run type:check",
|