@solazah/solazah-runtime 0.2.34 → 0.2.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solazah/solazah-runtime",
3
- "version": "0.2.34",
3
+ "version": "0.2.37",
4
4
  "main": "index.cjs",
5
5
  "module": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -6,6 +6,22 @@ export interface OCRTextBlock {
6
6
  /** 四个角点坐标,顺时针或逆时针,不是 x/y/width/height 矩形 */
7
7
  box: [number, number][];
8
8
  }
9
+ /** 检测结果,与主进程 OcrProtocol 的 OcrDetection 同构(真源在那里)。 */
10
+ export interface OCRDetection {
11
+ /** 帧句柄,交给 recognizeBoxes 按框取字。 */
12
+ frame: string;
13
+ width: number;
14
+ height: number;
15
+ /** 文字框,每个是四个角点坐标(顺时针,从左上起),按阅读顺序排列;recognizeBoxes 的 indices 指的就是这里的序号。 */
16
+ boxes: [number, number][][];
17
+ }
18
+ /** 按框识别的结果,与主进程 OcrProtocol 的 OcrBoxTexts 同构(真源在那里)。 */
19
+ export type OCRBoxTexts = {
20
+ found: true;
21
+ texts: Array<OCRTextBlock | null>;
22
+ } | {
23
+ found: false;
24
+ };
9
25
  export default class SystemOCR {
10
26
  private transport;
11
27
  constructor(transport?: IpcRenderer);
@@ -17,4 +33,31 @@ export default class SystemOCR {
17
33
  * @throws 图片解码失败或 OCR 引擎未就绪时抛错。
18
34
  */
19
35
  recognize: (base64String: string) => Promise<OCRTextBlock[]>;
36
+ /**
37
+ * 两步式识别的第一步:只检测出文字框,不认字。检测只占整图识别耗时的一小部分,大头是逐框认字;
38
+ * 先要框的位置(如框选、高亮)时用它,文字再用 recognizeBoxes 按需取。
39
+ * 同一张图重复调用命中缓存,直接返回同一个帧句柄。
40
+ *
41
+ * @param base64String Base64 编码的图片数据(PNG、JPEG、BMP)。
42
+ * @returns frame(帧句柄)、width/height(图片尺寸)、boxes(文字框,阅读顺序)。
43
+ * @throws 图片解码失败或 OCR 引擎未就绪时抛错。
44
+ */
45
+ detect: (base64String: string) => Promise<OCRDetection>;
46
+ /**
47
+ * 两步式识别的第二步:按框认字。已认过的框直接返回,同一个框不会重复推理。
48
+ *
49
+ * 返回 found: false 表示这一帧已不在引擎里(之后检测的图太多把它挤出、OCR 进程空闲回收或重启),
50
+ * 或要的框里有没认过的、而这一帧的原图已经释放(之后又有几张图检测完在等补字,引擎只给最近用过的几张留原图);
51
+ * 这是预期内的结果,不是失败:用同一张图重新 detect,拿新的 frame 再取(框的序号不变)。
52
+ *
53
+ * @param frame detect 返回的帧句柄。
54
+ * @param indices 要认的框在 detect 返回的 boxes 里的序号。
55
+ * @param options background 为 true 时排在一切前台请求之后,适合在后台分批把整帧补齐;
56
+ * 用户正在看、正在选的框不要带它。
57
+ * @returns found 为 true 时 texts 与 indices 一一对应,框里认不出字为 null。
58
+ * @throws 序号越界或 OCR 引擎出错时抛错。
59
+ */
60
+ recognizeBoxes: (frame: string, indices: number[], options?: {
61
+ background?: boolean;
62
+ }) => Promise<OCRBoxTexts>;
20
63
  }
@@ -151,6 +151,54 @@ export type BlobSource = string | {
151
151
  region?: ScreenRect;
152
152
  image?: string;
153
153
  };
154
+ /** findFlicker 的参数:在哪块截、截多久、多快,以及闪光判据。坐标都是显示器物理像素、相对显示器左上角。 */
155
+ export interface FlickerOptions {
156
+ /** 目标显示器 id;省略取光标所在显示器 */
157
+ displayId?: number;
158
+ /** 只看这一块;省略整屏。聊天框这类会滚字的界面要排除在外 */
159
+ region?: ScreenRect;
160
+ /** 连截多久,缺省 4000 */
161
+ durationMs?: number;
162
+ /** 每秒截几帧,1..30,缺省 4 */
163
+ fps?: number;
164
+ /** 和前后各几帧比,缺省 4 */
165
+ halfWindow?: number;
166
+ /** 亮度要比前后帧的中位数高出多少才算闪,0..255,缺省 45 */
167
+ lift?: number;
168
+ /** 闪光像素的最低亮度(三通道最大值),缺省 140 */
169
+ minValue?: number;
170
+ /** 闪光的色相范围(角度),缺省 45..85,即偏黄绿的星光 */
171
+ hueLow?: number;
172
+ hueHigh?: number;
173
+ /** 闪光的最低饱和度 0..1,缺省 0.25 */
174
+ minSaturation?: number;
175
+ /** 一个光点的像素数范围,缺省 4..40 */
176
+ minSize?: number;
177
+ maxSize?: number;
178
+ /** 同一帧里多近的闪光像素合成一个光点,缺省 6 */
179
+ groupRadius?: number;
180
+ /** 多近的光点算同一处,缺省 50 */
181
+ clusterRadius?: number;
182
+ /** 最多返回几处,缺省 10 */
183
+ maxResults?: number;
184
+ /** 取消记号,同 WaitOptions.token */
185
+ token?: string;
186
+ }
187
+ /** 反复冒光点的一处:中心(屏幕物理像素)、冒过光点的帧数、光点总数。 */
188
+ export interface FlickerCluster {
189
+ x: number;
190
+ y: number;
191
+ frames: number;
192
+ spots: number;
193
+ }
194
+ /** 按冒过光点的帧数降序;unstableFrames 是画面整体在动、被跳过的帧数。 */
195
+ export interface FlickerResult {
196
+ clusters: FlickerCluster[];
197
+ frames: number;
198
+ unstableFrames: number;
199
+ durationMs: number;
200
+ cancelled: boolean;
201
+ }
154
202
  export interface RecordStartOptions {
155
203
  /** 目标显示器 id;省略取光标所在显示器 */
156
204
  displayId?: number;
@@ -476,6 +524,14 @@ export default class SystemScreen {
476
524
  * @returns `[{x, y, width, height, area, cx, cy}]`;给图片时坐标相对图片左上角,截屏时是屏幕物理像素坐标。找不到是空数组。
477
525
  */
478
526
  findBlobs: (source: BlobSource, options: ColorBlobOptions) => Promise<ColorBlob[]>;
527
+ /**
528
+ * 闪烁光点:在显示器的一块区域上连截一段,找反复冒小光点的地方——游戏里可采集物冒出的星光、界面上闪的提示点。
529
+ * 静止的东西每帧一样亮,只有闪的才比前后帧亮出来;同一处反复冒光点的排在前面。截帧期间视角要保持不动。
530
+ *
531
+ * @param options `{displayId?, region?, durationMs?, fps?, hueLow?, hueHigh?, …, token?}`,见 FlickerOptions。
532
+ * @returns `{clusters: [{x, y, frames, spots}], frames, unstableFrames, durationMs, cancelled}`,坐标是屏幕物理像素;找不到 clusters 为空。
533
+ */
534
+ findFlicker: (options?: FlickerOptions) => Promise<FlickerResult>;
479
535
  /**
480
536
  * 屏幕录制:采集与编码全在宿主的原生线程(mac ScreenCaptureKit + VideoToolbox 硬件 H.264,Windows WGC + Media Foundation),
481
537
  * mp4 或 gif 直接写到给定路径,页面不经手任何帧。同一时刻只有一个会话;本视图销毁、到了 maxSeconds 都会自动停。