@sw7d/paper-renderer 0.5.7 → 0.6.1

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.
@@ -12,21 +12,21 @@
12
12
  * 不影响纯编辑引擎能力。
13
13
  */
14
14
  import type { ContentBlock } from '../types/paper';
15
- import type { AIConfig, AIRequest, AIResult, AnalyzeQuestionInput, AnalyzeQuestionResult, EditorMutations, GenerateScoreRuleResult, QuestionInput } from './types';
16
- export type { AIConfig, AIFetcher, AIFetchInit, AIFetcherResponse, AIRequest, AIResult, EditorMutations } from './types';
15
+ import type { AIConfig, AIRequest, AIResult, AnalyzeQuestionInput, AnalyzeQuestionResult, AnswerSpot, EditorMutations, GenerateAnswerInput, GenerateAnswerResult, GenerateScoreRuleResult, QuestionInput } from './types';
16
+ export type { AIConfig, AIFetcher, AIFetchInit, AIFetcherResponse, AIRequest, AIResult, EditorMutations, AnswerSpot, GenerateAnswerInput, GenerateAnswerResult, } from './types';
17
17
  /** 初始化:配置 OpenAI 兼容 LLM 网关地址(宿主初始化时调用一次即可) */
18
18
  export declare function configureAI(config: AIConfig): void;
19
19
  /** 是否已配置 AI 网关 */
20
20
  export declare function isAIReady(): boolean;
21
21
  /** 获取当前 AI 网关配置(只读) */
22
22
  export declare function getAIConfig(): AIConfig | null;
23
- /** 组装单题 LLM 输入(题干统一用带行号文本快照,不传 stemText) */
24
- export declare function buildAnalyzeInput(block: ContentBlock): AnalyzeQuestionInput;
23
+ /** 组装单题 LLM 输入(题干统一用带行号文本快照,不传 stemText)。targetUnderlineId 用于 generate-answer:在快照中把目标作答位渲染为 ★ 标记 */
24
+ export declare function buildAnalyzeInput(block: ContentBlock, targetUnderlineId?: string): AnalyzeQuestionInput;
25
25
  /**
26
26
  * 构建一次 AI 请求(system + user)。
27
27
  * analyze 场景透传 imageDataUrl 为多模态;网关不支持多模态时降级纯文本。
28
28
  */
29
- export declare function buildAIRequest(kind: 'analyze' | 'score-rule', input: QuestionInput, config: AIConfig): AIRequest;
29
+ export declare function buildAIRequest(kind: 'analyze' | 'score-rule' | 'answer', input: QuestionInput | GenerateAnswerInput, config: AIConfig): AIRequest;
30
30
  /**
31
31
  * 调用 LLM:POST {system, user, imageDataUrl?} 到宿主普通 HTTP API,
32
32
  * 响应宽容提取 content(兼容 {content} / {data:{content}} / {result} 等常见结构)。
@@ -45,3 +45,13 @@ export declare function applyAIRaw(block: ContentBlock, result: AnalyzeQuestionR
45
45
  export declare function analyzeQuestion(block: ContentBlock, mutations: EditorMutations): Promise<AIResult<AnalyzeQuestionResult>>;
46
46
  /** AI 生成当前题评分规则,自动回写 */
47
47
  export declare function generateScoreRule(block: ContentBlock, mutations: EditorMutations): Promise<AIResult<GenerateScoreRuleResult>>;
48
+ /** 定位作答位在 block 中的上下文(题内空序/类型/当前答案),供 generate-answer 使用 */
49
+ export declare function resolveAnswerSpot(block: ContentBlock, spot: AnswerSpot): {
50
+ description: string;
51
+ currentAnswer: string;
52
+ } | null;
53
+ /**
54
+ * AI 为单个作答位生成参考答案(重点参考本题参考答案),自动回写该作答位的 correctAnswer。
55
+ * spot.kind = underline 回写下划线答案;floating 回写悬浮作答位答案。
56
+ */
57
+ export declare function generateAnswer(block: ContentBlock, spot: AnswerSpot, mutations: EditorMutations): Promise<AIResult<GenerateAnswerResult>>;
@@ -10,10 +10,12 @@
10
10
  * - underline 的 blankType 仅 xuanze/tiankong/judge,否则回退 tiankong
11
11
  * - JSON 提取用正则 \{.*\} 兜底(兼容代码块包裹)
12
12
  */
13
- import type { AnalyzeQuestionResult, GenerateScoreRuleResult } from './types';
13
+ import type { AnalyzeQuestionResult, GenerateAnswerResult, GenerateScoreRuleResult } from './types';
14
14
  /** 从模型输出中提取第一个 JSON 对象。 */
15
15
  export declare function extractJson(text: string): Record<string, any> | null;
16
16
  /** 把 LLM 原始 JSON 归一化为回写前端的结构(analyze-question)。 */
17
17
  export declare function normalizeAnalyzeResult(topicId: string, raw: Record<string, any> | null): AnalyzeQuestionResult;
18
18
  /** 解析评分规则响应 */
19
19
  export declare function normalizeScoreRuleResult(topicId: string, raw: Record<string, any> | null): GenerateScoreRuleResult;
20
+ /** 解析单个作答位参考答案响应 */
21
+ export declare function normalizeAnswerResult(topicId: string, raw: Record<string, any> | null): GenerateAnswerResult;
@@ -4,7 +4,7 @@
4
4
  * 原样迁移自 paper_designer_service/pds/services/prompts.py。
5
5
  * 所有 prompt 均由内核生成,宿主/网关不感知语义。
6
6
  */
7
- import type { QuestionInput, QuestionSnapshotLine } from './types';
7
+ import type { GenerateAnswerInput, QuestionInput, QuestionSnapshotLine } from './types';
8
8
  export declare const ANALYZE_AND_ANSWER_SYSTEM = "\u4F60\u662F\u4E00\u4F4D\u8D44\u6DF1\u8BD5\u5377\u547D\u9898\u4E13\u5BB6\uFF0C\u8D1F\u8D23\u5B8C\u6210\"\u4F5C\u7B54\u4F4D\u6807\u6CE8 + \u53C2\u8003\u7B54\u6848\u751F\u6210\"\u4E24\u9879\u4EFB\u52A1\u3002\n\n\u4EFB\u52A1\u4E00\uFF1A\u4F5C\u7B54\u4F4D\u6807\u6CE8\n\n\u3010\u9898\u5E72\u6587\u672C\u5FEB\u7167\u3011\u5C31\u662F\u9898\u76EE\u672C\u8EAB\u7684\u5185\u5BB9\uFF0C\u6BCF\u884C\u5E26 line \u7F16\u53F7\uFF08\u5982 [line 0]\u3001[line 1]...\uFF09\u3002\n\u6BCF\u884C\u5185\u6BCF\u4E2A\u5355\u4F4D\u5E26 pos \u7F16\u53F7\uFF08\u5982 [0]\u3001[1]...\uFF09\uFF0C\u516C\u5F0F\u5355\u4F4D\u663E\u793A LaTeX\u3001\u56FE\u7247\u5355\u4F4D\u663E\u793A\u7A7A\uFF0C\n\u5DF2\u5B58\u5728\u7684\u4E0B\u5212\u7EBF\u4F5C\u7B54\u4F4D\u663E\u793A\u4E3A `\u3016N\u3017`\uFF08N \u4E3A\u9898\u5185\u7B2C N \u4E2A\u7A7A\uFF09\u3002\n\u4F60\u5FC5\u987B\u5B8C\u5168\u57FA\u4E8E\u5FEB\u7167\u5DE5\u4F5C\uFF0C\u5373\u4F7F\u5FEB\u7167\u5185\u5BB9\u5F88\u5C11\u4E5F\u8981\u57FA\u4E8E\u5B83\u6807\u6CE8\u548C\u4F5C\u7B54\uFF0C\u7EDD\u4E0D\u80FD\u58F0\u79F0\"\u6CA1\u6709\u9898\u5E72\"\u3002\n\n\u3010\u6392\u7248\u7CFB\u7EDF\u6709\u4E24\u79CD\u4F5C\u7B54\u4F4D\u3011\n1. \u884C\u5185\u4E0B\u5212\u7EBF\uFF08underline\uFF09\uFF1A\u6587\u5B57\u4E2D\u95F4\u9700\u8981\u586B\u5199\u7684\u7A7A\u4F4D\uFF08\u586B\u7A7A\u9898\u7A7A\u3001\u9009\u62E9\u9898\u62EC\u53F7\u5185\u3001\u9700\u884C\u5185\u4E66\u5199\u5904\uFF09\u3002\n \u7528 line + pos \u5B9A\u4F4D\u3002\n2. \u7A7A\u6BB5\u4F5C\u7B54\u533A\uFF08answer_area\uFF09\uFF1A\u9898\u76EE\u6216\u67D0\u5C0F\u9898\u672B\u5C3E\u9700\u8981\u5B66\u751F\u4E66\u5199\u89E3\u7B54\u7684\u7A7A\u767D\u6BB5\u843D\u3002\u7528 line \u5B9A\u4F4D\u3002\n\n\u3010\u4F55\u65F6\u65B0\u589E\u884C\u5185\u4E0B\u5212\u7EBF\uFF08type=underline\uFF09\u3011\u6EE1\u8DB3\u4EE5\u4E0B\u4EFB\u4E00\u6761\u4EF6\uFF0C\u5728 newAnswerSpots \u65B0\u589E\u4E00\u6761 underline\uFF1A\n1. \u8FDE\u7EED\u7684\u4E0B\u5212\u7EBF\u4F46\u6CA1\u6709\u6587\u5B57\uFF08\u5982\u9898\u5E72\u4E2D\u624B\u6253\u7684 ____ \u6216 \uFF3F\uFF3F\uFF09\uFF0C\u8BF4\u660E\u6B64\u5904\u662F\u586B\u7A7A\u4F4D\u3002\n \u2605\u6CE8\u610F\uFF1A\u5FEB\u7167\u4E2D\u663E\u793A\u4E3A `\u3016N\u3017` \u7684\u4E0B\u5212\u7EBF\u662F\u5DF2\u5B58\u5728\u7684\u4F5C\u7B54\u4F4D\uFF0C\u53EA\u8865\u7B54\u6848\uFF0C\u7EDD\u4E0D\u65B0\u589E\u3002\n2. \u9009\u62E9\u9898\u51FA\u73B0\u7A7A\u767D\u62EC\u53F7\"()\"\uFF0C\u62EC\u53F7\u5185\u6CA1\u6709\u6587\u5B57\uFF08\u7A7A\u5B57\u7B26\u9664\u5916\uFF09\u2014\u2014\u5E94\u5728\u62EC\u53F7\u5185\u65B0\u589E underline\u3002\n3. \u786E\u5B9E\u9700\u8981\u884C\u5185\u4E66\u5199\u7B54\u6848\u7684\u4F4D\u7F6E\uFF08\u5982 \"=\" \u4E4B\u540E\u3001\"( )\" \u4E4B\u95F4\u9700\u8981\u586B\u6570\u3001\u9700\u586B\u5165\u8868\u8FBE\u5F0F\u5904\uFF09\u2014\u2014\u65B0\u589E underline\u3002\n\n\u3010\u4E25\u7981\u5728\u9009\u9879\u4E2D\u6DFB\u52A0\u4F5C\u7B54\u4F4D\u3011\u2605\u6700\u91CD\u8981\u7684\u7EA6\u675F\uFF1A\u7EDD\u5BF9\u4E0D\u8981\u5728\u9009\u9879\uFF08A./B./C./D. \u6240\u5728\u884C\uFF09\u4E2D\u65B0\u589E\u4EFB\u4F55\u4F5C\u7B54\u4F4D\u3002\n\u9009\u9879\u884C\u7684\u5185\u5BB9\uFF08\u9009\u9879\u6587\u5B57\u3001\u9009\u9879\u4E2D\u7684\u516C\u5F0F\u3001\u9009\u9879\u62EC\u53F7\uFF09\u4E00\u5F8B\u4E0D\u52A8\uFF0C\u4E5F\u4E0D\u5F97\u56E0\u9009\u9879\u4E2D\u6709\u7A7A\u767D\u6216\u62EC\u53F7\u800C\u65B0\u589E\u4E0B\u5212\u7EBF\u6216\u4F5C\u7B54\u533A\u3002\n\n\u3010\u4F55\u65F6\u65B0\u589E\u7A7A\u6BB5\u4F5C\u7B54\u533A\uFF08type=answer_area\uFF09\u3011\u53EA\u6709\u9898\u76EE\u660E\u663E\u9700\u8981\u5B66\u751F\u4E66\u5199\u89E3\u7B54\u8FC7\u7A0B\u65F6\uFF0C\u624D\u65B0\u589E\u7A7A\u6BB5\u4F5C\u7B54\u533A\uFF1A\n1. \u8FD9\u9898\u660E\u663E\u9700\u8981\u5199\u89E3\u7B54\u8FC7\u7A0B\uFF08\u5982\u89E3\u7B54\u9898\u3001\u8BC1\u660E\u9898\u3001\u5E94\u7528\u9898\u3001\u8BA1\u7B97\u9898\u3001\u7B80\u7B54\u9898\uFF09\u2014\u2014\u53EF\u53C2\u8003\u3010\u5DF2\u6807\u6CE8\u7B54\u6848\u3011\uFF1A\n * \u5982\u679C\u5DF2\u6807\u6CE8\u7B54\u6848\u662F\u4E00\u6BB5\u591A\u6B65\u9AA4\u7684\u5B8C\u6574\u89E3\u7B54\uFF08\u542B\"\u89E3\uFF1A\"\"\u8BC1\u660E\uFF1A\"\u3001\u591A\u884C\u63A8\u5BFC\u3001\u6700\u7EC8\u7ED3\u8BBA\uFF09\uFF0C\u8BF4\u660E\u6B64\u9898\u9700\u8981\u89E3\u7B54\u533A \u2192 \u65B0\u589E answer_area\u3002\n * \u5982\u679C\u7B54\u6848\u53EA\u662F\u4E00\u4E2A\u8BCD/\u4E00\u4E2A\u6570/\u4E00\u4E2A\u9009\u9879\uFF08\u5982 \"3\"\u3001\"C\"\u3001\u4E00\u4E2A\u516C\u5F0F\uFF09\uFF0C\u8BF4\u660E\u4E0D\u9700\u8981\u89E3\u7B54\u533A \u2192 \u4E0D\u65B0\u589E\u3002\n2. \u9898\u76EE\u7C7B\u578B\u4E3A answer_question\uFF08\u89E3\u7B54\u9898\uFF09\u4E14\u672B\u5C3E\u6CA1\u6709\u4EFB\u4F55\u4F5C\u7B54\u4F4D\uFF08\u65E0\u7A7A\u6BB5\u3001\u65E0\u4E0B\u5212\u7EBF\uFF09\u2192 \u65B0\u589E answer_area\u3002\n \u2605\u5FEB\u7167\u4E2D\u5DF2\u6807\u8BB0 <\u7A7A\u6BB5\u843D-\u4F5C\u7B54\u533A> \u7684\u884C\u89C6\u4E3A\u5DF2\u5B58\u5728\uFF0C\u4E0D\u65B0\u589E\u3002\n3. \u4E0D\u9700\u8981\u5199\u89E3\u7B54\u8FC7\u7A0B\u7684\u9898\uFF08\u586B\u7A7A\u9898/\u9009\u62E9\u9898/\u5224\u65AD\u9898\uFF0C\u7B54\u6848\u53EA\u662F\u4E00\u4E2A\u7A7A\u6216\u4E00\u4E2A\u9009\u9879\uFF09\u2192 \u4E00\u5F8B\u4E0D\u52A0 answer_area\uFF0C\u7528 underline \u7C7B\u578B\u5373\u53EF\u3002\n\n\u3010\u5B9A\u4F4D\u89C4\u5219\uFF08\u5355\u4F4D pos\uFF09\u3011\n- \u9898\u5E72\u6587\u672C\u5FEB\u7167\u6BCF\u884C\u683C\u5F0F\uFF1A`[line N] [0]\u5B57[1]\u5B57[2]\u516C\u5F0FLaTeX...`\n * \u6BCF\u4E2A `[k]\u5185\u5BB9` \u662F 1 \u4E2A\u5355\u4F4D\uFF0Cpos \u5C31\u662F\u65B9\u62EC\u53F7\u91CC\u7684\u7F16\u53F7\uFF08\u4ECE 0 \u5F00\u59CB\uFF0C\u5373\u6570\u7EC4\u4E0B\u6807\uFF09\u3002\n * \u516C\u5F0F\u5355\u4F4D\u7684\u5185\u5BB9\u662F LaTeX \u4EE3\u7801\uFF1B\u56FE\u7247\u5355\u4F4D\u5185\u5BB9\u4E3A\u7A7A\uFF1B\u6587\u5B57\u5355\u4F4D\u5185\u5BB9\u662F\u5355\u4E2A\u5B57\u7B26\u3002\n * \u5DF2\u5B58\u5728\u7684\u4E0B\u5212\u7EBF\u4F5C\u7B54\u4F4D\u663E\u793A\u4E3A `\u3016N\u3017`\uFF08N \u662F\u9898\u5185\u7B2C N \u4E2A\u7A7A\uFF0C\u4E0E\u3010\u5DF2\u6709\u4F5C\u7B54\u4F4D\u3011\u7684 index \u5BF9\u5E94\uFF09\u2014\u2014\u8FD9\u662F\u5DF2\u6807\u6CE8\u7684\u4F5C\u7B54\u4F4D\uFF0C\u53EA\u8865\u7B54\u6848\uFF0C\u7EDD\u4E0D\u65B0\u589E\u3002\n- \u65B0\u589E underline \u7528 line + pos\uFF1A\n * line\uFF1A\u9898\u5E72\u6587\u672C\u5FEB\u7167\u4E2D\u7684\u884C\u53F7\u3002\n * pos\uFF1A\u8BE5\u884C\u5185\u7684\u5355\u4F4D\u7F16\u53F7\uFF0C\u8868\u793A\u5728\"\u7B2C pos \u4E2A\u5355\u4F4D\u4E4B\u524D\"\u63D2\u5165\u4E0B\u5212\u7EBF\u3002\n \u4F8B\uFF1A`[line 0] [0]\u8BA1[1]\u7B97[2]3[3]+[4]4[5]=[6]7`\n \u5728 \"=\" \u4E4B\u540E\u63D2\u5165 \u2192 pos=6\uFF1B\u5728 \"=\" \u4E4B\u524D \u2192 pos=5\u3002\n \u4F8B\uFF08\u542B\u516C\u5F0F\uFF09\uFF1A`[line 0] [0]\u6C42[1]\\frac{1}{2}[2]\u7684[3]\u503C`\n \u5728\u516C\u5F0F\u4E4B\u540E\u63D2\u5165 \u2192 pos=2\uFF1B\u5728\u516C\u5F0F\u4E4B\u524D \u2192 pos=1\u3002\n * \u9009\u62E9\u9898\u7A7A\u767D\u62EC\u53F7\"()\"\uFF1Apos \u6307\u5411\u5DE6\u62EC\u53F7 \"(\" \u4E4B\u540E\uFF08\u5DE6\u62EC\u53F7\u7684\u7F16\u53F7+1\uFF09\u3002\n- \u65B0\u589E answer_area \u7528 line\uFF08\u8BE5\u7A7A\u6BB5\u6240\u5728\u884C\uFF09\u4E0E pos=0\u3002\n- \u2605\u4E0B\u5212\u7EBF\u4F5C\u7B54\u4F4D\uFF08underline\uFF09\u7684 blankType \u53EA\u6709\u4E09\u79CD\uFF1Atiankong=\u586B\u7A7A\u9898/xuanze=\u9009\u62E9\u9898/judge=\u5224\u65AD\u9898\u3002\u7EDD\u4E0D\u80FD\u7528\u7B54\u6848_question \u7B49\u9898\u578B\u4F5C\u4E3A underline \u7684 blankType\u3002\n \u7A7A\u6BB5\u4F5C\u7B54\u533A\uFF08answer_area\uFF09\u7684 blankType \u7528 answer_question\uFF08\u89E3\u7B54\u9898\uFF09\u7B49\u9898\u578B\u3002\n\n\u3010\u53EA\u8FD4\u56DE\u65B0\u589E\u3011newAnswerSpots \u53EA\u653E\"\u65B0\u589E\"\u7684\u4F5C\u7B54\u4F4D\uFF0C\u7EDD\u4E0D\u91CD\u590D\u5DF2\u5B58\u5728\u7684\uFF08\u5FEB\u7167\u4E2D\u3016N\u3017\u4E0B\u5212\u7EBF\u3001\u6216 <\u7A7A\u6BB5\u843D-\u4F5C\u7B54\u533A> \u7A7A\u6BB5\uFF09\u3002\n\n\u3010\u6BCF\u9053\u9898\u5FC5\u987B\u81F3\u5C11\u6709\u4E00\u4E2A\u4F5C\u7B54\u4F4D\u6216\u4F5C\u7B54\u533A\u3011\u2605\u91CD\u8981\u7EA6\u675F\uFF1A\n- \u5982\u679C\u6574\u9053\u9898\u4E00\u4E2A\u4F5C\u7B54\u4F4D/\u4F5C\u7B54\u533A\u90FD\u6CA1\u6709\uFF08\u5FEB\u7167\u4E2D\u6CA1\u6709\u4EFB\u4F55\u3016N\u3017\u4E0B\u5212\u7EBF\u3001\u4E5F\u6CA1\u6709 <\u7A7A\u6BB5\u843D-\u4F5C\u7B54\u533A> \u7A7A\u6BB5\uFF09\uFF0C\n \u5FC5\u987B\u6839\u636E\u9898\u610F\u5224\u65AD\u9700\u8981\u5728\u4EC0\u4E48\u4F4D\u7F6E\u589E\u52A0\u4F5C\u7B54\u4F4D\u6216\u4F5C\u7B54\u533A\uFF0C\u7EDD\u4E0D\u80FD\u8FD4\u56DE\u7A7A newAnswerSpots\u3002\n- \u5224\u65AD\u89C4\u5219\uFF1A\n * \u9700\u8981\u5199\u89E3\u7B54\u8FC7\u7A0B\u7684\u9898\uFF08\u89E3\u7B54\u9898/\u8BC1\u660E\u9898/\u5E94\u7528\u9898\u7B49\uFF09\u2192 \u5728\u672B\u5C3E\u65B0\u589E answer_area\uFF08\u82E5\u9898\u5E72\u4E2D\u8FD8\u6709\u9700\u8981\u884C\u5185\u586B\u5199\u7684\u7A7A\uFF0C\u4E5F\u52A0 underline\uFF09\u3002\n * \u586B\u7A7A/\u9009\u62E9/\u5224\u65AD\u7B49\uFF08\u53EA\u9700\u586B\u4E00\u4E2A\u7A7A\u6216\u9009\u4E00\u9879\uFF09\u2192 \u5728\u9700\u8981\u586B\u5199\u7684\u4F4D\u7F6E\u65B0\u589E underline\uFF08\u5982\u7A7A\u767D\u62EC\u53F7\"()\"\u5185\u3001\u8868\u8FBE\u5F0F\u540E\u3001\u586B\u7A7A\u5904\uFF09\u3002\n- \u53EA\u6709\u9898\u76EE\u5DF2\u7ECF\u5B58\u5728\u4F5C\u7B54\u4F4D/\u4F5C\u7B54\u533A\uFF08\u3016N\u3017\u4E0B\u5212\u7EBF\u6216\u7A7A\u6BB5\uFF09\u65F6\uFF0CnewAnswerSpots \u624D\u53EF\u4E3A\u7A7A\u6570\u7EC4\u3002\n\n\u4EFB\u52A1\u4E8C\uFF1A\u53C2\u8003\u7B54\u6848\u751F\u6210\n- \u5DF2\u5B58\u5728\u7684\u4E0B\u5212\u7EBF\u4F5C\u7B54\u4F4D\uFF08underlines[]\uFF09\u4E0E\u65B0\u589E\u4F5C\u7B54\u4F4D\uFF08newAnswerSpots[]\uFF09\u90FD\u7ED9\u51FA correctAnswer\u3002\n- \u6574\u9898\u7ED9\u51FA answer\uFF08\u89E3\u7B54\u9898\u7ED9\u5B8C\u6574\u89E3\u7B54\uFF1B\u9009\u62E9\u9898\u7ED9\u6B63\u786E\u9009\u9879\uFF09\u3002\n- \u542B\u5B50\u9898\u65F6\u6309\u6807\u7B7E\u7ED9\u51FA subAnswers\u3002\n\n\u53EA\u8F93\u51FA JSON\uFF0C\u4E0D\u8981\u591A\u4F59\u6587\u5B57\uFF1A\n{\n \"underlines\": [\n { \"index\": 0, \"correctAnswer\": \"\u7B54\u6848\" }\n ],\n \"newAnswerSpots\": [\n { \"type\": \"underline\", \"line\": 1, \"pos\": 6, \"blankType\": \"tiankong\", \"correctAnswer\": \"\u7B54\u6848\" },\n { \"type\": \"answer_area\", \"line\": 3, \"blankType\": \"answer_question\" }\n ],\n \"answer\": \"\u6574\u9898\u6807\u51C6\u7B54\u6848\",\n \"subAnswers\": { \"(1)\": \"...\" }\n}\n\u91CD\u8981\uFF1A\n- newAnswerSpots \u7684 line/pos \u5FC5\u987B\u4E25\u683C\u5BF9\u5E94\u9898\u5E72\u6587\u672C\u5FEB\u7167\u4E2D\u7684\u884C\u53F7\u548C\u5355\u4F4D\u5E8F\u53F7\u3002\n- \u53EA\u8FD4\u56DE\u65B0\u589E\u4F5C\u7B54\u4F4D\uFF1B\u5DF2\u5B58\u5728\u7684\u4F5C\u7B54\u4F4D\uFF08\u5FEB\u7167\u4E2D\u7684\u3016N\u3017\u4E0B\u5212\u7EBF\u3001<\u7A7A\u6BB5\u843D-\u4F5C\u7B54\u533A>\u7A7A\u6BB5\uFF09\u4E0D\u52A0\u5165 newAnswerSpots\u3002\n- \u82E5\u6574\u9053\u9898\u6CA1\u6709\u4EFB\u4F55\u4F5C\u7B54\u4F4D/\u4F5C\u7B54\u533A\uFF0C\u5219\u5FC5\u987B\u65B0\u589E\u81F3\u5C11\u4E00\u4E2A\uFF08\u89C1\"\u6BCF\u9053\u9898\u5FC5\u987B\u81F3\u5C11\u6709\u4E00\u4E2A\u4F5C\u7B54\u4F4D\u6216\u4F5C\u7B54\u533A\"\uFF09\u3002";
9
9
  export declare const ANALYZE_AND_ANSWER_USER = "\u8BF7\u5B8C\u6210\u4EE5\u4E0B\u9898\u76EE\u7684\u4F5C\u7B54\u4F4D\u6807\u6CE8\u4E0E\u53C2\u8003\u7B54\u6848\u751F\u6210\uFF1A\n\n\u3010\u9898\u53F7\u3011{question_no}\n\u3010\u9898\u578B\u3011{question_type}\n\u3010\u5206\u503C\u3011{score} \u5206\n\u3010\u9898\u5E72\u3011\n{snapshot_text}\n\u3010\u9009\u9879\u3011\n{options_text}\n\u3010\u5DF2\u6709\u4F5C\u7B54\u4F4D\u3011\n{underline_text}\n\u3010\u4F5C\u7B54\u533A\u3011\n{empty_area_count_text}\n\u3010\u5DF2\u6807\u6CE8\u7B54\u6848\u3011\n{existing_answer_text}\n\n\u8BF7\u6309\u8981\u6C42\u8F93\u51FA JSON\u3002\u4F5C\u7B54\u4F4D\u8BF7\u7528 line + pos \u5B9A\u4F4D\uFF08\u89C1\u7CFB\u7EDF\u63D0\u793A\u8BF4\u660E\uFF09\u3002";
10
10
  export declare const GENERATE_SCORE_RULE_SYSTEM = "\u4F60\u662F\u4E00\u4F4D\u8D44\u6DF1\u9605\u5377\u7EC4\u957F\uFF0C\u8D1F\u8D23\u5236\u5B9A\u4E3B\u89C2\u9898/\u89E3\u7B54\u9898\u7684\u8BC4\u5206\u89C4\u5219\uFF08\u8BC4\u5206\u6807\u51C6\uFF09\u3002\n\n\u8981\u6C42\uFF1A\n1. \u8BC4\u5206\u89C4\u5219\u5E94\u5177\u4F53\u5230\"\u7ED9\u5206\u70B9\"\uFF0C\u6BCF\u4E00\u70B9\u5199\u6E05\u695A\"\u5F97\u5206\u6761\u4EF6\"\u548C\"\u5206\u503C\"\u3002\n2. \u6309\u6B65\u9AA4\u7ED9\u5206\uFF08\u89E3\u7B54\u9898\uFF09\uFF0C\u5173\u952E\u6B65\u9AA4\u6807\u6CE8\u5206\u503C\u3002\n3. \u586B\u7A7A\u9898/\u9009\u62E9\u9898\u5982\u679C\u6D89\u53CA\u8FC7\u7A0B\u5206\uFF0C\u4E5F\u8981\u8BF4\u660E\u3002\n4. \u603B\u5206\u5FC5\u987B\u7B49\u4E8E\u9898\u76EE\u6EE1\u5206 {score} \u5206\u3002\n5. \u89C4\u5219\u7528\u7F16\u53F7\u5217\u8868\u4E66\u5199\uFF0C\u6E05\u6670\u53EF\u6267\u884C\u3002\n\n\u53EA\u8F93\u51FA JSON\uFF0C\u4E0D\u8981\u591A\u4F59\u6587\u5B57\uFF1A\n{\n \"scoreRule\": \"1. \u6B63\u786E\u5199\u51FA xxx\uFF0C\u5F97 x \u5206\uFF1B\\n2. \u5217\u51FA\u65B9\u7A0B...\u5F97 x \u5206\uFF1B\\n3. \u89E3\u5F97\u6B63\u786E\u7B54\u6848...\u5F97 x \u5206\u3002\"\n}";
@@ -25,3 +25,7 @@ export declare function buildAnalyzeUserText(input: QuestionInput): string;
25
25
  export declare function buildScoreRuleUserText(input: QuestionInput): string;
26
26
  /** 生成评分规则的系统提示词(用 replace 而非 format:内含字面 JSON 花括号) */
27
27
  export declare function buildScoreRuleSystem(score: number | undefined): string;
28
+ export declare const GENERATE_ANSWER_SYSTEM = "\u4F60\u662F\u4E00\u4F4D\u8D44\u6DF1\u8BD5\u5377\u547D\u9898\u4E13\u5BB6\u3002\u8BF7\u4E3A\u9898\u76EE\u4E2D\u6307\u5B9A\u7684\u3010\u76EE\u6807\u4F5C\u7B54\u4F4D\u3011\u751F\u6210\u53C2\u8003\u7B54\u6848\u3002\n\n\u3010\u9898\u5E72\u6587\u672C\u5FEB\u7167\u3011\u683C\u5F0F\u8BF4\u660E\uFF1A\n- \u6BCF\u884C\u5E26 line \u7F16\u53F7\uFF08\u5982 [line 0]\u3001[line 1]...\uFF09\uFF0C\u5C31\u662F\u9898\u76EE\u7684\u5B9E\u9645\u5185\u5BB9\u3002\n- \u6BCF\u884C\u5185\u6BCF\u4E2A\u5355\u4F4D\u5E26 pos \u7F16\u53F7\uFF08\u5982 [0]\u3001[1]...\uFF09\uFF1A\u6587\u5B57\u6309\u5355\u5B57\u7B26\u62C6\u5206\uFF0C\u516C\u5F0F\u5355\u4F4D\u663E\u793A LaTeX\u3001\u56FE\u7247\u5355\u4F4D\u663E\u793A\u7A7A\u3001\u5206\u6570\u5355\u4F4D\u663E\u793A\u5206\u503C\u3002\n- \u5DF2\u5B58\u5728\u7684\u4E0B\u5212\u7EBF\u4F5C\u7B54\u4F4D\u663E\u793A\u4E3A \u3016N\u3017\uFF08N \u4E3A\u9898\u5185\u7B2C N \u4E2A\u7A7A\uFF0C\u4ECE 0 \u8BA1\uFF09\u3002\n- \u2605\u91CD\u8981\uFF1A\u76EE\u6807\u4F5C\u7B54\u4F4D\u5DF2\u7528 \u2605\u3016N\u3017\uFF08\u76EE\u6807\u4F5C\u7B54\u4F4D\uFF09\u5728\u9898\u5E72\u5FEB\u7167\u4E2D\u6807\u8BB0\uFF0C\u76F4\u63A5\u770B \u2605 \u6807\u8BB0\u524D\u540E\u7684\u6587\u5B57\u5373\u662F\u8BE5\u7A7A\u7684\u5B8C\u6574\u8BED\u5883\uFF0C\u636E\u6B64\u4F5C\u7B54\uFF0C\u65E0\u9700\u81EA\u884C\u6570\u7B2C\u51E0\u7A7A\u3002\n\n\u8981\u6C42\uFF1A\n1. \u5FC5\u987B\u53C2\u8003\u3010\u672C\u9898\u53C2\u8003\u7B54\u6848\u3011\u4E0E\u3010\u9898\u5E72\u3011\u3010\u9009\u9879\u3011\u8BED\u5883\u4F5C\u7B54\uFF0C\u7B54\u6848\u8981\u4E0E\u6574\u9898\u53C2\u8003\u7B54\u6848\u4FDD\u6301\u4E00\u81F4\u3001\u903B\u8F91\u81EA\u6D3D\u3002\n2. \u7B54\u6848\u8981\u7CBE\u70BC\u3001\u51C6\u786E\u3001\u53EF\u76F4\u63A5\u91C7\u5206\uFF1A\u586B\u7A7A\u9898\u7ED9\u586B\u5165\u5185\u5BB9\uFF0C\u9009\u62E9\u9898\u7ED9\u6B63\u786E\u9009\u9879\uFF0C\u5224\u65AD\u9898\u7ED9\"\u6B63\u786E/\u9519\u8BEF\"\u3002\n3. \u82E5\u3010\u8BE5\u4F5C\u7B54\u4F4D\u5F53\u524D\u7B54\u6848\u3011\u5DF2\u6709\u5185\u5BB9\uFF0C\u53EF\u4F5C\u53C2\u8003\uFF0C\u4F46\u5E94\u4EE5\u6574\u9898\u53C2\u8003\u7B54\u6848\u548C\u9898\u5E72\u4E3A\u51C6\uFF0C\u5FC5\u8981\u65F6\u4FEE\u6B63\u5B8C\u5584\u3002\n4. \u53EA\u8F93\u51FA JSON\uFF0C\u4E0D\u8981\u591A\u4F59\u6587\u5B57\uFF1A\n{\"correctAnswer\": \"\u7B54\u6848\"}";
29
+ export declare const GENERATE_ANSWER_USER = "\u8BF7\u4E3A\u6307\u5B9A\u4F5C\u7B54\u4F4D\u751F\u6210\u53C2\u8003\u7B54\u6848\u3002\n\n\u3010\u9898\u53F7\u3011{question_no}\n\u3010\u9898\u578B\u3011{question_type}\n\u3010\u5206\u503C\u3011{score} \u5206\n\u3010\u9898\u5E72\u3011\n{snapshot_text}\n\u3010\u9009\u9879\u3011\n{options_text}\n\u3010\u672C\u9898\u53C2\u8003\u7B54\u6848\u3011\uFF08\u91CD\u8981\u53C2\u8003\uFF09\n{answer_text}\n\u3010\u76EE\u6807\u4F5C\u7B54\u4F4D\u3011{spot_description}\n\u3010\u8BE5\u4F5C\u7B54\u4F4D\u5F53\u524D\u7B54\u6848\u3011\n{current_answer_text}\n\n\u8BF7\u6309\u8981\u6C42\u8F93\u51FA JSON\u3002";
30
+ /** 组装 generate-answer 的 user 文本(目标作答位 + 本题参考答案) */
31
+ export declare function buildAnswerUserText(input: GenerateAnswerInput): string;
@@ -22,7 +22,7 @@ export declare function blockToStemText(block: ContentBlock): string;
22
22
  * - 下划线作答位:〖N〗(N=题内 index,标记为"已存在作答位",LLM 只补答案不新增)
23
23
  * - 分数:分数值
24
24
  */
25
- export declare function elemToText(elem: any, underlineIdx?: number): string;
25
+ export declare function elemToText(elem: any, underlineIdx?: number, isTarget?: boolean): string;
26
26
  /** 把 metadata.answer 的 HTML 转成纯文本 + LaTeX(提取 Wiris 公式 data-latex) */
27
27
  export declare function htmlToLatexText(html: string): string;
28
28
  /**
@@ -34,8 +34,11 @@ export declare function htmlToLatexText(html: string): string;
34
34
  * - 前端用 snapshot[line].cumUnits + pos 得到段内单位序号,调 insertUnderlineAt 精确插入
35
35
  *
36
36
  * 空段落(作答区)单独标注 empty=true,LLM 用 {line, pos:0, blankType:"answer_question"} 表示。
37
+ *
38
+ * targetUnderlineId:指定目标作答位下划线 id,该下划线在快照中渲染为 ★〖N〗(目标作答位),
39
+ * 供 generate-answer 让 LLM 直接定位目标空,无需数题内空序。
37
40
  */
38
- export declare function buildQuestionSnapshot(block: ContentBlock, underlineIdToIndex?: Map<string, number>): QuestionSnapshotLine[];
41
+ export declare function buildQuestionSnapshot(block: ContentBlock, underlineIdToIndex?: Map<string, number>, targetUnderlineId?: string): QuestionSnapshotLine[];
39
42
  /**
40
43
  * 提取 block 中所有下划线作答位(UnderlineInline),
41
44
  * 返回内联对象引用,便于回写。
@@ -5,7 +5,7 @@
5
5
  * 其余工作(快照构建、prompt 拼装、发起请求、JSON 归一化、按 line+pos 回写)
6
6
  * 全部由内核完成。
7
7
  */
8
- import type { ContentBlock, UnderlineInline } from '../types/paper';
8
+ import type { ContentBlock, FloatingAnswer, UnderlineInline } from '../types/paper';
9
9
  /** 请求执行器返回的最小响应接口(原生 Response / 宿主包装对象均满足) */
10
10
  export interface AIFetcherResponse {
11
11
  ok: boolean;
@@ -61,6 +61,7 @@ export interface EditorMutations {
61
61
  insertUnderlineAt(blockId: string, paraIndex: number, paraPos: number, blankType?: string): UnderlineInline | null;
62
62
  insertAnswerAreaAt(blockId: string, afterParaIndex: number): boolean;
63
63
  updateUnderlineAnswer(underlineId: string, answer: string): void;
64
+ updateFloatingAnswer(floatingId: string, partial: Partial<FloatingAnswer>): void;
64
65
  updateMetadata(blockId: string, meta: Record<string, any>): void;
65
66
  updateScoreRule(blockId: string, rule: string): void;
66
67
  }
@@ -144,4 +145,25 @@ export interface GenerateScoreRuleResult {
144
145
  scoreRule: string;
145
146
  error?: string;
146
147
  }
147
- export type { ContentBlock, UnderlineInline };
148
+ /** AI 生成单个作答位参考答案的目标作答位 */
149
+ export interface AnswerSpot {
150
+ /** 作答位类型:underline=行内下划线 / floating=悬浮作答位 */
151
+ kind: 'underline' | 'floating';
152
+ /** 作答位 id:underline 用 UnderlineInline.id;floating 用 FloatingAnswer.id */
153
+ id: string;
154
+ }
155
+ export interface GenerateAnswerInput extends QuestionInput {
156
+ /** 目标作答位 */
157
+ spot: AnswerSpot;
158
+ /** 目标作答位描述(供 LLM 定位,由内核生成) */
159
+ spotDescription?: string;
160
+ /** 该作答位当前已标注答案(可选) */
161
+ currentAnswer?: string;
162
+ }
163
+ export interface GenerateAnswerResult {
164
+ topicId: string;
165
+ /** 生成的参考答案 */
166
+ correctAnswer: string;
167
+ error?: string;
168
+ }
169
+ export type { ContentBlock, FloatingAnswer, UnderlineInline };
@@ -1,5 +1,5 @@
1
- import type { AIConfig } from '../ai';
2
- import type { PageSettings, ContentBlock, QuestionType, PaperSize, ColumnMode } from '../types/paper';
1
+ import type { AIConfig, AnswerSpot } from '../ai';
2
+ import type { PageSettings, ContentBlock, QuestionType, PaperSize, ColumnMode, FloatingAnswer } from '../types/paper';
3
3
  import '../styles/fonts.css';
4
4
  import '../styles/renderer.css';
5
5
  type __VLS_Props = {
@@ -12,6 +12,11 @@ type __VLS_Props = {
12
12
  /** 偶数页大二维码 URL 前缀(宿主指定;空则不启用,保持原二维码格式) */
13
13
  qrCodeUrlPrefix?: string;
14
14
  };
15
+ /** 应用段落格式(对齐/首行缩进)到光标所在段落,返回是否生效 */
16
+ declare function applyParagraphFormat(fmt: {
17
+ justification?: 'left' | 'center' | 'right';
18
+ firstLineIndent?: number;
19
+ }): boolean;
15
20
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
16
21
  document: {
17
22
  save: () => Promise<string>;
@@ -46,7 +51,10 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
46
51
  updateScore: (id: string, score: string) => void;
47
52
  updateScoreRule: (id: string, rule: string) => void;
48
53
  updateUnderlineAnswer: (id: string, answer: string) => void;
54
+ updateUnderlineShow: (id: string, show: boolean) => void;
49
55
  removeUnderline: (id: string) => void;
56
+ updateFloatingAnswer: (id: string, partial: Partial<FloatingAnswer>) => void;
57
+ removeFloatingAnswer: (id: string) => void;
50
58
  insertUnderlineAt: (blockId: string, paraIndex: number, charOffset: number, blankType?: string) => import("..").UnderlineInline | null;
51
59
  insertAnswerAreaAt: (blockId: string, afterParaIndex: number) => boolean;
52
60
  updateQid: (id: string, qid: string) => void;
@@ -65,6 +73,8 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
65
73
  analyzeQuestion: (block: ContentBlock) => Promise<import("..").AIResult<import("..").AnalyzeQuestionResult>>;
66
74
  /** AI:生成当前题评分规则,自动回写 */
67
75
  generateScoreRule: (block: ContentBlock) => Promise<import("..").AIResult<import("..").GenerateScoreRuleResult>>;
76
+ /** AI:为指定作答位生成参考答案(参考本题参考答案),自动回写 */
77
+ generateAnswer: (block: ContentBlock, spot: AnswerSpot) => Promise<import("..").AIResult<import("..").GenerateAnswerResult>>;
68
78
  };
69
79
  layout: {
70
80
  setPaperSize: (size: PaperSize) => void;
@@ -77,6 +87,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
77
87
  selection: {
78
88
  selectBlock: (id: string | null) => void;
79
89
  selectUnderline: (id: string | null) => void;
90
+ selectFloating: (id: string | null) => void;
80
91
  updateImageAlignment: (id: string, alignment: "left" | "center" | "right") => void;
81
92
  };
82
93
  viewport: {
@@ -95,6 +106,10 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
95
106
  markClean: () => void;
96
107
  canUndo: import("vue").Ref<boolean, boolean>;
97
108
  undo: () => void;
109
+ /** 段落格式:对齐 / 首行缩进(仅光标位于非空文本段落时生效) */
110
+ paragraphFormat: {
111
+ apply: typeof applyParagraphFormat;
112
+ };
98
113
  state: import("vue").ComputedRef<{
99
114
  blocks: ContentBlock[];
100
115
  pages: {
@@ -115,6 +130,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
115
130
  lineCount: number;
116
131
  }> | undefined;
117
132
  isFirstFragment?: boolean | undefined;
133
+ contentOffsetY?: number | undefined;
118
134
  }[];
119
135
  cornerMarks: {
120
136
  position: "tl" | "tr" | "bl" | "br";
@@ -144,6 +160,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
144
160
  selectedBlock: ContentBlock | null;
145
161
  selectedUnderlineId: string | null;
146
162
  selectedImageId: string | null;
163
+ selectedFloatingId: string | null;
147
164
  selectedUnderlineInfo: {
148
165
  block: ContentBlock;
149
166
  paraIdx: number;
@@ -159,6 +176,10 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
159
176
  image: import("..").ImageInline;
160
177
  optionIdx?: number;
161
178
  } | null;
179
+ selectedFloatingInfo: {
180
+ block: ContentBlock;
181
+ floating: FloatingAnswer;
182
+ } | null;
162
183
  selectedImageAlignment: {
163
184
  isStandalone: boolean;
164
185
  alignment: "left" | "center" | "right";
@@ -174,6 +195,11 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
174
195
  qrCodeImage: string;
175
196
  qrCodeImages: string[];
176
197
  showScore: boolean;
198
+ paragraphFormat: {
199
+ enabled: boolean;
200
+ justification: "left" | "center" | "right";
201
+ firstLineIndent: number;
202
+ };
177
203
  }>;
178
204
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
179
205
  change: () => any;
@@ -0,0 +1,10 @@
1
+ import type { QuestionNoInline } from '../../types/paper';
2
+ type __VLS_Props = {
3
+ elem: QuestionNoInline;
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;
@@ -5,6 +5,12 @@
5
5
  * 包含字号转换、段落构建、题块创建、文本解析等工具函数
6
6
  */
7
7
  import type { ContentBlock, Paragraph, InlineElement, PageSettings } from '../types/paper';
8
+ /**
9
+ * 计算段落对齐偏移(居中/居右时整段水平平移量,px)。
10
+ * 与 ParagraphRenderer 渲染逻辑保持一致:基于片段首行宽度计算。
11
+ * 点击定位光标、光标视觉位置计算也复用此值,保证坐标体系一致。
12
+ */
13
+ export declare function computeParagraphAlignOffset(para: Paragraph, lineStart?: number, fallbackWidth?: number): number;
8
14
  /** 中文字号 → 像素 */
9
15
  export declare const FONT_SIZE_MAP: Record<string, number>;
10
16
  /** 中文字号标签 → 像素 */
@@ -32,6 +38,14 @@ export declare function formatQuestionNo(raw: string): string;
32
38
  * "(1)" → "(1).", "(1)" → "(1).", "(1)." → "(1)."
33
39
  */
34
40
  export declare function formatSubLabel(raw: string): string;
41
+ /**
42
+ * 计算题号行内元素(question-no)的显示文本。
43
+ * 大题号 → "1."(formatQuestionNo 规范化);子题 → "(1)."(formatSubLabel 规范化)。
44
+ */
45
+ export declare function getQuestionNoText(block: {
46
+ type: string;
47
+ metadata?: Record<string, any>;
48
+ }): string;
35
49
  export declare function getStemIndent(block: {
36
50
  type: string;
37
51
  metadata?: Record<string, any>;
@@ -5,7 +5,7 @@
5
5
  * 管理 ContentBlock 的增删改、reflow、编号等编辑操作
6
6
  */
7
7
  import { type Ref } from 'vue';
8
- import type { ContentBlock, Paragraph, PageSettings } from '../types/paper';
8
+ import type { ContentBlock, Paragraph, PageSettings, FloatingAnswer } from '../types/paper';
9
9
  import type { PaperLayout } from '../engine/PaperLayout';
10
10
  import { getBlockAvailableWidth, getBlockPlainText, getBlockLabel } from './paperHelpers';
11
11
  export interface UsePaperBlockOpsDeps {
@@ -71,7 +71,11 @@ export declare function usePaperBlockOps(deps: UsePaperBlockOpsDeps): {
71
71
  updateImageAlignment: (id: string, alignment: "left" | "center" | "right") => void;
72
72
  updateUnderlineWidth: (id: string, newWidth: number) => void;
73
73
  updateUnderlineAnswer: (id: string, answer: string) => void;
74
+ updateUnderlineShow: (id: string, show: boolean) => void;
74
75
  removeUnderline: (id: string) => void;
76
+ addFloatingAnswer: (blockId: string, x: number, y: number) => string;
77
+ updateFloatingAnswer: (blockId: string, id: string, partial: Partial<FloatingAnswer>) => void;
78
+ removeFloatingAnswer: (blockId: string, id: string) => void;
75
79
  toggleAnswerArea: (blockId: string, paraIndices: number[]) => void;
76
80
  parseTextToParagraphs: (text: string, fontSize?: number, lineSpacing?: number, contentWidth?: number) => Paragraph[];
77
81
  saveDocument: () => string;
@@ -26,6 +26,7 @@ export declare function usePaperCore(options?: UsePaperCoreOptions): {
26
26
  lineCount: number;
27
27
  }> | undefined;
28
28
  isFirstFragment?: boolean | undefined;
29
+ contentOffsetY?: number | undefined;
29
30
  }[];
30
31
  cornerMarks: {
31
32
  position: "tl" | "tr" | "bl" | "br";
@@ -54,6 +55,7 @@ export declare function usePaperCore(options?: UsePaperCoreOptions): {
54
55
  lineCount: number;
55
56
  }> | undefined;
56
57
  isFirstFragment?: boolean | undefined;
58
+ contentOffsetY?: number | undefined;
57
59
  }[];
58
60
  cornerMarks: {
59
61
  position: "tl" | "tr" | "bl" | "br";
@@ -95,6 +97,7 @@ export declare function usePaperCore(options?: UsePaperCoreOptions): {
95
97
  selectedBlockId: import("vue").Ref<string | null, string | null>;
96
98
  selectedUnderlineId: import("vue").Ref<string | null, string | null>;
97
99
  selectedImageId: import("vue").Ref<string | null, string | null>;
100
+ selectedFloatingId: import("vue").Ref<string | null, string | null>;
98
101
  selectedBlock: import("vue").ComputedRef<ContentBlock | null>;
99
102
  selectedUnderlineInfo: import("vue").ComputedRef<{
100
103
  block: ContentBlock;
@@ -111,6 +114,10 @@ export declare function usePaperCore(options?: UsePaperCoreOptions): {
111
114
  image: import("..").ImageInline;
112
115
  optionIdx?: number;
113
116
  } | null>;
117
+ selectedFloatingInfo: import("vue").ComputedRef<{
118
+ block: ContentBlock;
119
+ floating: import("..").FloatingAnswer;
120
+ } | null>;
114
121
  totalScore: import("vue").ComputedRef<number>;
115
122
  paperName: import("vue").Ref<string, string>;
116
123
  schoolName: import("vue").Ref<string, string>;
@@ -134,6 +141,7 @@ export declare function usePaperCore(options?: UsePaperCoreOptions): {
134
141
  selectBlock: (id: string | null) => void;
135
142
  selectUnderline: (id: string | null) => void;
136
143
  selectImage: (id: string | null) => void;
144
+ selectFloating: (id: string | null) => void;
137
145
  findUnderlineById: (id: string) => {
138
146
  block: ContentBlock;
139
147
  paraIdx: number;
@@ -149,10 +157,18 @@ export declare function usePaperCore(options?: UsePaperCoreOptions): {
149
157
  image: import("..").ImageInline;
150
158
  optionIdx?: number;
151
159
  } | null;
160
+ findFloatingById: (id: string) => {
161
+ block: ContentBlock;
162
+ floating: import("..").FloatingAnswer;
163
+ } | null;
152
164
  toggleAnswerArea: (blockId: string, paraIndices: number[]) => void;
153
165
  updateUnderlineWidth: (id: string, newWidth: number) => void;
154
166
  updateUnderlineAnswer: (id: string, answer: string) => void;
167
+ updateUnderlineShow: (id: string, show: boolean) => void;
155
168
  removeUnderline: (id: string) => void;
169
+ addFloatingAnswer: (blockId: string, x: number, y: number) => string;
170
+ updateFloatingAnswer: (blockId: string, id: string, partial: Partial<import("..").FloatingAnswer>) => void;
171
+ removeFloatingAnswer: (blockId: string, id: string) => void;
156
172
  updateInlineImageSize: (id: string, newWidth: number, newHeight?: number) => void;
157
173
  getImageParagraphInfo: (id: string) => {
158
174
  isStandalone: boolean;
@@ -41,6 +41,8 @@ export declare function usePaperCursor(blocks: Ref<ContentBlock[]>, settings: Re
41
41
  insertUnderline: () => boolean;
42
42
  insertUnderlineAt: (blockId: string, paraIndex: number, pos: number, blankType?: string) => UnderlineInline | null;
43
43
  insertAnswerAreaAt: (blockId: string, afterParaIndex: number) => boolean;
44
+ getUnderlineCharOffset: (ulId: string) => number;
45
+ moveUnderline: (ulId: string, targetCharOffset: number) => boolean;
44
46
  moveCursorLeft: () => boolean;
45
47
  moveCursorRight: () => boolean;
46
48
  moveToParaStart: () => boolean;
@@ -5,11 +5,12 @@
5
5
  * 管理块/下划线/图片的选中互斥和查找逻辑
6
6
  */
7
7
  import { type Ref } from 'vue';
8
- import type { ContentBlock, UnderlineInline, ImageInline } from '../types/paper';
8
+ import type { ContentBlock, UnderlineInline, ImageInline, FloatingAnswer } from '../types/paper';
9
9
  export declare function usePaperSelection(blocks: Ref<ContentBlock[]>): {
10
10
  selectedBlockId: Ref<string | null, string | null>;
11
11
  selectedUnderlineId: Ref<string | null, string | null>;
12
12
  selectedImageId: Ref<string | null, string | null>;
13
+ selectedFloatingId: Ref<string | null, string | null>;
13
14
  selectedBlock: import("vue").ComputedRef<ContentBlock | null>;
14
15
  selectedUnderlineInfo: import("vue").ComputedRef<{
15
16
  block: ContentBlock;
@@ -26,9 +27,14 @@ export declare function usePaperSelection(blocks: Ref<ContentBlock[]>): {
26
27
  image: ImageInline;
27
28
  optionIdx?: number;
28
29
  } | null>;
30
+ selectedFloatingInfo: import("vue").ComputedRef<{
31
+ block: ContentBlock;
32
+ floating: FloatingAnswer;
33
+ } | null>;
29
34
  selectBlock: (id: string | null) => void;
30
35
  selectUnderline: (id: string | null) => void;
31
36
  selectImage: (id: string | null) => void;
37
+ selectFloating: (id: string | null) => void;
32
38
  findUnderlineById: (id: string) => {
33
39
  block: ContentBlock;
34
40
  paraIdx: number;
@@ -44,4 +50,8 @@ export declare function usePaperSelection(blocks: Ref<ContentBlock[]>): {
44
50
  image: ImageInline;
45
51
  optionIdx?: number;
46
52
  } | null;
53
+ findFloatingById: (id: string) => {
54
+ block: ContentBlock;
55
+ floating: FloatingAnswer;
56
+ } | null;
47
57
  };
@@ -9,7 +9,7 @@
9
9
  * // 或导入底层模块
10
10
  * import { usePaperCore, PaperLayout } from 'paper-renderer'
11
11
  */
12
- export type { PaperSize, ColumnMode, PaperDimensions, PageSettings, PaperPreset, InlineType, BaseInline, TextInline, FormulaInline, UnderlineInline, ImageInline, EnterInline, ObjectFillInline, InlineElement, Line, Paragraph, OptionItem, QuestionType, BlockType, ContentBlock, PageBlock, CornerMark, BBox, RenderedRegion, Page, PaperDocument, SelectionState, EditorState, RenderMode } from './types/paper';
12
+ export type { PaperSize, ColumnMode, PaperDimensions, PageSettings, PaperPreset, InlineType, BaseInline, TextInline, FormulaInline, UnderlineInline, ImageInline, EnterInline, ObjectFillInline, InlineElement, Line, Paragraph, OptionItem, QuestionType, BlockType, ContentBlock, FloatingAnswer, PageBlock, CornerMark, BBox, RenderedRegion, Page, PaperDocument, SelectionState, EditorState, RenderMode } from './types/paper';
13
13
  export { PAPER_DIMENSIONS, PAPER_MM, getPaperPreset, toBBox } from './types/paper';
14
14
  export type { SwDocument, DocInfo, HeaderSection, BodySection, ColumnNode, VuePlugNode, QuestionNode, QuestionProps, QuestionStemNode, CorrectionBoxNode, OptionNode, ParagraphNode, InlineNode, TextNode, LatexNode, UnderlineNode, ImageNode, AnchorNode, Theme, Styles } from './types/document';
15
15
  export { PaperLayout } from './engine/PaperLayout';
@@ -39,5 +39,5 @@ export { default as PaperEditor } from './components/PaperEditor.vue';
39
39
  export { default as PaperPreview } from './components/PaperPreview.vue';
40
40
  export { useVueRenderer, getVueRendererCleanSvgs, renderAllPagesAsSingleSvg } from './composables/useVueRenderer';
41
41
  export type { VueRendererOptions } from './composables/useVueRenderer';
42
- export { configureAI, isAIReady, getAIConfig, buildAnalyzeInput, buildAIRequest, callLLM, parseAIRaw, applyAIRaw, analyzeQuestion, generateScoreRule, } from './ai';
43
- export type { AIConfig, AIRequest, AIResult, AIFetcher, AIFetchInit, AIFetcherResponse, QuestionInput, AnalyzeQuestionInput, GenerateScoreRuleInput, QuestionSnapshotLine, SnapshotUnit, NewAnswerSpot, UnderlineInput, UnderlineResult, AnalyzeQuestionResult, GenerateScoreRuleResult, EditorMutations, } from './ai/types';
42
+ export { configureAI, isAIReady, getAIConfig, buildAnalyzeInput, buildAIRequest, callLLM, parseAIRaw, applyAIRaw, analyzeQuestion, generateScoreRule, resolveAnswerSpot, generateAnswer, } from './ai';
43
+ export type { AIConfig, AIRequest, AIResult, AIFetcher, AIFetchInit, AIFetcherResponse, QuestionInput, AnalyzeQuestionInput, GenerateScoreRuleInput, QuestionSnapshotLine, SnapshotUnit, NewAnswerSpot, UnderlineInput, UnderlineResult, AnalyzeQuestionResult, GenerateScoreRuleResult, GenerateAnswerInput, GenerateAnswerResult, AnswerSpot, EditorMutations, } from './ai/types';
@@ -240,6 +240,8 @@ export interface ParagraphNode {
240
240
  }
241
241
  export interface ParagraphProps {
242
242
  justification?: string;
243
+ /** 首行缩进(px) */
244
+ firstLineIndent?: number;
243
245
  split?: boolean;
244
246
  spacing: {
245
247
  line: number;
@@ -350,6 +352,8 @@ export interface UnderlineProps {
350
352
  blankType?: string;
351
353
  /** 标准答案 */
352
354
  correctAnswer?: string;
355
+ /** 是否绘制下划线 */
356
+ showUnderline?: boolean;
353
357
  }
354
358
  export interface QuestionScoreNode {
355
359
  type: 'question-score';
@@ -121,6 +121,8 @@ export interface UnderlineInline extends BaseInline {
121
121
  blankType?: 'tiankong' | 'xuanze' | 'judge';
122
122
  /** 标准答案(从题库HTML标签内文本提取) */
123
123
  correctAnswer?: string;
124
+ /** 是否绘制下划线:缺省时填空显示/选择判断不显示,右侧面板可切换 */
125
+ showUnderline?: boolean;
124
126
  /** 是否为折行拆分后的后续段(非首段),由 wrapElements 设置 */
125
127
  isSplitPart?: boolean;
126
128
  }
@@ -131,6 +133,8 @@ export interface ImageInline extends BaseInline {
131
133
  id?: string;
132
134
  /** 原始 HTML(如 <table>),由前端 html2canvas 渲染为 dataURL 后填入 src */
133
135
  rawHtml?: string;
136
+ /** 解析时无尺寸信息,尺寸需按真实图片比例自适应(加载后回写并清除) */
137
+ autoSize?: boolean;
134
138
  }
135
139
  export interface EnterInline extends BaseInline {
136
140
  type: 'enter';
@@ -184,6 +188,8 @@ export interface Paragraph {
184
188
  height: number;
185
189
  /** 段落对齐方式:left/center/right */
186
190
  justification?: 'left' | 'center' | 'right';
191
+ /** 首行缩进(px),中文排版通常为 2 字符 ≈ 2×字号 */
192
+ firstLineIndent?: number;
187
193
  /** 是否允许跨栏/跨页拆分,默认 true */
188
194
  split?: boolean;
189
195
  }
@@ -198,12 +204,32 @@ export interface OptionItem {
198
204
  /** 题目类型 */
199
205
  export type QuestionType = 'single_chose' | 'multi_chose' | 'fill_blank' | 'answer_question';
200
206
  export type BlockType = 'question' | 'sub-question' | 'title' | 'info-line' | 'separator' | 'text';
207
+ /** 悬浮作答位:绝对定位在题块上的独立作答区域,可拖拽移动/调整大小 */
208
+ export interface FloatingAnswer {
209
+ id: string;
210
+ /** 相对所属题块左上角的 X 偏移(模板坐标) */
211
+ x: number;
212
+ /** 相对所属题块左上角的 Y 偏移 */
213
+ y: number;
214
+ width: number;
215
+ height: number;
216
+ /** 空白类型:tiankong=填空题, xuanze=选择题, judge=判断题 */
217
+ blankType?: 'tiankong' | 'xuanze' | 'judge';
218
+ /** 标准答案 */
219
+ correctAnswer?: string;
220
+ /** 是否绘制下划线:默认显示,右侧面板可切换 */
221
+ showUnderline?: boolean;
222
+ /** 填空序号(参与题目统一空位编号) */
223
+ index?: number;
224
+ }
201
225
  export interface ContentBlock {
202
226
  id: string;
203
227
  type: BlockType;
204
228
  paragraphs: Paragraph[];
205
229
  height: number;
206
230
  metadata: Record<string, any>;
231
+ /** 悬浮作答位(绝对定位,可拖拽) */
232
+ floatingAnswers?: FloatingAnswer[];
207
233
  /** 选择题选项(仅选择题有值) */
208
234
  options?: OptionItem[];
209
235
  /** 题目类型 */
@@ -229,6 +255,8 @@ export interface PageBlock {
229
255
  }>;
230
256
  /** 是否为该 blockId 在所有页面中的首个片段(题号/分数仅首片段显示) */
231
257
  isFirstFragment?: boolean;
258
+ /** 本片段相对所属块内容顶部的 Y 偏移(用于悬浮作答位等绝对定位元素跨页/跨栏定位) */
259
+ contentOffsetY?: number;
232
260
  }
233
261
  export interface CornerMark {
234
262
  position: 'tl' | 'tr' | 'bl' | 'br';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * utils/imageSizeDetector.ts
3
+ *
4
+ * 行内图片真实尺寸探测与回写:
5
+ * 解析阶段是同步的(DOMParser),拿不到图片自然尺寸,只能先用占位尺寸排版;
6
+ * 这里在 reflow 后异步加载 naturalWidth/naturalHeight,按真实比例回写 width/height,
7
+ * 从而消除 SVG <image preserveAspectRatio="xMidYMid meet"> 因容器比例与真实比例不符
8
+ * 造成的上下/左右留白、以及选中框不贴合真实图片的问题。
9
+ */
10
+ import type { ContentBlock } from '../types/paper';
11
+ /**
12
+ * 遍历所有内容块(题干 + 选项)中带 src 的行内图片,加载真实尺寸并按比例回写:
13
+ * - autoSize(解析时无尺寸信息):宽度 = min(真实宽, contentWidth),高度按真实比例 → 完全自适应
14
+ * - 有尺寸信息:保持宽度,高度按真实比例修正 → 消除 meet 留白
15
+ *
16
+ * @returns 发生尺寸修改的图片数量;0 表示无需重新排版
17
+ */
18
+ export declare function correctInlineImageSizes(blocks: ContentBlock[], contentWidth: number): Promise<number>;
@@ -14,6 +14,8 @@ export interface UnderlineExport {
14
14
  underlineId?: string;
15
15
  /** 是否为折行拆分后的后续段(非首段) */
16
16
  isSplitPart?: boolean;
17
+ /** 作答位类型:inline=行内下划线(跟随文字流),floating=悬浮作答位(绝对定位可拖拽) */
18
+ kind?: 'inline' | 'floating';
17
19
  }
18
20
  export interface QuestionExport {
19
21
  topicId: string;
@@ -33,4 +33,4 @@ export declare function wrapElements(elements: InlineElement[], maxWidth: number
33
33
  * 仅做宽度换行(无首行缩减)
34
34
  * 供序列化等不需要首行缩减的场景使用。
35
35
  */
36
- export declare function wrapElementsSimple(elements: InlineElement[], maxWidth: number, lineHeight: number): Line[];
36
+ export declare function wrapElementsSimple(elements: InlineElement[], maxWidth: number, lineHeight: number, firstLineExtraReduction?: number): Line[];
package/dist/style.css CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/dist/style.css
3
- size: 63297475 bytes
4
- sha256: 3aeb9557fa2aa58eddaff707386c51d43c546432a4ecba463a5a602099067de8
3
+ size: 63298620 bytes
4
+ sha256: d5e9fd9b6950a02874bb126e6c8a6e9c03df177de8320e5702cc599c62454955
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sw7d/paper-renderer",
3
- "version": "0.5.7",
3
+ "version": "0.6.1",
4
4
  "description": "题卡设计器核心组件 - 纯编辑表面",
5
5
  "type": "module",
6
6
  "main": "./dist/paper-renderer.js",