@sw7d/paper-renderer 0.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/README.MD +10 -0
- package/dist/paper-renderer.js +6862 -0
- package/dist/src/components/PaperEditor.vue.d.ts +172 -0
- package/dist/src/components/PaperPreview.vue.d.ts +26 -0
- package/dist/src/composables/paperHelpers.d.ts +35 -0
- package/dist/src/composables/usePageSvgRenderer.d.ts +26 -0
- package/dist/src/composables/usePaperBlockOps.d.ts +74 -0
- package/dist/src/composables/usePaperCore.d.ts +181 -0
- package/dist/src/composables/usePaperCursor.d.ts +45 -0
- package/dist/src/composables/usePaperSelection.d.ts +45 -0
- package/dist/src/composables/useTableRenderer.d.ts +33 -0
- package/dist/src/engine/PaperLayout.d.ts +59 -0
- package/dist/src/engine/SvgRenderer.d.ts +75 -0
- package/dist/src/engine/svg/headerRenderer.d.ts +36 -0
- package/dist/src/engine/svg/optionsRenderer.d.ts +23 -0
- package/dist/src/engine/svg/questionRenderer.d.ts +35 -0
- package/dist/src/index.d.ts +35 -0
- package/dist/src/types/document.d.ts +498 -0
- package/dist/src/types/paper.d.ts +278 -0
- package/dist/src/utils/charWidth.d.ts +46 -0
- package/dist/src/utils/chineseNumber.d.ts +50 -0
- package/dist/src/utils/deserialization/parseDocument.d.ts +19 -0
- package/dist/src/utils/deserialization/parseInlines.d.ts +13 -0
- package/dist/src/utils/deserialization/parseQuestions.d.ts +21 -0
- package/dist/src/utils/documentSerializer.d.ts +33 -0
- package/dist/src/utils/mathjax.d.ts +57 -0
- package/dist/src/utils/paperHtmlBuilder.d.ts +21 -0
- package/dist/src/utils/qrcode.d.ts +7 -0
- package/dist/src/utils/questionHtmlParser.d.ts +40 -0
- package/dist/src/utils/questionJsonParser.d.ts +61 -0
- package/dist/src/utils/serialization/buildBody.d.ts +11 -0
- package/dist/src/utils/serialization/buildPagesExport.d.ts +45 -0
- package/dist/src/utils/serialization/buildQuestions.d.ts +23 -0
- package/dist/src/utils/serialization/shared.d.ts +61 -0
- package/dist/src/utils/textWrap.d.ts +36 -0
- package/dist/style.css +2 -0
- package/dist/vite.config.d.ts +2 -0
- package/package.json +53 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { PageSettings, ContentBlock, QuestionType, PaperSize, ColumnMode } from '../types/paper';
|
|
2
|
+
import '../styles/renderer.css';
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
initialDataUrl?: string;
|
|
5
|
+
initialData?: string;
|
|
6
|
+
renderMode?: 'edit' | 'view';
|
|
7
|
+
paperName?: string;
|
|
8
|
+
schoolName?: string;
|
|
9
|
+
/** 二维码内容文本(内核自动生成二维码图片) */
|
|
10
|
+
qrCodeContent?: string;
|
|
11
|
+
};
|
|
12
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
13
|
+
document: {
|
|
14
|
+
save: () => string;
|
|
15
|
+
load: (json: string) => void;
|
|
16
|
+
loadFromUrl: (url: string) => Promise<void>;
|
|
17
|
+
getBlocks: () => ContentBlock[];
|
|
18
|
+
isDirty: () => boolean;
|
|
19
|
+
};
|
|
20
|
+
questions: {
|
|
21
|
+
addFromHtml: (html: string, no?: string, score?: string) => void;
|
|
22
|
+
addFromJson: (json: string, no?: string, score?: string) => void;
|
|
23
|
+
addFromText: (text: string, no?: string, score?: string) => void;
|
|
24
|
+
remove: (id: string) => void;
|
|
25
|
+
addTitleBlock: (title: string, beforeId?: string) => void;
|
|
26
|
+
reorder: (orderedIds: string[]) => void;
|
|
27
|
+
updateLabel: (id: string, label: string) => void;
|
|
28
|
+
updateSectionTitle: (id: string, title: string) => void;
|
|
29
|
+
recalculateNumbering: () => void;
|
|
30
|
+
updateContent: (id: string, content: string) => void;
|
|
31
|
+
updateScore: (id: string, score: string) => void;
|
|
32
|
+
updateQid: (id: string, qid: string) => void;
|
|
33
|
+
updateHeight: (id: string, height: number) => void;
|
|
34
|
+
updateType: (id: string, type: QuestionType) => void;
|
|
35
|
+
updateShowScore: (val: boolean) => void;
|
|
36
|
+
updateKeepNext: (id: string, keepNext: boolean) => void;
|
|
37
|
+
updateSplit: (id: string, split: boolean) => void;
|
|
38
|
+
};
|
|
39
|
+
layout: {
|
|
40
|
+
setPaperSize: (size: PaperSize) => void;
|
|
41
|
+
setColumns: (cols: ColumnMode) => void;
|
|
42
|
+
setFontSize: (size: number) => void;
|
|
43
|
+
setLineSpacing: (spacing: number) => void;
|
|
44
|
+
updateSettings: (s: Partial<PageSettings>) => void;
|
|
45
|
+
reflow: () => void;
|
|
46
|
+
};
|
|
47
|
+
selection: {
|
|
48
|
+
selectBlock: (id: string | null) => void;
|
|
49
|
+
selectUnderline: (id: string | null) => void;
|
|
50
|
+
updateImageAlignment: (id: string, alignment: "left" | "center" | "right") => void;
|
|
51
|
+
};
|
|
52
|
+
viewport: {
|
|
53
|
+
setZoom: (z: number) => void;
|
|
54
|
+
goToPage: (idx: number) => void;
|
|
55
|
+
};
|
|
56
|
+
render: {
|
|
57
|
+
getPageSvgs: () => string[];
|
|
58
|
+
getCleanPageSvgs: () => string[];
|
|
59
|
+
getAllPagesSvg: () => string;
|
|
60
|
+
};
|
|
61
|
+
state: import("vue").ComputedRef<{
|
|
62
|
+
blocks: ContentBlock[];
|
|
63
|
+
pages: {
|
|
64
|
+
index: number;
|
|
65
|
+
width: number;
|
|
66
|
+
height: number;
|
|
67
|
+
blocks: {
|
|
68
|
+
blockId: string;
|
|
69
|
+
blockType: import("..").BlockType;
|
|
70
|
+
paragraphStart: number;
|
|
71
|
+
paragraphCount: number;
|
|
72
|
+
x: number;
|
|
73
|
+
y: number;
|
|
74
|
+
width: number;
|
|
75
|
+
height: number;
|
|
76
|
+
}[];
|
|
77
|
+
cornerMarks: {
|
|
78
|
+
position: "tl" | "tr" | "bl" | "br";
|
|
79
|
+
bbox: [number, number, number, number];
|
|
80
|
+
}[];
|
|
81
|
+
renderedRegions: {
|
|
82
|
+
type: "header-desc" | "paper-name" | "qr-code" | "student-name" | "student-class" | "student-code" | "score" | "page-number" | "correction-box" | "title-embed" | "column-separator" | "question-border" | "underline";
|
|
83
|
+
bbox: [number, number, number, number];
|
|
84
|
+
meta?: Record<string, any> | undefined;
|
|
85
|
+
}[];
|
|
86
|
+
}[];
|
|
87
|
+
settings: {
|
|
88
|
+
paperSize: PaperSize;
|
|
89
|
+
columns: ColumnMode;
|
|
90
|
+
fontSize: number;
|
|
91
|
+
lineSpacing: number;
|
|
92
|
+
margins: [number, number, number, number];
|
|
93
|
+
showCornerMarks: boolean;
|
|
94
|
+
showBBoxes: boolean;
|
|
95
|
+
columnGap: number;
|
|
96
|
+
headerTop: number;
|
|
97
|
+
bodyTopEven: number;
|
|
98
|
+
bodyTopOdd: number;
|
|
99
|
+
showScore: boolean;
|
|
100
|
+
};
|
|
101
|
+
selectedBlockId: string | null;
|
|
102
|
+
selectedBlock: ContentBlock | null;
|
|
103
|
+
selectedUnderlineId: string | null;
|
|
104
|
+
selectedImageId: string | null;
|
|
105
|
+
selectedUnderlineInfo: {
|
|
106
|
+
block: ContentBlock;
|
|
107
|
+
paraIdx: number;
|
|
108
|
+
lineIdx: number;
|
|
109
|
+
elemIdx: number;
|
|
110
|
+
underline: import("..").UnderlineInline;
|
|
111
|
+
} | null;
|
|
112
|
+
selectedImageInfo: {
|
|
113
|
+
block: ContentBlock;
|
|
114
|
+
paraIdx: number;
|
|
115
|
+
lineIdx: number;
|
|
116
|
+
elemIdx: number;
|
|
117
|
+
image: import("..").ImageInline;
|
|
118
|
+
} | null;
|
|
119
|
+
selectedImageAlignment: {
|
|
120
|
+
isStandalone: boolean;
|
|
121
|
+
alignment: "left" | "center" | "right";
|
|
122
|
+
} | null;
|
|
123
|
+
totalScore: number;
|
|
124
|
+
zoom: number;
|
|
125
|
+
currentPage: number;
|
|
126
|
+
pageCount: number;
|
|
127
|
+
isDirty: boolean;
|
|
128
|
+
paperName: string;
|
|
129
|
+
schoolName: string;
|
|
130
|
+
qrCodeContent: string;
|
|
131
|
+
qrCodeImage: string;
|
|
132
|
+
showScore: boolean;
|
|
133
|
+
}>;
|
|
134
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
135
|
+
change: () => any;
|
|
136
|
+
save: (json: string) => any;
|
|
137
|
+
"block-click": (payload: {
|
|
138
|
+
blockId: string;
|
|
139
|
+
block: ContentBlock;
|
|
140
|
+
}) => any;
|
|
141
|
+
"underline-click": (payload: {
|
|
142
|
+
underlineId: string;
|
|
143
|
+
}) => any;
|
|
144
|
+
"anchor-click": (payload: {
|
|
145
|
+
anchorId: string;
|
|
146
|
+
}) => any;
|
|
147
|
+
"empty-click": () => any;
|
|
148
|
+
"page-change": (pageIndex: number) => any;
|
|
149
|
+
ready: () => any;
|
|
150
|
+
loaded: () => any;
|
|
151
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
152
|
+
onChange?: (() => any) | undefined;
|
|
153
|
+
onSave?: ((json: string) => any) | undefined;
|
|
154
|
+
"onBlock-click"?: ((payload: {
|
|
155
|
+
blockId: string;
|
|
156
|
+
block: ContentBlock;
|
|
157
|
+
}) => any) | undefined;
|
|
158
|
+
"onUnderline-click"?: ((payload: {
|
|
159
|
+
underlineId: string;
|
|
160
|
+
}) => any) | undefined;
|
|
161
|
+
"onAnchor-click"?: ((payload: {
|
|
162
|
+
anchorId: string;
|
|
163
|
+
}) => any) | undefined;
|
|
164
|
+
"onEmpty-click"?: (() => any) | undefined;
|
|
165
|
+
"onPage-change"?: ((pageIndex: number) => any) | undefined;
|
|
166
|
+
onReady?: (() => any) | undefined;
|
|
167
|
+
onLoaded?: (() => any) | undefined;
|
|
168
|
+
}>, {
|
|
169
|
+
renderMode: "edit" | "view";
|
|
170
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
171
|
+
declare const _default: typeof __VLS_export;
|
|
172
|
+
export default _default;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
/** 编辑器保存的 JSON 字符串(文档格式,与数据库存储一致) */
|
|
3
|
+
document: string;
|
|
4
|
+
/** 渲染模式:screen=屏幕预览, print=打印优化, pdf=PDF导出 */
|
|
5
|
+
mode?: 'screen' | 'print' | 'pdf';
|
|
6
|
+
/** 纯净模式:渲染器 renderMode 开关(edit → view),去掉虚线框等编辑辅助元素 */
|
|
7
|
+
pureMode?: boolean;
|
|
8
|
+
/** 辅助线总开关(默认关闭),用于标注框定位预览 */
|
|
9
|
+
showHelpers?: boolean;
|
|
10
|
+
/** 显示角标辅助线 */
|
|
11
|
+
showCornerMarks?: boolean;
|
|
12
|
+
/** 显示区域辅助线 */
|
|
13
|
+
showRegionBoxes?: boolean;
|
|
14
|
+
/** 显示页码标注 */
|
|
15
|
+
showPageNumbers?: boolean;
|
|
16
|
+
};
|
|
17
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
18
|
+
showCornerMarks: boolean;
|
|
19
|
+
mode: "screen" | "print" | "pdf";
|
|
20
|
+
pureMode: boolean;
|
|
21
|
+
showHelpers: boolean;
|
|
22
|
+
showRegionBoxes: boolean;
|
|
23
|
+
showPageNumbers: boolean;
|
|
24
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
25
|
+
declare const _default: typeof __VLS_export;
|
|
26
|
+
export default _default;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* composables/paperHelpers.ts
|
|
3
|
+
*
|
|
4
|
+
* usePaperCore 纯函数辅助模块(无 Vue 依赖)
|
|
5
|
+
* 包含字号转换、段落构建、题块创建、文本解析等工具函数
|
|
6
|
+
*/
|
|
7
|
+
import type { ContentBlock, Paragraph, InlineElement, PageSettings } from '../types/paper';
|
|
8
|
+
/** 中文字号 → 像素 */
|
|
9
|
+
export declare const FONT_SIZE_MAP: Record<string, number>;
|
|
10
|
+
/** 中文字号标签 → 像素 */
|
|
11
|
+
export declare function fontSizeLabelToPx(label: string): number;
|
|
12
|
+
/** 像素 → 中文字号标签 */
|
|
13
|
+
export declare function fontSizePxToLabel(px: number): string;
|
|
14
|
+
export declare function getFontSize(s: PageSettings): number;
|
|
15
|
+
export declare function getLineSpacing(s: PageSettings): number;
|
|
16
|
+
export declare function calcLineHeight(fontSize: number, lineSpacing: number): number;
|
|
17
|
+
export declare function createEmptyParagraph(fontSize: number, lineSpacing: number): Paragraph;
|
|
18
|
+
export declare function createParagraph(elements: InlineElement[], fontSize: number, lineSpacing: number, maxWidth?: number, firstLineExtraReduction?: number): Paragraph;
|
|
19
|
+
/**
|
|
20
|
+
* 从末尾向前跳过尾部空段落(答题区),遇到非空段落即停止
|
|
21
|
+
*/
|
|
22
|
+
export declare function countContentParagraphs(block: ContentBlock): number;
|
|
23
|
+
export declare function getBlockAvailableWidth(block: {
|
|
24
|
+
type: string;
|
|
25
|
+
metadata?: Record<string, any>;
|
|
26
|
+
}, columnWidth: number): number;
|
|
27
|
+
export declare function parseInlineSegments(text: string): Array<{
|
|
28
|
+
type: 'text' | 'formula' | 'blank';
|
|
29
|
+
value: string;
|
|
30
|
+
}>;
|
|
31
|
+
export declare function parseQuestionLine(text: string, fontSize: number): InlineElement[];
|
|
32
|
+
export declare function createQuestionBlock(no: string, score: string, textLines: string[], fontSize: number, lineSpacing: number, contentWidth?: number): ContentBlock;
|
|
33
|
+
export declare function createSubQuestionBlocks(no: string, score: string, textLines: string[], fontSize: number, lineSpacing: number, contentWidth?: number): ContentBlock[];
|
|
34
|
+
export declare function getBlockPlainText(block: ContentBlock): string;
|
|
35
|
+
export declare function getBlockLabel(block: ContentBlock): string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* usePageSvgRenderer - 共享的页面 SVG 渲染 composable
|
|
3
|
+
*
|
|
4
|
+
* 提取 PaperEditor 和 PaperPreview 共用的 SVG 渲染逻辑,
|
|
5
|
+
* 确保编辑和预览使用完全一致的渲染管线(所见即所得)。
|
|
6
|
+
*/
|
|
7
|
+
import { type Ref, type ComputedRef } from 'vue';
|
|
8
|
+
import type { usePaperCore } from './usePaperCore';
|
|
9
|
+
/** usePaperCore 返回值类型 */
|
|
10
|
+
type PaperCore = ReturnType<typeof usePaperCore>;
|
|
11
|
+
/** 渲染选项 */
|
|
12
|
+
export interface PageSvgOptions {
|
|
13
|
+
/** 缩放比例(默认 1) */
|
|
14
|
+
zoom?: Ref<number> | number;
|
|
15
|
+
/** 选中的 blockId(编辑器传入响应式值,预览传 null) */
|
|
16
|
+
selectedBlockId?: Ref<string | null> | string | null;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 生成各页 SVG 字符串
|
|
20
|
+
*
|
|
21
|
+
* @param core - usePaperCore 返回值
|
|
22
|
+
* @param options - 渲染选项
|
|
23
|
+
* @returns 各页 SVG 字符串数组
|
|
24
|
+
*/
|
|
25
|
+
export declare function usePageSvgRenderer(core: PaperCore, options?: PageSvgOptions): ComputedRef<string[]>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* composables/usePaperBlockOps.ts
|
|
3
|
+
*
|
|
4
|
+
* 块级 CRUD 操作 Composable
|
|
5
|
+
* 管理 ContentBlock 的增删改、reflow、编号等编辑操作
|
|
6
|
+
*/
|
|
7
|
+
import { type Ref } from 'vue';
|
|
8
|
+
import type { ContentBlock, Paragraph, PageSettings } from '../types/paper';
|
|
9
|
+
import type { PaperLayout } from '../engine/PaperLayout';
|
|
10
|
+
import type { SvgRenderer } from '../engine/SvgRenderer';
|
|
11
|
+
import { getBlockAvailableWidth, getBlockPlainText, getBlockLabel } from './paperHelpers';
|
|
12
|
+
export interface UsePaperBlockOpsDeps {
|
|
13
|
+
blocks: Ref<ContentBlock[]>;
|
|
14
|
+
settings: Ref<PageSettings>;
|
|
15
|
+
pages: Ref<any[]>;
|
|
16
|
+
isDirty: Ref<boolean>;
|
|
17
|
+
layoutEngine: Ref<PaperLayout>;
|
|
18
|
+
svgRenderer: Ref<SvgRenderer>;
|
|
19
|
+
paperName: Ref<string>;
|
|
20
|
+
schoolName: Ref<string>;
|
|
21
|
+
qrCodeContent: Ref<string>;
|
|
22
|
+
qrCodeImage: Ref<string>;
|
|
23
|
+
totalScore: {
|
|
24
|
+
value: number;
|
|
25
|
+
};
|
|
26
|
+
selectedBlockId: Ref<string | null>;
|
|
27
|
+
findInlineImageById: (id: string) => any;
|
|
28
|
+
findUnderlineById: (id: string) => any;
|
|
29
|
+
relayout: () => void;
|
|
30
|
+
}
|
|
31
|
+
export declare function usePaperBlockOps(deps: UsePaperBlockOpsDeps): {
|
|
32
|
+
reflowAllBlocks: () => void;
|
|
33
|
+
addBlock: (block: ContentBlock) => void;
|
|
34
|
+
addTitleBlock: (title: string, beforeId?: string) => void;
|
|
35
|
+
reorderBlocks: (orderedIds: string[]) => void;
|
|
36
|
+
removeBlock: (id: string) => void;
|
|
37
|
+
updateBlockLabel: (id: string, label: string) => void;
|
|
38
|
+
updateBlockContent: (id: string, contentParagraphs: Paragraph[]) => void;
|
|
39
|
+
updateBlockScore: (id: string, score: string) => void;
|
|
40
|
+
toggleContentProtection: (id: string) => void;
|
|
41
|
+
updateShowScore: (val: boolean) => void;
|
|
42
|
+
updateBlockQid: (id: string, qid: string) => void;
|
|
43
|
+
updateBlockHeight: (id: string, targetTotalHeight: number) => void;
|
|
44
|
+
updateBlockQuestionType: (id: string, questionType: string) => void;
|
|
45
|
+
updateBlockSplit: (id: string, split: boolean) => void;
|
|
46
|
+
updateBlockKeepNext: (id: string, keepNext: boolean) => void;
|
|
47
|
+
patchBlock: (id: string, partial: Partial<ContentBlock>) => void;
|
|
48
|
+
patchBlocksMeta: (updates: Array<{
|
|
49
|
+
id: string;
|
|
50
|
+
metadata: Record<string, any>;
|
|
51
|
+
}>) => void;
|
|
52
|
+
recalculateNumbering: () => void;
|
|
53
|
+
updateSectionTitle: (id: string, title: string) => void;
|
|
54
|
+
addNewQuestion: (data: {
|
|
55
|
+
no: string;
|
|
56
|
+
score: string;
|
|
57
|
+
content: string;
|
|
58
|
+
}) => void;
|
|
59
|
+
addQuestionFromHtml: (html: string, no?: string, score?: string) => void;
|
|
60
|
+
addQuestionFromJson: (jsonStr: string, no?: string, score?: string) => void;
|
|
61
|
+
updateInlineImageSize: (id: string, newWidth: number, newHeight?: number) => void;
|
|
62
|
+
getImageParagraphInfo: (id: string) => {
|
|
63
|
+
isStandalone: boolean;
|
|
64
|
+
alignment: "left" | "center" | "right";
|
|
65
|
+
} | null;
|
|
66
|
+
updateImageAlignment: (id: string, alignment: "left" | "center" | "right") => void;
|
|
67
|
+
updateUnderlineWidth: (id: string, newWidth: number) => void;
|
|
68
|
+
parseTextToParagraphs: (text: string, fontSize?: number, lineSpacing?: number, contentWidth?: number) => Paragraph[];
|
|
69
|
+
saveDocument: () => string;
|
|
70
|
+
loadDocument: (json: string, skipReflow?: boolean) => void;
|
|
71
|
+
getBlockPlainText: typeof getBlockPlainText;
|
|
72
|
+
getBlockLabel: typeof getBlockLabel;
|
|
73
|
+
getBlockAvailableWidth: typeof getBlockAvailableWidth;
|
|
74
|
+
};
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { ContentBlock, PageSettings, Page, RenderMode, PaperSize, ColumnMode } from '../types/paper';
|
|
2
|
+
import { PaperLayout } from '../engine/PaperLayout';
|
|
3
|
+
import { SvgRenderer } from '../engine/SvgRenderer';
|
|
4
|
+
export { FONT_SIZE_MAP, fontSizeLabelToPx, fontSizePxToLabel } from './paperHelpers';
|
|
5
|
+
export interface UsePaperCoreOptions {
|
|
6
|
+
renderMode?: RenderMode;
|
|
7
|
+
}
|
|
8
|
+
export declare function usePaperCore(options?: UsePaperCoreOptions): {
|
|
9
|
+
renderMode: import("vue").Ref<RenderMode, RenderMode>;
|
|
10
|
+
blocks: import("vue").ShallowRef<ContentBlock[], ContentBlock[]>;
|
|
11
|
+
pages: import("vue").Ref<{
|
|
12
|
+
index: number;
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
blocks: {
|
|
16
|
+
blockId: string;
|
|
17
|
+
blockType: import("..").BlockType;
|
|
18
|
+
paragraphStart: number;
|
|
19
|
+
paragraphCount: number;
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
}[];
|
|
25
|
+
cornerMarks: {
|
|
26
|
+
position: "tl" | "tr" | "bl" | "br";
|
|
27
|
+
bbox: [number, number, number, number];
|
|
28
|
+
}[];
|
|
29
|
+
renderedRegions: {
|
|
30
|
+
type: "header-desc" | "paper-name" | "qr-code" | "student-name" | "student-class" | "student-code" | "score" | "page-number" | "correction-box" | "title-embed" | "column-separator" | "question-border" | "underline";
|
|
31
|
+
bbox: [number, number, number, number];
|
|
32
|
+
meta?: Record<string, any> | undefined;
|
|
33
|
+
}[];
|
|
34
|
+
}[], Page[] | {
|
|
35
|
+
index: number;
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
blocks: {
|
|
39
|
+
blockId: string;
|
|
40
|
+
blockType: import("..").BlockType;
|
|
41
|
+
paragraphStart: number;
|
|
42
|
+
paragraphCount: number;
|
|
43
|
+
x: number;
|
|
44
|
+
y: number;
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
}[];
|
|
48
|
+
cornerMarks: {
|
|
49
|
+
position: "tl" | "tr" | "bl" | "br";
|
|
50
|
+
bbox: [number, number, number, number];
|
|
51
|
+
}[];
|
|
52
|
+
renderedRegions: {
|
|
53
|
+
type: "header-desc" | "paper-name" | "qr-code" | "student-name" | "student-class" | "student-code" | "score" | "page-number" | "correction-box" | "title-embed" | "column-separator" | "question-border" | "underline";
|
|
54
|
+
bbox: [number, number, number, number];
|
|
55
|
+
meta?: Record<string, any> | undefined;
|
|
56
|
+
}[];
|
|
57
|
+
}[]>;
|
|
58
|
+
settings: import("vue").Ref<{
|
|
59
|
+
paperSize: PaperSize;
|
|
60
|
+
columns: ColumnMode;
|
|
61
|
+
fontSize: number;
|
|
62
|
+
lineSpacing: number;
|
|
63
|
+
margins: [number, number, number, number];
|
|
64
|
+
showCornerMarks: boolean;
|
|
65
|
+
showBBoxes: boolean;
|
|
66
|
+
columnGap: number;
|
|
67
|
+
headerTop: number;
|
|
68
|
+
bodyTopEven: number;
|
|
69
|
+
bodyTopOdd: number;
|
|
70
|
+
showScore: boolean;
|
|
71
|
+
}, PageSettings | {
|
|
72
|
+
paperSize: PaperSize;
|
|
73
|
+
columns: ColumnMode;
|
|
74
|
+
fontSize: number;
|
|
75
|
+
lineSpacing: number;
|
|
76
|
+
margins: [number, number, number, number];
|
|
77
|
+
showCornerMarks: boolean;
|
|
78
|
+
showBBoxes: boolean;
|
|
79
|
+
columnGap: number;
|
|
80
|
+
headerTop: number;
|
|
81
|
+
bodyTopEven: number;
|
|
82
|
+
bodyTopOdd: number;
|
|
83
|
+
showScore: boolean;
|
|
84
|
+
}>;
|
|
85
|
+
selectedBlockId: import("vue").Ref<string | null, string | null>;
|
|
86
|
+
selectedUnderlineId: import("vue").Ref<string | null, string | null>;
|
|
87
|
+
selectedImageId: import("vue").Ref<string | null, string | null>;
|
|
88
|
+
selectedBlock: import("vue").ComputedRef<ContentBlock | null>;
|
|
89
|
+
selectedUnderlineInfo: import("vue").ComputedRef<{
|
|
90
|
+
block: ContentBlock;
|
|
91
|
+
paraIdx: number;
|
|
92
|
+
lineIdx: number;
|
|
93
|
+
elemIdx: number;
|
|
94
|
+
underline: import("..").UnderlineInline;
|
|
95
|
+
} | null>;
|
|
96
|
+
selectedImageInfo: import("vue").ComputedRef<{
|
|
97
|
+
block: ContentBlock;
|
|
98
|
+
paraIdx: number;
|
|
99
|
+
lineIdx: number;
|
|
100
|
+
elemIdx: number;
|
|
101
|
+
image: import("..").ImageInline;
|
|
102
|
+
} | null>;
|
|
103
|
+
totalScore: import("vue").ComputedRef<number>;
|
|
104
|
+
paperName: import("vue").Ref<string, string>;
|
|
105
|
+
schoolName: import("vue").Ref<string, string>;
|
|
106
|
+
qrCodeContent: import("vue").Ref<string, string>;
|
|
107
|
+
qrCodeImage: import("vue").Ref<string, string>;
|
|
108
|
+
isDirty: import("vue").Ref<boolean, boolean>;
|
|
109
|
+
layoutVersion: import("vue").Ref<number, number>;
|
|
110
|
+
setRenderMode: (mode: RenderMode) => void;
|
|
111
|
+
relayout: () => void;
|
|
112
|
+
reflowAllBlocks: () => void;
|
|
113
|
+
updateSettings: (s: Partial<PageSettings>) => void;
|
|
114
|
+
setPaperSize: (size: PaperSize) => void;
|
|
115
|
+
setColumns: (cols: ColumnMode) => void;
|
|
116
|
+
setFontSize: (size: number) => void;
|
|
117
|
+
setLineSpacing: (spacing: number) => void;
|
|
118
|
+
selectBlock: (id: string | null) => void;
|
|
119
|
+
selectUnderline: (id: string | null) => void;
|
|
120
|
+
selectImage: (id: string | null) => void;
|
|
121
|
+
findUnderlineById: (id: string) => {
|
|
122
|
+
block: ContentBlock;
|
|
123
|
+
paraIdx: number;
|
|
124
|
+
lineIdx: number;
|
|
125
|
+
elemIdx: number;
|
|
126
|
+
underline: import("..").UnderlineInline;
|
|
127
|
+
} | null;
|
|
128
|
+
findInlineImageById: (id: string) => {
|
|
129
|
+
block: ContentBlock;
|
|
130
|
+
paraIdx: number;
|
|
131
|
+
lineIdx: number;
|
|
132
|
+
elemIdx: number;
|
|
133
|
+
image: import("..").ImageInline;
|
|
134
|
+
} | null;
|
|
135
|
+
updateUnderlineWidth: (id: string, newWidth: number) => void;
|
|
136
|
+
updateInlineImageSize: (id: string, newWidth: number, newHeight?: number) => void;
|
|
137
|
+
getImageParagraphInfo: (id: string) => {
|
|
138
|
+
isStandalone: boolean;
|
|
139
|
+
alignment: "left" | "center" | "right";
|
|
140
|
+
} | null;
|
|
141
|
+
updateImageAlignment: (id: string, alignment: "left" | "center" | "right") => void;
|
|
142
|
+
addBlock: (block: ContentBlock) => void;
|
|
143
|
+
addTitleBlock: (title: string, beforeId?: string) => void;
|
|
144
|
+
reorderBlocks: (orderedIds: string[]) => void;
|
|
145
|
+
updateBlockLabel: (id: string, label: string) => void;
|
|
146
|
+
removeBlock: (id: string) => void;
|
|
147
|
+
updateBlockContent: (id: string, contentParagraphs: import("..").Paragraph[]) => void;
|
|
148
|
+
updateBlockScore: (id: string, score: string) => void;
|
|
149
|
+
toggleContentProtection: (id: string) => void;
|
|
150
|
+
updateShowScore: (val: boolean) => void;
|
|
151
|
+
updateBlockQid: (id: string, qid: string) => void;
|
|
152
|
+
updateBlockHeight: (id: string, targetTotalHeight: number) => void;
|
|
153
|
+
updateBlockQuestionType: (id: string, questionType: string) => void;
|
|
154
|
+
updateBlockSplit: (id: string, split: boolean) => void;
|
|
155
|
+
updateBlockKeepNext: (id: string, keepNext: boolean) => void;
|
|
156
|
+
addNewQuestion: (data: {
|
|
157
|
+
no: string;
|
|
158
|
+
score: string;
|
|
159
|
+
content: string;
|
|
160
|
+
}) => void;
|
|
161
|
+
addQuestionFromHtml: (html: string, no?: string, score?: string) => void;
|
|
162
|
+
addQuestionFromJson: (jsonStr: string, no?: string, score?: string) => void;
|
|
163
|
+
getBlockPlainText: typeof import("./paperHelpers").getBlockPlainText;
|
|
164
|
+
parseTextToParagraphs: (text: string, fontSize?: number, lineSpacing?: number, contentWidth?: number) => import("..").Paragraph[];
|
|
165
|
+
getBlockLabel: typeof import("./paperHelpers").getBlockLabel;
|
|
166
|
+
getContentWidth: (block: {
|
|
167
|
+
type: string;
|
|
168
|
+
metadata?: Record<string, any>;
|
|
169
|
+
}) => number;
|
|
170
|
+
recalculateNumbering: () => void;
|
|
171
|
+
updateSectionTitle: (id: string, title: string) => void;
|
|
172
|
+
patchBlock: (id: string, partial: Partial<ContentBlock>) => void;
|
|
173
|
+
patchBlocksMeta: (updates: Array<{
|
|
174
|
+
id: string;
|
|
175
|
+
metadata: Record<string, any>;
|
|
176
|
+
}>) => void;
|
|
177
|
+
saveDocument: () => string;
|
|
178
|
+
loadDocument: (json: string, skipReflow?: boolean) => void;
|
|
179
|
+
layoutEngine: import("vue").ShallowRef<PaperLayout, PaperLayout>;
|
|
180
|
+
svgRenderer: import("vue").ShallowRef<SvgRenderer, SvgRenderer>;
|
|
181
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* composables/usePaperCursor.ts
|
|
3
|
+
*
|
|
4
|
+
* 光标状态管理和段落编辑操作
|
|
5
|
+
* 提供 Enter 拆分段落、Backspace/Delete 删除文字/段落、文本插入功能
|
|
6
|
+
* 所有操作保留非文字元素(公式、图片、下划线等)
|
|
7
|
+
*/
|
|
8
|
+
import { type Ref } from 'vue';
|
|
9
|
+
import type { ContentBlock, Paragraph } from '../types/paper';
|
|
10
|
+
import type { PageSettings } from '../types/paper';
|
|
11
|
+
export interface CursorState {
|
|
12
|
+
blockId: string | null;
|
|
13
|
+
paraIndex: number;
|
|
14
|
+
charOffset: number;
|
|
15
|
+
}
|
|
16
|
+
export declare function usePaperCursor(blocks: Ref<ContentBlock[]>, settings: Ref<PageSettings>, reflowAllBlocks: () => void, markDirty: () => void): {
|
|
17
|
+
cursor: Ref<{
|
|
18
|
+
blockId: string | null;
|
|
19
|
+
paraIndex: number;
|
|
20
|
+
charOffset: number;
|
|
21
|
+
}, CursorState | {
|
|
22
|
+
blockId: string | null;
|
|
23
|
+
paraIndex: number;
|
|
24
|
+
charOffset: number;
|
|
25
|
+
}>;
|
|
26
|
+
setCursor: (blockId: string | null, paraIndex: number, charOffset: number) => void;
|
|
27
|
+
clearCursor: () => void;
|
|
28
|
+
getParagraphText: (para: Paragraph) => string;
|
|
29
|
+
isEmptyParagraph: (para: Paragraph) => boolean;
|
|
30
|
+
getTextStyle: (para: Paragraph) => {
|
|
31
|
+
fontFamily: string;
|
|
32
|
+
fontSize: number;
|
|
33
|
+
bold: boolean;
|
|
34
|
+
italic: boolean;
|
|
35
|
+
color: string;
|
|
36
|
+
};
|
|
37
|
+
splitAtCursor: () => boolean;
|
|
38
|
+
backspace: () => boolean;
|
|
39
|
+
deleteForward: () => boolean;
|
|
40
|
+
insertText: (text: string) => boolean;
|
|
41
|
+
moveCursorLeft: () => boolean;
|
|
42
|
+
moveCursorRight: () => boolean;
|
|
43
|
+
moveToParaStart: () => boolean;
|
|
44
|
+
moveToParaEnd: () => boolean;
|
|
45
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* composables/usePaperSelection.ts
|
|
3
|
+
*
|
|
4
|
+
* 选中状态管理 Composable
|
|
5
|
+
* 管理块/下划线/图片的选中互斥和查找逻辑
|
|
6
|
+
*/
|
|
7
|
+
import { type Ref } from 'vue';
|
|
8
|
+
import type { ContentBlock, UnderlineInline, ImageInline } from '../types/paper';
|
|
9
|
+
export declare function usePaperSelection(blocks: Ref<ContentBlock[]>): {
|
|
10
|
+
selectedBlockId: Ref<string | null, string | null>;
|
|
11
|
+
selectedUnderlineId: Ref<string | null, string | null>;
|
|
12
|
+
selectedImageId: Ref<string | null, string | null>;
|
|
13
|
+
selectedBlock: import("vue").ComputedRef<ContentBlock | null>;
|
|
14
|
+
selectedUnderlineInfo: import("vue").ComputedRef<{
|
|
15
|
+
block: ContentBlock;
|
|
16
|
+
paraIdx: number;
|
|
17
|
+
lineIdx: number;
|
|
18
|
+
elemIdx: number;
|
|
19
|
+
underline: UnderlineInline;
|
|
20
|
+
} | null>;
|
|
21
|
+
selectedImageInfo: import("vue").ComputedRef<{
|
|
22
|
+
block: ContentBlock;
|
|
23
|
+
paraIdx: number;
|
|
24
|
+
lineIdx: number;
|
|
25
|
+
elemIdx: number;
|
|
26
|
+
image: ImageInline;
|
|
27
|
+
} | null>;
|
|
28
|
+
selectBlock: (id: string | null) => void;
|
|
29
|
+
selectUnderline: (id: string | null) => void;
|
|
30
|
+
selectImage: (id: string | null) => void;
|
|
31
|
+
findUnderlineById: (id: string) => {
|
|
32
|
+
block: ContentBlock;
|
|
33
|
+
paraIdx: number;
|
|
34
|
+
lineIdx: number;
|
|
35
|
+
elemIdx: number;
|
|
36
|
+
underline: UnderlineInline;
|
|
37
|
+
} | null;
|
|
38
|
+
findInlineImageById: (id: string) => {
|
|
39
|
+
block: ContentBlock;
|
|
40
|
+
paraIdx: number;
|
|
41
|
+
lineIdx: number;
|
|
42
|
+
elemIdx: number;
|
|
43
|
+
image: ImageInline;
|
|
44
|
+
} | null;
|
|
45
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useTableRenderer.ts
|
|
3
|
+
*
|
|
4
|
+
* 表格渲染 Composable:将 HTML 表格(rawHtml)通过 html2canvas 渲染为图片
|
|
5
|
+
*
|
|
6
|
+
* 设计原则:
|
|
7
|
+
* - paper-renderer 核心无 html2canvas 依赖
|
|
8
|
+
* - html2canvas 函数由宿主应用注入
|
|
9
|
+
* - 渲染结果(dataURL)自动回填到 ImageInline.src
|
|
10
|
+
*
|
|
11
|
+
* 用法(宿主侧):
|
|
12
|
+
* import { renderTablePlaceholders } from 'paper-renderer'
|
|
13
|
+
* import html2canvas from 'html2canvas'
|
|
14
|
+
*
|
|
15
|
+
* // 导入题目后调用
|
|
16
|
+
* const blocks = parseQuestionHtml(html)
|
|
17
|
+
* await renderTablePlaceholders(blocks, html2canvas)
|
|
18
|
+
* // 此时 blocks 中的表格 ImageInline 已完成渲染,调用 reflowAllBlocks()
|
|
19
|
+
*/
|
|
20
|
+
import type { ContentBlock } from '../types/paper';
|
|
21
|
+
/**
|
|
22
|
+
* 将 ContentBlock[] 中所有 ImageInline 的 rawHtml
|
|
23
|
+
* 通过 html2canvas 渲染为 dataURL 并回填 src
|
|
24
|
+
*
|
|
25
|
+
* @param blocks ContentBlock 数组(会被原地修改)
|
|
26
|
+
* @param html2canvasFn html2canvas 函数(由宿主传入)
|
|
27
|
+
* @param scale 渲染倍率,默认 2(高清输出)
|
|
28
|
+
*/
|
|
29
|
+
export declare function renderTablePlaceholders(blocks: ContentBlock[], html2canvasFn: (element: HTMLElement, options?: any) => Promise<HTMLCanvasElement>, scale?: number): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* 检查 blocks 中是否包含待渲染的表格占位(ImageInline)
|
|
32
|
+
*/
|
|
33
|
+
export declare function hasTablePlaceholder(blocks: ContentBlock[]): boolean;
|