@glodon-aiot/dataset-annotation 3.22.2-alpha.4 → 3.22.2-alpha.6
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.
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ISample } from '@glodon-aiot/apis';
|
|
2
|
+
interface UseSamplePreloadOptions {
|
|
3
|
+
/** 内存中已加载的样本列表,预加载只在该范围内取相邻项 */
|
|
4
|
+
samples: ISample[];
|
|
5
|
+
/** 当前图片在 samples 中的位置 */
|
|
6
|
+
currentIndex: number;
|
|
7
|
+
/** 详情/标注弹窗是否开启,关闭时释放缓存 */
|
|
8
|
+
active: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 主图已加载完成的图片地址,作为启动信号,避免与主图争抢带宽。
|
|
11
|
+
* 与 samples[currentIndex] 比对而非与 currentSample 比对:翻页时 currentIndex 与
|
|
12
|
+
* currentSample 不在同一次提交里更新,用后者会出现“新索引 + 旧已加载地址”的空窗,
|
|
13
|
+
* 导致预加载抢在主图请求之前发出。
|
|
14
|
+
*/
|
|
15
|
+
loadedImageUrl?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 以当前图片为中心预加载相邻样本的图片:先向后(下一张方向)再向前,
|
|
19
|
+
* 与用户以“下一张”为主的浏览习惯一致。
|
|
20
|
+
*
|
|
21
|
+
* 只在 samples 已有的范围内取相邻项,不会触发 fetchSamples ——
|
|
22
|
+
* 那个函数会改写 pagination 并 append 样本,作为预加载的副作用会污染分页状态。
|
|
23
|
+
*/
|
|
24
|
+
declare const useSamplePreload: ({ samples, currentIndex, active, loadedImageUrl, }: UseSamplePreloadOptions) => void;
|
|
25
|
+
export default useSamplePreload;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** 以当前图片为中心,向后(下一张方向)预加载的张数 */
|
|
2
|
+
export declare const PRELOAD_FORWARD = 3;
|
|
3
|
+
/** 以当前图片为中心,向前(上一张方向)预加载的张数 */
|
|
4
|
+
export declare const PRELOAD_BACKWARD = 2;
|
|
5
|
+
/** 缓存的图片实例上限 */
|
|
6
|
+
export declare const PRELOAD_MAX_CACHE = 8;
|
|
7
|
+
/** 同时进行的预加载请求上限,避免与主图争抢连接 */
|
|
8
|
+
export declare const PRELOAD_CONCURRENCY = 2;
|
|
9
|
+
/**
|
|
10
|
+
* 预加载原生 Image 以预热浏览器的 HTTP 缓存与解码结果,
|
|
11
|
+
* 让 LabelMaker 里的 fabric.Image.fromURL 切图时能直接命中缓存。
|
|
12
|
+
*
|
|
13
|
+
* 注意:crossOrigin 必须与 fabric.Image.fromURL 的 { crossOrigin: 'anonymous' } 保持一致,
|
|
14
|
+
* 否则两次请求的 CORS 模式不同,浏览器会视为不同的缓存条目,预加载将完全失效。
|
|
15
|
+
*/
|
|
16
|
+
export declare class ImagePreloader {
|
|
17
|
+
/** 已加载完成的图片,插入顺序即淘汰顺序 */
|
|
18
|
+
private cache;
|
|
19
|
+
/** 待加载队列,每次窗口滑动整体替换 */
|
|
20
|
+
private queue;
|
|
21
|
+
private loading;
|
|
22
|
+
private disposed;
|
|
23
|
+
/**
|
|
24
|
+
* 替换待加载队列。已缓存或正在加载的 url 会被跳过,
|
|
25
|
+
* 上一轮尚未开始的目标会被丢弃,避免过期窗口占用并发额度。
|
|
26
|
+
*/
|
|
27
|
+
setTargets(urls: string[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* 清理不在 keep 列表内的缓存,并把剩余条目裁剪到上限以内。
|
|
30
|
+
*/
|
|
31
|
+
pruneExcept(keep: string[]): void;
|
|
32
|
+
/**
|
|
33
|
+
* 释放全部缓存并放弃后续预加载。进行中的请求不主动中断
|
|
34
|
+
* (给 Image 赋空 src 在部分浏览器会退化成对当前页面地址的请求),
|
|
35
|
+
* 它们完成后由 disposed 标记丢弃结果,只留下已预热的浏览器缓存。
|
|
36
|
+
*/
|
|
37
|
+
dispose(): void;
|
|
38
|
+
private pump;
|
|
39
|
+
private load;
|
|
40
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glodon-aiot/dataset-annotation",
|
|
3
|
-
"version": "3.22.2-alpha.
|
|
3
|
+
"version": "3.22.2-alpha.6",
|
|
4
4
|
"module": "./dist/es/index.mjs",
|
|
5
5
|
"main": "./dist/lib/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@ant-design/icons": "^5.3.4",
|
|
39
39
|
"@aws-crypto/sha256-js": "^3.0.0",
|
|
40
|
-
"@glodon-aiot/apis": "^3.22.2-alpha.
|
|
40
|
+
"@glodon-aiot/apis": "^3.22.2-alpha.6",
|
|
41
41
|
"@glodon-aiot/minio": "^0.1.6",
|
|
42
42
|
"@reduxjs/toolkit": "^1.9.5",
|
|
43
43
|
"@types/fabric": "^5.3.2",
|