kfb-view 3.2.0 → 3.2.2
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/lib/kfb-view.js +1 -1
- package/lib/kfb-view.js.LICENSE.txt +3 -3
- package/package.json +1 -1
- package/src/components/common/common.js +21 -22
- package/src/components/graduation/index.js +42 -20
- package/src/plugin/openseadragon/openseadragon.js +3351 -3851
- package/src/util/index.js +17 -0
- package/src/view.js +16 -4
package/src/util/index.js
CHANGED
|
@@ -64,9 +64,26 @@ function delayedTrigger(callback, time = 1000) {
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
function getUnitNumber(number, units, binary, index = 0) {
|
|
68
|
+
if (index) {
|
|
69
|
+
return (number / Math.pow(binary, index)).toFixed(2) / 1 + units[index];
|
|
70
|
+
}
|
|
71
|
+
let i = number;
|
|
72
|
+
while (i >= binary) {
|
|
73
|
+
i = i / binary;
|
|
74
|
+
index++;
|
|
75
|
+
}
|
|
76
|
+
if (!units[index]) {
|
|
77
|
+
index = units.length - 1;
|
|
78
|
+
}
|
|
79
|
+
return (number / Math.pow(binary, index)).toFixed(2) / 1 + units[index];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
67
83
|
export {
|
|
68
84
|
$,
|
|
69
85
|
dataType,
|
|
70
86
|
deepClone,
|
|
71
87
|
delayedTrigger,
|
|
88
|
+
getUnitNumber,
|
|
72
89
|
};
|
package/src/view.js
CHANGED
|
@@ -35,7 +35,9 @@ export default class KfbView extends EventEmitter {
|
|
|
35
35
|
* @param {number[]=} config.navigator.vestige.zooms 浏览痕迹触发倍率
|
|
36
36
|
* @param {Object} config.pxConversion 像素转换参数
|
|
37
37
|
* @param {number} config.pxConversion.imageCapRes 像素转换倍率
|
|
38
|
-
* @param {string} config.pxConversion.
|
|
38
|
+
* @param {string[]=} config.pxConversion.units 单位组 ['um', 'mm', 'cm']
|
|
39
|
+
* @param {string} config.pxConversion.unit 单位 废弃
|
|
40
|
+
* @param {number} config.pxConversion.binary 几进制, 2, 16, 24, 1000
|
|
39
41
|
* @param {Object} config.area 交互区域,触发点击、拖动等事件
|
|
40
42
|
* @param {boolean=} config.area.disabled 是否禁用area
|
|
41
43
|
* @param {boolean=} config.area.drag 是否允许拖动
|
|
@@ -63,7 +65,9 @@ export default class KfbView extends EventEmitter {
|
|
|
63
65
|
* @param {boolean=} config.graduation.disabled 是否禁用刻度
|
|
64
66
|
* @param {boolean=} config.graduation.show 是否显刻度
|
|
65
67
|
* @param {boolean=} config.graduation.custom 是否自定义刻度,抛出graduation-change事件
|
|
66
|
-
* @param {
|
|
68
|
+
* @param {Object} config.graduation.tick 刻度线参数
|
|
69
|
+
* @param {number=} config.graduation.tick.height 刻度线高度
|
|
70
|
+
* @param {number=} config.graduation.tick.number 刻度线段落
|
|
67
71
|
* @param {array=} config.graduation.microns 刻度长度数组,在对应倍率范围内显示的刻度长度
|
|
68
72
|
* @param {boolean=} config.grid.disabled 是否禁用网格线
|
|
69
73
|
* @param {boolean=} config.grid.show 是否显示网格线
|
|
@@ -81,6 +85,7 @@ export default class KfbView extends EventEmitter {
|
|
|
81
85
|
* @param {function=} config.label.drawing 标注绘制回调,
|
|
82
86
|
* @param {function=} config.labelDrawing 标注绘制回调 @deprecated Use label.drawing instead
|
|
83
87
|
* @param {array} config.labelList 标注列表
|
|
88
|
+
* @param {function} config.handleKey 按钮处理回调
|
|
84
89
|
*/
|
|
85
90
|
constructor(config) {
|
|
86
91
|
super();
|
|
@@ -285,7 +290,7 @@ function createCanvas(kv) {
|
|
|
285
290
|
|
|
286
291
|
function initComponentsOptions(kv, type) {
|
|
287
292
|
const config = kv.$options;
|
|
288
|
-
const pxConversion = config.pxConversion || {imageCapRes: 1,
|
|
293
|
+
const pxConversion = config.pxConversion || {imageCapRes: 1, units: []};
|
|
289
294
|
return {
|
|
290
295
|
kv,
|
|
291
296
|
viewer: kv.viewer,
|
|
@@ -306,6 +311,7 @@ function initComponentsOptions(kv, type) {
|
|
|
306
311
|
},
|
|
307
312
|
...config[type],
|
|
308
313
|
...pxConversion,
|
|
314
|
+
units: pxConversion.units ?? [pxConversion.unit ?? ''], // 兼容之前只显示一个的单位
|
|
309
315
|
thumb: config.thumb ? {
|
|
310
316
|
radius: 5,
|
|
311
317
|
activeRadius: 7,
|
|
@@ -368,7 +374,9 @@ function initEvent(kv) {
|
|
|
368
374
|
|
|
369
375
|
kv.viewer.addHandler('canvas-key', (e) => {
|
|
370
376
|
const {originalEvent} = e;
|
|
371
|
-
e.preventDefaultAction =
|
|
377
|
+
e.preventDefaultAction = kv.$options.handleKey ?
|
|
378
|
+
kv.$options.handleKey(originalEvent.key) :
|
|
379
|
+
handlerKey(originalEvent.key);
|
|
372
380
|
handlerCacheEvent(originalEvent, kv);
|
|
373
381
|
if (kv.board?.isInDraw) {
|
|
374
382
|
kv.board?.onCanvasKey?.(e);
|
|
@@ -448,6 +456,10 @@ function initEvent(kv) {
|
|
|
448
456
|
});
|
|
449
457
|
}
|
|
450
458
|
|
|
459
|
+
function handlerKey(key) {
|
|
460
|
+
return ['Escape', 'Delete', 'Backspace', 'z', 'y'].includes(key);
|
|
461
|
+
}
|
|
462
|
+
|
|
451
463
|
function handlerCacheEvent(e, kv) {
|
|
452
464
|
if (e.key === 'z' && e.ctrlKey) {
|
|
453
465
|
if (kv.cache.currentIndex === 0) return;
|