@sw7d/paper-renderer 0.2.4 → 0.4.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.
Files changed (44) hide show
  1. package/dist/paper-renderer.js +4304 -2541
  2. package/dist/src/components/PaperEditor.vue.d.ts +10 -1
  3. package/dist/src/components/blocks/QuestionBlock.vue.d.ts +9 -0
  4. package/dist/src/components/blocks/TextBlock.vue.d.ts +9 -0
  5. package/dist/src/components/blocks/TitleBlock.vue.d.ts +9 -0
  6. package/dist/src/components/footers/FooterPageNumber.vue.d.ts +8 -0
  7. package/dist/src/components/headers/HeaderEvenPage.vue.d.ts +13 -0
  8. package/dist/src/components/headers/HeaderOddPage.vue.d.ts +12 -0
  9. package/dist/src/components/headers/HeaderSchoolInfo.vue.d.ts +12 -0
  10. package/dist/src/components/inlines/InlineDispatcher.vue.d.ts +12 -0
  11. package/dist/src/components/inlines/InlineEnter.vue.d.ts +10 -0
  12. package/dist/src/components/inlines/InlineFormula.vue.d.ts +10 -0
  13. package/dist/src/components/inlines/InlineImage.vue.d.ts +12 -0
  14. package/dist/src/components/inlines/InlineText.vue.d.ts +12 -0
  15. package/dist/src/components/inlines/InlineUnderline.vue.d.ts +10 -0
  16. package/dist/src/components/inlines/OptionLabelInline.vue.d.ts +10 -0
  17. package/dist/src/components/inlines/ParagraphRenderer.vue.d.ts +19 -0
  18. package/dist/src/components/inlines/QrCodeImage.vue.d.ts +7 -0
  19. package/dist/src/components/inlines/QuestionScoreInline.vue.d.ts +10 -0
  20. package/dist/src/composables/paperHelpers.d.ts +6 -0
  21. package/dist/src/composables/usePaperBlockOps.d.ts +3 -2
  22. package/dist/src/composables/usePaperCore.d.ts +17 -4
  23. package/dist/src/composables/usePaperSelection.d.ts +2 -0
  24. package/dist/src/composables/useVueRenderer.d.ts +39 -0
  25. package/dist/src/engine/AutoLayout.d.ts +74 -0
  26. package/dist/src/engine/BlockRendererRegistry.d.ts +50 -0
  27. package/dist/src/engine/PaperLayout.d.ts +4 -41
  28. package/dist/src/engine/registerDefaults.d.ts +5 -0
  29. package/dist/src/engine/svg/headerRenderer.d.ts +2 -28
  30. package/dist/src/index.d.ts +10 -5
  31. package/dist/src/types/document.d.ts +2 -0
  32. package/dist/src/types/paper.d.ts +39 -7
  33. package/dist/src/types/plugin.d.ts +129 -0
  34. package/dist/src/utils/blockStructure.d.ts +104 -0
  35. package/dist/src/utils/buildAnswerHtml.d.ts +29 -0
  36. package/dist/src/utils/pageRegionCalculator.d.ts +20 -0
  37. package/dist/src/utils/paragraphHeight.d.ts +68 -0
  38. package/dist/src/utils/questionHtmlParser.d.ts +2 -2
  39. package/dist/style.css +1 -1
  40. package/package.json +1 -1
  41. package/dist/src/composables/usePageSvgRenderer.d.ts +0 -26
  42. package/dist/src/engine/SvgRenderer.d.ts +0 -78
  43. package/dist/src/engine/svg/optionsRenderer.d.ts +0 -27
  44. package/dist/src/engine/svg/questionRenderer.d.ts +0 -35
@@ -21,6 +21,9 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
21
21
  addFromText: (text: string, no?: string, score?: string, protectContent?: boolean) => void;
22
22
  remove: (id: string) => void;
23
23
  addTitleBlock: (title: string, beforeId?: string) => void;
24
+ addTextBlock: (beforeId?: string) => void;
25
+ addTextBlockFromContent: (content: string) => void;
26
+ addTextBlockFromHtml: (html: string) => void;
24
27
  reorder: (orderedIds: string[]) => void;
25
28
  updateLabel: (id: string, label: string) => void;
26
29
  updateSectionTitle: (id: string, title: string) => void;
@@ -78,13 +81,18 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
78
81
  y: number;
79
82
  width: number;
80
83
  height: number;
84
+ paraLineRanges?: Record<number, {
85
+ lineStart: number;
86
+ lineCount: number;
87
+ }> | undefined;
88
+ isFirstFragment?: boolean | undefined;
81
89
  }[];
82
90
  cornerMarks: {
83
91
  position: "tl" | "tr" | "bl" | "br";
84
92
  bbox: [number, number, number, number];
85
93
  }[];
86
94
  renderedRegions: {
87
- type: "header-desc" | "paper-name" | "qr-code" | "student-name" | "student-class" | "student-code" | "student-code-filler" | "score" | "page-number" | "correction-box" | "title-embed" | "column-separator" | "question-border" | "underline";
95
+ type: "header-desc" | "paper-name" | "qr-code" | "student-name" | "student-class" | "student-code" | "student-code-filler" | "score" | "page-number" | "correction-box" | "title-embed" | "column-separator" | "question-border" | "underline" | "text-block";
88
96
  bbox: [number, number, number, number];
89
97
  meta?: Record<string, any> | undefined;
90
98
  }[];
@@ -120,6 +128,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
120
128
  lineIdx: number;
121
129
  elemIdx: number;
122
130
  image: import("..").ImageInline;
131
+ optionIdx?: number;
123
132
  } | null;
124
133
  selectedImageAlignment: {
125
134
  isStandalone: boolean;
@@ -0,0 +1,9 @@
1
+ import type { ContentBlock } from '../../types/paper';
2
+ import type { RenderContext } from '../../types/plugin';
3
+ type __VLS_Props = {
4
+ block: ContentBlock;
5
+ ctx: RenderContext;
6
+ };
7
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
8
+ declare const _default: typeof __VLS_export;
9
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import type { ContentBlock } from '../../types/paper';
2
+ import type { RenderContext } from '../../types/plugin';
3
+ type __VLS_Props = {
4
+ block: ContentBlock;
5
+ ctx: RenderContext;
6
+ };
7
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
8
+ declare const _default: typeof __VLS_export;
9
+ export default _default;
@@ -0,0 +1,9 @@
1
+ import type { ContentBlock } from '../../types/paper';
2
+ import type { RenderContext } from '../../types/plugin';
3
+ type __VLS_Props = {
4
+ block: ContentBlock;
5
+ ctx: RenderContext;
6
+ };
7
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
8
+ declare const _default: typeof __VLS_export;
9
+ export default _default;
@@ -0,0 +1,8 @@
1
+ type __VLS_Props = {
2
+ pageIndex: number;
3
+ totalPages: number;
4
+ contentWidth: number;
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
@@ -0,0 +1,13 @@
1
+ type __VLS_Props = {
2
+ schoolName: string;
3
+ paperName: string;
4
+ totalScore: number;
5
+ schoolContentWidth: number;
6
+ contentWidth: number;
7
+ showScore: boolean;
8
+ qrCodeImage?: string;
9
+ editable?: boolean;
10
+ };
11
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
12
+ declare const _default: typeof __VLS_export;
13
+ export default _default;
@@ -0,0 +1,12 @@
1
+ type __VLS_Props = {
2
+ schoolName: string;
3
+ totalScore: number;
4
+ contentWidth: number;
5
+ contentX: number;
6
+ showScore: boolean;
7
+ qrCodeImage?: string;
8
+ editable?: boolean;
9
+ };
10
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,12 @@
1
+ type __VLS_Props = {
2
+ schoolName: string;
3
+ totalScore: number;
4
+ contentX: number;
5
+ contentWidth: number;
6
+ offsetY: number;
7
+ showScore: boolean;
8
+ editable?: boolean;
9
+ };
10
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import type { InlineElement } from '../../types/paper';
2
+ type __VLS_Props = {
3
+ elem: InlineElement;
4
+ x: number;
5
+ baseline: number;
6
+ renderMode: string;
7
+ isImageOnlyLine?: boolean;
8
+ imageId?: string;
9
+ };
10
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import type { EnterInline } from '../../types/paper';
2
+ type __VLS_Props = {
3
+ elem: EnterInline;
4
+ x: number;
5
+ baseline: number;
6
+ renderMode: string;
7
+ };
8
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ declare const _default: typeof __VLS_export;
10
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import type { FormulaInline } from '../../types/paper';
2
+ type __VLS_Props = {
3
+ elem: FormulaInline;
4
+ x: number;
5
+ baseline: number;
6
+ renderMode: string;
7
+ };
8
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ declare const _default: typeof __VLS_export;
10
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import type { ImageInline } from '../../types/paper';
2
+ type __VLS_Props = {
3
+ elem: ImageInline;
4
+ x: number;
5
+ baseline: number;
6
+ renderMode: string;
7
+ isImageOnlyLine?: boolean;
8
+ imageId?: string;
9
+ };
10
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import type { TextInline } from '../../types/paper';
2
+ type __VLS_Props = {
3
+ elem: TextInline;
4
+ x: number;
5
+ baseline: number;
6
+ renderMode: string;
7
+ isImageOnlyLine?: boolean;
8
+ imageId?: string;
9
+ };
10
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import type { UnderlineInline } from '../../types/paper';
2
+ type __VLS_Props = {
3
+ elem: UnderlineInline;
4
+ x: number;
5
+ baseline: number;
6
+ renderMode: string;
7
+ };
8
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ declare const _default: typeof __VLS_export;
10
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import type { OptionLabelInline } from '../../types/paper';
2
+ type __VLS_Props = {
3
+ elem: OptionLabelInline;
4
+ x: number;
5
+ baseline: number;
6
+ renderMode: string;
7
+ };
8
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ declare const _default: typeof __VLS_export;
10
+ export default _default;
@@ -0,0 +1,19 @@
1
+ import type { Paragraph } from '../../types/paper';
2
+ type __VLS_Props = {
3
+ para: Paragraph;
4
+ maxWidth: number;
5
+ /** 段落索引(用于 data-para,PaperEditor 点击定位光标) */
6
+ paraIndex?: number;
7
+ /** 段落 Y 偏移(多段落堆叠时需要) */
8
+ yOffset?: number;
9
+ renderMode: string;
10
+ scoreText?: string;
11
+ isFirstPara?: boolean;
12
+ /** 行级折断:起始行索引(0-based) */
13
+ lineStart?: number;
14
+ /** 行级折断:渲染行数 */
15
+ lineCount?: number;
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<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
18
+ declare const _default: typeof __VLS_export;
19
+ export default _default;
@@ -0,0 +1,7 @@
1
+ type __VLS_Props = {
2
+ src: string;
3
+ size?: number;
4
+ };
5
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
6
+ declare const _default: typeof __VLS_export;
7
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import type { QuestionScoreInline } from '../../types/paper';
2
+ type __VLS_Props = {
3
+ elem: QuestionScoreInline;
4
+ x: number;
5
+ baseline: number;
6
+ renderMode: string;
7
+ };
8
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ declare const _default: typeof __VLS_export;
10
+ export default _default;
@@ -11,6 +11,8 @@ export declare const FONT_SIZE_MAP: Record<string, number>;
11
11
  export declare function fontSizeLabelToPx(label: string): number;
12
12
  /** 像素 → 中文字号标签 */
13
13
  export declare function fontSizePxToLabel(px: number): string;
14
+ /** 段落高度额外偏移量(段落底部留白) */
15
+ export declare const PARA_HEIGHT_EXTRA = 4;
14
16
  export declare function getFontSize(s: PageSettings): number;
15
17
  export declare function getLineSpacing(s: PageSettings): number;
16
18
  export declare function calcLineHeight(fontSize: number, lineSpacing: number): number;
@@ -20,6 +22,10 @@ export declare function createParagraph(elements: InlineElement[], fontSize: num
20
22
  * 从末尾向前跳过尾部空段落(答题区),遇到非空段落即停止
21
23
  */
22
24
  export declare function countContentParagraphs(block: ContentBlock): number;
25
+ export declare function getStemIndent(block: {
26
+ type: string;
27
+ metadata?: Record<string, any>;
28
+ }): number;
23
29
  export declare function getBlockAvailableWidth(block: {
24
30
  type: string;
25
31
  metadata?: Record<string, any>;
@@ -7,7 +7,6 @@
7
7
  import { type Ref } from 'vue';
8
8
  import type { ContentBlock, Paragraph, PageSettings } from '../types/paper';
9
9
  import type { PaperLayout } from '../engine/PaperLayout';
10
- import type { SvgRenderer } from '../engine/SvgRenderer';
11
10
  import { getBlockAvailableWidth, getBlockPlainText, getBlockLabel } from './paperHelpers';
12
11
  export interface UsePaperBlockOpsDeps {
13
12
  blocks: Ref<ContentBlock[]>;
@@ -15,7 +14,6 @@ export interface UsePaperBlockOpsDeps {
15
14
  pages: Ref<any[]>;
16
15
  isDirty: Ref<boolean>;
17
16
  layoutEngine: Ref<PaperLayout>;
18
- svgRenderer: Ref<SvgRenderer>;
19
17
  paperName: Ref<string>;
20
18
  schoolName: Ref<string>;
21
19
  qrCodeContent: Ref<string>;
@@ -36,6 +34,8 @@ export declare function usePaperBlockOps(deps: UsePaperBlockOpsDeps): {
36
34
  canUndo: Ref<boolean, boolean>;
37
35
  addBlock: (block: ContentBlock) => void;
38
36
  addTitleBlock: (title: string, beforeId?: string) => void;
37
+ addTextBlock: (beforeId?: string, content?: string) => void;
38
+ addTextBlockFromHtml: (html: string) => void;
39
39
  reorderBlocks: (orderedIds: string[]) => void;
40
40
  removeBlock: (id: string) => void;
41
41
  updateBlockLabel: (id: string, label: string) => void;
@@ -77,4 +77,5 @@ export declare function usePaperBlockOps(deps: UsePaperBlockOpsDeps): {
77
77
  getBlockAvailableWidth: typeof getBlockAvailableWidth;
78
78
  mergeSubQuestionGroup: (groupId: string) => void;
79
79
  splitMergedBlock: (blockId: string) => void;
80
+ resizeBlockHeight: (id: string, targetTotalHeight: number) => void;
80
81
  };
@@ -1,6 +1,5 @@
1
1
  import type { ContentBlock, PageSettings, Page, RenderMode, PaperSize, ColumnMode } from '../types/paper';
2
2
  import { PaperLayout } from '../engine/PaperLayout';
3
- import { SvgRenderer } from '../engine/SvgRenderer';
4
3
  export { FONT_SIZE_MAP, fontSizeLabelToPx, fontSizePxToLabel } from './paperHelpers';
5
4
  export interface UsePaperCoreOptions {
6
5
  renderMode?: RenderMode;
@@ -21,13 +20,18 @@ export declare function usePaperCore(options?: UsePaperCoreOptions): {
21
20
  y: number;
22
21
  width: number;
23
22
  height: number;
23
+ paraLineRanges?: Record<number, {
24
+ lineStart: number;
25
+ lineCount: number;
26
+ }> | undefined;
27
+ isFirstFragment?: boolean | undefined;
24
28
  }[];
25
29
  cornerMarks: {
26
30
  position: "tl" | "tr" | "bl" | "br";
27
31
  bbox: [number, number, number, number];
28
32
  }[];
29
33
  renderedRegions: {
30
- type: "header-desc" | "paper-name" | "qr-code" | "student-name" | "student-class" | "student-code" | "student-code-filler" | "score" | "page-number" | "correction-box" | "title-embed" | "column-separator" | "question-border" | "underline";
34
+ type: "header-desc" | "paper-name" | "qr-code" | "student-name" | "student-class" | "student-code" | "student-code-filler" | "score" | "page-number" | "correction-box" | "title-embed" | "column-separator" | "question-border" | "underline" | "text-block";
31
35
  bbox: [number, number, number, number];
32
36
  meta?: Record<string, any> | undefined;
33
37
  }[];
@@ -44,13 +48,18 @@ export declare function usePaperCore(options?: UsePaperCoreOptions): {
44
48
  y: number;
45
49
  width: number;
46
50
  height: number;
51
+ paraLineRanges?: Record<number, {
52
+ lineStart: number;
53
+ lineCount: number;
54
+ }> | undefined;
55
+ isFirstFragment?: boolean | undefined;
47
56
  }[];
48
57
  cornerMarks: {
49
58
  position: "tl" | "tr" | "bl" | "br";
50
59
  bbox: [number, number, number, number];
51
60
  }[];
52
61
  renderedRegions: {
53
- type: "header-desc" | "paper-name" | "qr-code" | "student-name" | "student-class" | "student-code" | "student-code-filler" | "score" | "page-number" | "correction-box" | "title-embed" | "column-separator" | "question-border" | "underline";
62
+ type: "header-desc" | "paper-name" | "qr-code" | "student-name" | "student-class" | "student-code" | "student-code-filler" | "score" | "page-number" | "correction-box" | "title-embed" | "column-separator" | "question-border" | "underline" | "text-block";
54
63
  bbox: [number, number, number, number];
55
64
  meta?: Record<string, any> | undefined;
56
65
  }[];
@@ -99,6 +108,7 @@ export declare function usePaperCore(options?: UsePaperCoreOptions): {
99
108
  lineIdx: number;
100
109
  elemIdx: number;
101
110
  image: import("..").ImageInline;
111
+ optionIdx?: number;
102
112
  } | null>;
103
113
  totalScore: import("vue").ComputedRef<number>;
104
114
  paperName: import("vue").Ref<string, string>;
@@ -135,6 +145,7 @@ export declare function usePaperCore(options?: UsePaperCoreOptions): {
135
145
  lineIdx: number;
136
146
  elemIdx: number;
137
147
  image: import("..").ImageInline;
148
+ optionIdx?: number;
138
149
  } | null;
139
150
  updateUnderlineWidth: (id: string, newWidth: number) => void;
140
151
  updateInlineImageSize: (id: string, newWidth: number, newHeight?: number) => void;
@@ -145,6 +156,8 @@ export declare function usePaperCore(options?: UsePaperCoreOptions): {
145
156
  updateImageAlignment: (id: string, alignment: "left" | "center" | "right") => void;
146
157
  addBlock: (block: ContentBlock) => void;
147
158
  addTitleBlock: (title: string, beforeId?: string) => void;
159
+ addTextBlock: (beforeId?: string, content?: string) => void;
160
+ addTextBlockFromHtml: (html: string) => void;
148
161
  reorderBlocks: (orderedIds: string[]) => void;
149
162
  updateBlockLabel: (id: string, label: string) => void;
150
163
  removeBlock: (id: string) => void;
@@ -180,8 +193,8 @@ export declare function usePaperCore(options?: UsePaperCoreOptions): {
180
193
  }>) => void;
181
194
  mergeSubQuestionGroup: (groupId: string) => void;
182
195
  splitMergedBlock: (blockId: string) => void;
196
+ resizeBlockHeight: (id: string, targetTotalHeight: number) => void;
183
197
  saveDocument: () => string;
184
198
  loadDocument: (json: string, skipReflow?: boolean) => void;
185
199
  layoutEngine: import("vue").ShallowRef<PaperLayout, PaperLayout>;
186
- svgRenderer: import("vue").ShallowRef<SvgRenderer, SvgRenderer>;
187
200
  };
@@ -24,6 +24,7 @@ export declare function usePaperSelection(blocks: Ref<ContentBlock[]>): {
24
24
  lineIdx: number;
25
25
  elemIdx: number;
26
26
  image: ImageInline;
27
+ optionIdx?: number;
27
28
  } | null>;
28
29
  selectBlock: (id: string | null) => void;
29
30
  selectUnderline: (id: string | null) => void;
@@ -41,5 +42,6 @@ export declare function usePaperSelection(blocks: Ref<ContentBlock[]>): {
41
42
  lineIdx: number;
42
43
  elemIdx: number;
43
44
  image: ImageInline;
45
+ optionIdx?: number;
44
46
  } | null;
45
47
  };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * composables/useVueRenderer.ts — Vue 驱动的 SVG 渲染管线
3
+ *
4
+ * 使用 Vue 组件树渲染 SVG,替代旧 SvgRenderer 字符串拼接模式。
5
+ * 通过 BlockRendererRegistry 查找 block 对应的 Vue 组件,通过 <component :is> 动态渲染。
6
+ *
7
+ * 使用方式:
8
+ * const renderer = useVueRenderer(core)
9
+ * // renderer.pagesSvg 是响应式的 SVG 字符串数组(与现有 v-html 兼容)
10
+ * // renderer.getCleanPagesSvg() 是纯净模式
11
+ *
12
+ * 注意:此 composable 保持与现有 v-html 管线的兼容性,
13
+ * 输出格式仍是 SVG 字符串数组,但内部已使用 Vue 组件渲染。
14
+ */
15
+ import { type Ref, type ComputedRef } from 'vue';
16
+ import type { usePaperCore } from './usePaperCore';
17
+ type PaperCore = ReturnType<typeof usePaperCore>;
18
+ export interface VueRendererOptions {
19
+ /** 缩放比例 */
20
+ zoom?: Ref<number> | number;
21
+ /** 选中的 blockId */
22
+ selectedBlockId?: Ref<string | null> | string | null;
23
+ }
24
+ /**
25
+ * useVueRenderer — 使用 Vue 组件渲染 SVG 页面的 composable
26
+ *
27
+ * @param core - usePaperCore 实例
28
+ * @param options - 配置选项
29
+ * @returns 各页 SVG 字符串数组(响应式)
30
+ */
31
+ export declare function useVueRenderer(core: PaperCore, options?: VueRendererOptions): ComputedRef<string[]>;
32
+ export declare function getVueRendererCleanSvgs(core: PaperCore): string[];
33
+ /**
34
+ * 将所有页面渲染为单个 SVG 字符串(与旧 SvgRenderer.renderAllPages 兼容)
35
+ * @param core - usePaperCore 实例
36
+ * @returns 单个 <svg> 字符串,所有页面按顺序纵向排列
37
+ */
38
+ export declare function renderAllPagesAsSingleSvg(core: PaperCore): string;
39
+ export {};
@@ -0,0 +1,74 @@
1
+ import type { ContentBlock, Page, PageSettings } from '../types/paper';
2
+ import type { PlacedBlockInfo } from '../types/plugin';
3
+ /** 页面布局约束 — 由 PaperLayout/usePaperCore 传入 */
4
+ export interface AutoLayoutConstraints {
5
+ /** 纸张尺寸 */
6
+ paperSize: string;
7
+ /** 纸张宽度 (px) */
8
+ pageWidth: number;
9
+ /** 纸张高度 (px) */
10
+ pageHeight: number;
11
+ /** 栏数 */
12
+ columns: number;
13
+ /** 栏间距 (px) */
14
+ columnGap: number;
15
+ /** 边距 [top, right, bottom, left] (px) */
16
+ margins: [number, number, number, number];
17
+ /** 首页 body Y 偏移 */
18
+ bodyTopEven: number;
19
+ /** 其他页 body Y 偏移 */
20
+ bodyTopOdd: number;
21
+ /** 字号 (px) */
22
+ fontSize: number;
23
+ /** 行距倍数 */
24
+ lineSpacing: number;
25
+ /** 是否显示分数 */
26
+ showScore: boolean;
27
+ /** footer 距页面顶部距离 (px) */
28
+ footerY: number;
29
+ }
30
+ /** 布局结果 */
31
+ export interface AutoLayoutResult {
32
+ /** 页面数组 */
33
+ pages: Page[];
34
+ /** 每块详细的放置信息 */
35
+ placements: PlacedBlockInfo[];
36
+ }
37
+ export declare class AutoLayout {
38
+ private constraints;
39
+ /**
40
+ * 主入口:将内容块自动排布到页面中
41
+ *
42
+ * @param blocks - 内容块列表
43
+ * @param constraints - 排版约束
44
+ * @returns 排版结果(页 + 放置信息)
45
+ */
46
+ layout(blocks: ContentBlock[], constraints: AutoLayoutConstraints): AutoLayoutResult;
47
+ /**
48
+ * 将单个块放置到页面上(支持段落级拆分)
49
+ * 高度计算已经走注册表,但段落拆分逻辑保留以支持跨页截断
50
+ */
51
+ private placeBlockFragments;
52
+ /**
53
+ * 计算从 lineStart 开始,在 availHeight 内最多能放多少行
54
+ */
55
+ private countFitLines;
56
+ /**
57
+ * 前进到下一栏或下一页(消除重复的换栏/换页逻辑)
58
+ */
59
+ private advanceColumnOrPage;
60
+ private getColumnWidth;
61
+ private getColumnX;
62
+ private createNewPage;
63
+ private finalizePage;
64
+ /**
65
+ * 构建原子段落组:每个组内的段落不可被拆分到不同片段
66
+ *
67
+ * 委托 parseBlockStructure 统一解析块结构,消除重复推算逻辑。
68
+ * 横排选项使用 computeFragmentHeight(取 MAX),竖排选项使用累加高度。
69
+ */
70
+ private buildAtomicGroups;
71
+ private createCornerMarks;
72
+ /** 构建 AutoLayoutConstraints 从 PageSettings */
73
+ static fromSettings(settings: PageSettings, pageWidth: number, pageHeight: number): AutoLayoutConstraints;
74
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * engine/BlockRendererRegistry.ts — 块渲染器与内联元素渲染器注册表
3
+ *
4
+ * 全局静态注册表,管理所有 BlockRenderer 和 InlineRenderer。
5
+ * registerDefaults() 在引擎初始化时调用,注册内置的 question/title/renderInline 等。
6
+ *
7
+ * 第三方扩展方式:
8
+ * import { BlockRendererRegistry } from 'paper-renderer'
9
+ * BlockRendererRegistry.registerBlock({
10
+ * type: 'matching',
11
+ * measureHeight: (block, constraints) => { ... },
12
+ * render: (block, ctx) => { ... }
13
+ * })
14
+ */
15
+ import type { ContentBlock, RenderedRegion, PageBlock } from '../types/paper';
16
+ import type { BlockRenderer, RenderContext, LayoutConstraints } from '../types/plugin';
17
+ export declare class BlockRendererRegistry {
18
+ private static blocks;
19
+ private static _defaultsRegistered;
20
+ /** 注册一个块类型渲染器 */
21
+ static registerBlock(renderer: BlockRenderer): void;
22
+ /** 获取指定类型的块渲染器 */
23
+ static getBlock(type: string): BlockRenderer | undefined;
24
+ /** 获取所有已注册的块类型 */
25
+ static getAllBlockTypes(): string[];
26
+ /** 检查某类型是否已注册 */
27
+ static hasBlock(type: string): boolean;
28
+ /** 移除一个块类型渲染器 */
29
+ static unregisterBlock(type: string): boolean;
30
+ /**
31
+ * 根据 block.type 分派渲染
32
+ * 找不到注册的渲染器时返回空字符串
33
+ */
34
+ static renderBlock(block: ContentBlock, ctx: RenderContext): string;
35
+ /**
36
+ * 测量 block 的自然高度
37
+ * 找不到注册的渲染器时返回 0
38
+ */
39
+ static measureBlock(block: ContentBlock, constraints: LayoutConstraints): number;
40
+ /**
41
+ * 计算 block 的区域坐标(用于 _pages 导出)
42
+ */
43
+ static computeBlockRegions(block: ContentBlock, pb: PageBlock, ctx: RenderContext): RenderedRegion[];
44
+ /** 是否已注册默认渲染器 */
45
+ static get defaultsRegistered(): boolean;
46
+ /** 标记默认渲染器已注册 */
47
+ static markDefaultsRegistered(): void;
48
+ /** 清除所有注册(测试用) */
49
+ static reset(): void;
50
+ }
@@ -2,13 +2,12 @@
2
2
  * PaperLayout - 试卷版面布局引擎
3
3
  *
4
4
  * 核心职责:
5
- * 1. 将内容块流式布局到各页面
5
+ * 1. 将内容块流式布局到各页面(委托给 AutoLayout)
6
6
  * 2. 自动跨页截断(一个题块可在多页间拆分)
7
- * 3. 精确计算每个元素在 SVG 中的坐标
8
- * 4. 支持 A4/A3 切换、单栏/双栏
9
- * 5. 生成四角定位标记
7
+ * 3. 支持 A4/A3 切换、单栏/双栏
8
+ * 4. 生成四角定位标记
10
9
  */
11
- import type { ContentBlock, Page, CornerMark, PageSettings } from '../types/paper';
10
+ import type { ContentBlock, Page, PageSettings } from '../types/paper';
12
11
  export declare class PaperLayout {
13
12
  settings: PageSettings;
14
13
  pageWidth: number;
@@ -17,46 +16,10 @@ export declare class PaperLayout {
17
16
  contentHeight: number;
18
17
  columnWidth: number;
19
18
  columnGap: number;
20
- private readonly FOOTER_EXTRA_GAP;
21
- /** FOOTER_TOP 根据页面高度和底部边距动态计算 */
22
- private get footerTop();
23
19
  constructor(settings?: Partial<PageSettings>);
24
20
  private getDefaultSettings;
25
21
  private updateDimensions;
26
22
  updateSettings(settings: Partial<PageSettings>): void;
27
23
  getColumnX(col: number): number;
28
- /**
29
- * 将内容块排版到页面中
30
- * 支持跨栏/跨页按段落折断
31
- * bodyTop 从 settings.bodyTopEven / bodyTopOdd 读取,不再靠参数传递
32
- */
33
24
  layout(blocks: ContentBlock[]): Page[];
34
- /**
35
- * 统一块折断:将一个 ContentBlock 按段落分发到各栏/各页
36
- * 每个 PageBlock 只包含该片段能容纳的段落(paragraphStart / paragraphCount)
37
- */
38
- private placeBlockFragments;
39
- private finalizePage;
40
- /**
41
- * 测量块高度(包含选项区域)
42
- */
43
- measureBlock(block: ContentBlock): number;
44
- /**
45
- * 测量选项区域总高度
46
- *
47
- * 与 calcOptionsHeight 使用相同的布局策略,确保布局预留高度 = 实际渲染高度:
48
- * - 一行等分排列 → 返回最高选项高度
49
- * - 每个选项单独一行 → 返回高度之和
50
- */
51
- private measureOptionsHeight;
52
- measureParagraph(p: {
53
- lines: Array<{
54
- lineHeight: number;
55
- }>;
56
- }): number;
57
- /**
58
- * 创建四角定位标记 — 根据当前页面尺寸动态计算
59
- * offset 为角标离页面边缘的距离,与参考保持一致(26.46px ≈ 7mm)
60
- */
61
- createCornerMarks(): CornerMark[];
62
25
  }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 注册所有内置默认渲染器
3
+ * 在引擎初始化时调用一次
4
+ */
5
+ export declare function registerDefaultRenderers(): void;