@hufe921/canvas-editor 0.9.72 → 0.9.74

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/canvas-editor.es.js +493 -265
  3. package/dist/canvas-editor.es.js.map +1 -1
  4. package/dist/canvas-editor.umd.js +37 -37
  5. package/dist/canvas-editor.umd.js.map +1 -1
  6. package/dist/src/editor/core/cursor/Cursor.d.ts +1 -1
  7. package/dist/src/editor/core/draw/Draw.d.ts +3 -2
  8. package/dist/src/editor/core/draw/control/Control.d.ts +4 -1
  9. package/dist/src/editor/core/draw/control/interactive/ControlSearch.d.ts +1 -1
  10. package/dist/src/editor/core/draw/control/richtext/Border.d.ts +10 -0
  11. package/dist/src/editor/core/draw/particle/block/modules/IFrameBlock.d.ts +1 -0
  12. package/dist/src/editor/core/history/HistoryManager.d.ts +1 -0
  13. package/dist/src/editor/core/range/RangeManager.d.ts +4 -2
  14. package/dist/src/editor/dataset/constant/Element.d.ts +2 -0
  15. package/dist/src/editor/dataset/constant/Regular.d.ts +1 -0
  16. package/dist/src/editor/dataset/enum/List.d.ts +4 -2
  17. package/dist/src/editor/interface/Block.d.ts +2 -1
  18. package/dist/src/editor/interface/Catalog.d.ts +1 -1
  19. package/dist/src/editor/interface/Common.d.ts +5 -5
  20. package/dist/src/editor/interface/Control.d.ts +15 -4
  21. package/dist/src/editor/interface/Draw.d.ts +6 -0
  22. package/dist/src/editor/interface/Editor.d.ts +1 -1
  23. package/dist/src/editor/interface/Element.d.ts +3 -2
  24. package/dist/src/editor/interface/Listener.d.ts +11 -10
  25. package/dist/src/editor/interface/Margin.d.ts +1 -1
  26. package/dist/src/editor/interface/Plugin.d.ts +2 -2
  27. package/dist/src/editor/interface/Position.d.ts +1 -1
  28. package/dist/src/editor/interface/Range.d.ts +8 -4
  29. package/dist/src/editor/interface/Row.d.ts +1 -1
  30. package/dist/src/editor/interface/Search.d.ts +1 -1
  31. package/dist/src/editor/interface/Title.d.ts +1 -1
  32. package/package.json +6 -6
@@ -3,7 +3,7 @@ import { ICursorOption } from '../../interface/Cursor';
3
3
  import { IElementPosition } from '../../interface/Element';
4
4
  import { Draw } from '../draw/Draw';
5
5
  import { CanvasEvent } from '../event/CanvasEvent';
6
- export declare type IDrawCursorOption = ICursorOption & {
6
+ export type IDrawCursorOption = ICursorOption & {
7
7
  isShow?: boolean;
8
8
  isBlink?: boolean;
9
9
  isFocus?: boolean;
@@ -1,4 +1,4 @@
1
- import { IAppendElementListOption, IDrawOption, IDrawRowPayload, IGetImageOption, IGetValueOption, IPainterOption } from '../../interface/Draw';
1
+ import { IAppendElementListOption, IComputeRowListPayload, IDrawOption, IDrawRowPayload, IGetImageOption, IGetValueOption, IPainterOption } from '../../interface/Draw';
2
2
  import { IEditorData, IEditorOption, IEditorResult } from '../../interface/Editor';
3
3
  import { IElement, IElementStyle } from '../../interface/Element';
4
4
  import { IRow } from '../../interface/Row';
@@ -196,7 +196,8 @@ export declare class Draw {
196
196
  private _initPageContext;
197
197
  getElementFont(el: IElement, scale?: number): string;
198
198
  getElementSize(el: IElement): number;
199
- computeRowList(innerWidth: number, elementList: IElement[]): IRow[];
199
+ getElementRowMargin(el: IElement): number;
200
+ computeRowList(payload: IComputeRowListPayload): IRow[];
200
201
  private _computePageList;
201
202
  private _drawHighlight;
202
203
  drawRow(ctx: CanvasRenderingContext2D, payload: IDrawRowPayload): void;
@@ -7,6 +7,7 @@ interface IMoveCursorResult {
7
7
  newElement: IElement;
8
8
  }
9
9
  export declare class Control {
10
+ private controlBorder;
10
11
  private draw;
11
12
  private range;
12
13
  private listener;
@@ -30,7 +31,7 @@ export declare class Control {
30
31
  getPosition(): IElementPosition | null;
31
32
  getPreY(): number;
32
33
  getRange(): IRange;
33
- shrinkBoundary(): void;
34
+ shrinkBoundary(context?: IControlContext): void;
34
35
  getActiveControl(): IControlInstance | null;
35
36
  initControl(): void;
36
37
  destroyControl(): void;
@@ -47,5 +48,7 @@ export declare class Control {
47
48
  setExtensionByConceptId(payload: ISetControlExtensionOption): void;
48
49
  setPropertiesByConceptId(payload: ISetControlProperties): void;
49
50
  getList(): IElement[];
51
+ recordBorderInfo(x: number, y: number, width: number, height: number): void;
52
+ drawBorder(ctx: CanvasRenderingContext2D): void;
50
53
  }
51
54
  export {};
@@ -1,7 +1,7 @@
1
1
  import { IControlHighlight, IControlHighlightRule } from '../../../../interface/Control';
2
2
  import { ISearchResult } from '../../../../interface/Search';
3
3
  import { Control } from '../Control';
4
- declare type IHighlightMatchResult = (ISearchResult & IControlHighlightRule)[];
4
+ type IHighlightMatchResult = (ISearchResult & IControlHighlightRule)[];
5
5
  export declare class ControlSearch {
6
6
  private draw;
7
7
  private options;
@@ -0,0 +1,10 @@
1
+ import { IElementFillRect } from '../../../../interface/Element';
2
+ import { Draw } from '../../Draw';
3
+ export declare class ControlBorder {
4
+ protected borderRect: IElementFillRect;
5
+ private options;
6
+ constructor(draw: Draw);
7
+ clearBorderInfo(): IElementFillRect;
8
+ recordBorderInfo(x: number, y: number, width: number, height: number): void;
9
+ render(ctx: CanvasRenderingContext2D): void;
10
+ }
@@ -3,5 +3,6 @@ export declare class IFrameBlock {
3
3
  private static readonly sandbox;
4
4
  private element;
5
5
  constructor(element: IRowElement);
6
+ private _defineIframeProperties;
6
7
  render(blockItemContainer: HTMLDivElement): void;
7
8
  }
@@ -9,5 +9,6 @@ export declare class HistoryManager {
9
9
  execute(fn: Function): void;
10
10
  isCanUndo(): boolean;
11
11
  isCanRedo(): boolean;
12
+ isStackEmpty(): boolean;
12
13
  recovery(): void;
13
14
  }
@@ -1,5 +1,6 @@
1
+ import { IControlContext } from '../../interface/Control';
1
2
  import { IElement } from '../../interface/Element';
2
- import { IRange, RangeRowArray, RangeRowMap } from '../../interface/Range';
3
+ import { IRange, IRangeParagraphInfo, RangeRowArray, RangeRowMap } from '../../interface/Range';
3
4
  import { Draw } from '../draw/Draw';
4
5
  export declare class RangeManager {
5
6
  private draw;
@@ -20,6 +21,7 @@ export declare class RangeManager {
20
21
  getRangeRow(): RangeRowMap | null;
21
22
  getRangeRowElementList(): IElement[] | null;
22
23
  getRangeParagraph(): RangeRowArray | null;
24
+ getRangeParagraphInfo(): IRangeParagraphInfo | null;
23
25
  getRangeParagraphElementList(): IElement[] | null;
24
26
  getIsSelectAll(): boolean;
25
27
  getIsPointInRange(x: number, y: number): boolean;
@@ -29,7 +31,7 @@ export declare class RangeManager {
29
31
  replaceRange(range: IRange): void;
30
32
  setRangeStyle(): void;
31
33
  recoveryRangeStyle(): void;
32
- shrinkBoundary(): void;
34
+ shrinkBoundary(context?: IControlContext): void;
33
35
  render(ctx: CanvasRenderingContext2D, x: number, y: number, width: number, height: number): void;
34
36
  toString(): string;
35
37
  }
@@ -1,6 +1,7 @@
1
1
  import { ElementType } from '../enum/Element';
2
2
  import { IElement } from '../../interface/Element';
3
3
  import { ITd } from '../../interface/table/Td';
4
+ import { IControlStyle } from '../../interface/Control';
4
5
  export declare const EDITOR_ELEMENT_STYLE_ATTR: Array<keyof IElement>;
5
6
  export declare const EDITOR_ROW_ATTR: Array<keyof IElement>;
6
7
  export declare const EDITOR_ELEMENT_COPY_ATTR: Array<keyof IElement>;
@@ -10,6 +11,7 @@ export declare const TABLE_CONTEXT_ATTR: Array<keyof IElement>;
10
11
  export declare const TITLE_CONTEXT_ATTR: Array<keyof IElement>;
11
12
  export declare const LIST_CONTEXT_ATTR: Array<keyof IElement>;
12
13
  export declare const CONTROL_CONTEXT_ATTR: Array<keyof IElement>;
14
+ export declare const CONTROL_STYLE_ATTR: Array<keyof IControlStyle>;
13
15
  export declare const EDITOR_ELEMENT_CONTEXT_ATTR: Array<keyof IElement>;
14
16
  export declare const TEXTLIKE_ELEMENT_TYPE: ElementType[];
15
17
  export declare const INLINE_ELEMENT_TYPE: ElementType[];
@@ -5,3 +5,4 @@ export declare const SURROGATE_PAIR_REG: RegExp;
5
5
  export declare const EMOJI_REG: RegExp;
6
6
  export declare const UNICODE_SYMBOL_REG: RegExp;
7
7
  export declare const PUNCTUATION_REG: RegExp;
8
+ export declare const START_LINE_BREAK_REG: RegExp;
@@ -5,7 +5,8 @@ export declare enum ListType {
5
5
  export declare enum UlStyle {
6
6
  DISC = "disc",
7
7
  CIRCLE = "circle",
8
- SQUARE = "square"
8
+ SQUARE = "square",
9
+ CHECKBOX = "checkbox"
9
10
  }
10
11
  export declare enum OlStyle {
11
12
  DECIMAL = "decimal"
@@ -14,5 +15,6 @@ export declare enum ListStyle {
14
15
  DISC = "disc",
15
16
  CIRCLE = "circle",
16
17
  SQUARE = "square",
17
- DECIMAL = "decimal"
18
+ DECIMAL = "decimal",
19
+ CHECKBOX = "checkbox"
18
20
  }
@@ -1,6 +1,7 @@
1
1
  import { BlockType } from '../dataset/enum/Block';
2
2
  export interface IIFrameBlock {
3
- src: string;
3
+ src?: string;
4
+ srcdoc?: string;
4
5
  }
5
6
  export interface IVideoBlock {
6
7
  src: string;
@@ -5,4 +5,4 @@ export interface ICatalogItem {
5
5
  level: TitleLevel;
6
6
  subCatalog: ICatalogItem[];
7
7
  }
8
- export declare type ICatalog = ICatalogItem[];
8
+ export type ICatalog = ICatalogItem[];
@@ -1,12 +1,12 @@
1
- export declare type Primitive = string | number | boolean | bigint | symbol | undefined | null;
2
- export declare type Builtin = Primitive | Function | Date | Error | RegExp;
3
- export declare type DeepRequired<T> = T extends Error ? Required<T> : T extends Builtin ? T : T extends Map<infer K, infer V> ? Map<DeepRequired<K>, DeepRequired<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepRequired<K>, DeepRequired<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepRequired<K>, DeepRequired<V>> : T extends Set<infer U> ? Set<DeepRequired<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepRequired<U>> : T extends WeakSet<infer U> ? WeakSet<DeepRequired<U>> : T extends Promise<infer U> ? Promise<DeepRequired<U>> : T extends {} ? {
1
+ export type Primitive = string | number | boolean | bigint | symbol | undefined | null;
2
+ export type Builtin = Primitive | Function | Date | Error | RegExp;
3
+ export type DeepRequired<T> = T extends Error ? Required<T> : T extends Builtin ? T : T extends Map<infer K, infer V> ? Map<DeepRequired<K>, DeepRequired<V>> : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<DeepRequired<K>, DeepRequired<V>> : T extends WeakMap<infer K, infer V> ? WeakMap<DeepRequired<K>, DeepRequired<V>> : T extends Set<infer U> ? Set<DeepRequired<U>> : T extends ReadonlySet<infer U> ? ReadonlySet<DeepRequired<U>> : T extends WeakSet<infer U> ? WeakSet<DeepRequired<U>> : T extends Promise<infer U> ? Promise<DeepRequired<U>> : T extends {} ? {
4
4
  [K in keyof T]-?: DeepRequired<T[K]>;
5
5
  } : Required<T>;
6
- export declare type DeepPartial<T> = {
6
+ export type DeepPartial<T> = {
7
7
  [P in keyof T]?: DeepPartial<T[P]>;
8
8
  };
9
- export declare type IPadding = [
9
+ export type IPadding = [
10
10
  top: number,
11
11
  right: number,
12
12
  bottom: number,
@@ -40,15 +40,26 @@ export interface IControlBasic {
40
40
  postfix?: string;
41
41
  minWidth?: number;
42
42
  underline?: boolean;
43
+ border?: boolean;
43
44
  extension?: unknown;
44
45
  indentation?: ControlIndentation;
45
46
  }
46
- export declare type IControl = IControlBasic & IControlRule & Partial<IControlSelect> & Partial<IControlCheckbox>;
47
+ export interface IControlStyle {
48
+ font?: string;
49
+ size?: number;
50
+ bold?: boolean;
51
+ highlight?: string;
52
+ italic?: boolean;
53
+ strikeout?: boolean;
54
+ }
55
+ export type IControl = IControlBasic & IControlRule & Partial<IControlSelect> & Partial<IControlCheckbox> & Partial<IControlStyle>;
47
56
  export interface IControlOption {
48
57
  placeholderColor?: string;
49
58
  bracketColor?: string;
50
59
  prefix?: string;
51
60
  postfix?: string;
61
+ borderWidth?: number;
62
+ borderColor?: string;
52
63
  }
53
64
  export interface IControlInitOption {
54
65
  index: number;
@@ -77,7 +88,7 @@ export interface IControlRuleOption {
77
88
  export interface IGetControlValueOption {
78
89
  conceptId: string;
79
90
  }
80
- export declare type IGetControlValueResult = (Omit<IControl, 'value'> & {
91
+ export type IGetControlValueResult = (Omit<IControl, 'value'> & {
81
92
  value: string | null;
82
93
  innerText: string | null;
83
94
  zone: EditorZone;
@@ -90,8 +101,8 @@ export interface ISetControlExtensionOption {
90
101
  conceptId: string;
91
102
  extension: unknown;
92
103
  }
93
- export declare type ISetControlHighlightOption = IControlHighlight[];
94
- export declare type ISetControlProperties = {
104
+ export type ISetControlHighlightOption = IControlHighlight[];
105
+ export type ISetControlProperties = {
95
106
  conceptId: string;
96
107
  properties: Partial<Omit<IControl, 'value'>>;
97
108
  };
@@ -10,6 +10,7 @@ export interface IDrawOption {
10
10
  isLazy?: boolean;
11
11
  isInit?: boolean;
12
12
  isSourceHistory?: boolean;
13
+ isFirstRender?: boolean;
13
14
  }
14
15
  export interface IForceUpdateOption {
15
16
  isSubmitHistory?: boolean;
@@ -51,3 +52,8 @@ export interface IGetImageOption {
51
52
  pixelRatio?: number;
52
53
  mode?: EditorMode;
53
54
  }
55
+ export interface IComputeRowListPayload {
56
+ innerWidth: number;
57
+ elementList: IElement[];
58
+ isPagingMode?: boolean;
59
+ }
@@ -90,4 +90,4 @@ export interface IEditorHTML {
90
90
  main: string;
91
91
  footer: string;
92
92
  }
93
- export declare type IEditorText = IEditorHTML;
93
+ export type IEditorText = IEditorHTML;
@@ -15,6 +15,7 @@ export interface IElementBasic {
15
15
  id?: string;
16
16
  type?: ElementType;
17
17
  value: string;
18
+ extension?: unknown;
18
19
  }
19
20
  export interface IElementStyle {
20
21
  font?: string;
@@ -59,7 +60,7 @@ export interface ITableElement {
59
60
  conceptId?: string;
60
61
  pagingId?: string;
61
62
  }
62
- export declare type ITable = ITableAttr & ITableElement;
63
+ export type ITable = ITableAttr & ITableElement;
63
64
  export interface IHyperlinkElement {
64
65
  valueList?: IElement[];
65
66
  url?: string;
@@ -96,7 +97,7 @@ export interface IImageElement {
96
97
  export interface IBlockElement {
97
98
  block?: IBlock;
98
99
  }
99
- export declare type IElement = IElementBasic & IElementStyle & IElementGroup & ITable & IHyperlinkElement & ISuperscriptSubscript & ISeparator & IControlElement & ICheckboxElement & ILaTexElement & IDateElement & IImageElement & IBlockElement & ITitleElement & IListElement;
100
+ export type IElement = IElementBasic & IElementStyle & IElementGroup & ITable & IHyperlinkElement & ISuperscriptSubscript & ISeparator & IControlElement & ICheckboxElement & ILaTexElement & IDateElement & IImageElement & IBlockElement & ITitleElement & IListElement;
100
101
  export interface IElementMetrics {
101
102
  width: number;
102
103
  height: number;
@@ -24,14 +24,15 @@ export interface IRangeStyle {
24
24
  listStyle: ListStyle | null;
25
25
  groupIds: string[] | null;
26
26
  textDecoration: ITextDecoration | null;
27
+ extension?: unknown | null;
27
28
  }
28
- export declare type IRangeStyleChange = (payload: IRangeStyle) => void;
29
- export declare type IVisiblePageNoListChange = (payload: number[]) => void;
30
- export declare type IIntersectionPageNoChange = (payload: number) => void;
31
- export declare type IPageSizeChange = (payload: number) => void;
32
- export declare type IPageScaleChange = (payload: number) => void;
33
- export declare type ISaved = (payload: IEditorResult) => void;
34
- export declare type IContentChange = () => void;
35
- export declare type IControlChange = (payload: IControl | null) => void;
36
- export declare type IPageModeChange = (payload: PageMode) => void;
37
- export declare type IZoneChange = (payload: EditorZone) => void;
29
+ export type IRangeStyleChange = (payload: IRangeStyle) => void;
30
+ export type IVisiblePageNoListChange = (payload: number[]) => void;
31
+ export type IIntersectionPageNoChange = (payload: number) => void;
32
+ export type IPageSizeChange = (payload: number) => void;
33
+ export type IPageScaleChange = (payload: number) => void;
34
+ export type ISaved = (payload: IEditorResult) => void;
35
+ export type IContentChange = () => void;
36
+ export type IControlChange = (payload: IControl | null) => void;
37
+ export type IPageModeChange = (payload: PageMode) => void;
38
+ export type IZoneChange = (payload: EditorZone) => void;
@@ -1 +1 @@
1
- export declare type IMargin = [top: number, right: number, bottom: number, left: number];
1
+ export type IMargin = [top: number, right: number, bottom: number, left: number];
@@ -1,3 +1,3 @@
1
1
  import Editor from '..';
2
- export declare type PluginFunction<Options> = (editor: Editor, options?: Options) => any;
3
- export declare type UsePlugin = <Options>(pluginFunction: PluginFunction<Options>, options?: Options) => void;
2
+ export type PluginFunction<Options> = (editor: Editor, options?: Options) => any;
3
+ export type UsePlugin = <Options>(pluginFunction: PluginFunction<Options>, options?: Options) => void;
@@ -31,7 +31,7 @@ export interface IGetPositionByXYPayload {
31
31
  elementList?: IElement[];
32
32
  positionList?: IElementPosition[];
33
33
  }
34
- export declare type IGetFloatPositionByXYPayload = IGetPositionByXYPayload & {
34
+ export type IGetFloatPositionByXYPayload = IGetPositionByXYPayload & {
35
35
  imgDisplay: ImageDisplay;
36
36
  };
37
37
  export interface IPositionContext {
@@ -11,10 +11,10 @@ export interface IRange {
11
11
  endTrIndex?: number;
12
12
  zone?: EditorZone;
13
13
  }
14
- export declare type RangeRowArray = Map<number, number[]>;
15
- export declare type RangeRowMap = Map<number, Set<number>>;
16
- export declare type RangeRect = IElementFillRect;
17
- export declare type RangeContext = {
14
+ export type RangeRowArray = Map<number, number[]>;
15
+ export type RangeRowMap = Map<number, Set<number>>;
16
+ export type RangeRect = IElementFillRect;
17
+ export type RangeContext = {
18
18
  isCollapsed: boolean;
19
19
  startElement: IElement;
20
20
  endElement: IElement;
@@ -24,3 +24,7 @@ export declare type RangeContext = {
24
24
  zone: EditorZone;
25
25
  isTable: boolean;
26
26
  };
27
+ export interface IRangeParagraphInfo {
28
+ elementList: IElement[];
29
+ startIndex: number;
30
+ }
@@ -1,6 +1,6 @@
1
1
  import { RowFlex } from '../dataset/enum/Row';
2
2
  import { IElement, IElementMetrics } from './Element';
3
- export declare type IRowElement = IElement & {
3
+ export type IRowElement = IElement & {
4
4
  metrics: IElementMetrics;
5
5
  style: string;
6
6
  left?: number;
@@ -12,4 +12,4 @@ export interface ISearchResultRestArgs {
12
12
  tdId?: string;
13
13
  startIndex?: number;
14
14
  }
15
- export declare type ISearchResult = ISearchResultBasic & ISearchResultRestArgs;
15
+ export type ISearchResult = ISearchResultBasic & ISearchResultRestArgs;
@@ -6,4 +6,4 @@ export interface ITitleSizeOption {
6
6
  defaultFifthSize?: number;
7
7
  defaultSixthSize?: number;
8
8
  }
9
- export declare type ITitleOption = ITitleSizeOption & {};
9
+ export type ITitleOption = ITitleSizeOption & {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@hufe921/canvas-editor",
3
3
  "author": "Hufe",
4
4
  "license": "MIT",
5
- "version": "0.9.72",
5
+ "version": "0.9.74",
6
6
  "description": "rich text editor by canvas/svg",
7
7
  "publishConfig": {
8
8
  "registry": "https://registry.npmjs.org/",
@@ -30,7 +30,7 @@
30
30
  "emr"
31
31
  ],
32
32
  "engines": {
33
- "node": ">=12.0.0"
33
+ "node": ">=16.9.1"
34
34
  },
35
35
  "type": "module",
36
36
  "scripts": {
@@ -49,15 +49,15 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@rollup/plugin-typescript": "^10.0.1",
52
- "@types/node": "^16.11.12",
52
+ "@types/node": "16.18.96",
53
53
  "@types/prismjs": "^1.26.0",
54
- "@typescript-eslint/eslint-plugin": "4.33.0",
55
- "@typescript-eslint/parser": "4.33.0",
54
+ "@typescript-eslint/eslint-plugin": "5.62.0",
55
+ "@typescript-eslint/parser": "5.62.0",
56
56
  "cypress": "13.6.0",
57
57
  "cypress-file-upload": "^5.0.8",
58
58
  "eslint": "7.32.0",
59
59
  "simple-git-hooks": "^2.8.1",
60
- "typescript": "^4.3.2",
60
+ "typescript": "4.9.5",
61
61
  "vite": "^2.4.2",
62
62
  "vite-plugin-css-injected-by-js": "^2.1.1",
63
63
  "vitepress": "1.0.0-beta.6",