@hamster-note/reader 0.2.0-beta.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.
- package/LICENSE +21 -0
- package/README.md +267 -0
- package/dist/components/IntermediateDocumentViewer/IntermediateDocumentPageContent.d.ts +40 -0
- package/dist/components/IntermediateDocumentViewer/IntermediateDocumentPageContent.d.ts.map +1 -0
- package/dist/components/IntermediateDocumentViewer/IntermediateDocumentViewer.d.ts +356 -0
- package/dist/components/IntermediateDocumentViewer/IntermediateDocumentViewer.d.ts.map +1 -0
- package/dist/components/IntermediateDocumentViewer/index.d.ts +7 -0
- package/dist/components/IntermediateDocumentViewer/index.d.ts.map +1 -0
- package/dist/components/IntermediateDocumentViewer/pageContentGeometry.d.ts +84 -0
- package/dist/components/IntermediateDocumentViewer/pageContentGeometry.d.ts.map +1 -0
- package/dist/components/IntermediateDocumentViewer/rangeJumpHelpers.d.ts +131 -0
- package/dist/components/IntermediateDocumentViewer/rangeJumpHelpers.d.ts.map +1 -0
- package/dist/components/IntermediateDocumentViewer/renderTiming.d.ts +44 -0
- package/dist/components/IntermediateDocumentViewer/renderTiming.d.ts.map +1 -0
- package/dist/components/IntermediateDocumentViewer/selectionAdapter.d.ts +25 -0
- package/dist/components/IntermediateDocumentViewer/selectionAdapter.d.ts.map +1 -0
- package/dist/components/IntermediateDocumentViewer/textSpanStyle.d.ts +4 -0
- package/dist/components/IntermediateDocumentViewer/textSpanStyle.d.ts.map +1 -0
- package/dist/components/IntermediateDocumentViewer/useLazyPageQueue.d.ts +73 -0
- package/dist/components/IntermediateDocumentViewer/useLazyPageQueue.d.ts.map +1 -0
- package/dist/components/IntermediateDocumentViewer.d.ts +2 -0
- package/dist/components/IntermediateDocumentViewer.d.ts.map +1 -0
- package/dist/components/PopoverPortal.d.ts +21 -0
- package/dist/components/PopoverPortal.d.ts.map +1 -0
- package/dist/components/Reader.d.ts +122 -0
- package/dist/components/Reader.d.ts.map +1 -0
- package/dist/components/gestureRouting.d.ts +73 -0
- package/dist/components/gestureRouting.d.ts.map +1 -0
- package/dist/components/selection/caretResolver.d.ts +33 -0
- package/dist/components/selection/caretResolver.d.ts.map +1 -0
- package/dist/components/selection/index.d.ts +2 -0
- package/dist/components/selection/index.d.ts.map +1 -0
- package/dist/components/selection/savedSelection.d.ts +71 -0
- package/dist/components/selection/savedSelection.d.ts.map +1 -0
- package/dist/components/selection/selectionComposer.d.ts +3 -0
- package/dist/components/selection/selectionComposer.d.ts.map +1 -0
- package/dist/components/selection/selectionPayloadSerializer.d.ts +21 -0
- package/dist/components/selection/selectionPayloadSerializer.d.ts.map +1 -0
- package/dist/components/selection/wordRange.d.ts +17 -0
- package/dist/components/selection/wordRange.d.ts.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2933 -0
- package/dist/style.css +323 -0
- package/dist/types/selection.d.ts +42 -0
- package/dist/types/selection.d.ts.map +1 -0
- package/dist/vendor/clipper-lib.d.ts +3 -0
- package/dist/vendor/clipper-lib.d.ts.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { IntermediateDocument, type IntermediateDocumentSerialized, type IntermediateText } from '@hamster-note/types';
|
|
2
|
+
import { type IntermediateDocumentRenderTimingCallback } from './renderTiming';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { type ReaderSelectedTextSegment } from '../selection/selectionPayloadSerializer';
|
|
5
|
+
import type { ReaderMousePosition, ReaderLinkedSelectionData, ReaderSelectionOverlayRectType, ReaderSelectionRange, ReaderSelectionRef } from '../../types/selection';
|
|
6
|
+
export { getNearestTextElementForPoint, getPageElementByPageNumber, getPageElementForPoint, resolveCaret } from '../selection/caretResolver';
|
|
7
|
+
export { composeSelection, createOrderedRange } from '../selection/selectionComposer';
|
|
8
|
+
export { buildSelectionPayload, getClosestTextElement, type ReaderSelectedTextSegment, type ReaderSelectionPayload, textElementRecords } from '../selection/selectionPayloadSerializer';
|
|
9
|
+
export { buildSavedSelection, denormalizePageRects, normalizePageRects, resolveSavedSelection, textHash, type NormalizedRect, type TextElementInfo } from '../selection/savedSelection';
|
|
10
|
+
export type ReaderTextSelectionDetail = {
|
|
11
|
+
text: IntermediateText;
|
|
12
|
+
texts: IntermediateText[];
|
|
13
|
+
selectedText: string;
|
|
14
|
+
pageNumber: number;
|
|
15
|
+
selection: Selection;
|
|
16
|
+
};
|
|
17
|
+
export type { ReaderLinkedSelectionData, ReaderLinkedSelectionRange, ReaderMousePosition, ReaderSelectionEndpoint, ReaderSelectionOverlayRectType, ReaderSelectionRange, ReaderSelectionRect, ReaderSelectionRef } from '../../types/selection';
|
|
18
|
+
export type ReaderPageRange = {
|
|
19
|
+
start: number;
|
|
20
|
+
end: number;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* 选择覆盖层矩形区域。
|
|
24
|
+
*
|
|
25
|
+
* 坐标原由可选 `origin` 字段标识:
|
|
26
|
+
* - `'viewport'` — 来自 Range.getClientRects / getBoundingClientRect 的浏览器视口坐标,
|
|
27
|
+
* viewer 边界需调用 convertSavedSelectionRectToPageRect 转为页面相对坐标。
|
|
28
|
+
* - `'page-relative'` — 已是页面像素相对坐标(来自归一化 bbox 反归一化或 visual fallback),
|
|
29
|
+
* viewer 边界不应再做 viewport→page-relative 转换,否则会双重偏移。
|
|
30
|
+
* - `undefined` — 历史调用方未显式标注,按 viewport 坐标处理(向后兼容)。
|
|
31
|
+
*/
|
|
32
|
+
export type ReaderSelectionOverlayRect = {
|
|
33
|
+
x: number;
|
|
34
|
+
y: number;
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
pageNumber: number;
|
|
38
|
+
/** 坐标原点标识,用于 viewer 边界区分 viewport / page-relative */
|
|
39
|
+
origin?: 'viewport' | 'page-relative';
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* 已保存选择的文本锚点信息。
|
|
43
|
+
* 用于精确定位选择在文档中的起始/结束位置。
|
|
44
|
+
* bbox 使用归一化坐标(0-1),相对于页面尺寸。
|
|
45
|
+
*/
|
|
46
|
+
export type ReaderSavedSelectionAnchor = {
|
|
47
|
+
/** 锚点所在页码 */
|
|
48
|
+
pageNumber: number;
|
|
49
|
+
/** 文本元素的唯一标识符(可选,用于精确匹配) */
|
|
50
|
+
textId?: string;
|
|
51
|
+
/** 文本内容的哈希值(可选,用于文本变化后的模糊匹配) */
|
|
52
|
+
textHash?: string;
|
|
53
|
+
/** 锚点在文本元素中的字符索引(可选) */
|
|
54
|
+
charIndex?: number;
|
|
55
|
+
/** 锚点前的上下文文本(可选,用于上下文匹配回退) */
|
|
56
|
+
contextBefore?: string;
|
|
57
|
+
/** 锚点后的上下文文本(可选,用于上下文匹配回退) */
|
|
58
|
+
contextAfter?: string;
|
|
59
|
+
/** 归一化的边界框坐标(可选,0-1 范围,相对于页面尺寸) */
|
|
60
|
+
bbox?: {
|
|
61
|
+
x: number;
|
|
62
|
+
y: number;
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* 已保存选择中的一个文本段落。
|
|
69
|
+
* 描述选择在单页内的一段连续文本及其位置信息。
|
|
70
|
+
*/
|
|
71
|
+
export type ReaderSavedSelectionSegment = {
|
|
72
|
+
/** 段落所在页码 */
|
|
73
|
+
pageNumber: number;
|
|
74
|
+
/** 文本元素的唯一标识符(可选) */
|
|
75
|
+
textId?: string;
|
|
76
|
+
/** 文本内容的哈希值(可选) */
|
|
77
|
+
textHash?: string;
|
|
78
|
+
/** 段落起始字符索引(可选) */
|
|
79
|
+
startCharIndex?: number;
|
|
80
|
+
/** 段落结束字符索引(可选) */
|
|
81
|
+
endCharIndex?: number;
|
|
82
|
+
/** 段落中的已选文本内容(可选) */
|
|
83
|
+
selectedText?: string;
|
|
84
|
+
/** 段落前的上下文文本(可选) */
|
|
85
|
+
contextBefore?: string;
|
|
86
|
+
/** 段落后的上下文文本(可选) */
|
|
87
|
+
contextAfter?: string;
|
|
88
|
+
/** 归一化的边界框坐标(可选,0-1 范围,相对于页面尺寸) */
|
|
89
|
+
bbox?: {
|
|
90
|
+
x: number;
|
|
91
|
+
y: number;
|
|
92
|
+
width: number;
|
|
93
|
+
height: number;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* 已保存选择的视觉回退数据(单页)。
|
|
98
|
+
* 当文本锚点无法解析时,使用归一化矩形区域进行视觉渲染。
|
|
99
|
+
*/
|
|
100
|
+
export type ReaderSavedSelectionVisualPage = {
|
|
101
|
+
/** 页码 */
|
|
102
|
+
pageNumber: number;
|
|
103
|
+
/** 页面尺寸(像素) */
|
|
104
|
+
pageSize: {
|
|
105
|
+
width: number;
|
|
106
|
+
height: number;
|
|
107
|
+
};
|
|
108
|
+
/** 归一化的矩形区域列表(0-1 范围,相对于页面尺寸) */
|
|
109
|
+
rects: Array<{
|
|
110
|
+
x: number;
|
|
111
|
+
y: number;
|
|
112
|
+
width: number;
|
|
113
|
+
height: number;
|
|
114
|
+
}>;
|
|
115
|
+
};
|
|
116
|
+
/** 已保存选择的恢复状态 */
|
|
117
|
+
export type ReaderSavedSelectionRestoreStatus = 'resolved' | 'visual-fallback' | 'unresolved';
|
|
118
|
+
/**
|
|
119
|
+
* 已保存选择的恢复结果。
|
|
120
|
+
* 包含恢复状态、覆盖层矩形、段落信息和提取的文本。
|
|
121
|
+
*/
|
|
122
|
+
export type ReaderSavedSelectionRestoreResult = {
|
|
123
|
+
/** 已保存选择的唯一标识符 */
|
|
124
|
+
id: string;
|
|
125
|
+
/** 原始的已保存选择数据 */
|
|
126
|
+
selection: ReaderSavedSelection;
|
|
127
|
+
/** 恢复状态 */
|
|
128
|
+
status: ReaderSavedSelectionRestoreStatus;
|
|
129
|
+
/** 可编辑的恢复 Range;视觉回退和未解析状态为空 */
|
|
130
|
+
range?: Range;
|
|
131
|
+
/** 恢复后的覆盖层矩形,坐标原点由 rectsOrigin 标识 */
|
|
132
|
+
rects: ReaderSelectionOverlayRect[];
|
|
133
|
+
/**
|
|
134
|
+
* rects 的坐标原点:
|
|
135
|
+
* - `'viewport'` — 浏览器视口坐标,viewer 需转为 page-relative
|
|
136
|
+
* - `'page-relative'` — 已是页面相对像素坐标,viewer 不应二次转换
|
|
137
|
+
* - `'mixed'` — 混合来源,需逐 rect 检查 origin 字段
|
|
138
|
+
* - `undefined` — 历史行为,按 viewport 处理(向后兼容)
|
|
139
|
+
*/
|
|
140
|
+
rectsOrigin?: 'viewport' | 'page-relative' | 'mixed';
|
|
141
|
+
/** 恢复后的段落信息,未解析时为空数组 */
|
|
142
|
+
segments: ReaderSavedSelectionSegment[];
|
|
143
|
+
/** 提取的文本内容,未解析时为空字符串 */
|
|
144
|
+
extractedText: string;
|
|
145
|
+
/** 未完全解析的原因说明(可选) */
|
|
146
|
+
reason?: string;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* 已保存选择编辑事件的详细信息。
|
|
150
|
+
* 当用户通过拖动手柄编辑已保存选择时触发。
|
|
151
|
+
*/
|
|
152
|
+
export type ReaderSavedSelectionEditDetail = {
|
|
153
|
+
/** 已保存选择的唯一标识符 */
|
|
154
|
+
id: string;
|
|
155
|
+
/** 编辑后的选择数据 */
|
|
156
|
+
selection: ReaderSavedSelection;
|
|
157
|
+
/** 编辑前的选择数据 */
|
|
158
|
+
previousSelection: ReaderSavedSelection;
|
|
159
|
+
/** 恢复状态 */
|
|
160
|
+
status: ReaderSavedSelectionRestoreStatus;
|
|
161
|
+
/** 编辑后的段落信息 */
|
|
162
|
+
segments: ReaderSavedSelectionSegment[];
|
|
163
|
+
/** 编辑后提取的文本内容 */
|
|
164
|
+
extractedText: string;
|
|
165
|
+
/** 状态说明(可选) */
|
|
166
|
+
reason?: string;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* 已保存选择的公共数据模型(v1 版本)。
|
|
170
|
+
*
|
|
171
|
+
* 设计原则:
|
|
172
|
+
* - **版本化**:`version` 字段为字面量 `1`,未来 schema 变更时递增。
|
|
173
|
+
* - **归一化坐标**:所有 bbox 和 visual rects 使用 0-1 归一化坐标,
|
|
174
|
+
* 相对于页面尺寸,确保跨分辨率一致性。
|
|
175
|
+
* - **调用方持久化**:Reader 和 IntermediateDocumentViewer 不实现持久化逻辑;
|
|
176
|
+
* 调用方负责保存/加载 savedSelections 数据。
|
|
177
|
+
* - **只读回退**:当文本锚点无法解析时,使用 visual 数据渲染只读覆盖层;
|
|
178
|
+
* 回退选择不可编辑,不显示拖动手柄。
|
|
179
|
+
*/
|
|
180
|
+
/**
|
|
181
|
+
* 已保存选择上的评论。评论数据由调用方维护,库本身只负责透传与
|
|
182
|
+
* 在编辑选区时保留这些数据,不会主动渲染或修改评论内容。
|
|
183
|
+
*/
|
|
184
|
+
export type ReaderSavedSelectionComment = {
|
|
185
|
+
/** 评论唯一标识符(由调用方生成) */
|
|
186
|
+
id: string;
|
|
187
|
+
/** 评论文本内容 */
|
|
188
|
+
text: string;
|
|
189
|
+
/** 评论创建时间戳(毫秒) */
|
|
190
|
+
createdAt: number;
|
|
191
|
+
/** 评论作者(可选) */
|
|
192
|
+
author?: string;
|
|
193
|
+
};
|
|
194
|
+
export type ReaderSavedSelection = {
|
|
195
|
+
/** 数据格式版本,当前固定为 1 */
|
|
196
|
+
version: 1;
|
|
197
|
+
/** 已保存选择的唯一标识符(由调用方生成和管理) */
|
|
198
|
+
id: string;
|
|
199
|
+
/** 文档标识符(可选,用于区分不同文档的选择) */
|
|
200
|
+
document?: string;
|
|
201
|
+
/** 选择的完整文本内容 */
|
|
202
|
+
text: string;
|
|
203
|
+
/** 选择起始锚点 */
|
|
204
|
+
start: ReaderSavedSelectionAnchor;
|
|
205
|
+
/** 选择结束锚点 */
|
|
206
|
+
end: ReaderSavedSelectionAnchor;
|
|
207
|
+
/** 选择包含的文本段落列表(支持跨页选择) */
|
|
208
|
+
segments: ReaderSavedSelectionSegment[];
|
|
209
|
+
/** 视觉回退数据(按页分组,用于无法解析文本时的只读渲染) */
|
|
210
|
+
visual: ReaderSavedSelectionVisualPage[];
|
|
211
|
+
/**
|
|
212
|
+
* 选区上的评论(可选)。库不解释这些数据,仅在 rebuildSavedSelectionFromEdit
|
|
213
|
+
* 等内部流程中保留它们,避免编辑手柄拖动时评论被意外丢弃。
|
|
214
|
+
*/
|
|
215
|
+
comments?: ReaderSavedSelectionComment[];
|
|
216
|
+
};
|
|
217
|
+
export declare const isNonSpaceBlankText: (content: string) => boolean;
|
|
218
|
+
/** 交互模式:'default' 为默认触摸/鼠标模式,'stylus' 为手写笔优化模式 */
|
|
219
|
+
export type ReaderInteractionMode = 'default' | 'stylus';
|
|
220
|
+
export type IntermediateDocumentViewerProps = {
|
|
221
|
+
document?: IntermediateDocument | IntermediateDocumentSerialized | null;
|
|
222
|
+
serializedDocument?: IntermediateDocumentSerialized | null;
|
|
223
|
+
className?: string;
|
|
224
|
+
overscan?: number;
|
|
225
|
+
pageRange?: ReaderPageRange;
|
|
226
|
+
ocr?: boolean | {
|
|
227
|
+
enabled?: boolean;
|
|
228
|
+
};
|
|
229
|
+
onOcrError?: (error: unknown, detail: {
|
|
230
|
+
pageNumber: number;
|
|
231
|
+
}) => void;
|
|
232
|
+
onTextSelectionChange?: (text: IntermediateText, detail: ReaderTextSelectionDetail) => void;
|
|
233
|
+
onTextSelectionEnd?: (text: IntermediateText, detail: ReaderTextSelectionDetail) => void;
|
|
234
|
+
onSelectText?: (selection: Selection, segments: ReaderSelectedTextSegment[], extractedText: string) => void;
|
|
235
|
+
/**
|
|
236
|
+
* Controlled zoom scale. When provided, internal wheel/pinch gestures do not
|
|
237
|
+
* mutate scale state; they call `onScaleChange` with the next clamped value
|
|
238
|
+
* and wait for the caller to pass that value back. Invalid/non-positive values
|
|
239
|
+
* are treated as the safe default scale of `1`, then clamped to the active
|
|
240
|
+
* bounds.
|
|
241
|
+
*/
|
|
242
|
+
scale?: number;
|
|
243
|
+
/**
|
|
244
|
+
* Initial zoom scale for uncontrolled mode. Defaults to `1`, is clamped to the
|
|
245
|
+
* effective `minScale`/`maxScale` range, and is read only during initial state
|
|
246
|
+
* creation so later `defaultScale` prop changes do not reset user zoom.
|
|
247
|
+
*/
|
|
248
|
+
defaultScale?: number;
|
|
249
|
+
/**
|
|
250
|
+
* Fires only when a wheel or pinch gesture produces a changed, clamped scale.
|
|
251
|
+
* The detail object reports `source: 'wheel' | 'pinch'` and may include the
|
|
252
|
+
* viewport focal point used to preserve scroll anchoring.
|
|
253
|
+
*/
|
|
254
|
+
onScaleChange?: (scale: number, detail: {
|
|
255
|
+
source: 'wheel' | 'pinch';
|
|
256
|
+
focalPoint?: {
|
|
257
|
+
x: number;
|
|
258
|
+
y: number;
|
|
259
|
+
};
|
|
260
|
+
}) => void;
|
|
261
|
+
/**
|
|
262
|
+
* Lower zoom bound. Defaults to `0.25`; invalid or non-positive values fall
|
|
263
|
+
* back to the default. If the normalized minimum is greater than the maximum,
|
|
264
|
+
* the maximum is raised to the minimum to keep clamping deterministic.
|
|
265
|
+
*/
|
|
266
|
+
minScale?: number;
|
|
267
|
+
/**
|
|
268
|
+
* Upper zoom bound. Defaults to `4`; invalid or non-positive values fall back
|
|
269
|
+
* to the default before the final range is normalized.
|
|
270
|
+
*/
|
|
271
|
+
maxScale?: number;
|
|
272
|
+
/**
|
|
273
|
+
* Maximum number of concurrently loaded pages before lazy eviction. Defaults
|
|
274
|
+
* to `max(5, overscan * 2 + 5)`. Only `Infinity` disables eviction entirely;
|
|
275
|
+
* `0`, negative, `NaN`, or other invalid values fall back to the default cap.
|
|
276
|
+
* Finite values are floored by protected pages (visible pages, overscan,
|
|
277
|
+
* in-flight work, active selection/drag/pinch state, and saved-selection
|
|
278
|
+
* anchors), so more pages may remain loaded than the raw value. With
|
|
279
|
+
*/
|
|
280
|
+
maxLoadedPages?: number;
|
|
281
|
+
/** 交互模式,影响手势处理行为 */
|
|
282
|
+
interactionMode?: ReaderInteractionMode;
|
|
283
|
+
/** 受控的已高亮 range 列表;传入时组件不内部 mutation,缺失则用内部 state 从 defaultRanges 初始化 */
|
|
284
|
+
ranges?: ReaderSelectionRange[];
|
|
285
|
+
/** 非受控模式下 ranges 的初始值,默认空数组 */
|
|
286
|
+
defaultRanges?: ReaderSelectionRange[];
|
|
287
|
+
/** 受控的当前选中 range ID;null 表示未选中;缺失则用内部 state 从 defaultSelectedRangeId 初始化 */
|
|
288
|
+
selectedRangeId?: string | null;
|
|
289
|
+
/** 非受控模式下 selectedRangeId 的初始值,默认 null */
|
|
290
|
+
defaultSelectedRangeId?: string | null;
|
|
291
|
+
/** 用户确认高亮时触发;非受控 ranges 模式下内部先 append range 再回调 */
|
|
292
|
+
onSelect?: (range: ReaderSelectionRange) => void;
|
|
293
|
+
onLinkedDataChange?: (next: ReaderLinkedSelectionData) => void;
|
|
294
|
+
onLinkedSelect?: (range: ReaderSelectionRange) => void;
|
|
295
|
+
onLinkedUpdateRange?: (range: ReaderSelectionRange) => void;
|
|
296
|
+
onLinkedSelectRange?: (id: string | null) => void;
|
|
297
|
+
/** 用户点击或取消选中某个已高亮 range 时触发 */
|
|
298
|
+
onSelectRange?: (id: string | null) => void;
|
|
299
|
+
/** 用户拖动已高亮 range 的首尾手柄调整范围时触发;非受控 ranges 模式下内部先替换对应 range */
|
|
300
|
+
onUpdateRange?: (range: ReaderSelectionRange) => void;
|
|
301
|
+
/** 用户开始选择时触发(容器内 mousedown),mousePos 为 viewport 坐标 */
|
|
302
|
+
onSelectionStart?: (mousePos: ReaderMousePosition, selection: Selection) => void;
|
|
303
|
+
/** 用户结束选择时触发(容器内 mouseup 且有有效选区);注意 Selection 库此回调基于 mouseup,touch 选择可能不触发 */
|
|
304
|
+
onSelectionEnd?: (mousePos: ReaderMousePosition, selection: Selection) => void;
|
|
305
|
+
/** 执行高亮操作时额外触发(在 onSelect 之后) */
|
|
306
|
+
onHighlight?: (range: ReaderSelectionRange) => void;
|
|
307
|
+
/** 已确认高亮的 Overlay 颜色(CSS color),默认半透明黄 */
|
|
308
|
+
highlightColor?: string;
|
|
309
|
+
/** 正在选择中的临时 Overlay 颜色(CSS color),默认半透明粉 */
|
|
310
|
+
selectionColor?: string;
|
|
311
|
+
/** 当某个高亮被选中时,在其上方弹出的 Popover 内容(ReactNode),由调用方完全控制 */
|
|
312
|
+
selectionPopover?: React.ReactNode;
|
|
313
|
+
/** 被高亮的片段上方弹出的 Popover 内容,未提供时 fallback 到 selectionPopover */
|
|
314
|
+
highlightPopover?: React.ReactNode;
|
|
315
|
+
/** 是否在选区结束时自动触发高亮,默认为 false */
|
|
316
|
+
autoHighlight?: boolean;
|
|
317
|
+
/** Selection 组件的命令式 ref,暴露 highlight()/clear() 方法 */
|
|
318
|
+
selectionRef?: React.Ref<ReaderSelectionRef>;
|
|
319
|
+
/** 选区 Overlay 矩形坐标类型;默认 'percent' */
|
|
320
|
+
overlayRectType?: ReaderSelectionOverlayRectType;
|
|
321
|
+
/**
|
|
322
|
+
* 初始立即加载的页数。省略时默认 `1`。
|
|
323
|
+
*/
|
|
324
|
+
initialLoadedPages?: number;
|
|
325
|
+
/**
|
|
326
|
+
* 同时并发加载的页数上限。省略时默认 `3`。
|
|
327
|
+
*/
|
|
328
|
+
pageLoadConcurrency?: number;
|
|
329
|
+
/**
|
|
330
|
+
* 页面进入可加载窗口后、真正发起加载前的延迟(毫秒)。省略时默认 `500`。
|
|
331
|
+
*/
|
|
332
|
+
pageLoadEnterDelayMs?: number;
|
|
333
|
+
/**
|
|
334
|
+
* 页面离开可加载窗口后、卸载其内容的延迟(毫秒)。省略时默认 `5000`。
|
|
335
|
+
*/
|
|
336
|
+
pageUnloadDelayMs?: number;
|
|
337
|
+
/** intermediate-document 渲染阶段计时回调 */
|
|
338
|
+
onIntermediateDocumentRenderTiming?: IntermediateDocumentRenderTimingCallback;
|
|
339
|
+
};
|
|
340
|
+
/**
|
|
341
|
+
* Merge overlapping or adjacent rectangles on the same line.
|
|
342
|
+
* Uses a tolerance of 2px to handle minor gaps between text spans.
|
|
343
|
+
*/
|
|
344
|
+
export declare const mergeSelectionRects: (rects: Array<{
|
|
345
|
+
x: number;
|
|
346
|
+
y: number;
|
|
347
|
+
width: number;
|
|
348
|
+
height: number;
|
|
349
|
+
}>) => Array<{
|
|
350
|
+
x: number;
|
|
351
|
+
y: number;
|
|
352
|
+
width: number;
|
|
353
|
+
height: number;
|
|
354
|
+
}>;
|
|
355
|
+
export declare function IntermediateDocumentViewer({ document, serializedDocument, className, overscan, pageRange, ocr, onOcrError, onTextSelectionChange, onTextSelectionEnd, onSelectText, scale, defaultScale, onScaleChange, minScale, maxScale, maxLoadedPages, interactionMode, ranges, defaultRanges, selectedRangeId, defaultSelectedRangeId, onSelect, onLinkedDataChange, onLinkedSelect, onLinkedUpdateRange, onLinkedSelectRange, onSelectRange, onUpdateRange, onSelectionStart: onSelectionStartProp, onSelectionEnd: onSelectionEndProp, onHighlight, highlightColor, selectionColor, selectionPopover, highlightPopover, autoHighlight, selectionRef, overlayRectType, initialLoadedPages, pageLoadConcurrency, pageLoadEnterDelayMs, pageUnloadDelayMs, onIntermediateDocumentRenderTiming }: IntermediateDocumentViewerProps): import("react/jsx-runtime").JSX.Element;
|
|
356
|
+
//# sourceMappingURL=IntermediateDocumentViewer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IntermediateDocumentViewer.d.ts","sourceRoot":"","sources":["../../../src/components/IntermediateDocumentViewer/IntermediateDocumentViewer.tsx"],"names":[],"mappings":"AAOA,OAAO,EACL,oBAAoB,EAEpB,KAAK,8BAA8B,EAEnC,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAEL,KAAK,wCAAwC,EAE9C,MAAM,gBAAgB,CAAA;AAYvB,OAAO,KAQN,MAAM,OAAO,CAAA;AAGd,OAAO,EAGL,KAAK,yBAAyB,EAE/B,MAAM,yCAAyC,CAAA;AAChD,OAAO,KAAK,EACV,mBAAmB,EACnB,yBAAyB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,EAChB,aAAa,EACb,YAAY,EACZ,eAA2B,EAC3B,kBAAsB,EACtB,mBAAuB,EACvB,oBAA0B,EAC1B,iBAAwB,EACxB,kCAAkC,EACnC,EAAE,+BAA+B,2CAquDjC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { IntermediateDocumentViewer, isNonSpaceBlankText, mergeSelectionRects, type IntermediateDocumentViewerProps, type ReaderInteractionMode, type ReaderPageRange, type ReaderSavedSelection, type ReaderSavedSelectionAnchor, type ReaderSavedSelectionComment, type ReaderSavedSelectionEditDetail, type ReaderSavedSelectionRestoreResult, type ReaderSavedSelectionRestoreStatus, type ReaderSavedSelectionSegment, type ReaderSavedSelectionVisualPage, type ReaderSelectionOverlayRect, type ReaderTextSelectionDetail } from './IntermediateDocumentViewer';
|
|
2
|
+
export { getNearestTextElementForPoint, getPageElementByPageNumber, getPageElementForPoint, resolveCaret } from '../selection/caretResolver';
|
|
3
|
+
export { composeSelection, createOrderedRange } from '../selection/selectionComposer';
|
|
4
|
+
export { buildSelectionPayload, getClosestTextElement, textElementRecords, type ReaderSelectedTextSegment, type ReaderSelectionPayload } from '../selection/selectionPayloadSerializer';
|
|
5
|
+
export { buildSavedSelection, denormalizePageRects, normalizePageRects, resolveSavedSelection, textHash, type NormalizedRect, type TextElementInfo } from '../selection/savedSelection';
|
|
6
|
+
export { createIntermediateDocumentRenderTiming, type CreateIntermediateDocumentRenderTimingOptions, type IntermediateDocumentRenderTiming, type IntermediateDocumentRenderTimingCallback, type IntermediateDocumentRenderTimingClock, type IntermediateDocumentRenderTimingEntry, type IntermediateDocumentRenderTimingStage } from './renderTiming';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/IntermediateDocumentViewer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,mBAAmB,EACnB,KAAK,+BAA+B,EACpC,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,0BAA0B,EAC/B,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,EACnC,KAAK,iCAAiC,EACtC,KAAK,iCAAiC,EACtC,KAAK,2BAA2B,EAChC,KAAK,8BAA8B,EACnC,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC/B,MAAM,8BAA8B,CAAA;AACrC,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,EAC1B,sBAAsB,EACtB,YAAY,EACb,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC5B,MAAM,yCAAyC,CAAA;AAChD,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,QAAQ,EACR,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,sCAAsC,EACtC,KAAK,6CAA6C,EAClD,KAAK,gCAAgC,EACrC,KAAK,wCAAwC,EAC7C,KAAK,qCAAqC,EAC1C,KAAK,qCAAqC,EAC1C,KAAK,qCAAqC,EAC3C,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { IntermediateImage, IntermediateText } from '@hamster-note/types';
|
|
2
|
+
import type { CSSProperties } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* intermediate-document 渲染器使用的
|
|
5
|
+
* 纯几何与样式辅助函数。
|
|
6
|
+
*
|
|
7
|
+
* 这些函数从 `IntermediateDocumentViewer.tsx` 中抽取出来,供新的
|
|
8
|
+
* `IntermediateDocumentPageContent` 渲染器复用,避免在
|
|
9
|
+
* 巨大的 viewer 文件中继续膨胀。所有函数均为纯函数,无闭包依赖,
|
|
10
|
+
* 由现有 intermediate-document 测试覆盖验证行为一致性。
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* 几何计算用的单个点([x, y])。声明为 readonly tuple,既兼容运行期
|
|
14
|
+
* 解析器/OCR 提供的可变 `[number, number][]`,也兼容 `@hamster-note/types`
|
|
15
|
+
* 中 `IntermediateImage.polygon` / `IntermediateText.polygon` 的只读四点
|
|
16
|
+
* 多边形(`Polygon`),从而无需 `as unknown` 逃逸即可统一处理。
|
|
17
|
+
*/
|
|
18
|
+
export type GeometryPoint = readonly [number, number];
|
|
19
|
+
/**
|
|
20
|
+
* 几何计算用的多边形:任意数量的 {@link GeometryPoint} 只读数组。
|
|
21
|
+
* `IntermediateImage.polygon`(4 点 `Polygon`)与运行期文本的
|
|
22
|
+
* `[number, number][]` 均可直接赋值给该类型。
|
|
23
|
+
*/
|
|
24
|
+
export type GeometryPolygon = readonly GeometryPoint[];
|
|
25
|
+
/**
|
|
26
|
+
* 渲染时可用的 IntermediateText —— 序列化字段之外,运行期可能附带
|
|
27
|
+
* 解析器/OCR 提供的 x/y/width/height/polygon/rotate/skew 几何信息。
|
|
28
|
+
*/
|
|
29
|
+
export type RenderableIntermediateText = IntermediateText & Partial<{
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
polygon: GeometryPolygon;
|
|
35
|
+
rotate: number;
|
|
36
|
+
skew: number;
|
|
37
|
+
}>;
|
|
38
|
+
/** 多边形几何计算结果 */
|
|
39
|
+
export type PolygonGeometry = {
|
|
40
|
+
x: number;
|
|
41
|
+
y: number;
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
rotation: number;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* 合并多边形顶点为一个轴对齐包围盒(适用于少于 4 个有效顶点或非标准四边形)。
|
|
48
|
+
*/
|
|
49
|
+
export declare const getTextBoundingBox: (polygon: GeometryPolygon) => {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
width: number;
|
|
53
|
+
height: number;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* 从标准四边形多边形(4 个顶点)推导精确的位置、尺寸与旋转角。
|
|
57
|
+
* 返回 null 表示多边形不规范,调用方应回退到轴对齐包围盒。
|
|
58
|
+
*/
|
|
59
|
+
export declare const getPolygonTextGeometry: (polygon: GeometryPolygon | undefined) => PolygonGeometry | null;
|
|
60
|
+
/**
|
|
61
|
+
* 计算单个文本 span 的包围盒(优先使用四边形精确几何,回退到轴对齐包围盒,
|
|
62
|
+
* 最后回退到 x/y/width/height 字段)。
|
|
63
|
+
*/
|
|
64
|
+
export declare const getTextBbox: (text: RenderableIntermediateText) => {
|
|
65
|
+
x: number;
|
|
66
|
+
y: number;
|
|
67
|
+
width: number;
|
|
68
|
+
height: number;
|
|
69
|
+
rotation: number;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* 从 IntermediateImage 的四边形 polygon 计算位置、尺寸与旋转角。
|
|
73
|
+
* 复用与文本相同的四边形几何逻辑;polygon 缺失或非法时回退到 0 尺寸。
|
|
74
|
+
*/
|
|
75
|
+
export declare const getImageGeometry: (image: IntermediateImage) => PolygonGeometry;
|
|
76
|
+
/**
|
|
77
|
+
* 根据 IntermediateImage 的几何与透明度/裁剪属性构建 `<img>` 的内联样式。
|
|
78
|
+
*
|
|
79
|
+
* - 位置与尺寸由 polygon 几何决定(绝对定位在页面内容层内)。
|
|
80
|
+
* - opacity 直接透传。
|
|
81
|
+
* - clip(如果存在)转换为 CSS `clip-path: inset(...)`,以图片自身盒子为参考。
|
|
82
|
+
*/
|
|
83
|
+
export declare const buildImageStyle: (image: IntermediateImage, geometry: PolygonGeometry) => CSSProperties;
|
|
84
|
+
//# sourceMappingURL=pageContentGeometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageContent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G;AACH,eAAO,MAAM,eAAe,GAC1B,OAAO,iBAAiB,EACxB,UAAU,eAAe,KACxB,aA6BF,CAAA"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure range-jump helpers for public page ids and rect units.
|
|
3
|
+
*
|
|
4
|
+
* Given a range id and the public ReaderSelectionRange[],
|
|
5
|
+
* these helpers return a jump target { pageNumber, centerX, centerY }
|
|
6
|
+
* or null for no-op. No React hooks or DOM access.
|
|
7
|
+
*/
|
|
8
|
+
import type { ReaderSelectionRange, ReaderSelectionRect } from '../../types/selection';
|
|
9
|
+
export type RangeJumpTarget = {
|
|
10
|
+
/** 1-based public page number parsed from the page-N id. */
|
|
11
|
+
readonly pageNumber: number;
|
|
12
|
+
/** Horizontal center in page-local pixels. */
|
|
13
|
+
readonly centerX: number;
|
|
14
|
+
/** Vertical center in page-local pixels. */
|
|
15
|
+
readonly centerY: number;
|
|
16
|
+
};
|
|
17
|
+
/** Parse a public `page-N` id → 1-based page number, or null for malformed ids. */
|
|
18
|
+
export declare function parsePublicPageId(pageId: string): number | null;
|
|
19
|
+
/**
|
|
20
|
+
* Find a range by its public `id` in the ranges array.
|
|
21
|
+
* Returns null when no range matches.
|
|
22
|
+
*/
|
|
23
|
+
export declare function findRangeById(ranges: readonly ReaderSelectionRange[], rangeId: string): ReaderSelectionRange | null;
|
|
24
|
+
type SelectedRect = {
|
|
25
|
+
readonly rect: ReaderSelectionRect;
|
|
26
|
+
/** Page id that owns this rect (e.g. "page-3"). */
|
|
27
|
+
readonly pageId: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Choose the best rect for jumping.
|
|
31
|
+
*
|
|
32
|
+
* Strategy (deterministic):
|
|
33
|
+
* 1. First rect under `range.start.selectionId` when that key exists.
|
|
34
|
+
* 2. Otherwise first rect from the first key in sorted key order.
|
|
35
|
+
*
|
|
36
|
+
* Returns null when rectsBySelectionId is empty or contains only empty arrays.
|
|
37
|
+
*/
|
|
38
|
+
export declare function selectTargetRect(range: ReaderSelectionRange): SelectedRect | null;
|
|
39
|
+
/**
|
|
40
|
+
* Convert a rect's center from either percent (0-100) or px units
|
|
41
|
+
* to page-local pixel coordinates.
|
|
42
|
+
*
|
|
43
|
+
* @param rect The overlay rect (x, y, width, height).
|
|
44
|
+
* @param rectType 'percent' treats x/y/width/height as 0-100;
|
|
45
|
+
* 'px' treats them as page-local pixels.
|
|
46
|
+
* @param pageWidth Page width in pixels.
|
|
47
|
+
* @param pageHeight Page height in pixels.
|
|
48
|
+
*/
|
|
49
|
+
export declare function rectCenterToPagePixels(rect: ReaderSelectionRect, rectType: 'percent' | 'px', pageWidth: number, pageHeight: number): {
|
|
50
|
+
centerX: number;
|
|
51
|
+
centerY: number;
|
|
52
|
+
};
|
|
53
|
+
export type ResolveRangeJumpTargetParams = {
|
|
54
|
+
readonly ranges: readonly ReaderSelectionRange[];
|
|
55
|
+
readonly rangeId: string;
|
|
56
|
+
/** Rect unit type to apply; falls back to range.overlayRectType then 'percent'. */
|
|
57
|
+
readonly rectType?: 'percent' | 'px';
|
|
58
|
+
readonly pageWidth: number;
|
|
59
|
+
readonly pageHeight: number;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Resolve a range id to a concrete page-local jump target.
|
|
63
|
+
*
|
|
64
|
+
* Flow:
|
|
65
|
+
* 1. Find the range by id → null if not found.
|
|
66
|
+
* 2. Select the best rect (start page → fallback) → null if no rects.
|
|
67
|
+
* 3. Parse the page id to a 1-based page number → null if malformed.
|
|
68
|
+
* 4. Convert the rect center to page-local pixels.
|
|
69
|
+
*/
|
|
70
|
+
export declare function resolveRangeJumpTarget(params: ResolveRangeJumpTargetParams): RangeJumpTarget | null;
|
|
71
|
+
/**
|
|
72
|
+
* A VirtualPaper transform: `{ x, y, scale }`.
|
|
73
|
+
* Applied as `translate3d(x, y, 0) scale(scale)` on the content container.
|
|
74
|
+
*/
|
|
75
|
+
export type VirtualPaperTransform = {
|
|
76
|
+
readonly x: number;
|
|
77
|
+
readonly y: number;
|
|
78
|
+
readonly scale: number;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Compute the content-space origin (top-left) of a page by summing the
|
|
82
|
+
* heights of preceding pages and inter-page gaps. X is 0 because the
|
|
83
|
+
* `.hamster-note-document` flex-column centers pages horizontally
|
|
84
|
+
* relative to the widest page (content coordinate 0 = left edge of the
|
|
85
|
+
* widest page, not necessarily the target page — but for transform
|
|
86
|
+
* clamping we only need the vertical origin; horizontal centering is
|
|
87
|
+
* handled by the page-local `targetCenterX`).
|
|
88
|
+
*
|
|
89
|
+
* This is the deterministic fallback for jsdom and zero-layout cases
|
|
90
|
+
* where real DOM measurement is unavailable.
|
|
91
|
+
*/
|
|
92
|
+
export declare function computePageOriginY(pageNumber: number, pageNumbers: readonly number[], pageSizesByPageNumber: ReadonlyMap<number, {
|
|
93
|
+
width: number;
|
|
94
|
+
height: number;
|
|
95
|
+
}>): number;
|
|
96
|
+
export type ComputeTransformParams = {
|
|
97
|
+
/** Viewport width in CSS pixels (the VirtualPaper wrapper element). */
|
|
98
|
+
readonly viewportWidth: number;
|
|
99
|
+
/** Viewport height in CSS pixels. */
|
|
100
|
+
readonly viewportHeight: number;
|
|
101
|
+
/** Content element total width in CSS pixels (pre-scale). */
|
|
102
|
+
readonly contentWidth: number;
|
|
103
|
+
/** Content element total height in CSS pixels (pre-scale). */
|
|
104
|
+
readonly contentHeight: number;
|
|
105
|
+
/** Content-space X coordinate to center on. */
|
|
106
|
+
readonly targetContentX: number;
|
|
107
|
+
/** Content-space Y coordinate to center on. */
|
|
108
|
+
readonly targetContentY: number;
|
|
109
|
+
/** Scale to apply. */
|
|
110
|
+
readonly scale: number;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Compute a VirtualPaper transform that centers `(targetContentX,
|
|
114
|
+
* targetContentY)` in the viewport, clamped to VirtualPaper contain
|
|
115
|
+
* semantics.
|
|
116
|
+
*
|
|
117
|
+
* Math:
|
|
118
|
+
* screen = content * scale + translate
|
|
119
|
+
* → translate = viewportCenter - targetContent * scale
|
|
120
|
+
*
|
|
121
|
+
* Contain clamping per axis:
|
|
122
|
+
* - If scaledContentSize ≤ viewportSize → center the content:
|
|
123
|
+
* translate = (viewportSize - scaledContentSize) / 2
|
|
124
|
+
* - Otherwise → clamp so content edges stay visible:
|
|
125
|
+
* translate ∈ [viewportSize - scaledContentSize, 0]
|
|
126
|
+
*
|
|
127
|
+
* Returns `null` when inputs are invalid (zero, negative, non-finite).
|
|
128
|
+
*/
|
|
129
|
+
export declare function computeTransform(params: ComputeTransformParams): VirtualPaperTransform | null;
|
|
130
|
+
export {};
|
|
131
|
+
//# sourceMappingURL=rangeJumpHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rangeJumpHelpers.d.ts","sourceRoot":"","sources":["../../../src/components/IntermediateDocumentViewer/rangeJumpHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,uBAAuB,CAAA;AAI9B,MAAM,MAAM,eAAe,GAAG;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,8CAA8C;IAC9C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,4CAA4C;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB,CAAA;AAID,mFAAmF;AACnF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAQ/D;AAID;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,SAAS,oBAAoB,EAAE,EACvC,OAAO,EAAE,MAAM,GACd,oBAAoB,GAAG,IAAI,CAE7B;AAID,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAA;IAClC,mDAAmD;IACnD,QAAQ,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M,sBAAsB,GAAG;IACnC,uEAAuE;IACvE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,qCAAqC;IACrC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,6DAA6D;IAC7D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,8DAA8D;IAC9D,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,+CAA+C;IAC/C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,+CAA+C;IAC/C,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,sBAAsB;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,sBAAsB,GAC7B,qBAAqB,GAAG,IAAI,CA4C9B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** 渲染计时阶段枚举 */
|
|
2
|
+
export type IntermediateDocumentRenderTimingStage = 'document-resolution' | 'shell-rendering' | 'initial-page-loading' | 'content-extraction' | 'page-content-rendering' | 'visibility-lazy-loading' | 'offscreen-unload' | 'ocr-processing';
|
|
3
|
+
/** 渲染计时记录条目 */
|
|
4
|
+
export type DetailValue = string | number | boolean | null;
|
|
5
|
+
export interface IntermediateDocumentRenderTimingEntry {
|
|
6
|
+
stage: IntermediateDocumentRenderTimingStage;
|
|
7
|
+
startedAt: number;
|
|
8
|
+
endedAt: number;
|
|
9
|
+
durationMs: number;
|
|
10
|
+
pageNumber?: number;
|
|
11
|
+
detail?: Readonly<Record<string, DetailValue>>;
|
|
12
|
+
}
|
|
13
|
+
/** 渲染计时回调 */
|
|
14
|
+
export type IntermediateDocumentRenderTimingCallback = (entry: IntermediateDocumentRenderTimingEntry) => void;
|
|
15
|
+
/** 时钟抽象,便于测试注入 */
|
|
16
|
+
export interface IntermediateDocumentRenderTimingClock {
|
|
17
|
+
now: () => number;
|
|
18
|
+
}
|
|
19
|
+
/** 工厂函数选项 */
|
|
20
|
+
export interface CreateIntermediateDocumentRenderTimingOptions {
|
|
21
|
+
callback?: IntermediateDocumentRenderTimingCallback;
|
|
22
|
+
clock?: IntermediateDocumentRenderTimingClock;
|
|
23
|
+
/** 显式覆盖环境变量检测结果;未提供时读取 import.meta.env */
|
|
24
|
+
envEnabled?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** 工厂函数返回的计时实例 */
|
|
27
|
+
export interface IntermediateDocumentRenderTiming {
|
|
28
|
+
readonly enabled: boolean;
|
|
29
|
+
/** 开始计时,返回结束函数(disabled 时返回 no-op) */
|
|
30
|
+
start: (stage: IntermediateDocumentRenderTimingStage, context?: {
|
|
31
|
+
pageNumber?: number;
|
|
32
|
+
detail?: Record<string, DetailValue>;
|
|
33
|
+
}) => () => void;
|
|
34
|
+
/** 同步测量 fn 执行耗时并返回 fn 结果 */
|
|
35
|
+
measure: <T>(stage: IntermediateDocumentRenderTimingStage, context: {
|
|
36
|
+
pageNumber?: number;
|
|
37
|
+
detail?: Record<string, DetailValue>;
|
|
38
|
+
} | undefined, fn: () => T) => T;
|
|
39
|
+
/** 直接记录一条已构造的 entry */
|
|
40
|
+
record: (entry: IntermediateDocumentRenderTimingEntry) => void;
|
|
41
|
+
}
|
|
42
|
+
/** 创建 intermediate-document 渲染计时器 */
|
|
43
|
+
export declare function createIntermediateDocumentRenderTiming(options?: CreateIntermediateDocumentRenderTimingOptions): IntermediateDocumentRenderTiming;
|
|
44
|
+
//# sourceMappingURL=renderTiming.d.ts.map
|