@hufe921/canvas-editor 1.0.6 → 1.1.0
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 +32 -0
- package/README.md +9 -8
- package/dist/assets/catalog-ezAM0r6o.js.map +1 -0
- package/dist/assets/group-BZtj1M7o.js.map +1 -1
- package/dist/assets/value-DKLIEqC1.js.map +1 -0
- package/dist/assets/wordCount-xSvDqE7d.js.map +1 -0
- package/dist/canvas-editor.js +4446 -2824
- package/dist/canvas-editor.js.map +1 -1
- package/dist/canvas-editor.umd.cjs +42 -42
- package/dist/canvas-editor.umd.cjs.map +1 -1
- package/dist/src/editor/core/command/Command.d.ts +5 -0
- package/dist/src/editor/core/command/CommandAdapt.d.ts +7 -2
- package/dist/src/editor/core/contextmenu/ContextMenu.d.ts +7 -0
- package/dist/src/editor/core/draw/Draw.d.ts +17 -10
- package/dist/src/editor/core/draw/column/ColumnManager.d.ts +2 -1
- package/dist/src/editor/core/draw/control/Control.d.ts +3 -2
- package/dist/src/editor/core/draw/control/interactive/ControlSearch.d.ts +2 -1
- package/dist/src/editor/core/draw/control/richtext/Border.d.ts +2 -1
- package/dist/src/editor/core/draw/frame/Background.d.ts +2 -1
- package/dist/src/editor/core/draw/frame/Badge.d.ts +3 -1
- package/dist/src/editor/core/draw/frame/Footer.d.ts +2 -1
- package/dist/src/editor/core/draw/frame/Header.d.ts +2 -1
- package/dist/src/editor/core/draw/frame/LineNumber.d.ts +2 -1
- package/dist/src/editor/core/draw/frame/Margin.d.ts +2 -1
- package/dist/src/editor/core/draw/frame/PageBorder.d.ts +2 -1
- package/dist/src/editor/core/draw/frame/PageNumber.d.ts +2 -1
- package/dist/src/editor/core/draw/frame/Placeholder.d.ts +2 -1
- package/dist/src/editor/core/draw/frame/Watermark.d.ts +4 -3
- package/dist/src/editor/core/draw/graffiti/Graffiti.d.ts +2 -1
- package/dist/src/editor/core/draw/interactive/Area.d.ts +2 -1
- package/dist/src/editor/core/draw/interactive/Group.d.ts +2 -1
- package/dist/src/editor/core/draw/interactive/Search.d.ts +2 -1
- package/dist/src/editor/core/draw/interactive/Spellcheck.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/CheckboxParticle.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/HyperlinkParticle.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/ImageParticle.d.ts +3 -1
- package/dist/src/editor/core/draw/particle/LabelParticle.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/LineBreakParticle.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/ListParticle.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/PageBreakParticle.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/RadioParticle.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/SeparatorParticle.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/SubscriptParticle.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/SuperscriptParticle.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/TextParticle.d.ts +8 -2
- package/dist/src/editor/core/draw/particle/TraceParticle.d.ts +3 -2
- package/dist/src/editor/core/draw/particle/WhiteSpaceParticle.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/block/BlockParticle.d.ts +3 -1
- package/dist/src/editor/core/draw/particle/block/modules/BaseBlock.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/block/modules/VideoBlock.d.ts +2 -1
- package/dist/src/editor/core/draw/particle/latex/LaTexParticle.d.ts +6 -1
- package/dist/src/editor/core/draw/particle/table/TableParticle.d.ts +3 -2
- package/dist/src/editor/core/draw/richtext/AbstractRichText.d.ts +3 -2
- package/dist/src/editor/core/draw/richtext/Highlight.d.ts +2 -1
- package/dist/src/editor/core/draw/richtext/Strikeout.d.ts +2 -1
- package/dist/src/editor/core/draw/richtext/Underline.d.ts +2 -1
- package/dist/src/editor/core/draw/ruler/Ruler.d.ts +31 -2
- package/dist/src/editor/core/event/pagePointer.d.ts +8 -0
- package/dist/src/editor/core/layout/LayoutEngine.d.ts +31 -0
- package/dist/src/editor/core/layout/TextMeasurer.d.ts +10 -0
- package/dist/src/editor/core/range/RangeManager.d.ts +2 -1
- package/dist/src/editor/core/render/BackendFactory.d.ts +3 -0
- package/dist/src/editor/core/render/RenderBackend.d.ts +24 -0
- package/dist/src/editor/core/render/canvas/CanvasBackend.d.ts +19 -0
- package/dist/src/editor/core/render/canvas/CanvasRenderer.d.ts +5 -0
- package/dist/src/editor/core/render/canvas/CanvasSurface.d.ts +17 -0
- package/dist/src/editor/core/render/model/DisplayList.d.ts +62 -0
- package/dist/src/editor/core/render/model/RenderContext.d.ts +48 -0
- package/dist/src/editor/core/render/svg/SvgBackend.d.ts +22 -0
- package/dist/src/editor/core/render/svg/SvgRenderer.d.ts +9 -0
- package/dist/src/editor/core/render/svg/SvgSurface.d.ts +13 -0
- package/dist/src/editor/core/render/svg/scene/PathCompiler.d.ts +16 -0
- package/dist/src/editor/core/render/svg/scene/ResourceKey.d.ts +7 -0
- package/dist/src/editor/core/render/svg/scene/SceneCompiler.d.ts +9 -0
- package/dist/src/editor/core/render/svg/scene/SceneKey.d.ts +28 -0
- package/dist/src/editor/core/render/svg/scene/SceneNode.d.ts +20 -0
- package/dist/src/editor/core/render/svg/scene/SceneReconciler.d.ts +12 -0
- package/dist/src/editor/core/render/svg/scene/SvgNodeFactory.d.ts +14 -0
- package/dist/src/editor/dataset/constant/Common.d.ts +1 -0
- package/dist/src/editor/dataset/enum/Editor.d.ts +4 -0
- package/dist/src/editor/dataset/enum/TabStop.d.ts +11 -0
- package/dist/src/editor/index.d.ts +5 -4
- package/dist/src/editor/interface/Draw.d.ts +4 -0
- package/dist/src/editor/interface/Editor.d.ts +6 -0
- package/dist/src/editor/interface/Element.d.ts +10 -0
- package/dist/src/editor/interface/Listener.d.ts +5 -1
- package/dist/src/editor/interface/Row.d.ts +3 -0
- package/dist/src/editor/utils/element.d.ts +1 -0
- package/dist/src/editor/utils/print.d.ts +1 -0
- package/package.json +10 -10
- package/dist/assets/catalog-B-cbxN0s.js.map +0 -1
- package/dist/assets/value-93HzxRrf.js.map +0 -1
- package/dist/assets/wordCount-BWZRHbSB.js.map +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type SceneGroupKind = 'page' | 'layer' | 'group' | 'row' | 'table-fragment' | 'repeat-header';
|
|
2
|
+
export type SceneNodeKind = SceneGroupKind | 'text' | 'path' | 'rect' | 'image';
|
|
3
|
+
export interface ISceneResourceIdentity {
|
|
4
|
+
key: string;
|
|
5
|
+
revision?: string | number;
|
|
6
|
+
}
|
|
7
|
+
export interface SceneDefinition {
|
|
8
|
+
key: string;
|
|
9
|
+
kind: 'clipPath' | 'pattern';
|
|
10
|
+
attributes: Record<string, unknown>;
|
|
11
|
+
children: SceneNode[];
|
|
12
|
+
cacheKey?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface SceneNode {
|
|
15
|
+
key: string;
|
|
16
|
+
kind: SceneNodeKind;
|
|
17
|
+
attributes: Record<string, unknown>;
|
|
18
|
+
children: SceneNode[];
|
|
19
|
+
defs?: SceneDefinition[];
|
|
20
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SceneNode } from './SceneNode';
|
|
2
|
+
export declare class SceneReconciler {
|
|
3
|
+
private readonly factory;
|
|
4
|
+
private readonly elements;
|
|
5
|
+
private readonly rootScenes;
|
|
6
|
+
private readonly definitionElements;
|
|
7
|
+
reconcile(host: SVGElement, scene: SceneNode, previous?: SceneNode | undefined): SVGElement;
|
|
8
|
+
private _mount;
|
|
9
|
+
private _patch;
|
|
10
|
+
private _reconcileDefinitions;
|
|
11
|
+
private _reconcileChildren;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SceneDefinition, SceneNode } from './SceneNode';
|
|
2
|
+
export declare const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
|
|
3
|
+
type SceneElement = SceneNode | SceneDefinition;
|
|
4
|
+
export declare class SvgNodeFactory {
|
|
5
|
+
private readonly patternHrefs;
|
|
6
|
+
create(node: SceneElement): SVGElement;
|
|
7
|
+
patch(element: SVGElement, previous: SceneElement | null, next: SceneElement): void;
|
|
8
|
+
getChildren(node: SceneElement): SceneNode[];
|
|
9
|
+
private _patchPatternImage;
|
|
10
|
+
private _getAttributes;
|
|
11
|
+
private _getPatternImageHref;
|
|
12
|
+
private _getImageHref;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
@@ -5,6 +5,7 @@ export declare const HORIZON_TAB = "\t";
|
|
|
5
5
|
export declare const NBSP = " ";
|
|
6
6
|
export declare const NON_BREAKING_SPACE = " ";
|
|
7
7
|
export declare const PUNCTUATION_LIST: string[];
|
|
8
|
+
export declare const HANG_PUNCTUATION_LIST: string[];
|
|
8
9
|
export declare const maxHeightRadioMapping: Record<MaxHeightRatio, number>;
|
|
9
10
|
export declare const LETTER_CLASS: {
|
|
10
11
|
ENGLISH: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './assets/css/index.css';
|
|
2
2
|
import { IEditorData, IEditorOption, IEditorResult } from './interface/Editor';
|
|
3
|
-
import { IElement } from './interface/Element';
|
|
3
|
+
import { IElement, ITabStop } 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';
|
|
@@ -8,7 +8,7 @@ import { FlexDirection, CheckboxMarkType, ImageDisplay, LocationPosition, Surrou
|
|
|
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';
|
|
11
|
-
import { EditorComponent, EditorZone, EditorMode, PageMode, PaperDirection, WordBreak, RenderMode } from './dataset/enum/Editor';
|
|
11
|
+
import { BackendType, EditorComponent, EditorZone, EditorMode, PageMode, PaperDirection, WordBreak, RenderMode } from './dataset/enum/Editor';
|
|
12
12
|
import { EDITOR_CLIPBOARD, EDITOR_COMPONENT } from './dataset/constant/Editor';
|
|
13
13
|
import { IWatermark } from './interface/Watermark';
|
|
14
14
|
import { ControlComponent, ControlIndentation, ControlState, ControlType } from './dataset/enum/Control';
|
|
@@ -23,6 +23,7 @@ import { TableBorder, TdBorder, TdSlash } from './dataset/enum/table/Table';
|
|
|
23
23
|
import { MaxHeightRatio, NumberType } from './dataset/enum/Common';
|
|
24
24
|
import { TitleLevel } from './dataset/enum/Title';
|
|
25
25
|
import { ListStyle, ListType } from './dataset/enum/List';
|
|
26
|
+
import { TabStopLeader, TabStopType } from './dataset/enum/TabStop';
|
|
26
27
|
import { ICatalog, ICatalogItem } from './interface/Catalog';
|
|
27
28
|
import { UsePlugin } from './interface/Plugin';
|
|
28
29
|
import { MacroManager } from './core/macro/MacroManager';
|
|
@@ -56,5 +57,5 @@ export default class Editor {
|
|
|
56
57
|
}
|
|
57
58
|
export { splitText, createDomFromElementList, getElementListByHTML, getTextFromElementList };
|
|
58
59
|
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, SurroundPosition, AreaMode, ControlState, FlexDirection, CheckboxMarkType, WatermarkType, WatermarkLayer };
|
|
60
|
-
export type { IElement, IEditorData, IEditorOption, IEditorResult, IContextMenuContext, IRegisterContextMenu, IWatermark, INavigateInfo, IBlock, ILang, ICatalog, ICatalogItem, IRange, IRangeStyle, RangeRect, IBadge, IGetElementListByHTMLOption };
|
|
60
|
+
export { Editor, RowFlex, VerticalAlign, EditorZone, EditorMode, ElementType, ControlType, EditorComponent, PageMode, RenderMode, BackendType, ImageDisplay, Command, KeyMap, BlockType, MacroType, PaperDirection, TableBorder, TdBorder, TdSlash, MaxHeightRatio, NumberType, TitleLevel, ListType, ListStyle, TabStopType, TabStopLeader, WordBreak, ControlIndentation, ControlComponent, BackgroundRepeat, BackgroundSize, TextDecorationStyle, LineNumberType, LocationPosition, SurroundPosition, AreaMode, ControlState, FlexDirection, CheckboxMarkType, WatermarkType, WatermarkLayer };
|
|
61
|
+
export type { IElement, ITabStop, IEditorData, IEditorOption, IEditorResult, IContextMenuContext, IRegisterContextMenu, IWatermark, INavigateInfo, IBlock, ILang, ICatalog, ICatalogItem, IRange, IRangeStyle, RangeRect, IBadge, IGetElementListByHTMLOption };
|
|
@@ -36,6 +36,10 @@ export interface IDrawRowPayload {
|
|
|
36
36
|
startIndex: number;
|
|
37
37
|
innerWidth: number;
|
|
38
38
|
zone?: EditorZone;
|
|
39
|
+
keyContext?: {
|
|
40
|
+
containerKey?: string;
|
|
41
|
+
tablePath?: string[];
|
|
42
|
+
};
|
|
39
43
|
isDrawLineBreak?: boolean;
|
|
40
44
|
isDrawWhiteSpace?: boolean;
|
|
41
45
|
isDrawRange?: boolean;
|
|
@@ -34,11 +34,14 @@ import { ITraceOption } from './Trace';
|
|
|
34
34
|
import { IRulerOption } from './Ruler';
|
|
35
35
|
import { IHintOption } from './Hint';
|
|
36
36
|
import type { ISpellcheckOption } from './Spellcheck';
|
|
37
|
+
import { BackendType } from '../dataset/enum/Editor';
|
|
37
38
|
export interface ILabOption {
|
|
38
39
|
/**
|
|
39
40
|
* 行级增量行计算:编辑时仅从受影响行断点续算,区间外行复用。
|
|
40
41
|
* 复杂结构(表格/控件/浮动图/分栏/minWidth 控件占位等)自动退化全量。
|
|
41
42
|
* 默认:false
|
|
43
|
+
* @deprecated 自 1.1.0 起不再生效,请使用
|
|
44
|
+
* IEditorOption.incrementalCompute,后续版本移除。
|
|
42
45
|
*/
|
|
43
46
|
incrementalCompute?: boolean;
|
|
44
47
|
}
|
|
@@ -82,6 +85,7 @@ export interface IEditorOption {
|
|
|
82
85
|
margins?: IMargin;
|
|
83
86
|
pageMode?: PageMode;
|
|
84
87
|
renderMode?: RenderMode;
|
|
88
|
+
backend?: BackendType;
|
|
85
89
|
defaultHyperlinkColor?: string;
|
|
86
90
|
paperDirection?: PaperDirection;
|
|
87
91
|
inactiveAlpha?: number;
|
|
@@ -94,6 +98,8 @@ export interface IEditorOption {
|
|
|
94
98
|
scrollContainerSelector?: string;
|
|
95
99
|
pageOuterSelectionDisable?: boolean;
|
|
96
100
|
wordBreak?: WordBreak;
|
|
101
|
+
hangPunctuation?: boolean;
|
|
102
|
+
incrementalCompute?: boolean;
|
|
97
103
|
lab?: ILabOption;
|
|
98
104
|
table?: ITableOption;
|
|
99
105
|
header?: IHeader;
|
|
@@ -5,6 +5,7 @@ import { ElementType } from '../dataset/enum/Element';
|
|
|
5
5
|
import { TraceType } from '../dataset/enum/Trace';
|
|
6
6
|
import { ListStyle, ListType } from '../dataset/enum/List';
|
|
7
7
|
import { RowFlex } from '../dataset/enum/Row';
|
|
8
|
+
import { TabStopLeader, TabStopType } from '../dataset/enum/TabStop';
|
|
8
9
|
import { TitleLevel } from '../dataset/enum/Title';
|
|
9
10
|
import { TableBorder } from '../dataset/enum/table/Table';
|
|
10
11
|
import { IArea } from './Area';
|
|
@@ -41,11 +42,20 @@ export interface IElementStyle {
|
|
|
41
42
|
rowMargin?: number;
|
|
42
43
|
spacingBefore?: number;
|
|
43
44
|
spacingAfter?: number;
|
|
45
|
+
indentLeft?: number;
|
|
46
|
+
indentRight?: number;
|
|
47
|
+
indentFirstLine?: number;
|
|
48
|
+
tabStops?: ITabStop[];
|
|
44
49
|
level?: TitleLevel;
|
|
45
50
|
title?: ITitle;
|
|
46
51
|
letterSpacing?: number;
|
|
47
52
|
textDecoration?: ITextDecoration;
|
|
48
53
|
}
|
|
54
|
+
export interface ITabStop {
|
|
55
|
+
position: number;
|
|
56
|
+
type: TabStopType;
|
|
57
|
+
leader?: TabStopLeader;
|
|
58
|
+
}
|
|
49
59
|
export interface IElementRule {
|
|
50
60
|
hide?: boolean;
|
|
51
61
|
}
|
|
@@ -5,7 +5,7 @@ import { RowFlex } from '../dataset/enum/Row';
|
|
|
5
5
|
import { TitleLevel } from '../dataset/enum/Title';
|
|
6
6
|
import { IControlChangeResult, IControlContentChangeResult } from './Control';
|
|
7
7
|
import { IEditorResult } from './Editor';
|
|
8
|
-
import { IElement } from './Element';
|
|
8
|
+
import { IElement, ITabStop } from './Element';
|
|
9
9
|
import { IPositionContext } from './Position';
|
|
10
10
|
import { IRange } from './Range';
|
|
11
11
|
import { ITextDecoration } from './Text';
|
|
@@ -26,6 +26,10 @@ export interface IRangeStyle {
|
|
|
26
26
|
rowMargin: number;
|
|
27
27
|
spacingBefore: number;
|
|
28
28
|
spacingAfter: number;
|
|
29
|
+
indentLeft: number;
|
|
30
|
+
indentRight: number;
|
|
31
|
+
indentFirstLine: number;
|
|
32
|
+
tabStops: ITabStop[] | null;
|
|
29
33
|
dashArray: number[];
|
|
30
34
|
level: TitleLevel | null;
|
|
31
35
|
listType: ListType | null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PaperDirection } from '../dataset/enum/Editor';
|
|
2
2
|
import { RowFlex } from '../dataset/enum/Row';
|
|
3
|
+
import { TabStopLeader } from '../dataset/enum/TabStop';
|
|
3
4
|
import { IElement, IElementMetrics, IElementPosition, ITableRowFragment } from './Element';
|
|
4
5
|
import { IMargin } from './Margin';
|
|
5
6
|
import { ITd } from './table/Td';
|
|
@@ -7,6 +8,8 @@ export type IRowElement = IElement & {
|
|
|
7
8
|
metrics: IElementMetrics;
|
|
8
9
|
style: string;
|
|
9
10
|
left?: number;
|
|
11
|
+
tabLeader?: TabStopLeader;
|
|
12
|
+
hang?: boolean;
|
|
10
13
|
};
|
|
11
14
|
export interface IRow {
|
|
12
15
|
width: number;
|
|
@@ -73,4 +73,5 @@ export declare function scanToOwner(elementList: IElement[], index: number, dire
|
|
|
73
73
|
*/
|
|
74
74
|
export declare function getOutermostOwner(elementList: IElement[], index: number): string | null;
|
|
75
75
|
export declare function visitElementTree(elementList: IElement[], visitor: (element: IElement) => void): void;
|
|
76
|
+
export declare function getFirstLineIndentElement(elementList: IElement[], zeroIndex: number): IElement | undefined;
|
|
76
77
|
export {};
|
|
@@ -8,4 +8,5 @@ interface IPrintOption {
|
|
|
8
8
|
iframeInfoList?: IIframeInfo[][];
|
|
9
9
|
}
|
|
10
10
|
export declare function print(base64List: string[], options: IPrintOption): Promise<void>;
|
|
11
|
+
export declare function printSvg(pageList: SVGSVGElement[], options: IPrintOption): Promise<void>;
|
|
11
12
|
export {};
|
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.1.0",
|
|
6
6
|
"description": "A Canvas/SVG-based rich text editor",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -50,26 +50,26 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@eslint/js": "^10.0.1",
|
|
53
|
-
"@rollup/plugin-typescript": "^12.3.
|
|
53
|
+
"@rollup/plugin-typescript": "^12.3.1",
|
|
54
54
|
"@types/jsdom": "^28.0.3",
|
|
55
55
|
"@types/node": "^24.19.2",
|
|
56
56
|
"@types/prismjs": "^1.26.6",
|
|
57
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
58
|
-
"@typescript-eslint/parser": "^8.
|
|
59
|
-
"@vitest/coverage-v8": "^4.1.
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^8.72.1",
|
|
58
|
+
"@typescript-eslint/parser": "^8.72.1",
|
|
59
|
+
"@vitest/coverage-v8": "^4.1.12",
|
|
60
60
|
"cypress": "^15.21.1",
|
|
61
61
|
"cypress-file-upload": "^5.0.8",
|
|
62
|
-
"eslint": "^10.
|
|
62
|
+
"eslint": "^10.13.0",
|
|
63
63
|
"globals": "^17.13.0",
|
|
64
64
|
"jsdom": "^29.1.1",
|
|
65
65
|
"simple-git-hooks": "^2.14.0",
|
|
66
66
|
"tslib": "^2.8.1",
|
|
67
67
|
"typescript": "^6.0.3",
|
|
68
|
-
"typescript-eslint": "^8.
|
|
69
|
-
"vite": "^8.3.
|
|
70
|
-
"vite-plugin-css-injected-by-js": "^5.0.
|
|
68
|
+
"typescript-eslint": "^8.72.1",
|
|
69
|
+
"vite": "^8.3.5",
|
|
70
|
+
"vite-plugin-css-injected-by-js": "^5.0.3",
|
|
71
71
|
"vitepress": "^1.6.4",
|
|
72
|
-
"vitest": "^4.1.
|
|
72
|
+
"vitest": "^4.1.12",
|
|
73
73
|
"vitest-canvas-mock": "^1.2.0",
|
|
74
74
|
"vue": "^3.5.44"
|
|
75
75
|
},
|
|
@@ -1 +0,0 @@
|
|
|
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,CACtC,MAAA,EACC,OAAA,EACD,MAAA,EACC,OAAA,EACD,MAAA,EACA,MAAA,CACtB,EAEM,EAAuC,sEAQ7C,EAIA,SAAS,EAAkB,EAA4B,CACrD,MAAO,CAAC,EAAQ,MAAQ,EAAsB,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