kfb-view 2.1.20 → 2.2.0

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/src/view.js CHANGED
@@ -6,7 +6,7 @@ import {pointsToRegion} from './util/calculate';
6
6
  import * as COMPONENTS from './const/component';
7
7
  import * as EVENTS from './const/event';
8
8
  import * as Components from './components';
9
- import {MARKS} from './const/mark';
9
+ import {MARKS, POLYGON} from './const/mark';
10
10
  import {LabelModel} from './model/label.model';
11
11
 
12
12
  /**
@@ -37,9 +37,14 @@ export default class KfbView extends EventEmitter {
37
37
  * @param {Object} config.area 交互区域,触发点击、拖动等事件
38
38
  * @param {boolean=} config.area.disabled 是否禁用area
39
39
  * @param {boolean=} config.area.drag 是否允许拖动
40
- * @param {boolean=} config.area.thumb 选中区域时是否显示标注点
41
- * @param {boolean=} config.area.thumbRadius 选中区域标注点的半径
42
- * @param {boolean=} config.area.thumbColor 选中区域标注点的颜色
40
+ * @param {Object} config.thumb 选中区域时标注点配置
41
+ * @param {boolean=} config.thumb.show 选中区域时是否标注点
42
+ * @param {number=} config.thumb.radius 选中区域标注点的半径
43
+ * @param {String=} config.thumb.color 选中区域标注点的颜色
44
+ * @param {String=} config.thumb.bgColor 选中区域标注点的背景颜色
45
+ * @param {number=} config.thumb.activeRadius 标注点激活状态下的半径
46
+ * @param {boolean=} config.thumb.activeColor 标注点激活状态下颜色
47
+ * @param {boolean=} config.thumb.activeBgColor 标注点激活状态下背景颜色
43
48
  * @param {Object} config.rotation 旋转图像参数
44
49
  * @param {boolean=} config.rotation.disabled 是否禁用旋转
45
50
  * @param {Object} config.tailoring 裁剪图像参数
@@ -254,7 +259,18 @@ function initComponentsOptions(kv, type) {
254
259
  viewer: kv.viewer,
255
260
  cache: kv.cache,
256
261
  canvas: createCanvas(kv),
257
- options: {...config[type], ...pxConversion},
262
+ options: {
263
+ ...config[type], ...pxConversion, thumb: config.thumb ? {
264
+ radius: 5,
265
+ activeRadius: 7,
266
+ activeBgColor: '#01d0b0',
267
+ ...config.thumb,
268
+ } : {
269
+ radius: 5,
270
+ activeRadius: 7,
271
+ activeBgColor: '#01d0b0',
272
+ },
273
+ },
258
274
  };
259
275
  }
260
276
 
@@ -287,8 +303,7 @@ function initEvent(kv) {
287
303
  e.preventDefaultAction = true;
288
304
  kv.tailoring.onCanvasDrag(e.position);
289
305
  } else if (kv.area?.movePoint) {
290
- e.preventDefaultAction = true;
291
- kv.area.onCanvasDrag(e.position);
306
+ kv.area.onCanvasDrag(e.position, e);
292
307
  kv.change();
293
308
  }
294
309
  });
@@ -308,12 +323,17 @@ function initEvent(kv) {
308
323
  e.preventDefaultAction = true;
309
324
  const {originalEvent} = e;
310
325
  handlerCacheEvent(originalEvent, kv);
311
- handlerLabelEvent(originalEvent, kv);
312
- kv.area?.onCanvasKey?.(e);
313
- kv.shape?.onCanvasKey?.(e);
314
- kv.board?.onCanvasKey?.(e);
315
- kv.tailoring?.onCanvasKey?.(e);
316
- kv.rotation?.onCanvasKey?.(e);
326
+ if (kv.board?.isInDraw) {
327
+ kv.board?.onCanvasKey?.(e);
328
+ } else if (kv.rotation?.isInRotation) {
329
+ kv.rotation?.onCanvasKey?.(e);
330
+ } else if (kv.tailoring?.isInTailoring) {
331
+ kv.tailoring?.onCanvasKey?.(e);
332
+ } else {
333
+ handlerLabelEvent(originalEvent, kv);
334
+ kv.area?.change?.(e);
335
+ kv.shape?.change?.(e);
336
+ }
317
337
  }, 100));
318
338
 
319
339
  kv.viewer.addHandler('canvas-double-click', (e) => {
@@ -391,17 +411,36 @@ function handlerCacheEvent(e, kv) {
391
411
  }
392
412
 
393
413
  function handlerLabelEvent(e, kv) {
414
+ const index = kv.labelList.findIndex((item) => item.select);
415
+ const label = kv.labelList[index];
394
416
  if (e.key === 'h') {
395
- const label = kv.labelList.find((label) => label.select);
396
417
  if (!label) return;
397
418
  label.show = false;
398
419
  kv.$emit(EVENTS.EVENT_HIDDEN_LABEL, label);
399
- }
400
- if (e.key === 'Delete' || e.key === 'Backspace') {
401
- const index = kv.labelList.findIndex((label) => label.select);
402
- if (!~index) return;
403
- kv.$emit(EVENTS.EVENT_DELETE_LABEL, kv.labelList[index]);
404
- kv.labelList.splice(index, 1);
420
+ } else if (e.key === 'Delete' || e.key === 'Backspace') {
421
+ if (!label) return;
422
+ if (kv.area?.movePoint?.label?.tool === POLYGON) {
423
+ const movePoint = kv.area.movePoint;
424
+ movePoint.label.points.splice(movePoint.position, 1);
425
+ if (movePoint.label.points.length === 0) {
426
+ kv.$emit(EVENTS.EVENT_DELETE_LABEL, label);
427
+ kv.labelList.splice(index, 1);
428
+ } else {
429
+ kv.$emit(EVENTS.EVENT_DELETE_POLYGON_POINT, movePoint.label);
430
+ }
431
+ kv.area.movePoint = undefined;
432
+ } else {
433
+ kv.$emit(EVENTS.EVENT_DELETE_LABEL, label);
434
+ kv.labelList.splice(index, 1);
435
+ }
436
+ } else if (e.key === 'Escape') {
437
+ if (label) {
438
+ kv.$emit(EVENTS.EVENT_CANCEL_SELECT_LABEL, label);
439
+ }
440
+ kv.labelList.forEach((item) => {
441
+ item.select = false;
442
+ item.show = true;
443
+ });
405
444
  }
406
445
  }
407
446