next-element-vue 0.3.5 → 0.3.7

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/dist/index.js CHANGED
@@ -2,8 +2,8 @@
2
2
  /**
3
3
  * 作  者:huangteng
4
4
  * 邮  箱:htengweb@163.com
5
- * 当前版本:0.3.5 v
6
- * 发布日期:2024-09-03
5
+ * 当前版本:0.3.7 v
6
+ * 发布日期:2024-09-21
7
7
  * 地  址:https://www.npmjs.com/package/next-element-vue
8
8
  */
9
9
 
@@ -895,7 +895,8 @@ var merge = createAssigner((function(object, source, srcIndex) {
895
895
  confirmDeleteLabel: "确定要删除该标注吗?",
896
896
  saveLabel: "保存当前标注",
897
897
  instructions: "使用说明",
898
- labelNoUpdate: "暂无标签数据更新"
898
+ labelNoUpdate: "暂无标签数据更新",
899
+ zoomRestore: "还原"
899
900
  },
900
901
  labelme: {
901
902
  saveLabel: "保存",
@@ -979,7 +980,8 @@ var merge = createAssigner((function(object, source, srcIndex) {
979
980
  confirmDeleteLabel: "Are you sure you want to delete this annotation?",
980
981
  saveLabel: "save label",
981
982
  instructions: "instructions",
982
- labelNoUpdate: "No label data update"
983
+ labelNoUpdate: "No label data update",
984
+ zoomRestore: "restore zoom"
983
985
  },
984
986
  labelme: {
985
987
  saveLabel: "saving...",
@@ -1063,7 +1065,8 @@ var merge = createAssigner((function(object, source, srcIndex) {
1063
1065
  confirmDeleteLabel: "确定要删除该标注吗?",
1064
1066
  saveLabel: "保存当前标注",
1065
1067
  instructions: "使用说明",
1066
- labelNoUpdate: "暂无标签数据更新"
1068
+ labelNoUpdate: "暂无标签数据更新",
1069
+ zoomRestore: "还原"
1067
1070
  },
1068
1071
  labelme: {
1069
1072
  saveLabel: "保存"
@@ -6021,8 +6024,8 @@ var ToolHeader = defineComponent({
6021
6024
  },
6022
6025
  emits: [ "fullscreen", "save" ],
6023
6026
  setup(props, {emit: emit}) {
6024
- const _ns = inject("ns", {}), {t: t} = useLocale(), switchFillscreen = val => {
6025
- emit("fullscreen", val);
6027
+ const _ns = inject("ns", {}), scaleTranslateManager = inject("scaleTranslateManager", {}), scaleTranslate = scaleTranslateManager.scaleTranslate, {t: t} = useLocale(), switchFillscreen = val => {
6028
+ emit("fullscreen", val), document.body.style.overflow = val ? "hidden" : "auto";
6026
6029
  };
6027
6030
  return () => createVNode(Fragment, null, [ createVNode(Fragment, null, [ createVNode("ul", {
6028
6031
  class: [ _ns.be("header", "tool") ]
@@ -6048,7 +6051,28 @@ var ToolHeader = defineComponent({
6048
6051
  style: "padding-left: 3px"
6049
6052
  }, [ t("next.labelimg.saveLabel") ]) ]) ]), createVNode("ul", {
6050
6053
  class: [ _ns.be("header", "tool") ]
6051
- }, [ props.imageLength ? createVNode("li", null, [ createVNode("span", null, [ createTextVNode("第 "), props.imageIndex + 1, createTextVNode(" 张") ]), createVNode("em", {
6054
+ }, [ createVNode("li", {
6055
+ class: "hover",
6056
+ onClick: () => scaleTranslateManager.onResetScaleTranslate()
6057
+ }, [ createVNode("svg", {
6058
+ t: "1725840994827",
6059
+ class: "icon",
6060
+ viewBox: "0 0 1024 1024",
6061
+ version: "1.1",
6062
+ xmlns: "http://www.w3.org/2000/svg",
6063
+ "p-id": "6051",
6064
+ width: "18",
6065
+ height: "18"
6066
+ }, [ createVNode("path", {
6067
+ d: "M322.794667 445.205333a34.133333 34.133333 0 0 1 2.218666 45.824l-2.218666 2.432a34.133333 34.133333 0 0 1-45.824 2.218667l-2.432-2.218667-149.333334-149.333333a34.133333 34.133333 0 0 1-2.218666-45.824l2.218666-2.432 149.333334-149.333333a34.133333 34.133333 0 0 1 50.474666 45.824l-2.218666 2.432-91.050667 91.050666L640 285.866667c160.234667 0 290.133333 129.898667 290.133333 290.133333 0 158.016-126.314667 286.506667-283.477333 290.048L640 866.133333H234.666667a34.133333 34.133333 0 0 1-3.114667-68.117333L234.666667 797.866667h405.333333c122.538667 0 221.866667-99.328 221.866667-221.866667 0-120.533333-96.106667-218.602667-215.850667-221.781333L640 354.133333l-408.256-0.021333 91.050667 91.093333z",
6068
+ "p-id": "6052"
6069
+ }, null) ]), createVNode("span", {
6070
+ style: "padding-left: 3px"
6071
+ }, [ t("next.labelimg.zoomRestore") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("缩放比例") ]), createVNode("span", null, [ parseInt((100 * scaleTranslate.value.scale).toString()), createTextVNode("%") ]), createVNode("span", {
6072
+ style: "padding: 0 10px;"
6073
+ }, [ createTextVNode("偏移量") ]), createVNode("span", {
6074
+ style: "min-width: 120px; text-align: left;"
6075
+ }, [ createTextVNode("X: "), scaleTranslate.value.x, createTextVNode(", Y: "), scaleTranslate.value.y ]) ]), props.imageLength ? createVNode("li", null, [ createVNode("span", null, [ createTextVNode("第 "), props.imageIndex + 1, createTextVNode(" 张") ]), createVNode("em", {
6052
6076
  style: "padding: 0 5px;"
6053
6077
  }, [ createTextVNode("/") ]), createVNode("span", null, [ createTextVNode("共 "), props.imageLength, createTextVNode(" 张") ]) ]) : null, createVNode("li", {
6054
6078
  style: "margin-right: 30px;",
@@ -6069,7 +6093,7 @@ var ToolHeader = defineComponent({
6069
6093
  }) ]),
6070
6094
  default: () => createVNode("ul", {
6071
6095
  style: "font-size: 12px;white-space: nowrap;"
6072
- }, [ createVNode("li", null, [ createVNode("span", null, [ createTextVNode("W:") ]), createVNode("span", null, [ createTextVNode("鼠标移入图片中,长按W键,鼠标按下左键,移动鼠标开始绘制,鼠标抬起结束绘制") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("A:") ]), createVNode("span", null, [ createTextVNode("A键进入上一张图片进行标注") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("D:") ]), createVNode("span", null, [ createTextVNode("D键进入下一张图片进行标注") ]) ]) ])
6096
+ }, [ createVNode("li", null, [ createVNode("span", null, [ createTextVNode("W:") ]), createVNode("span", null, [ createTextVNode("鼠标移入图片中,长按W键,鼠标按下左键,移动鼠标开始绘制,鼠标抬起结束绘制") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("A:") ]), createVNode("span", null, [ createTextVNode("A键进入上一张图片进行标注") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("D:") ]), createVNode("span", null, [ createTextVNode("D键进入下一张图片进行标注") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("Ctrl+鼠标滚轮:") ]), createVNode("span", null, [ createTextVNode("长按Ctrl+鼠标滚轮对图片进行缩放") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("Ctrl+鼠标左键:") ]), createVNode("span", null, [ createTextVNode("长按Ctrl+鼠标左键对图片进行拖拽移动") ]) ]) ])
6073
6097
  }) ]), props.isFullscreen ? createVNode("li", {
6074
6098
  class: "hover",
6075
6099
  onClick: () => switchFillscreen(!1)
@@ -6217,6 +6241,101 @@ var ContextMenuLabel = defineComponent({
6217
6241
  }
6218
6242
  });
6219
6243
 
6244
+ class CanvasSceneDragZoom {
6245
+ canvas;
6246
+ canvasWidth;
6247
+ canvasHeight;
6248
+ ctx;
6249
+ scaleFactor=1;
6250
+ preScaleFactor=1;
6251
+ offset={
6252
+ x: 0,
6253
+ y: 0
6254
+ };
6255
+ preOffset={
6256
+ x: 0,
6257
+ y: 0
6258
+ };
6259
+ mousePositioin={
6260
+ x: 0,
6261
+ y: 0
6262
+ };
6263
+ maxScale=8;
6264
+ minScale=.5;
6265
+ scaleStep=.1;
6266
+ clickX=0;
6267
+ clickY=0;
6268
+ observers=[];
6269
+ constructor(canvas) {
6270
+ this.canvas = canvas, this.canvasWidth = canvas.width, this.canvasHeight = canvas.height,
6271
+ this.ctx = canvas.getContext("2d"), this.canvasMousedown = this.canvasMousedown.bind(this),
6272
+ this.canvasMousemove = this.canvasMousemove.bind(this), this.canvasMouseup = this.canvasMouseup.bind(this),
6273
+ this.canvas.addEventListener("mousedown", this.canvasMousedown), this.canvas.addEventListener("wheel", this.canvasMousewheel, {
6274
+ passive: !1
6275
+ }), window.addEventListener("wheel", this.onWindowWheel, {
6276
+ passive: !1
6277
+ });
6278
+ }
6279
+ notifyObservers(scale, offset) {
6280
+ this.observers.forEach((listener => {
6281
+ listener({
6282
+ scale: scale,
6283
+ ...offset
6284
+ });
6285
+ }));
6286
+ }
6287
+ changeZoom(callback) {
6288
+ this.observers.push(callback);
6289
+ }
6290
+ reset() {
6291
+ this.scaleFactor = 1, this.preScaleFactor = 1, this.offset = {
6292
+ x: 0,
6293
+ y: 0
6294
+ }, this.preOffset = {
6295
+ x: 0,
6296
+ y: 0
6297
+ }, this.mousePositioin = {
6298
+ x: 0,
6299
+ y: 0
6300
+ }, this.zoom();
6301
+ }
6302
+ render() {
6303
+ this.canvas.width = this.canvasWidth, this.notifyObservers(this.scaleFactor, this.offset);
6304
+ }
6305
+ zoom() {
6306
+ const offset_x = this.mousePositioin.x - (this.mousePositioin.x - this.offset.x) * this.scaleFactor / this.preScaleFactor, offset_y = this.mousePositioin.y - (this.mousePositioin.y - this.offset.y) * this.scaleFactor / this.preScaleFactor;
6307
+ this.offset.x = Math.ceil(offset_x), this.offset.y = Math.ceil(offset_y), this.render(),
6308
+ this.preScaleFactor = this.scaleFactor, this.preOffset.x = this.offset.x, this.preOffset.y = this.offset.y;
6309
+ }
6310
+ onWindowWheel=e => {
6311
+ e.ctrlKey && e.preventDefault();
6312
+ };
6313
+ canvasMousewheel=event => {
6314
+ event.preventDefault(), event.ctrlKey && (this.mousePositioin.x = event.offsetX,
6315
+ this.mousePositioin.y = event.offsetY, event.deltaY > 0 ? (this.scaleFactor = parseFloat((this.scaleFactor + this.scaleStep).toFixed(1)),
6316
+ this.scaleFactor > this.maxScale && (this.scaleFactor = this.maxScale)) : (this.scaleFactor = parseFloat((this.scaleFactor - this.scaleStep).toFixed(1)),
6317
+ this.scaleFactor < this.minScale && (this.scaleFactor = this.minScale)), this.zoom());
6318
+ };
6319
+ canvasMousedown(event) {
6320
+ event.preventDefault(), 0 === event.button && event.ctrlKey && (this.clickX = event.offsetX,
6321
+ this.clickY = event.offsetY, this.canvas.addEventListener("mousemove", this.canvasMousemove),
6322
+ this.canvas.addEventListener("mouseup", this.canvasMouseup));
6323
+ }
6324
+ canvasMousemove(event) {
6325
+ event.preventDefault(), event.ctrlKey && (this.offset.x = Math.ceil(this.preOffset.x + (event.offsetX - this.clickX)),
6326
+ this.offset.y = Math.ceil(this.preOffset.y + (event.offsetY - this.clickY)), this.render());
6327
+ }
6328
+ canvasMouseup(event) {
6329
+ event.preventDefault(), event.ctrlKey && (this.preOffset.x = this.offset.x, this.preOffset.y = this.offset.y,
6330
+ this.canvas.removeEventListener("mousemove", this.canvasMousemove), this.canvas.removeEventListener("mouseup", this.canvasMouseup));
6331
+ }
6332
+ destroy() {
6333
+ this.canvas.removeEventListener("mousedown", this.canvasMousedown), this.canvas.removeEventListener("mousemove", this.canvasMousemove),
6334
+ this.canvas.removeEventListener("mouseup", this.canvasMouseup), this.canvas.removeEventListener("wheel", this.canvasMousewheel),
6335
+ window.removeEventListener("wheel", this.onWindowWheel);
6336
+ }
6337
+ }
6338
+
6220
6339
  const {hexToRgb: hexToRgb} = useChangeColor();
6221
6340
 
6222
6341
  var DraggableRect = defineComponent({
@@ -6236,7 +6355,7 @@ var DraggableRect = defineComponent({
6236
6355
  },
6237
6356
  emits: [ "draggle-resize", "contextmenu" ],
6238
6357
  setup(props, {emit: emit}) {
6239
- const isDraggle = ref(!1), isResizeCorner = ref({
6358
+ const scaleTranslate = inject("scaleTranslateManager", {}).scaleTranslate, isDraggle = ref(!1), isResizeCorner = ref({
6240
6359
  topLeft: !1,
6241
6360
  topCenter: !1,
6242
6361
  topRight: !1,
@@ -6256,66 +6375,68 @@ var DraggableRect = defineComponent({
6256
6375
  isResizeCorner.value.rightCenter = !1, isResizeCorner.value.bottomLeft = !1, isResizeCorner.value.bottomCenter = !1,
6257
6376
  isResizeCorner.value.bottomRight = !1, emit("draggle-resize", rect.value);
6258
6377
  }, onMousemove = e => {
6378
+ const {scale: scale, x: x, y: y} = scaleTranslate.value, min_size = 30 / scale, startX = Math.ceil(rect.value.startX * scale + x), startY = Math.ceil(rect.value.startY * scale + y);
6259
6379
  if (isDraggle.value) {
6260
- const newLeft = e.clientX - parentRect.left - draggleOffset.value.diff_x, newTop = e.clientY - parentRect.top - draggleOffset.value.diff_y;
6261
- rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6262
- rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6380
+ const newLeft = e.clientX - parentRect.left - draggleOffset.value.diff_x, newTop = e.clientY - parentRect.top - draggleOffset.value.diff_y, offsetX = Math.ceil((newLeft - x) / scale), offsetY = Math.ceil((newTop - y) / scale);
6381
+ rect.value.startX = Math.max(0, Math.min(offsetX, parentRect.width - rect.value.rectWidth)),
6382
+ rect.value.startY = Math.max(0, Math.min(offsetY, parentRect.height - rect.value.rectHeight));
6263
6383
  }
6264
6384
  if (isResizeCorner.value.bottomCenter) {
6265
- let newHeight = e.clientY - parentRect.top - rect.value.startY;
6266
- newHeight < 30 && (newHeight = 30), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6385
+ let newHeight = Math.floor((e.clientY - parentRect.top - startY) / scale);
6386
+ newHeight < min_size && (newHeight = min_size), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6267
6387
  rect.value.rectHeight = newHeight;
6268
6388
  }
6269
6389
  if (isResizeCorner.value.topCenter) {
6270
- let newTop = e.clientY - parentRect.top, newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6390
+ let newTop = Math.floor((e.clientY - parentRect.top - y) / scale), newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6271
6391
  if (newTop < 0) return;
6272
- if (newHeight < 30) return;
6392
+ if (newHeight < min_size) return;
6273
6393
  rect.value.rectHeight = newHeight, rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6274
6394
  }
6275
6395
  if (isResizeCorner.value.leftCenter) {
6276
- let newLeft = e.clientX - parentRect.left, newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6396
+ let newLeft = Math.floor((e.clientX - parentRect.left - x) / scale), newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6277
6397
  if (newLeft < 0) return;
6278
- if (newWidth < 30) return;
6398
+ if (newWidth < min_size) return;
6279
6399
  rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6280
6400
  rect.value.rectWidth = newWidth;
6281
6401
  }
6282
6402
  if (isResizeCorner.value.rightCenter) {
6283
- let newWidth = e.clientX - parentRect.left - rect.value.startX;
6284
- newWidth < 30 && (newWidth = 30), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6403
+ let newWidth = Math.floor((e.clientX - parentRect.left - startX) / scale);
6404
+ newWidth < min_size && (newWidth = min_size), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6285
6405
  rect.value.rectWidth = newWidth;
6286
6406
  }
6287
6407
  if (isResizeCorner.value.bottomRight) {
6288
- let newWidth = e.clientX - parentRect.left - rect.value.startX, newHeight = e.clientY - parentRect.top - rect.value.startY;
6289
- newWidth < 30 && (newWidth = 30), newHeight < 30 && (newHeight = 30), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6408
+ let newWidth = Math.floor((e.clientX - parentRect.left - startX) / scale), newHeight = Math.floor((e.clientY - parentRect.top - startY) / scale);
6409
+ newWidth < min_size && (newWidth = min_size), newHeight < min_size && (newHeight = min_size),
6410
+ newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6290
6411
  newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6291
6412
  rect.value.rectWidth = newWidth, rect.value.rectHeight = newHeight;
6292
6413
  }
6293
6414
  if (isResizeCorner.value.bottomLeft) {
6294
- let newLeft = e.clientX - parentRect.left, newWidth = rect.value.startX - newLeft + rect.value.rectWidth, newHeight = e.clientY - parentRect.top - rect.value.startY;
6415
+ let newLeft = Math.floor((e.clientX - parentRect.left - x) / scale), newWidth = rect.value.startX - newLeft + rect.value.rectWidth, newHeight = Math.floor((e.clientY - parentRect.top - startY) / scale);
6295
6416
  if (newLeft < 0) return;
6296
- if (newWidth < 30) return;
6297
- newHeight < 30 && (newHeight = 30), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6417
+ if (newWidth < min_size) return;
6418
+ newHeight < min_size && (newHeight = min_size), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6298
6419
  rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6299
6420
  rect.value.rectWidth = newWidth, rect.value.rectHeight = newHeight;
6300
6421
  }
6301
6422
  if (isResizeCorner.value.topLeft) {
6302
- let newTop = e.clientY - parentRect.top, newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6423
+ let newTop = Math.floor((e.clientY - parentRect.top - y) / scale), newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6303
6424
  if (newTop < 0) return;
6304
- if (newHeight < 30) return;
6425
+ if (newHeight < min_size) return;
6305
6426
  rect.value.rectHeight = newHeight, rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6306
- let newLeft = e.clientX - parentRect.left, newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6427
+ let newLeft = Math.floor((e.clientX - parentRect.left - x) / scale), newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6307
6428
  if (newLeft < 0) return;
6308
- if (newWidth < 30) return;
6429
+ if (newWidth < min_size) return;
6309
6430
  rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6310
6431
  rect.value.rectWidth = newWidth;
6311
6432
  }
6312
6433
  if (isResizeCorner.value.topRight) {
6313
- let newTop = e.clientY - parentRect.top, newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6434
+ let newTop = Math.floor((e.clientY - parentRect.top - y) / scale), newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6314
6435
  if (newTop < 0) return;
6315
- if (newHeight < 30) return;
6436
+ if (newHeight < min_size) return;
6316
6437
  rect.value.rectHeight = newHeight, rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6317
- let newWidth = e.clientX - parentRect.left - rect.value.startX;
6318
- newWidth < 30 && (newWidth = 30), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6438
+ let newWidth = Math.floor((e.clientX - parentRect.left - startX) / scale);
6439
+ newWidth < min_size && (newWidth = min_size), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6319
6440
  rect.value.rectWidth = newWidth;
6320
6441
  }
6321
6442
  };
@@ -6340,11 +6461,23 @@ var DraggableRect = defineComponent({
6340
6461
  };
6341
6462
  },
6342
6463
  render() {
6343
- const _ns = inject("ns", {}), props = this.$props;
6464
+ const _ns = inject("ns", {}), scaleTranslate = inject("scaleTranslateManager", {}).scaleTranslate, props = this.$props;
6344
6465
  return createVNode("div", {
6345
6466
  class: [ _ns.b("draggable-rect") ],
6346
6467
  style: (() => {
6347
- const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = this.rect, style = {
6468
+ const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = ((rect, scaleOffset) => {
6469
+ const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect, {scale: scale, x: x, y: y} = scaleOffset;
6470
+ return {
6471
+ startX: Math.ceil(startX * scale + x),
6472
+ startY: Math.ceil(startY * scale + y),
6473
+ rectWidth: Math.ceil(rectWidth * scale),
6474
+ rectHeight: Math.ceil(rectHeight * scale),
6475
+ canvasWidth: rect.canvasWidth,
6476
+ canvasHeight: rect.canvasHeight,
6477
+ originWidth: rect.originWidth,
6478
+ originHeight: rect.originHeight
6479
+ };
6480
+ })(this.rect, scaleTranslate.value), style = {
6348
6481
  top: startY + "px",
6349
6482
  left: startX + "px",
6350
6483
  width: rectWidth + "px",
@@ -6405,7 +6538,7 @@ var DraggableRect = defineComponent({
6405
6538
  },
6406
6539
  emits: [ "change" ],
6407
6540
  setup(props, {emit: emit, expose: expose}) {
6408
- const ns = inject("ns", {}), _emit = inject("_emit", null), canvasMainRef = ref(), canvasBaseRef = ref(), canvasRectRef = ref(), labels = ref([]), drawBaseCanvas = ref({}), formatLabelsType = () => {
6541
+ const ns = inject("ns", {}), _emit = inject("_emit", null), scaleTranslateManager = inject("scaleTranslateManager", {}), mainBasaeRef = ref(), canvasMainRef = ref(), canvasBaseRef = ref(), canvasRectRef = ref(), labels = ref([]), drawBaseCanvas = ref({}), canvasDragZoom = ref(), formatLabelsType = () => {
6409
6542
  const _labels = deepClone(labels.value);
6410
6543
  let yolo_label = [];
6411
6544
  return {
@@ -6423,22 +6556,39 @@ var DraggableRect = defineComponent({
6423
6556
  canvasRectRef.value.width = canvasWidth, canvasRectRef.value.height = canvasHeight,
6424
6557
  canvasRectRef.value.style.width = canvasWidth + "px", canvasRectRef.value.style.height = canvasHeight + "px";
6425
6558
  }, loadingImage = ref(!1), renderImageLabel = rowInfo => {
6426
- labels.value = (rowInfo => rowInfo.labels ? rowInfo.labels.map((rect => {
6427
- const typeName = props.classes[rect.type];
6428
- return typeName && (rect.typeName = typeName), rect;
6429
- })) : [])(rowInfo);
6430
- const clientHeight = canvasMainRef.value?.clientHeight, ctx = canvasBaseRef.value?.getContext("2d");
6559
+ const ctx = canvasBaseRef.value?.getContext("2d");
6431
6560
  if (rowInfo?.imageSrc) {
6432
6561
  const image = new Image;
6433
6562
  image.src = rowInfo.imageSrc, loadingImage.value = !0, image.onload = () => {
6434
6563
  loadingImage.value = !1;
6435
- let {width: width, height: height} = image;
6436
- if (height > clientHeight) {
6437
- const scale = height / clientHeight;
6438
- height = clientHeight, image.style.height = height + "px", width /= scale;
6439
- }
6440
- const canvasHeight = height, scaleFactor = parseFloat((canvasHeight / height).toFixed(3)), canvasWidth = Math.ceil(width * scaleFactor);
6441
- setContainerWidthHeight(canvasWidth, canvasHeight), labels.value = ((labels, canvasHeight) => {
6564
+ const {canvasWidth: canvasWidth, canvasHeight: canvasHeight, scaleFactor: scaleFactor, originWidth: originWidth, originHeight: originHeight} = (image => {
6565
+ const clientWidth = mainBasaeRef.value?.elementInstance.clientWidth, clientHeight = mainBasaeRef.value?.elementInstance.clientHeight;
6566
+ let {width: width, height: height} = image, scaleFactor = 1;
6567
+ const scale = width / height;
6568
+ if (scale > 1 ? (width = clientWidth, height = clientWidth / scale) : (width = clientHeight * scale,
6569
+ height = clientHeight), height > clientHeight) {
6570
+ const scale = height / clientHeight;
6571
+ height = clientHeight, width /= scale;
6572
+ } else if (width > clientWidth) {
6573
+ const scale = width / clientWidth;
6574
+ width = clientWidth, height /= scale;
6575
+ }
6576
+ const canvasWidth = parseInt(width.toString()), canvasHeight = parseInt(height.toString());
6577
+ return scaleFactor = Number((canvasWidth / canvasHeight).toFixed(2)), {
6578
+ canvasWidth: canvasWidth,
6579
+ canvasHeight: canvasHeight,
6580
+ scaleFactor: scaleFactor,
6581
+ originWidth: image.width,
6582
+ originHeight: image.height
6583
+ };
6584
+ })(image);
6585
+ labels.value = ((rowInfo, originWidth, originHeight) => rowInfo.labels ? rowInfo.labels.map((rect => {
6586
+ const typeName = props.classes[rect.type];
6587
+ return typeName && (rect.typeName = typeName), rect.originWidth || (rect.originWidth = originWidth),
6588
+ rect.originHeight || (rect.originHeight = originHeight), rect;
6589
+ })) : [])(rowInfo, originWidth, originHeight), image.style.width = canvasWidth + "px",
6590
+ image.style.height = canvasHeight + "px", setContainerWidthHeight(canvasWidth, canvasHeight),
6591
+ labels.value = ((labels, canvasHeight) => {
6442
6592
  let scale_rects = [];
6443
6593
  for (let i = 0; i < labels.length; i++) {
6444
6594
  const rect = labels[i], scale = parseFloat((canvasHeight / rect.canvasHeight).toFixed(3));
@@ -6450,8 +6600,10 @@ var DraggableRect = defineComponent({
6450
6600
  return scale_rects;
6451
6601
  })(labels.value, canvasHeight);
6452
6602
  const {updateLabels: updateLabels, addDrawRect: addDrawRect, hitCanvasLabel: hitCanvasLabel} = (options => {
6453
- const {ctx: ctx, labels: labels, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight} = options, updateLabels = () => {
6454
- ctx.clearRect(0, 0, canvasWidth, canvasHeight), ctx.drawImage(image, 0, 0, canvasWidth, canvasHeight);
6603
+ const {canvas: canvas, ctx: ctx, labels: labels, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight, scaleOffset: scaleOffset} = options, updateLabels = () => {
6604
+ canvas.width = canvasWidth, scaleOffset.value && (ctx.save(), ctx.translate(scaleOffset.value.x, scaleOffset.value.y),
6605
+ ctx.scale(scaleOffset.value.scale, scaleOffset.value.scale)), ctx.clearRect(0, 0, canvasWidth, canvasHeight),
6606
+ ctx.drawImage(image, 0, 0, canvasWidth, canvasHeight);
6455
6607
  for (let i = 0; i < labels.length; i++) {
6456
6608
  const rect = labels[i], {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight, type: type} = rect, color = colors$1[type % colors$1.length];
6457
6609
  if (ctx.font = "bold 14px serif", ctx.textBaseline = "top", ctx.save(), ctx.strokeStyle = color,
@@ -6466,7 +6618,8 @@ var DraggableRect = defineComponent({
6466
6618
  updateLabels: updateLabels,
6467
6619
  addDrawRect: (rect, color = "#f30635") => {
6468
6620
  const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect;
6469
- ctx.strokeStyle = color, ctx.strokeRect(startX, startY, rectWidth, rectHeight);
6621
+ ctx.save(), ctx.strokeStyle = color, ctx.strokeRect(startX, startY, rectWidth, rectHeight),
6622
+ ctx.restore();
6470
6623
  },
6471
6624
  hitCanvasLabel: (x, y) => {
6472
6625
  let hit_rect = null, hit_index = null, color = null;
@@ -6489,11 +6642,12 @@ var DraggableRect = defineComponent({
6489
6642
  canvasWidth: canvasWidth,
6490
6643
  canvasHeight: canvasHeight,
6491
6644
  labels: labels.value,
6492
- scaleFactor: scaleFactor
6645
+ scaleFactor: scaleFactor,
6646
+ scaleOffset: scaleTranslateManager.scaleTranslate
6493
6647
  });
6494
6648
  drawBaseCanvas.value.updateLabels = updateLabels, drawBaseCanvas.value.addDrawRect = addDrawRect,
6495
6649
  drawBaseCanvas.value.hitCanvasLabel = hitCanvasLabel;
6496
- const {clearCanvas: clearCanvas, removeEventAll: removeEventAll} = ((canvas, callback, keyW) => {
6650
+ const {clearCanvas: clearCanvas, removeEventAll: removeEventAll} = (({canvas: canvas, originWidth: originWidth, originHeight: originHeight}, callback, keyW) => {
6497
6651
  const canvasWidth = canvas.width, canvasHeight = canvas.height, ctx = canvas?.getContext("2d"), clearCanvas = () => {
6498
6652
  ctx.clearRect(0, 0, canvasWidth, canvasHeight);
6499
6653
  };
@@ -6507,14 +6661,16 @@ var DraggableRect = defineComponent({
6507
6661
  rectWidth: rectWidth,
6508
6662
  rectHeight: rectHeight,
6509
6663
  canvasWidth: canvasWidth,
6510
- canvasHeight: canvasHeight
6664
+ canvasHeight: canvasHeight,
6665
+ originWidth: originWidth,
6666
+ originHeight: originHeight
6511
6667
  }, {
6512
6668
  endX: endX,
6513
6669
  endY: endY
6514
6670
  });
6515
6671
  }, documentKeydown = event => {
6516
- "KeyW" === event.code && (isWKeyPressed = !0, canvas.style.cursor = "crosshair",
6517
- canvas.style.zIndex = "11", keyW && keyW());
6672
+ isWKeyPressed || "KeyW" === event.code && (event.preventDefault(), isWKeyPressed = !0,
6673
+ canvas.style.cursor = "crosshair", canvas.style.zIndex = "11", keyW && keyW());
6518
6674
  }, documentKeyup = event => {
6519
6675
  isDrawing || "KeyW" === event.code && (isWKeyPressed = !1, canvas.style.cursor = "unset",
6520
6676
  canvas.style.zIndex = "0");
@@ -6524,13 +6680,13 @@ var DraggableRect = defineComponent({
6524
6680
  };
6525
6681
  document.addEventListener("keydown", documentKeydown), document.addEventListener("keyup", documentKeyup),
6526
6682
  document.addEventListener("mouseup", documentMouseup);
6527
- const canvasMousedown = e => {
6528
- isWKeyPressed && (isDrawing = !0, startX = e.offsetX, startY = e.offsetY);
6529
- }, canvasMousemove = e => {
6530
- isDrawing && isWKeyPressed && (isRectDraw = !0, endX = e.offsetX, endY = e.offsetY,
6683
+ const canvasMousedown = event => {
6684
+ isWKeyPressed && (isDrawing = !0, startX = event.offsetX, startY = event.offsetY);
6685
+ }, canvasMousemove = event => {
6686
+ isDrawing && isWKeyPressed && (isRectDraw = !0, endX = event.offsetX, endY = event.offsetY,
6531
6687
  drawRect());
6532
- }, canvasMouseup = e => {
6533
- e.stopPropagation(), isRectDraw && (isDrawing = !1, isWKeyPressed = !1, canvas.style.cursor = "unset",
6688
+ }, canvasMouseup = event => {
6689
+ event.stopPropagation(), isRectDraw && (isDrawing = !1, isWKeyPressed = !1, canvas.style.cursor = "unset",
6534
6690
  canvas.style.zIndex = "0", drawRectDone(), isRectDraw = !1);
6535
6691
  };
6536
6692
  canvas.addEventListener("mousedown", canvasMousedown), canvas.addEventListener("mousemove", canvasMousemove),
@@ -6544,31 +6700,53 @@ var DraggableRect = defineComponent({
6544
6700
  clearCanvas: clearCanvas,
6545
6701
  drawRect: drawRect,
6546
6702
  removeEventAll: () => {
6547
- document.removeEventListener("mousedown", documentKeydown), document.removeEventListener("keyup", documentKeyup),
6703
+ document.removeEventListener("keydown", documentKeydown), document.removeEventListener("keyup", documentKeyup),
6548
6704
  document.removeEventListener("mouseup", documentMouseup), canvas.removeEventListener("mousedown", canvasMousedown),
6549
6705
  canvas.removeEventListener("mousemove", canvasMousemove), canvas.removeEventListener("mouseup", canvasMouseup);
6550
6706
  }
6551
6707
  };
6552
- })(canvasRectRef.value, ((rect, {endX: endX, endY: endY}) => {
6553
- activate_add_label.value = rect, drawBaseCanvas.value.addDrawRect(rect), updateContextmenuLabelFixed(endX, endY, rect);
6708
+ })({
6709
+ canvas: canvasRectRef.value,
6710
+ originWidth: originWidth,
6711
+ originHeight: originHeight
6712
+ }, ((rect, {endX: endX, endY: endY}) => {
6713
+ activate_add_label.value = rect;
6714
+ const newRect = ((rect, scaleOffset) => {
6715
+ const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect, {scale: scale, x: x, y: y} = scaleOffset;
6716
+ return {
6717
+ startX: Math.ceil((startX - x) / scale),
6718
+ startY: Math.ceil((startY - y) / scale),
6719
+ rectWidth: Math.ceil(rectWidth / scale),
6720
+ rectHeight: Math.ceil(rectHeight / scale),
6721
+ canvasWidth: rect.canvasWidth,
6722
+ canvasHeight: rect.canvasHeight,
6723
+ originWidth: rect.originWidth,
6724
+ originHeight: rect.originHeight
6725
+ };
6726
+ })(rect, scaleTranslateManager.scaleTranslate.value);
6727
+ drawBaseCanvas.value.addDrawRect(newRect), updateContextmenuLabelFixed(endX, endY, newRect);
6554
6728
  }), (() => {
6555
6729
  onCloseDraggableRectFixed();
6556
6730
  }));
6557
- drawBaseCanvas.value.clearCanvasRect = clearCanvas, drawBaseCanvas.value.removeEventAll = removeEventAll;
6731
+ drawBaseCanvas.value.clearCanvasRect = clearCanvas, drawBaseCanvas.value.removeEventAll = removeEventAll,
6732
+ canvasDragZoom.value = new CanvasSceneDragZoom(canvasBaseRef.value), canvasDragZoom.value.changeZoom((scaleOffset => {
6733
+ scaleTranslateManager.onChangeScaleTranslate(scaleOffset), drawBaseCanvas.value.updateLabels();
6734
+ }));
6558
6735
  }, image.onerror = () => {
6559
6736
  loadingImage.value = !1;
6560
6737
  };
6561
6738
  }
6562
6739
  canvasBaseRef.value.addEventListener("contextmenu", (e => {
6563
6740
  e.preventDefault();
6564
- const x = e.offsetX, y = e.offsetY, {hit_rect: hit_rect} = drawBaseCanvas.value.hitCanvasLabel(x, y);
6741
+ const offsetX = e.offsetX, offsetY = e.offsetY, {scale: scale, x: x, y: y} = scaleTranslateManager.scaleTranslate.value, new_x = Math.floor((offsetX - x) / scale), new_y = Math.floor((offsetY - y) / scale), {hit_rect: hit_rect} = drawBaseCanvas.value.hitCanvasLabel(new_x, new_y);
6565
6742
  onCloseContentmenuLabel(), onCloseDraggableRectFixed(), hit_rect && nextTick((() => {
6566
- updateContextmenuLabelFixed(x, y, hit_rect);
6743
+ updateContextmenuLabelFixed(offsetX, offsetY, hit_rect);
6567
6744
  }));
6568
6745
  })), canvasBaseRef.value.addEventListener("click", (e => {
6569
- const x = e.offsetX, y = e.offsetY, {hit_rect: hit_rect, hit_index: hit_index, color: color} = drawBaseCanvas.value.hitCanvasLabel(x, y);
6746
+ if (e.ctrlKey) return;
6747
+ const offsetX = e.offsetX, offsetY = e.offsetY, {scale: scale, x: x, y: y} = scaleTranslateManager.scaleTranslate.value, new_x = Math.floor((offsetX - x) / scale), new_y = Math.floor((offsetY - y) / scale), {hit_rect: hit_rect, hit_index: hit_index, color: color} = drawBaseCanvas.value.hitCanvasLabel(new_x, new_y);
6570
6748
  onCloseDraggableRectFixed(), onCloseContentmenuLabel(), hit_rect && nextTick((() => {
6571
- updateDraggableRectFixed(x, y, hit_rect, hit_index, color);
6749
+ updateDraggableRectFixed(offsetX, offsetY, hit_rect, hit_index, color);
6572
6750
  }));
6573
6751
  }));
6574
6752
  };
@@ -6579,7 +6757,10 @@ var DraggableRect = defineComponent({
6579
6757
  }), {
6580
6758
  deep: !0,
6581
6759
  immediate: !0
6582
- }), watch((() => props.contextClientHeight), (height => {
6760
+ }), watch((() => props.classes), (() => {
6761
+ const rowInfo = toRaw(props.rowInfo);
6762
+ renderImageLabel(rowInfo);
6763
+ })), watch((() => props.contextClientHeight), (height => {
6583
6764
  if (valueExist(height)) {
6584
6765
  canvasMainRef.value.style.height = height + "px";
6585
6766
  const rowInfo = toRaw(props.rowInfo);
@@ -6587,7 +6768,7 @@ var DraggableRect = defineComponent({
6587
6768
  }
6588
6769
  }));
6589
6770
  })), onUnmounted((() => {
6590
- drawBaseCanvas.value.removeEventAll();
6771
+ drawBaseCanvas.value.removeEventAll?.(), canvasDragZoom.value.destroy();
6591
6772
  }));
6592
6773
  const contextmenuLabelFixed = ref({
6593
6774
  show: !1,
@@ -6631,9 +6812,9 @@ var DraggableRect = defineComponent({
6631
6812
  draggableRectFixed.value.width = 0, draggableRectFixed.value.height = 0, draggableRectFixed.value.activateRect = null,
6632
6813
  draggableRectFixed.value.activateIndex = null, draggableRectFixed.value.color = null;
6633
6814
  }, onDraggleRectResize = rect => {
6634
- draggableRectFixed.value.activateRect = rect, drawBaseCanvas.value.updateLabels();
6815
+ draggableRectFixed.value.activateRect = rect;
6635
6816
  const i = labels.value.findIndex((o => isEqual(o, rect)));
6636
- i > -1 && labels.value.splice(i, 1, rect);
6817
+ i > -1 && labels.value.splice(i, 1, rect), drawBaseCanvas.value.updateLabels();
6637
6818
  const {rects: rects, label_txt: label_txt} = formatLabelsType();
6638
6819
  _emit("change", rects, label_txt), emit("change", rects, label_txt);
6639
6820
  }, onContextmenuDraggable = (e, rect) => {
@@ -6674,9 +6855,13 @@ var DraggableRect = defineComponent({
6674
6855
  const rowInfo = toRaw(props.rowInfo);
6675
6856
  renderImageLabel(rowInfo);
6676
6857
  }));
6858
+ },
6859
+ resetScaleOffset: () => {
6860
+ canvasDragZoom.value.reset();
6677
6861
  }
6678
6862
  });
6679
6863
  return () => createVNode(Fragment, null, [ createVNode(NextSpinLoading, {
6864
+ ref: mainBasaeRef,
6680
6865
  loading: loadingImage.value,
6681
6866
  class: [ ns.b("loading") ]
6682
6867
  }, {
@@ -6721,13 +6906,15 @@ var DraggableRect = defineComponent({
6721
6906
  },
6722
6907
  emits: [ "delete", "select" ],
6723
6908
  setup(props, {emit: emit}) {
6724
- const {t: t} = useLocale(), ns = inject("ns", {}), labels = ref([]);
6725
- watch((() => props.labels), (rects => {
6909
+ const {t: t} = useLocale(), ns = inject("ns", {}), labels = ref([]), formatLabelsTypeName = labels => labels.length ? labels.map((rect => {
6910
+ const typeName = props.classes[rect.type];
6911
+ return typeName && (rect.typeName = typeName), rect;
6912
+ })) : [];
6913
+ watch((() => props.classes), (() => {
6914
+ labels.value = formatLabelsTypeName(labels.value);
6915
+ })), watch((() => props.labels), (rects => {
6726
6916
  const _rects = toRaw(rects);
6727
- labels.value = (labels => labels.length ? labels.map((rect => {
6728
- const typeName = props.classes[rect.type];
6729
- return typeName && (rect.typeName = typeName), rect;
6730
- })) : [])(_rects);
6917
+ labels.value = formatLabelsTypeName(_rects);
6731
6918
  }), {
6732
6919
  deep: !0,
6733
6920
  immediate: !0
@@ -6872,7 +7059,11 @@ var Element$1 = defineComponent({
6872
7059
  label_txt: label_txt
6873
7060
  }, (imageItem => {
6874
7061
  labelImages.value[activateNodeIndex.value] = imageItem || node, activateNodeIndex.value = index,
6875
- loading.value = !1;
7062
+ loading.value = !1, scaleTranslate.value = {
7063
+ scale: 1,
7064
+ x: 0,
7065
+ y: 0
7066
+ };
6876
7067
  }), (() => {
6877
7068
  loading.value = !1;
6878
7069
  })), !0);
@@ -6905,8 +7096,20 @@ var Element$1 = defineComponent({
6905
7096
  isFullscreen.value = val, updateMainContentHeight(), nextTick((() => {
6906
7097
  canvasContextRef.value.rerenderImage();
6907
7098
  }));
6908
- };
6909
- expose({
7099
+ }, scaleTranslate = ref({
7100
+ scale: 1,
7101
+ x: 0,
7102
+ y: 0
7103
+ });
7104
+ provide("scaleTranslateManager", {
7105
+ scaleTranslate: scaleTranslate,
7106
+ onChangeScaleTranslate: val => {
7107
+ scaleTranslate.value = val;
7108
+ },
7109
+ onResetScaleTranslate: () => {
7110
+ canvasContextRef.value.resetScaleOffset();
7111
+ }
7112
+ }), expose({
6910
7113
  convertToLabel: convertToLabel,
6911
7114
  canvertToCanvas: canvertToCanvas
6912
7115
  });
@@ -7297,15 +7500,17 @@ class CreateDrawCanvas {
7297
7500
  canvasWidth;
7298
7501
  canvasHeight;
7299
7502
  paths;
7503
+ scaleX;
7504
+ scaleY;
7300
7505
  editDrawPolygon;
7301
7506
  createPolygonVertexes;
7302
7507
  editVertexes;
7303
7508
  editPolygonObservers=[];
7304
7509
  constructor(options) {
7305
- const {canvas: canvas, ctx: ctx, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight, paths: paths} = options;
7510
+ const {canvas: canvas, ctx: ctx, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight, paths: paths, scaleX: scaleX, scaleY: scaleY} = options;
7306
7511
  this.canvas = canvas, this.ctx = ctx, this.image = image, this.canvasWidth = canvasWidth,
7307
- this.canvasHeight = canvasHeight, this.paths = paths || [], this.editVertexes = [],
7308
- this.render(), this.createPolygonVertexes = new CreatePolygonVertexes(canvas, ctx),
7512
+ this.canvasHeight = canvasHeight, this.paths = paths || [], this.scaleX = scaleX || 1,
7513
+ this.scaleY = scaleY || 1, this.editVertexes = [], this.render(), this.createPolygonVertexes = new CreatePolygonVertexes(canvas, ctx),
7309
7514
  this.editDrawPolygon = new EditPolygonPath(canvas, ctx), this.createPolygonVertexes.vertexesChangeEventListener(((vertexes, mouseOffset) => {
7310
7515
  this.render(), this.editDrawPolygon.drawPolygon(vertexes, mouseOffset), this.editVertexes = vertexes,
7311
7516
  this.notifyObservers();
@@ -7326,12 +7531,14 @@ class CreateDrawCanvas {
7326
7531
  }
7327
7532
  drawPolygons(paths) {
7328
7533
  const ctx = this.ctx;
7534
+ ctx.scale(this.scaleX, this.scaleY);
7329
7535
  for (let i = 0; i < paths.length; i++) {
7330
7536
  const path = paths[i].path;
7331
7537
  if (!path.length) return;
7332
7538
  const color = colors[i % colors.length];
7333
- ctx.beginPath(), ctx.lineWidth = 2, ctx.strokeStyle = color, ctx.fillStyle = hexToRgba(color, .2),
7334
- ctx.moveTo(path[0][0], path[0][1]);
7539
+ ctx.beginPath(), ctx.lineWidth = 2, ctx.strokeStyle = color, ctx.fillStyle = hexToRgba(color, .2);
7540
+ const startX = path[0][0], startY = path[0][1];
7541
+ ctx.moveTo(startX, startY);
7335
7542
  for (let i = 1; i < path.length; i++) {
7336
7543
  const [x, y] = path[i];
7337
7544
  ctx.lineTo(x, y);
@@ -7341,7 +7548,7 @@ class CreateDrawCanvas {
7341
7548
  }
7342
7549
  initCanvas=() => {
7343
7550
  this.ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight), this.ctx.drawImage(this.image, 0, 0, this.canvasWidth, this.canvasHeight),
7344
- this.drawPolygons(this.paths);
7551
+ this.ctx.save(), this.drawPolygons(this.paths), this.ctx.restore();
7345
7552
  };
7346
7553
  render=() => {
7347
7554
  this.initCanvas();
@@ -7368,22 +7575,40 @@ var CanvasContext = defineComponent({
7368
7575
  },
7369
7576
  emits: [ "editPolygon" ],
7370
7577
  setup(props, {emit: emit, expose: expose}) {
7371
- const ns = inject("ns", {}), canvasMainRef = ref(), canvasBaseRef = ref(), drawCanvas = ref(), setContainerWidthHeight = (canvasWidth, canvasHeight) => {
7578
+ const ns = inject("ns", {}), mainBasaeRef = ref(), canvasMainRef = ref(), canvasBaseRef = ref(), drawCanvas = ref(), setContainerWidthHeight = (canvasWidth, canvasHeight) => {
7372
7579
  canvasMainRef.value.style.width = canvasWidth + "px", canvasMainRef.value.style.height = canvasHeight + "px",
7373
7580
  canvasBaseRef.value.width = canvasWidth, canvasBaseRef.value.height = canvasHeight,
7374
7581
  canvasBaseRef.value.style.width = canvasWidth + "px", canvasBaseRef.value.style.height = canvasHeight + "px";
7375
7582
  }, loadingImage = ref(!1), renderImageLabel = rowInfo => {
7376
- const clientHeight = canvasMainRef.value?.clientHeight, ctx = canvasBaseRef.value?.getContext("2d");
7583
+ const ctx = canvasBaseRef.value?.getContext("2d");
7377
7584
  if (rowInfo?.imageSrc) {
7378
7585
  const image = new Image;
7379
7586
  image.src = rowInfo.imageSrc, loadingImage.value = !0, image.onload = () => {
7380
7587
  loadingImage.value = !1;
7381
- let {width: width, height: height} = image;
7382
- if (height > clientHeight) {
7383
- const scale = height / clientHeight;
7384
- height = clientHeight, image.style.height = height + "px", width /= scale;
7385
- }
7386
- const canvasHeight = height, scaleFactor = parseFloat((canvasHeight / height).toFixed(3)), canvasWidth = Math.ceil(width * scaleFactor);
7588
+ const {canvasWidth: canvasWidth, canvasHeight: canvasHeight, scaleFactor: scaleFactor, scaleX: scaleX, scaleY: scaleY} = (image => {
7589
+ const clientWidth = mainBasaeRef.value?.elementInstance.clientWidth, clientHeight = mainBasaeRef.value?.elementInstance.clientHeight;
7590
+ let {width: width, height: height} = image, scaleFactor = 1;
7591
+ const aspect_ratio = width / height;
7592
+ if (aspect_ratio > 1 ? (width = clientWidth, height = clientWidth / aspect_ratio) : (width = clientHeight * aspect_ratio,
7593
+ height = clientHeight), height > clientHeight) {
7594
+ const scale = height / clientHeight;
7595
+ height = clientHeight, width /= scale;
7596
+ } else if (width > clientWidth) {
7597
+ const scale = width / clientWidth;
7598
+ width = clientWidth, height /= scale;
7599
+ }
7600
+ const canvasWidth = parseInt(width.toString()), canvasHeight = parseInt(height.toString());
7601
+ scaleFactor = Number((canvasWidth / canvasHeight).toFixed(2));
7602
+ const scaleX = (canvasWidth / image.width).toFixed(8), scaleY = (canvasHeight / image.height).toFixed(8);
7603
+ return {
7604
+ canvasWidth: canvasWidth,
7605
+ canvasHeight: canvasHeight,
7606
+ scaleFactor: scaleFactor,
7607
+ scaleX: Number(scaleX),
7608
+ scaleY: Number(scaleY)
7609
+ };
7610
+ })(image);
7611
+ image.style.width = canvasWidth + "px", image.style.height = canvasHeight + "px",
7387
7612
  setContainerWidthHeight(canvasWidth, canvasHeight), drawCanvas.value = new CreateDrawCanvas({
7388
7613
  canvas: canvasBaseRef.value,
7389
7614
  ctx: ctx,
@@ -7391,7 +7616,9 @@ var CanvasContext = defineComponent({
7391
7616
  canvasWidth: canvasWidth,
7392
7617
  canvasHeight: canvasHeight,
7393
7618
  scaleFactor: scaleFactor,
7394
- paths: rowInfo.labels
7619
+ paths: rowInfo.labels,
7620
+ scaleX: scaleX,
7621
+ scaleY: scaleY
7395
7622
  }), drawCanvas.value.updatePolygon((vertexes => {
7396
7623
  emit("editPolygon", {
7397
7624
  vertexes: vertexes,
@@ -7427,6 +7654,7 @@ var CanvasContext = defineComponent({
7427
7654
  }));
7428
7655
  }
7429
7656
  }), () => createVNode(Fragment, null, [ createVNode(NextSpinLoading, {
7657
+ ref: mainBasaeRef,
7430
7658
  loading: loadingImage.value,
7431
7659
  class: [ ns.b("loading") ],
7432
7660
  style: {
@@ -7460,7 +7688,7 @@ var CanvasContext = defineComponent({
7460
7688
  emits: [ "fullscreen", "save" ],
7461
7689
  setup(props, {emit: emit}) {
7462
7690
  const _ns = inject("ns", {}), {t: t} = useLocale(), switchFillscreen = val => {
7463
- emit("fullscreen", val);
7691
+ emit("fullscreen", val), document.body.style.overflow = val ? "hidden" : "auto";
7464
7692
  };
7465
7693
  return () => createVNode(Fragment, null, [ createVNode(Fragment, null, [ createVNode("ul", {
7466
7694
  class: [ _ns.be("header", "tool") ]
@@ -7682,20 +7910,25 @@ var Element = defineComponent({
7682
7910
  if (loading.value) return;
7683
7911
  loading.value = !0;
7684
7912
  const node = currentNode.value;
7685
- emit("save", {
7913
+ return emit("save", {
7686
7914
  node: node
7687
7915
  }, (imageItem => {
7688
7916
  labelImages.value[activateNodeIndex.value] = imageItem || node, activateNodeIndex.value = index,
7689
7917
  loading.value = !1;
7690
7918
  }), (() => {
7691
7919
  loading.value = !1;
7692
- }));
7920
+ })), !0;
7693
7921
  }, isFullscreen = ref(!1), onSwitchFillscreen = val => {
7694
7922
  isFullscreen.value = val, updateMainContentHeight(), nextTick((() => {
7695
7923
  canvasContextRef.value.rerenderImage();
7696
7924
  }));
7697
7925
  }, onEditPlygonChange = plygon => {
7698
- emit("edit-polygon", plygon);
7926
+ currentNode.value.labels = plygon, emit("edit-polygon", plygon);
7927
+ }, onToolHeaderSave = () => {
7928
+ onChangeActivateNode(activateNodeIndex.value) || ElMessage({
7929
+ type: "info",
7930
+ message: t("next.labelimg.labelNoUpdate")
7931
+ });
7699
7932
  };
7700
7933
  return () => createVNode(Fragment, null, [ createVNode("div", {
7701
7934
  ref: layoutLabelRef,
@@ -7716,7 +7949,8 @@ var Element = defineComponent({
7716
7949
  isFullscreen: isFullscreen.value,
7717
7950
  imageIndex: activateNodeIndex.value,
7718
7951
  imageLength: labelImages.value.length,
7719
- onFullscreen: onSwitchFillscreen
7952
+ onFullscreen: onSwitchFillscreen,
7953
+ onSave: onToolHeaderSave
7720
7954
  }, null) ]), createVNode("div", {
7721
7955
  ref: mainRef,
7722
7956
  class: [ ns.b("main") ]
@@ -7828,7 +8062,7 @@ const zoomDialog = app => {
7828
8062
  }));
7829
8063
  }
7830
8064
  });
7831
- }, version = "0.3.5", install = function(app) {
8065
+ }, version = "0.3.7", install = function(app) {
7832
8066
  Object.keys(components).forEach((key => {
7833
8067
  const component = components[key];
7834
8068
  app.component(component.name, component);
@@ -7838,7 +8072,7 @@ const zoomDialog = app => {
7838
8072
  };
7839
8073
 
7840
8074
  var index = {
7841
- version: "0.3.5",
8075
+ version: "0.3.7",
7842
8076
  install: install
7843
8077
  };
7844
8078