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.umd.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
 
@@ -797,7 +797,8 @@
797
797
  confirmDeleteLabel: "确定要删除该标注吗?",
798
798
  saveLabel: "保存当前标注",
799
799
  instructions: "使用说明",
800
- labelNoUpdate: "暂无标签数据更新"
800
+ labelNoUpdate: "暂无标签数据更新",
801
+ zoomRestore: "还原"
801
802
  },
802
803
  labelme: {
803
804
  saveLabel: "保存",
@@ -881,7 +882,8 @@
881
882
  confirmDeleteLabel: "Are you sure you want to delete this annotation?",
882
883
  saveLabel: "save label",
883
884
  instructions: "instructions",
884
- labelNoUpdate: "No label data update"
885
+ labelNoUpdate: "No label data update",
886
+ zoomRestore: "restore zoom"
885
887
  },
886
888
  labelme: {
887
889
  saveLabel: "saving...",
@@ -965,7 +967,8 @@
965
967
  confirmDeleteLabel: "确定要删除该标注吗?",
966
968
  saveLabel: "保存当前标注",
967
969
  instructions: "使用说明",
968
- labelNoUpdate: "暂无标签数据更新"
970
+ labelNoUpdate: "暂无标签数据更新",
971
+ zoomRestore: "还原"
969
972
  },
970
973
  labelme: {
971
974
  saveLabel: "保存"
@@ -5778,8 +5781,8 @@
5778
5781
  },
5779
5782
  emits: [ "fullscreen", "save" ],
5780
5783
  setup(props, {emit: emit}) {
5781
- const _ns = vue.inject("ns", {}), {t: t} = useLocale(), switchFillscreen = val => {
5782
- emit("fullscreen", val);
5784
+ const _ns = vue.inject("ns", {}), scaleTranslateManager = vue.inject("scaleTranslateManager", {}), scaleTranslate = scaleTranslateManager.scaleTranslate, {t: t} = useLocale(), switchFillscreen = val => {
5785
+ emit("fullscreen", val), document.body.style.overflow = val ? "hidden" : "auto";
5783
5786
  };
5784
5787
  return () => vue.createVNode(vue.Fragment, null, [ vue.createVNode(vue.Fragment, null, [ vue.createVNode("ul", {
5785
5788
  class: [ _ns.be("header", "tool") ]
@@ -5805,7 +5808,28 @@
5805
5808
  style: "padding-left: 3px"
5806
5809
  }, [ t("next.labelimg.saveLabel") ]) ]) ]), vue.createVNode("ul", {
5807
5810
  class: [ _ns.be("header", "tool") ]
5808
- }, [ props.imageLength ? vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("第 "), props.imageIndex + 1, vue.createTextVNode(" 张") ]), vue.createVNode("em", {
5811
+ }, [ vue.createVNode("li", {
5812
+ class: "hover",
5813
+ onClick: () => scaleTranslateManager.onResetScaleTranslate()
5814
+ }, [ vue.createVNode("svg", {
5815
+ t: "1725840994827",
5816
+ class: "icon",
5817
+ viewBox: "0 0 1024 1024",
5818
+ version: "1.1",
5819
+ xmlns: "http://www.w3.org/2000/svg",
5820
+ "p-id": "6051",
5821
+ width: "18",
5822
+ height: "18"
5823
+ }, [ vue.createVNode("path", {
5824
+ 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",
5825
+ "p-id": "6052"
5826
+ }, null) ]), vue.createVNode("span", {
5827
+ style: "padding-left: 3px"
5828
+ }, [ t("next.labelimg.zoomRestore") ]) ]), vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("缩放比例") ]), vue.createVNode("span", null, [ parseInt((100 * scaleTranslate.value.scale).toString()), vue.createTextVNode("%") ]), vue.createVNode("span", {
5829
+ style: "padding: 0 10px;"
5830
+ }, [ vue.createTextVNode("偏移量") ]), vue.createVNode("span", {
5831
+ style: "min-width: 120px; text-align: left;"
5832
+ }, [ vue.createTextVNode("X: "), scaleTranslate.value.x, vue.createTextVNode(", Y: "), scaleTranslate.value.y ]) ]), props.imageLength ? vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("第 "), props.imageIndex + 1, vue.createTextVNode(" 张") ]), vue.createVNode("em", {
5809
5833
  style: "padding: 0 5px;"
5810
5834
  }, [ vue.createTextVNode("/") ]), vue.createVNode("span", null, [ vue.createTextVNode("共 "), props.imageLength, vue.createTextVNode(" 张") ]) ]) : null, vue.createVNode("li", {
5811
5835
  style: "margin-right: 30px;",
@@ -5826,7 +5850,7 @@
5826
5850
  }) ]),
5827
5851
  default: () => vue.createVNode("ul", {
5828
5852
  style: "font-size: 12px;white-space: nowrap;"
5829
- }, [ vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("W:") ]), vue.createVNode("span", null, [ vue.createTextVNode("鼠标移入图片中,长按W键,鼠标按下左键,移动鼠标开始绘制,鼠标抬起结束绘制") ]) ]), vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("A:") ]), vue.createVNode("span", null, [ vue.createTextVNode("A键进入上一张图片进行标注") ]) ]), vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("D:") ]), vue.createVNode("span", null, [ vue.createTextVNode("D键进入下一张图片进行标注") ]) ]) ])
5853
+ }, [ vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("W:") ]), vue.createVNode("span", null, [ vue.createTextVNode("鼠标移入图片中,长按W键,鼠标按下左键,移动鼠标开始绘制,鼠标抬起结束绘制") ]) ]), vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("A:") ]), vue.createVNode("span", null, [ vue.createTextVNode("A键进入上一张图片进行标注") ]) ]), vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("D:") ]), vue.createVNode("span", null, [ vue.createTextVNode("D键进入下一张图片进行标注") ]) ]), vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("Ctrl+鼠标滚轮:") ]), vue.createVNode("span", null, [ vue.createTextVNode("长按Ctrl+鼠标滚轮对图片进行缩放") ]) ]), vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("Ctrl+鼠标左键:") ]), vue.createVNode("span", null, [ vue.createTextVNode("长按Ctrl+鼠标左键对图片进行拖拽移动") ]) ]) ])
5830
5854
  }) ]), props.isFullscreen ? vue.createVNode("li", {
5831
5855
  class: "hover",
5832
5856
  onClick: () => switchFillscreen(!1)
@@ -5971,6 +5995,100 @@
5971
5995
  return () => vue.createVNode(vue.Fragment, null, [ renderContent() ]);
5972
5996
  }
5973
5997
  });
5998
+ class CanvasSceneDragZoom {
5999
+ canvas;
6000
+ canvasWidth;
6001
+ canvasHeight;
6002
+ ctx;
6003
+ scaleFactor=1;
6004
+ preScaleFactor=1;
6005
+ offset={
6006
+ x: 0,
6007
+ y: 0
6008
+ };
6009
+ preOffset={
6010
+ x: 0,
6011
+ y: 0
6012
+ };
6013
+ mousePositioin={
6014
+ x: 0,
6015
+ y: 0
6016
+ };
6017
+ maxScale=8;
6018
+ minScale=.5;
6019
+ scaleStep=.1;
6020
+ clickX=0;
6021
+ clickY=0;
6022
+ observers=[];
6023
+ constructor(canvas) {
6024
+ this.canvas = canvas, this.canvasWidth = canvas.width, this.canvasHeight = canvas.height,
6025
+ this.ctx = canvas.getContext("2d"), this.canvasMousedown = this.canvasMousedown.bind(this),
6026
+ this.canvasMousemove = this.canvasMousemove.bind(this), this.canvasMouseup = this.canvasMouseup.bind(this),
6027
+ this.canvas.addEventListener("mousedown", this.canvasMousedown), this.canvas.addEventListener("wheel", this.canvasMousewheel, {
6028
+ passive: !1
6029
+ }), window.addEventListener("wheel", this.onWindowWheel, {
6030
+ passive: !1
6031
+ });
6032
+ }
6033
+ notifyObservers(scale, offset) {
6034
+ this.observers.forEach((listener => {
6035
+ listener({
6036
+ scale: scale,
6037
+ ...offset
6038
+ });
6039
+ }));
6040
+ }
6041
+ changeZoom(callback) {
6042
+ this.observers.push(callback);
6043
+ }
6044
+ reset() {
6045
+ this.scaleFactor = 1, this.preScaleFactor = 1, this.offset = {
6046
+ x: 0,
6047
+ y: 0
6048
+ }, this.preOffset = {
6049
+ x: 0,
6050
+ y: 0
6051
+ }, this.mousePositioin = {
6052
+ x: 0,
6053
+ y: 0
6054
+ }, this.zoom();
6055
+ }
6056
+ render() {
6057
+ this.canvas.width = this.canvasWidth, this.notifyObservers(this.scaleFactor, this.offset);
6058
+ }
6059
+ zoom() {
6060
+ 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;
6061
+ this.offset.x = Math.ceil(offset_x), this.offset.y = Math.ceil(offset_y), this.render(),
6062
+ this.preScaleFactor = this.scaleFactor, this.preOffset.x = this.offset.x, this.preOffset.y = this.offset.y;
6063
+ }
6064
+ onWindowWheel=e => {
6065
+ e.ctrlKey && e.preventDefault();
6066
+ };
6067
+ canvasMousewheel=event => {
6068
+ event.preventDefault(), event.ctrlKey && (this.mousePositioin.x = event.offsetX,
6069
+ this.mousePositioin.y = event.offsetY, event.deltaY > 0 ? (this.scaleFactor = parseFloat((this.scaleFactor + this.scaleStep).toFixed(1)),
6070
+ this.scaleFactor > this.maxScale && (this.scaleFactor = this.maxScale)) : (this.scaleFactor = parseFloat((this.scaleFactor - this.scaleStep).toFixed(1)),
6071
+ this.scaleFactor < this.minScale && (this.scaleFactor = this.minScale)), this.zoom());
6072
+ };
6073
+ canvasMousedown(event) {
6074
+ event.preventDefault(), 0 === event.button && event.ctrlKey && (this.clickX = event.offsetX,
6075
+ this.clickY = event.offsetY, this.canvas.addEventListener("mousemove", this.canvasMousemove),
6076
+ this.canvas.addEventListener("mouseup", this.canvasMouseup));
6077
+ }
6078
+ canvasMousemove(event) {
6079
+ event.preventDefault(), event.ctrlKey && (this.offset.x = Math.ceil(this.preOffset.x + (event.offsetX - this.clickX)),
6080
+ this.offset.y = Math.ceil(this.preOffset.y + (event.offsetY - this.clickY)), this.render());
6081
+ }
6082
+ canvasMouseup(event) {
6083
+ event.preventDefault(), event.ctrlKey && (this.preOffset.x = this.offset.x, this.preOffset.y = this.offset.y,
6084
+ this.canvas.removeEventListener("mousemove", this.canvasMousemove), this.canvas.removeEventListener("mouseup", this.canvasMouseup));
6085
+ }
6086
+ destroy() {
6087
+ this.canvas.removeEventListener("mousedown", this.canvasMousedown), this.canvas.removeEventListener("mousemove", this.canvasMousemove),
6088
+ this.canvas.removeEventListener("mouseup", this.canvasMouseup), this.canvas.removeEventListener("wheel", this.canvasMousewheel),
6089
+ window.removeEventListener("wheel", this.onWindowWheel);
6090
+ }
6091
+ }
5974
6092
  const {hexToRgb: hexToRgb} = useChangeColor();
5975
6093
  var DraggableRect = vue.defineComponent({
5976
6094
  props: {
@@ -5989,7 +6107,7 @@
5989
6107
  },
5990
6108
  emits: [ "draggle-resize", "contextmenu" ],
5991
6109
  setup(props, {emit: emit}) {
5992
- const isDraggle = vue.ref(!1), isResizeCorner = vue.ref({
6110
+ const scaleTranslate = vue.inject("scaleTranslateManager", {}).scaleTranslate, isDraggle = vue.ref(!1), isResizeCorner = vue.ref({
5993
6111
  topLeft: !1,
5994
6112
  topCenter: !1,
5995
6113
  topRight: !1,
@@ -6009,66 +6127,68 @@
6009
6127
  isResizeCorner.value.rightCenter = !1, isResizeCorner.value.bottomLeft = !1, isResizeCorner.value.bottomCenter = !1,
6010
6128
  isResizeCorner.value.bottomRight = !1, emit("draggle-resize", rect.value);
6011
6129
  }, onMousemove = e => {
6130
+ 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);
6012
6131
  if (isDraggle.value) {
6013
- const newLeft = e.clientX - parentRect.left - draggleOffset.value.diff_x, newTop = e.clientY - parentRect.top - draggleOffset.value.diff_y;
6014
- rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6015
- rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6132
+ 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);
6133
+ rect.value.startX = Math.max(0, Math.min(offsetX, parentRect.width - rect.value.rectWidth)),
6134
+ rect.value.startY = Math.max(0, Math.min(offsetY, parentRect.height - rect.value.rectHeight));
6016
6135
  }
6017
6136
  if (isResizeCorner.value.bottomCenter) {
6018
- let newHeight = e.clientY - parentRect.top - rect.value.startY;
6019
- newHeight < 30 && (newHeight = 30), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6137
+ let newHeight = Math.floor((e.clientY - parentRect.top - startY) / scale);
6138
+ newHeight < min_size && (newHeight = min_size), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6020
6139
  rect.value.rectHeight = newHeight;
6021
6140
  }
6022
6141
  if (isResizeCorner.value.topCenter) {
6023
- let newTop = e.clientY - parentRect.top, newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6142
+ let newTop = Math.floor((e.clientY - parentRect.top - y) / scale), newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6024
6143
  if (newTop < 0) return;
6025
- if (newHeight < 30) return;
6144
+ if (newHeight < min_size) return;
6026
6145
  rect.value.rectHeight = newHeight, rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6027
6146
  }
6028
6147
  if (isResizeCorner.value.leftCenter) {
6029
- let newLeft = e.clientX - parentRect.left, newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6148
+ let newLeft = Math.floor((e.clientX - parentRect.left - x) / scale), newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6030
6149
  if (newLeft < 0) return;
6031
- if (newWidth < 30) return;
6150
+ if (newWidth < min_size) return;
6032
6151
  rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6033
6152
  rect.value.rectWidth = newWidth;
6034
6153
  }
6035
6154
  if (isResizeCorner.value.rightCenter) {
6036
- let newWidth = e.clientX - parentRect.left - rect.value.startX;
6037
- newWidth < 30 && (newWidth = 30), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6155
+ let newWidth = Math.floor((e.clientX - parentRect.left - startX) / scale);
6156
+ newWidth < min_size && (newWidth = min_size), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6038
6157
  rect.value.rectWidth = newWidth;
6039
6158
  }
6040
6159
  if (isResizeCorner.value.bottomRight) {
6041
- let newWidth = e.clientX - parentRect.left - rect.value.startX, newHeight = e.clientY - parentRect.top - rect.value.startY;
6042
- newWidth < 30 && (newWidth = 30), newHeight < 30 && (newHeight = 30), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6160
+ let newWidth = Math.floor((e.clientX - parentRect.left - startX) / scale), newHeight = Math.floor((e.clientY - parentRect.top - startY) / scale);
6161
+ newWidth < min_size && (newWidth = min_size), newHeight < min_size && (newHeight = min_size),
6162
+ newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6043
6163
  newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6044
6164
  rect.value.rectWidth = newWidth, rect.value.rectHeight = newHeight;
6045
6165
  }
6046
6166
  if (isResizeCorner.value.bottomLeft) {
6047
- let newLeft = e.clientX - parentRect.left, newWidth = rect.value.startX - newLeft + rect.value.rectWidth, newHeight = e.clientY - parentRect.top - rect.value.startY;
6167
+ 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);
6048
6168
  if (newLeft < 0) return;
6049
- if (newWidth < 30) return;
6050
- newHeight < 30 && (newHeight = 30), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6169
+ if (newWidth < min_size) return;
6170
+ newHeight < min_size && (newHeight = min_size), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6051
6171
  rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6052
6172
  rect.value.rectWidth = newWidth, rect.value.rectHeight = newHeight;
6053
6173
  }
6054
6174
  if (isResizeCorner.value.topLeft) {
6055
- let newTop = e.clientY - parentRect.top, newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6175
+ let newTop = Math.floor((e.clientY - parentRect.top - y) / scale), newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6056
6176
  if (newTop < 0) return;
6057
- if (newHeight < 30) return;
6177
+ if (newHeight < min_size) return;
6058
6178
  rect.value.rectHeight = newHeight, rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6059
- let newLeft = e.clientX - parentRect.left, newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6179
+ let newLeft = Math.floor((e.clientX - parentRect.left - x) / scale), newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6060
6180
  if (newLeft < 0) return;
6061
- if (newWidth < 30) return;
6181
+ if (newWidth < min_size) return;
6062
6182
  rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6063
6183
  rect.value.rectWidth = newWidth;
6064
6184
  }
6065
6185
  if (isResizeCorner.value.topRight) {
6066
- let newTop = e.clientY - parentRect.top, newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6186
+ let newTop = Math.floor((e.clientY - parentRect.top - y) / scale), newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6067
6187
  if (newTop < 0) return;
6068
- if (newHeight < 30) return;
6188
+ if (newHeight < min_size) return;
6069
6189
  rect.value.rectHeight = newHeight, rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6070
- let newWidth = e.clientX - parentRect.left - rect.value.startX;
6071
- newWidth < 30 && (newWidth = 30), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6190
+ let newWidth = Math.floor((e.clientX - parentRect.left - startX) / scale);
6191
+ newWidth < min_size && (newWidth = min_size), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6072
6192
  rect.value.rectWidth = newWidth;
6073
6193
  }
6074
6194
  };
@@ -6093,11 +6213,23 @@
6093
6213
  };
6094
6214
  },
6095
6215
  render() {
6096
- const _ns = vue.inject("ns", {}), props = this.$props;
6216
+ const _ns = vue.inject("ns", {}), scaleTranslate = vue.inject("scaleTranslateManager", {}).scaleTranslate, props = this.$props;
6097
6217
  return vue.createVNode("div", {
6098
6218
  class: [ _ns.b("draggable-rect") ],
6099
6219
  style: (() => {
6100
- const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = this.rect, style = {
6220
+ const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = ((rect, scaleOffset) => {
6221
+ const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect, {scale: scale, x: x, y: y} = scaleOffset;
6222
+ return {
6223
+ startX: Math.ceil(startX * scale + x),
6224
+ startY: Math.ceil(startY * scale + y),
6225
+ rectWidth: Math.ceil(rectWidth * scale),
6226
+ rectHeight: Math.ceil(rectHeight * scale),
6227
+ canvasWidth: rect.canvasWidth,
6228
+ canvasHeight: rect.canvasHeight,
6229
+ originWidth: rect.originWidth,
6230
+ originHeight: rect.originHeight
6231
+ };
6232
+ })(this.rect, scaleTranslate.value), style = {
6101
6233
  top: startY + "px",
6102
6234
  left: startX + "px",
6103
6235
  width: rectWidth + "px",
@@ -6158,7 +6290,7 @@
6158
6290
  },
6159
6291
  emits: [ "change" ],
6160
6292
  setup(props, {emit: emit, expose: expose}) {
6161
- const ns = vue.inject("ns", {}), _emit = vue.inject("_emit", null), canvasMainRef = vue.ref(), canvasBaseRef = vue.ref(), canvasRectRef = vue.ref(), labels = vue.ref([]), drawBaseCanvas = vue.ref({}), formatLabelsType = () => {
6293
+ const ns = vue.inject("ns", {}), _emit = vue.inject("_emit", null), scaleTranslateManager = vue.inject("scaleTranslateManager", {}), mainBasaeRef = vue.ref(), canvasMainRef = vue.ref(), canvasBaseRef = vue.ref(), canvasRectRef = vue.ref(), labels = vue.ref([]), drawBaseCanvas = vue.ref({}), canvasDragZoom = vue.ref(), formatLabelsType = () => {
6162
6294
  const _labels = deepClone(labels.value);
6163
6295
  let yolo_label = [];
6164
6296
  return {
@@ -6176,22 +6308,39 @@
6176
6308
  canvasRectRef.value.width = canvasWidth, canvasRectRef.value.height = canvasHeight,
6177
6309
  canvasRectRef.value.style.width = canvasWidth + "px", canvasRectRef.value.style.height = canvasHeight + "px";
6178
6310
  }, loadingImage = vue.ref(!1), renderImageLabel = rowInfo => {
6179
- labels.value = (rowInfo => rowInfo.labels ? rowInfo.labels.map((rect => {
6180
- const typeName = props.classes[rect.type];
6181
- return typeName && (rect.typeName = typeName), rect;
6182
- })) : [])(rowInfo);
6183
- const clientHeight = canvasMainRef.value?.clientHeight, ctx = canvasBaseRef.value?.getContext("2d");
6311
+ const ctx = canvasBaseRef.value?.getContext("2d");
6184
6312
  if (rowInfo?.imageSrc) {
6185
6313
  const image = new Image;
6186
6314
  image.src = rowInfo.imageSrc, loadingImage.value = !0, image.onload = () => {
6187
6315
  loadingImage.value = !1;
6188
- let {width: width, height: height} = image;
6189
- if (height > clientHeight) {
6190
- const scale = height / clientHeight;
6191
- height = clientHeight, image.style.height = height + "px", width /= scale;
6192
- }
6193
- const canvasHeight = height, scaleFactor = parseFloat((canvasHeight / height).toFixed(3)), canvasWidth = Math.ceil(width * scaleFactor);
6194
- setContainerWidthHeight(canvasWidth, canvasHeight), labels.value = ((labels, canvasHeight) => {
6316
+ const {canvasWidth: canvasWidth, canvasHeight: canvasHeight, scaleFactor: scaleFactor, originWidth: originWidth, originHeight: originHeight} = (image => {
6317
+ const clientWidth = mainBasaeRef.value?.elementInstance.clientWidth, clientHeight = mainBasaeRef.value?.elementInstance.clientHeight;
6318
+ let {width: width, height: height} = image, scaleFactor = 1;
6319
+ const scale = width / height;
6320
+ if (scale > 1 ? (width = clientWidth, height = clientWidth / scale) : (width = clientHeight * scale,
6321
+ height = clientHeight), height > clientHeight) {
6322
+ const scale = height / clientHeight;
6323
+ height = clientHeight, width /= scale;
6324
+ } else if (width > clientWidth) {
6325
+ const scale = width / clientWidth;
6326
+ width = clientWidth, height /= scale;
6327
+ }
6328
+ const canvasWidth = parseInt(width.toString()), canvasHeight = parseInt(height.toString());
6329
+ return scaleFactor = Number((canvasWidth / canvasHeight).toFixed(2)), {
6330
+ canvasWidth: canvasWidth,
6331
+ canvasHeight: canvasHeight,
6332
+ scaleFactor: scaleFactor,
6333
+ originWidth: image.width,
6334
+ originHeight: image.height
6335
+ };
6336
+ })(image);
6337
+ labels.value = ((rowInfo, originWidth, originHeight) => rowInfo.labels ? rowInfo.labels.map((rect => {
6338
+ const typeName = props.classes[rect.type];
6339
+ return typeName && (rect.typeName = typeName), rect.originWidth || (rect.originWidth = originWidth),
6340
+ rect.originHeight || (rect.originHeight = originHeight), rect;
6341
+ })) : [])(rowInfo, originWidth, originHeight), image.style.width = canvasWidth + "px",
6342
+ image.style.height = canvasHeight + "px", setContainerWidthHeight(canvasWidth, canvasHeight),
6343
+ labels.value = ((labels, canvasHeight) => {
6195
6344
  let scale_rects = [];
6196
6345
  for (let i = 0; i < labels.length; i++) {
6197
6346
  const rect = labels[i], scale = parseFloat((canvasHeight / rect.canvasHeight).toFixed(3));
@@ -6203,8 +6352,10 @@
6203
6352
  return scale_rects;
6204
6353
  })(labels.value, canvasHeight);
6205
6354
  const {updateLabels: updateLabels, addDrawRect: addDrawRect, hitCanvasLabel: hitCanvasLabel} = (options => {
6206
- const {ctx: ctx, labels: labels, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight} = options, updateLabels = () => {
6207
- ctx.clearRect(0, 0, canvasWidth, canvasHeight), ctx.drawImage(image, 0, 0, canvasWidth, canvasHeight);
6355
+ const {canvas: canvas, ctx: ctx, labels: labels, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight, scaleOffset: scaleOffset} = options, updateLabels = () => {
6356
+ canvas.width = canvasWidth, scaleOffset.value && (ctx.save(), ctx.translate(scaleOffset.value.x, scaleOffset.value.y),
6357
+ ctx.scale(scaleOffset.value.scale, scaleOffset.value.scale)), ctx.clearRect(0, 0, canvasWidth, canvasHeight),
6358
+ ctx.drawImage(image, 0, 0, canvasWidth, canvasHeight);
6208
6359
  for (let i = 0; i < labels.length; i++) {
6209
6360
  const rect = labels[i], {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight, type: type} = rect, color = colors$1[type % colors$1.length];
6210
6361
  if (ctx.font = "bold 14px serif", ctx.textBaseline = "top", ctx.save(), ctx.strokeStyle = color,
@@ -6219,7 +6370,8 @@
6219
6370
  updateLabels: updateLabels,
6220
6371
  addDrawRect: (rect, color = "#f30635") => {
6221
6372
  const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect;
6222
- ctx.strokeStyle = color, ctx.strokeRect(startX, startY, rectWidth, rectHeight);
6373
+ ctx.save(), ctx.strokeStyle = color, ctx.strokeRect(startX, startY, rectWidth, rectHeight),
6374
+ ctx.restore();
6223
6375
  },
6224
6376
  hitCanvasLabel: (x, y) => {
6225
6377
  let hit_rect = null, hit_index = null, color = null;
@@ -6242,11 +6394,12 @@
6242
6394
  canvasWidth: canvasWidth,
6243
6395
  canvasHeight: canvasHeight,
6244
6396
  labels: labels.value,
6245
- scaleFactor: scaleFactor
6397
+ scaleFactor: scaleFactor,
6398
+ scaleOffset: scaleTranslateManager.scaleTranslate
6246
6399
  });
6247
6400
  drawBaseCanvas.value.updateLabels = updateLabels, drawBaseCanvas.value.addDrawRect = addDrawRect,
6248
6401
  drawBaseCanvas.value.hitCanvasLabel = hitCanvasLabel;
6249
- const {clearCanvas: clearCanvas, removeEventAll: removeEventAll} = ((canvas, callback, keyW) => {
6402
+ const {clearCanvas: clearCanvas, removeEventAll: removeEventAll} = (({canvas: canvas, originWidth: originWidth, originHeight: originHeight}, callback, keyW) => {
6250
6403
  const canvasWidth = canvas.width, canvasHeight = canvas.height, ctx = canvas?.getContext("2d"), clearCanvas = () => {
6251
6404
  ctx.clearRect(0, 0, canvasWidth, canvasHeight);
6252
6405
  };
@@ -6260,14 +6413,16 @@
6260
6413
  rectWidth: rectWidth,
6261
6414
  rectHeight: rectHeight,
6262
6415
  canvasWidth: canvasWidth,
6263
- canvasHeight: canvasHeight
6416
+ canvasHeight: canvasHeight,
6417
+ originWidth: originWidth,
6418
+ originHeight: originHeight
6264
6419
  }, {
6265
6420
  endX: endX,
6266
6421
  endY: endY
6267
6422
  });
6268
6423
  }, documentKeydown = event => {
6269
- "KeyW" === event.code && (isWKeyPressed = !0, canvas.style.cursor = "crosshair",
6270
- canvas.style.zIndex = "11", keyW && keyW());
6424
+ isWKeyPressed || "KeyW" === event.code && (event.preventDefault(), isWKeyPressed = !0,
6425
+ canvas.style.cursor = "crosshair", canvas.style.zIndex = "11", keyW && keyW());
6271
6426
  }, documentKeyup = event => {
6272
6427
  isDrawing || "KeyW" === event.code && (isWKeyPressed = !1, canvas.style.cursor = "unset",
6273
6428
  canvas.style.zIndex = "0");
@@ -6277,13 +6432,13 @@
6277
6432
  };
6278
6433
  document.addEventListener("keydown", documentKeydown), document.addEventListener("keyup", documentKeyup),
6279
6434
  document.addEventListener("mouseup", documentMouseup);
6280
- const canvasMousedown = e => {
6281
- isWKeyPressed && (isDrawing = !0, startX = e.offsetX, startY = e.offsetY);
6282
- }, canvasMousemove = e => {
6283
- isDrawing && isWKeyPressed && (isRectDraw = !0, endX = e.offsetX, endY = e.offsetY,
6435
+ const canvasMousedown = event => {
6436
+ isWKeyPressed && (isDrawing = !0, startX = event.offsetX, startY = event.offsetY);
6437
+ }, canvasMousemove = event => {
6438
+ isDrawing && isWKeyPressed && (isRectDraw = !0, endX = event.offsetX, endY = event.offsetY,
6284
6439
  drawRect());
6285
- }, canvasMouseup = e => {
6286
- e.stopPropagation(), isRectDraw && (isDrawing = !1, isWKeyPressed = !1, canvas.style.cursor = "unset",
6440
+ }, canvasMouseup = event => {
6441
+ event.stopPropagation(), isRectDraw && (isDrawing = !1, isWKeyPressed = !1, canvas.style.cursor = "unset",
6287
6442
  canvas.style.zIndex = "0", drawRectDone(), isRectDraw = !1);
6288
6443
  };
6289
6444
  canvas.addEventListener("mousedown", canvasMousedown), canvas.addEventListener("mousemove", canvasMousemove),
@@ -6297,31 +6452,53 @@
6297
6452
  clearCanvas: clearCanvas,
6298
6453
  drawRect: drawRect,
6299
6454
  removeEventAll: () => {
6300
- document.removeEventListener("mousedown", documentKeydown), document.removeEventListener("keyup", documentKeyup),
6455
+ document.removeEventListener("keydown", documentKeydown), document.removeEventListener("keyup", documentKeyup),
6301
6456
  document.removeEventListener("mouseup", documentMouseup), canvas.removeEventListener("mousedown", canvasMousedown),
6302
6457
  canvas.removeEventListener("mousemove", canvasMousemove), canvas.removeEventListener("mouseup", canvasMouseup);
6303
6458
  }
6304
6459
  };
6305
- })(canvasRectRef.value, ((rect, {endX: endX, endY: endY}) => {
6306
- activate_add_label.value = rect, drawBaseCanvas.value.addDrawRect(rect), updateContextmenuLabelFixed(endX, endY, rect);
6460
+ })({
6461
+ canvas: canvasRectRef.value,
6462
+ originWidth: originWidth,
6463
+ originHeight: originHeight
6464
+ }, ((rect, {endX: endX, endY: endY}) => {
6465
+ activate_add_label.value = rect;
6466
+ const newRect = ((rect, scaleOffset) => {
6467
+ const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect, {scale: scale, x: x, y: y} = scaleOffset;
6468
+ return {
6469
+ startX: Math.ceil((startX - x) / scale),
6470
+ startY: Math.ceil((startY - y) / scale),
6471
+ rectWidth: Math.ceil(rectWidth / scale),
6472
+ rectHeight: Math.ceil(rectHeight / scale),
6473
+ canvasWidth: rect.canvasWidth,
6474
+ canvasHeight: rect.canvasHeight,
6475
+ originWidth: rect.originWidth,
6476
+ originHeight: rect.originHeight
6477
+ };
6478
+ })(rect, scaleTranslateManager.scaleTranslate.value);
6479
+ drawBaseCanvas.value.addDrawRect(newRect), updateContextmenuLabelFixed(endX, endY, newRect);
6307
6480
  }), (() => {
6308
6481
  onCloseDraggableRectFixed();
6309
6482
  }));
6310
- drawBaseCanvas.value.clearCanvasRect = clearCanvas, drawBaseCanvas.value.removeEventAll = removeEventAll;
6483
+ drawBaseCanvas.value.clearCanvasRect = clearCanvas, drawBaseCanvas.value.removeEventAll = removeEventAll,
6484
+ canvasDragZoom.value = new CanvasSceneDragZoom(canvasBaseRef.value), canvasDragZoom.value.changeZoom((scaleOffset => {
6485
+ scaleTranslateManager.onChangeScaleTranslate(scaleOffset), drawBaseCanvas.value.updateLabels();
6486
+ }));
6311
6487
  }, image.onerror = () => {
6312
6488
  loadingImage.value = !1;
6313
6489
  };
6314
6490
  }
6315
6491
  canvasBaseRef.value.addEventListener("contextmenu", (e => {
6316
6492
  e.preventDefault();
6317
- const x = e.offsetX, y = e.offsetY, {hit_rect: hit_rect} = drawBaseCanvas.value.hitCanvasLabel(x, y);
6493
+ 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);
6318
6494
  onCloseContentmenuLabel(), onCloseDraggableRectFixed(), hit_rect && vue.nextTick((() => {
6319
- updateContextmenuLabelFixed(x, y, hit_rect);
6495
+ updateContextmenuLabelFixed(offsetX, offsetY, hit_rect);
6320
6496
  }));
6321
6497
  })), canvasBaseRef.value.addEventListener("click", (e => {
6322
- const x = e.offsetX, y = e.offsetY, {hit_rect: hit_rect, hit_index: hit_index, color: color} = drawBaseCanvas.value.hitCanvasLabel(x, y);
6498
+ if (e.ctrlKey) return;
6499
+ 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);
6323
6500
  onCloseDraggableRectFixed(), onCloseContentmenuLabel(), hit_rect && vue.nextTick((() => {
6324
- updateDraggableRectFixed(x, y, hit_rect, hit_index, color);
6501
+ updateDraggableRectFixed(offsetX, offsetY, hit_rect, hit_index, color);
6325
6502
  }));
6326
6503
  }));
6327
6504
  };
@@ -6332,7 +6509,10 @@
6332
6509
  }), {
6333
6510
  deep: !0,
6334
6511
  immediate: !0
6335
- }), vue.watch((() => props.contextClientHeight), (height => {
6512
+ }), vue.watch((() => props.classes), (() => {
6513
+ const rowInfo = vue.toRaw(props.rowInfo);
6514
+ renderImageLabel(rowInfo);
6515
+ })), vue.watch((() => props.contextClientHeight), (height => {
6336
6516
  if (valueExist(height)) {
6337
6517
  canvasMainRef.value.style.height = height + "px";
6338
6518
  const rowInfo = vue.toRaw(props.rowInfo);
@@ -6340,7 +6520,7 @@
6340
6520
  }
6341
6521
  }));
6342
6522
  })), vue.onUnmounted((() => {
6343
- drawBaseCanvas.value.removeEventAll();
6523
+ drawBaseCanvas.value.removeEventAll?.(), canvasDragZoom.value.destroy();
6344
6524
  }));
6345
6525
  const contextmenuLabelFixed = vue.ref({
6346
6526
  show: !1,
@@ -6384,9 +6564,9 @@
6384
6564
  draggableRectFixed.value.width = 0, draggableRectFixed.value.height = 0, draggableRectFixed.value.activateRect = null,
6385
6565
  draggableRectFixed.value.activateIndex = null, draggableRectFixed.value.color = null;
6386
6566
  }, onDraggleRectResize = rect => {
6387
- draggableRectFixed.value.activateRect = rect, drawBaseCanvas.value.updateLabels();
6567
+ draggableRectFixed.value.activateRect = rect;
6388
6568
  const i = labels.value.findIndex((o => isEqual(o, rect)));
6389
- i > -1 && labels.value.splice(i, 1, rect);
6569
+ i > -1 && labels.value.splice(i, 1, rect), drawBaseCanvas.value.updateLabels();
6390
6570
  const {rects: rects, label_txt: label_txt} = formatLabelsType();
6391
6571
  _emit("change", rects, label_txt), emit("change", rects, label_txt);
6392
6572
  }, onContextmenuDraggable = (e, rect) => {
@@ -6427,9 +6607,13 @@
6427
6607
  const rowInfo = vue.toRaw(props.rowInfo);
6428
6608
  renderImageLabel(rowInfo);
6429
6609
  }));
6610
+ },
6611
+ resetScaleOffset: () => {
6612
+ canvasDragZoom.value.reset();
6430
6613
  }
6431
6614
  });
6432
6615
  return () => vue.createVNode(vue.Fragment, null, [ vue.createVNode(NextSpinLoading, {
6616
+ ref: mainBasaeRef,
6433
6617
  loading: loadingImage.value,
6434
6618
  class: [ ns.b("loading") ]
6435
6619
  }, {
@@ -6474,13 +6658,15 @@
6474
6658
  },
6475
6659
  emits: [ "delete", "select" ],
6476
6660
  setup(props, {emit: emit}) {
6477
- const {t: t} = useLocale(), ns = vue.inject("ns", {}), labels = vue.ref([]);
6478
- vue.watch((() => props.labels), (rects => {
6661
+ const {t: t} = useLocale(), ns = vue.inject("ns", {}), labels = vue.ref([]), formatLabelsTypeName = labels => labels.length ? labels.map((rect => {
6662
+ const typeName = props.classes[rect.type];
6663
+ return typeName && (rect.typeName = typeName), rect;
6664
+ })) : [];
6665
+ vue.watch((() => props.classes), (() => {
6666
+ labels.value = formatLabelsTypeName(labels.value);
6667
+ })), vue.watch((() => props.labels), (rects => {
6479
6668
  const _rects = vue.toRaw(rects);
6480
- labels.value = (labels => labels.length ? labels.map((rect => {
6481
- const typeName = props.classes[rect.type];
6482
- return typeName && (rect.typeName = typeName), rect;
6483
- })) : [])(_rects);
6669
+ labels.value = formatLabelsTypeName(_rects);
6484
6670
  }), {
6485
6671
  deep: !0,
6486
6672
  immediate: !0
@@ -6623,7 +6809,11 @@
6623
6809
  label_txt: label_txt
6624
6810
  }, (imageItem => {
6625
6811
  labelImages.value[activateNodeIndex.value] = imageItem || node, activateNodeIndex.value = index,
6626
- loading.value = !1;
6812
+ loading.value = !1, scaleTranslate.value = {
6813
+ scale: 1,
6814
+ x: 0,
6815
+ y: 0
6816
+ };
6627
6817
  }), (() => {
6628
6818
  loading.value = !1;
6629
6819
  })), !0);
@@ -6656,8 +6846,20 @@
6656
6846
  isFullscreen.value = val, updateMainContentHeight(), vue.nextTick((() => {
6657
6847
  canvasContextRef.value.rerenderImage();
6658
6848
  }));
6659
- };
6660
- expose({
6849
+ }, scaleTranslate = vue.ref({
6850
+ scale: 1,
6851
+ x: 0,
6852
+ y: 0
6853
+ });
6854
+ vue.provide("scaleTranslateManager", {
6855
+ scaleTranslate: scaleTranslate,
6856
+ onChangeScaleTranslate: val => {
6857
+ scaleTranslate.value = val;
6858
+ },
6859
+ onResetScaleTranslate: () => {
6860
+ canvasContextRef.value.resetScaleOffset();
6861
+ }
6862
+ }), expose({
6661
6863
  convertToLabel: convertToLabel,
6662
6864
  canvertToCanvas: canvertToCanvas
6663
6865
  });
@@ -7042,15 +7244,17 @@
7042
7244
  canvasWidth;
7043
7245
  canvasHeight;
7044
7246
  paths;
7247
+ scaleX;
7248
+ scaleY;
7045
7249
  editDrawPolygon;
7046
7250
  createPolygonVertexes;
7047
7251
  editVertexes;
7048
7252
  editPolygonObservers=[];
7049
7253
  constructor(options) {
7050
- const {canvas: canvas, ctx: ctx, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight, paths: paths} = options;
7254
+ const {canvas: canvas, ctx: ctx, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight, paths: paths, scaleX: scaleX, scaleY: scaleY} = options;
7051
7255
  this.canvas = canvas, this.ctx = ctx, this.image = image, this.canvasWidth = canvasWidth,
7052
- this.canvasHeight = canvasHeight, this.paths = paths || [], this.editVertexes = [],
7053
- this.render(), this.createPolygonVertexes = new CreatePolygonVertexes(canvas, ctx),
7256
+ this.canvasHeight = canvasHeight, this.paths = paths || [], this.scaleX = scaleX || 1,
7257
+ this.scaleY = scaleY || 1, this.editVertexes = [], this.render(), this.createPolygonVertexes = new CreatePolygonVertexes(canvas, ctx),
7054
7258
  this.editDrawPolygon = new EditPolygonPath(canvas, ctx), this.createPolygonVertexes.vertexesChangeEventListener(((vertexes, mouseOffset) => {
7055
7259
  this.render(), this.editDrawPolygon.drawPolygon(vertexes, mouseOffset), this.editVertexes = vertexes,
7056
7260
  this.notifyObservers();
@@ -7071,12 +7275,14 @@
7071
7275
  }
7072
7276
  drawPolygons(paths) {
7073
7277
  const ctx = this.ctx;
7278
+ ctx.scale(this.scaleX, this.scaleY);
7074
7279
  for (let i = 0; i < paths.length; i++) {
7075
7280
  const path = paths[i].path;
7076
7281
  if (!path.length) return;
7077
7282
  const color = colors[i % colors.length];
7078
- ctx.beginPath(), ctx.lineWidth = 2, ctx.strokeStyle = color, ctx.fillStyle = hexToRgba(color, .2),
7079
- ctx.moveTo(path[0][0], path[0][1]);
7283
+ ctx.beginPath(), ctx.lineWidth = 2, ctx.strokeStyle = color, ctx.fillStyle = hexToRgba(color, .2);
7284
+ const startX = path[0][0], startY = path[0][1];
7285
+ ctx.moveTo(startX, startY);
7080
7286
  for (let i = 1; i < path.length; i++) {
7081
7287
  const [x, y] = path[i];
7082
7288
  ctx.lineTo(x, y);
@@ -7086,7 +7292,7 @@
7086
7292
  }
7087
7293
  initCanvas=() => {
7088
7294
  this.ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight), this.ctx.drawImage(this.image, 0, 0, this.canvasWidth, this.canvasHeight),
7089
- this.drawPolygons(this.paths);
7295
+ this.ctx.save(), this.drawPolygons(this.paths), this.ctx.restore();
7090
7296
  };
7091
7297
  render=() => {
7092
7298
  this.initCanvas();
@@ -7112,22 +7318,40 @@
7112
7318
  },
7113
7319
  emits: [ "editPolygon" ],
7114
7320
  setup(props, {emit: emit, expose: expose}) {
7115
- const ns = vue.inject("ns", {}), canvasMainRef = vue.ref(), canvasBaseRef = vue.ref(), drawCanvas = vue.ref(), setContainerWidthHeight = (canvasWidth, canvasHeight) => {
7321
+ const ns = vue.inject("ns", {}), mainBasaeRef = vue.ref(), canvasMainRef = vue.ref(), canvasBaseRef = vue.ref(), drawCanvas = vue.ref(), setContainerWidthHeight = (canvasWidth, canvasHeight) => {
7116
7322
  canvasMainRef.value.style.width = canvasWidth + "px", canvasMainRef.value.style.height = canvasHeight + "px",
7117
7323
  canvasBaseRef.value.width = canvasWidth, canvasBaseRef.value.height = canvasHeight,
7118
7324
  canvasBaseRef.value.style.width = canvasWidth + "px", canvasBaseRef.value.style.height = canvasHeight + "px";
7119
7325
  }, loadingImage = vue.ref(!1), renderImageLabel = rowInfo => {
7120
- const clientHeight = canvasMainRef.value?.clientHeight, ctx = canvasBaseRef.value?.getContext("2d");
7326
+ const ctx = canvasBaseRef.value?.getContext("2d");
7121
7327
  if (rowInfo?.imageSrc) {
7122
7328
  const image = new Image;
7123
7329
  image.src = rowInfo.imageSrc, loadingImage.value = !0, image.onload = () => {
7124
7330
  loadingImage.value = !1;
7125
- let {width: width, height: height} = image;
7126
- if (height > clientHeight) {
7127
- const scale = height / clientHeight;
7128
- height = clientHeight, image.style.height = height + "px", width /= scale;
7129
- }
7130
- const canvasHeight = height, scaleFactor = parseFloat((canvasHeight / height).toFixed(3)), canvasWidth = Math.ceil(width * scaleFactor);
7331
+ const {canvasWidth: canvasWidth, canvasHeight: canvasHeight, scaleFactor: scaleFactor, scaleX: scaleX, scaleY: scaleY} = (image => {
7332
+ const clientWidth = mainBasaeRef.value?.elementInstance.clientWidth, clientHeight = mainBasaeRef.value?.elementInstance.clientHeight;
7333
+ let {width: width, height: height} = image, scaleFactor = 1;
7334
+ const aspect_ratio = width / height;
7335
+ if (aspect_ratio > 1 ? (width = clientWidth, height = clientWidth / aspect_ratio) : (width = clientHeight * aspect_ratio,
7336
+ height = clientHeight), height > clientHeight) {
7337
+ const scale = height / clientHeight;
7338
+ height = clientHeight, width /= scale;
7339
+ } else if (width > clientWidth) {
7340
+ const scale = width / clientWidth;
7341
+ width = clientWidth, height /= scale;
7342
+ }
7343
+ const canvasWidth = parseInt(width.toString()), canvasHeight = parseInt(height.toString());
7344
+ scaleFactor = Number((canvasWidth / canvasHeight).toFixed(2));
7345
+ const scaleX = (canvasWidth / image.width).toFixed(8), scaleY = (canvasHeight / image.height).toFixed(8);
7346
+ return {
7347
+ canvasWidth: canvasWidth,
7348
+ canvasHeight: canvasHeight,
7349
+ scaleFactor: scaleFactor,
7350
+ scaleX: Number(scaleX),
7351
+ scaleY: Number(scaleY)
7352
+ };
7353
+ })(image);
7354
+ image.style.width = canvasWidth + "px", image.style.height = canvasHeight + "px",
7131
7355
  setContainerWidthHeight(canvasWidth, canvasHeight), drawCanvas.value = new CreateDrawCanvas({
7132
7356
  canvas: canvasBaseRef.value,
7133
7357
  ctx: ctx,
@@ -7135,7 +7359,9 @@
7135
7359
  canvasWidth: canvasWidth,
7136
7360
  canvasHeight: canvasHeight,
7137
7361
  scaleFactor: scaleFactor,
7138
- paths: rowInfo.labels
7362
+ paths: rowInfo.labels,
7363
+ scaleX: scaleX,
7364
+ scaleY: scaleY
7139
7365
  }), drawCanvas.value.updatePolygon((vertexes => {
7140
7366
  emit("editPolygon", {
7141
7367
  vertexes: vertexes,
@@ -7171,6 +7397,7 @@
7171
7397
  }));
7172
7398
  }
7173
7399
  }), () => vue.createVNode(vue.Fragment, null, [ vue.createVNode(NextSpinLoading, {
7400
+ ref: mainBasaeRef,
7174
7401
  loading: loadingImage.value,
7175
7402
  class: [ ns.b("loading") ],
7176
7403
  style: {
@@ -7204,7 +7431,7 @@
7204
7431
  emits: [ "fullscreen", "save" ],
7205
7432
  setup(props, {emit: emit}) {
7206
7433
  const _ns = vue.inject("ns", {}), {t: t} = useLocale(), switchFillscreen = val => {
7207
- emit("fullscreen", val);
7434
+ emit("fullscreen", val), document.body.style.overflow = val ? "hidden" : "auto";
7208
7435
  };
7209
7436
  return () => vue.createVNode(vue.Fragment, null, [ vue.createVNode(vue.Fragment, null, [ vue.createVNode("ul", {
7210
7437
  class: [ _ns.be("header", "tool") ]
@@ -7424,20 +7651,25 @@
7424
7651
  if (loading.value) return;
7425
7652
  loading.value = !0;
7426
7653
  const node = currentNode.value;
7427
- emit("save", {
7654
+ return emit("save", {
7428
7655
  node: node
7429
7656
  }, (imageItem => {
7430
7657
  labelImages.value[activateNodeIndex.value] = imageItem || node, activateNodeIndex.value = index,
7431
7658
  loading.value = !1;
7432
7659
  }), (() => {
7433
7660
  loading.value = !1;
7434
- }));
7661
+ })), !0;
7435
7662
  }, isFullscreen = vue.ref(!1), onSwitchFillscreen = val => {
7436
7663
  isFullscreen.value = val, updateMainContentHeight(), vue.nextTick((() => {
7437
7664
  canvasContextRef.value.rerenderImage();
7438
7665
  }));
7439
7666
  }, onEditPlygonChange = plygon => {
7440
- emit("edit-polygon", plygon);
7667
+ currentNode.value.labels = plygon, emit("edit-polygon", plygon);
7668
+ }, onToolHeaderSave = () => {
7669
+ onChangeActivateNode(activateNodeIndex.value) || elementPlus.ElMessage({
7670
+ type: "info",
7671
+ message: t("next.labelimg.labelNoUpdate")
7672
+ });
7441
7673
  };
7442
7674
  return () => vue.createVNode(vue.Fragment, null, [ vue.createVNode("div", {
7443
7675
  ref: layoutLabelRef,
@@ -7458,7 +7690,8 @@
7458
7690
  isFullscreen: isFullscreen.value,
7459
7691
  imageIndex: activateNodeIndex.value,
7460
7692
  imageLength: labelImages.value.length,
7461
- onFullscreen: onSwitchFillscreen
7693
+ onFullscreen: onSwitchFillscreen,
7694
+ onSave: onToolHeaderSave
7462
7695
  }, null) ]), vue.createVNode("div", {
7463
7696
  ref: mainRef,
7464
7697
  class: [ ns.b("main") ]
@@ -7576,7 +7809,7 @@
7576
7809
  })(app);
7577
7810
  };
7578
7811
  var index = {
7579
- version: "0.3.5",
7812
+ version: "0.3.7",
7580
7813
  install: install
7581
7814
  };
7582
7815
  exports.NextContainer = NextContainer, exports.NextCrudTable = NextCrudTable, exports.NextCrudTableVirtualized = NextCrudTableVirtualized,
@@ -7623,7 +7856,7 @@
7623
7856
  }), exports.useGetDerivedNamespace = useGetDerivedNamespace, exports.useLanguage = (locale, lang) => {
7624
7857
  const localeRef = vue.isRef(locale) ? locale : vue.ref(locale), nextLang = localeLang[lang] || localeLang["zh-cn"];
7625
7858
  localeRef.value.name = lang, localeRef.value.next = nextLang.next;
7626
- }, exports.useLocale = useLocale, exports.useNamespace = useNamespace, exports.version = "0.3.5",
7859
+ }, exports.useLocale = useLocale, exports.useNamespace = useNamespace, exports.version = "0.3.7",
7627
7860
  Object.defineProperty(exports, "__esModule", {
7628
7861
  value: !0
7629
7862
  });