next-element-vue 0.3.6 → 0.3.8

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.6 v
6
- * 发布日期:2024-09-15
5
+ * 当前版本:0.3.8 v
6
+ * 发布日期:2024-09-26
7
7
  * 地  址:https://www.npmjs.com/package/next-element-vue
8
8
  */
9
9
 
@@ -3808,7 +3808,11 @@
3808
3808
  const {operationsBtnPlain: operationsBtnPlain, operationsBtnText: operationsBtnText} = options;
3809
3809
  return operationsBtnText || operationsBtnPlain;
3810
3810
  })), renderContent = () => {
3811
- const btnText = options.operationsBtnText, btnPlain = options.operationsBtnPlain, btnSize = options.operationsBtnSize;
3811
+ const btnText = options.operationsBtnText, btnPlain = options.operationsBtnPlain, btnSize = options.operationsBtnSize, btnCfg = {
3812
+ text: btnText,
3813
+ plain: btnPlain,
3814
+ size: btnSize
3815
+ };
3812
3816
  return vue.createVNode(elementPlus.ElTableColumn, {
3813
3817
  fixed: "right",
3814
3818
  label: t("next.table.operation"),
@@ -3816,10 +3820,9 @@
3816
3820
  headerAlign: valueExist(options.operationsHeaderAlign, options.headerAlign),
3817
3821
  align: valueExist(options.operationsColumnAlign, options.cellAlign)
3818
3822
  }, {
3819
- default: scoped => vue.createVNode(vue.Fragment, null, [ slots["operation-column-prefix"]?.(scoped, {
3820
- text: btnText,
3821
- plain: btnPlain,
3822
- size: btnSize
3823
+ default: scoped => vue.createVNode(vue.Fragment, null, [ slots["operation-column-prefix"]?.({
3824
+ scoped: scoped,
3825
+ btn: btnCfg
3823
3826
  }), options.editBtn ? vue.createVNode(elementPlus.ElTooltip, {
3824
3827
  enterable: !1,
3825
3828
  effect: "dark",
@@ -3899,10 +3902,9 @@
3899
3902
  }),
3900
3903
  default: () => t("next.table.delete")
3901
3904
  }) ]
3902
- }) : null, slots["operation-column-suffix"]?.(scoped, {
3903
- text: btnText,
3904
- plain: btnPlain,
3905
- size: btnSize
3905
+ }) : null, slots["operation-column-suffix"]?.({
3906
+ scoped: scoped,
3907
+ btn: btnCfg
3906
3908
  }) ])
3907
3909
  });
3908
3910
  };
@@ -5781,7 +5783,7 @@
5781
5783
  },
5782
5784
  emits: [ "fullscreen", "save" ],
5783
5785
  setup(props, {emit: emit}) {
5784
- const _ns = vue.inject("ns", {}), {t: t} = useLocale(), switchFillscreen = val => {
5786
+ const _ns = vue.inject("ns", {}), scaleTranslateManager = vue.inject("scaleTranslateManager", {}), scaleTranslate = scaleTranslateManager.scaleTranslate, {t: t} = useLocale(), switchFillscreen = val => {
5785
5787
  emit("fullscreen", val), document.body.style.overflow = val ? "hidden" : "auto";
5786
5788
  };
5787
5789
  return () => vue.createVNode(vue.Fragment, null, [ vue.createVNode(vue.Fragment, null, [ vue.createVNode("ul", {
@@ -5808,7 +5810,28 @@
5808
5810
  style: "padding-left: 3px"
5809
5811
  }, [ t("next.labelimg.saveLabel") ]) ]) ]), vue.createVNode("ul", {
5810
5812
  class: [ _ns.be("header", "tool") ]
5811
- }, [ props.imageLength ? vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("第 "), props.imageIndex + 1, vue.createTextVNode(" 张") ]), vue.createVNode("em", {
5813
+ }, [ vue.createVNode("li", {
5814
+ class: "hover",
5815
+ onClick: () => scaleTranslateManager.onResetScaleTranslate()
5816
+ }, [ vue.createVNode("svg", {
5817
+ t: "1725840994827",
5818
+ class: "icon",
5819
+ viewBox: "0 0 1024 1024",
5820
+ version: "1.1",
5821
+ xmlns: "http://www.w3.org/2000/svg",
5822
+ "p-id": "6051",
5823
+ width: "18",
5824
+ height: "18"
5825
+ }, [ vue.createVNode("path", {
5826
+ 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",
5827
+ "p-id": "6052"
5828
+ }, null) ]), vue.createVNode("span", {
5829
+ style: "padding-left: 3px"
5830
+ }, [ 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", {
5831
+ style: "padding: 0 10px;"
5832
+ }, [ vue.createTextVNode("偏移量") ]), vue.createVNode("span", {
5833
+ style: "min-width: 120px; text-align: left;"
5834
+ }, [ 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", {
5812
5835
  style: "padding: 0 5px;"
5813
5836
  }, [ vue.createTextVNode("/") ]), vue.createVNode("span", null, [ vue.createTextVNode("共 "), props.imageLength, vue.createTextVNode(" 张") ]) ]) : null, vue.createVNode("li", {
5814
5837
  style: "margin-right: 30px;",
@@ -5829,7 +5852,7 @@
5829
5852
  }) ]),
5830
5853
  default: () => vue.createVNode("ul", {
5831
5854
  style: "font-size: 12px;white-space: nowrap;"
5832
- }, [ 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键进入下一张图片进行标注") ]) ]) ])
5855
+ }, [ 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+鼠标左键对图片进行拖拽移动") ]) ]) ])
5833
5856
  }) ]), props.isFullscreen ? vue.createVNode("li", {
5834
5857
  class: "hover",
5835
5858
  onClick: () => switchFillscreen(!1)
@@ -5974,6 +5997,100 @@
5974
5997
  return () => vue.createVNode(vue.Fragment, null, [ renderContent() ]);
5975
5998
  }
5976
5999
  });
6000
+ class CanvasSceneDragZoom {
6001
+ canvas;
6002
+ canvasWidth;
6003
+ canvasHeight;
6004
+ ctx;
6005
+ scaleFactor=1;
6006
+ preScaleFactor=1;
6007
+ offset={
6008
+ x: 0,
6009
+ y: 0
6010
+ };
6011
+ preOffset={
6012
+ x: 0,
6013
+ y: 0
6014
+ };
6015
+ mousePositioin={
6016
+ x: 0,
6017
+ y: 0
6018
+ };
6019
+ maxScale=8;
6020
+ minScale=.5;
6021
+ scaleStep=.1;
6022
+ clickX=0;
6023
+ clickY=0;
6024
+ observers=[];
6025
+ constructor(canvas) {
6026
+ this.canvas = canvas, this.canvasWidth = canvas.width, this.canvasHeight = canvas.height,
6027
+ this.ctx = canvas.getContext("2d"), this.canvasMousedown = this.canvasMousedown.bind(this),
6028
+ this.canvasMousemove = this.canvasMousemove.bind(this), this.canvasMouseup = this.canvasMouseup.bind(this),
6029
+ this.canvas.addEventListener("mousedown", this.canvasMousedown), this.canvas.addEventListener("wheel", this.canvasMousewheel, {
6030
+ passive: !1
6031
+ }), window.addEventListener("wheel", this.onWindowWheel, {
6032
+ passive: !1
6033
+ });
6034
+ }
6035
+ notifyObservers(scale, offset) {
6036
+ this.observers.forEach((listener => {
6037
+ listener({
6038
+ scale: scale,
6039
+ ...offset
6040
+ });
6041
+ }));
6042
+ }
6043
+ changeZoom(callback) {
6044
+ this.observers.push(callback);
6045
+ }
6046
+ reset() {
6047
+ this.scaleFactor = 1, this.preScaleFactor = 1, this.offset = {
6048
+ x: 0,
6049
+ y: 0
6050
+ }, this.preOffset = {
6051
+ x: 0,
6052
+ y: 0
6053
+ }, this.mousePositioin = {
6054
+ x: 0,
6055
+ y: 0
6056
+ }, this.zoom();
6057
+ }
6058
+ render() {
6059
+ this.canvas.width = this.canvasWidth, this.notifyObservers(this.scaleFactor, this.offset);
6060
+ }
6061
+ zoom() {
6062
+ 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;
6063
+ this.offset.x = Math.ceil(offset_x), this.offset.y = Math.ceil(offset_y), this.render(),
6064
+ this.preScaleFactor = this.scaleFactor, this.preOffset.x = this.offset.x, this.preOffset.y = this.offset.y;
6065
+ }
6066
+ onWindowWheel=e => {
6067
+ e.ctrlKey && e.preventDefault();
6068
+ };
6069
+ canvasMousewheel=event => {
6070
+ event.preventDefault(), event.ctrlKey && (this.mousePositioin.x = event.offsetX,
6071
+ this.mousePositioin.y = event.offsetY, event.deltaY > 0 ? (this.scaleFactor = parseFloat((this.scaleFactor + this.scaleStep).toFixed(1)),
6072
+ this.scaleFactor > this.maxScale && (this.scaleFactor = this.maxScale)) : (this.scaleFactor = parseFloat((this.scaleFactor - this.scaleStep).toFixed(1)),
6073
+ this.scaleFactor < this.minScale && (this.scaleFactor = this.minScale)), this.zoom());
6074
+ };
6075
+ canvasMousedown(event) {
6076
+ event.preventDefault(), 0 === event.button && event.ctrlKey && (this.clickX = event.offsetX,
6077
+ this.clickY = event.offsetY, this.canvas.addEventListener("mousemove", this.canvasMousemove),
6078
+ this.canvas.addEventListener("mouseup", this.canvasMouseup));
6079
+ }
6080
+ canvasMousemove(event) {
6081
+ event.preventDefault(), event.ctrlKey && (this.offset.x = Math.ceil(this.preOffset.x + (event.offsetX - this.clickX)),
6082
+ this.offset.y = Math.ceil(this.preOffset.y + (event.offsetY - this.clickY)), this.render());
6083
+ }
6084
+ canvasMouseup(event) {
6085
+ event.preventDefault(), event.ctrlKey && (this.preOffset.x = this.offset.x, this.preOffset.y = this.offset.y,
6086
+ this.canvas.removeEventListener("mousemove", this.canvasMousemove), this.canvas.removeEventListener("mouseup", this.canvasMouseup));
6087
+ }
6088
+ destroy() {
6089
+ this.canvas.removeEventListener("mousedown", this.canvasMousedown), this.canvas.removeEventListener("mousemove", this.canvasMousemove),
6090
+ this.canvas.removeEventListener("mouseup", this.canvasMouseup), this.canvas.removeEventListener("wheel", this.canvasMousewheel),
6091
+ window.removeEventListener("wheel", this.onWindowWheel);
6092
+ }
6093
+ }
5977
6094
  const {hexToRgb: hexToRgb} = useChangeColor();
5978
6095
  var DraggableRect = vue.defineComponent({
5979
6096
  props: {
@@ -5992,7 +6109,7 @@
5992
6109
  },
5993
6110
  emits: [ "draggle-resize", "contextmenu" ],
5994
6111
  setup(props, {emit: emit}) {
5995
- const isDraggle = vue.ref(!1), isResizeCorner = vue.ref({
6112
+ const scaleTranslate = vue.inject("scaleTranslateManager", {}).scaleTranslate, isDraggle = vue.ref(!1), isResizeCorner = vue.ref({
5996
6113
  topLeft: !1,
5997
6114
  topCenter: !1,
5998
6115
  topRight: !1,
@@ -6012,66 +6129,68 @@
6012
6129
  isResizeCorner.value.rightCenter = !1, isResizeCorner.value.bottomLeft = !1, isResizeCorner.value.bottomCenter = !1,
6013
6130
  isResizeCorner.value.bottomRight = !1, emit("draggle-resize", rect.value);
6014
6131
  }, onMousemove = e => {
6132
+ 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);
6015
6133
  if (isDraggle.value) {
6016
- const newLeft = e.clientX - parentRect.left - draggleOffset.value.diff_x, newTop = e.clientY - parentRect.top - draggleOffset.value.diff_y;
6017
- rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6018
- rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6134
+ 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);
6135
+ rect.value.startX = Math.max(0, Math.min(offsetX, parentRect.width - rect.value.rectWidth)),
6136
+ rect.value.startY = Math.max(0, Math.min(offsetY, parentRect.height - rect.value.rectHeight));
6019
6137
  }
6020
6138
  if (isResizeCorner.value.bottomCenter) {
6021
- let newHeight = e.clientY - parentRect.top - rect.value.startY;
6022
- newHeight < 30 && (newHeight = 30), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6139
+ let newHeight = Math.floor((e.clientY - parentRect.top - startY) / scale);
6140
+ newHeight < min_size && (newHeight = min_size), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6023
6141
  rect.value.rectHeight = newHeight;
6024
6142
  }
6025
6143
  if (isResizeCorner.value.topCenter) {
6026
- let newTop = e.clientY - parentRect.top, newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6144
+ let newTop = Math.floor((e.clientY - parentRect.top - y) / scale), newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6027
6145
  if (newTop < 0) return;
6028
- if (newHeight < 30) return;
6146
+ if (newHeight < min_size) return;
6029
6147
  rect.value.rectHeight = newHeight, rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6030
6148
  }
6031
6149
  if (isResizeCorner.value.leftCenter) {
6032
- let newLeft = e.clientX - parentRect.left, newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6150
+ let newLeft = Math.floor((e.clientX - parentRect.left - x) / scale), newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6033
6151
  if (newLeft < 0) return;
6034
- if (newWidth < 30) return;
6152
+ if (newWidth < min_size) return;
6035
6153
  rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6036
6154
  rect.value.rectWidth = newWidth;
6037
6155
  }
6038
6156
  if (isResizeCorner.value.rightCenter) {
6039
- let newWidth = e.clientX - parentRect.left - rect.value.startX;
6040
- newWidth < 30 && (newWidth = 30), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6157
+ let newWidth = Math.floor((e.clientX - parentRect.left - startX) / scale);
6158
+ newWidth < min_size && (newWidth = min_size), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6041
6159
  rect.value.rectWidth = newWidth;
6042
6160
  }
6043
6161
  if (isResizeCorner.value.bottomRight) {
6044
- let newWidth = e.clientX - parentRect.left - rect.value.startX, newHeight = e.clientY - parentRect.top - rect.value.startY;
6045
- newWidth < 30 && (newWidth = 30), newHeight < 30 && (newHeight = 30), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6162
+ let newWidth = Math.floor((e.clientX - parentRect.left - startX) / scale), newHeight = Math.floor((e.clientY - parentRect.top - startY) / scale);
6163
+ newWidth < min_size && (newWidth = min_size), newHeight < min_size && (newHeight = min_size),
6164
+ newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6046
6165
  newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6047
6166
  rect.value.rectWidth = newWidth, rect.value.rectHeight = newHeight;
6048
6167
  }
6049
6168
  if (isResizeCorner.value.bottomLeft) {
6050
- let newLeft = e.clientX - parentRect.left, newWidth = rect.value.startX - newLeft + rect.value.rectWidth, newHeight = e.clientY - parentRect.top - rect.value.startY;
6169
+ 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);
6051
6170
  if (newLeft < 0) return;
6052
- if (newWidth < 30) return;
6053
- newHeight < 30 && (newHeight = 30), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6171
+ if (newWidth < min_size) return;
6172
+ newHeight < min_size && (newHeight = min_size), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6054
6173
  rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6055
6174
  rect.value.rectWidth = newWidth, rect.value.rectHeight = newHeight;
6056
6175
  }
6057
6176
  if (isResizeCorner.value.topLeft) {
6058
- let newTop = e.clientY - parentRect.top, newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6177
+ let newTop = Math.floor((e.clientY - parentRect.top - y) / scale), newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6059
6178
  if (newTop < 0) return;
6060
- if (newHeight < 30) return;
6179
+ if (newHeight < min_size) return;
6061
6180
  rect.value.rectHeight = newHeight, rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6062
- let newLeft = e.clientX - parentRect.left, newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6181
+ let newLeft = Math.floor((e.clientX - parentRect.left - x) / scale), newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6063
6182
  if (newLeft < 0) return;
6064
- if (newWidth < 30) return;
6183
+ if (newWidth < min_size) return;
6065
6184
  rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6066
6185
  rect.value.rectWidth = newWidth;
6067
6186
  }
6068
6187
  if (isResizeCorner.value.topRight) {
6069
- let newTop = e.clientY - parentRect.top, newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6188
+ let newTop = Math.floor((e.clientY - parentRect.top - y) / scale), newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6070
6189
  if (newTop < 0) return;
6071
- if (newHeight < 30) return;
6190
+ if (newHeight < min_size) return;
6072
6191
  rect.value.rectHeight = newHeight, rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6073
- let newWidth = e.clientX - parentRect.left - rect.value.startX;
6074
- newWidth < 30 && (newWidth = 30), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6192
+ let newWidth = Math.floor((e.clientX - parentRect.left - startX) / scale);
6193
+ newWidth < min_size && (newWidth = min_size), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6075
6194
  rect.value.rectWidth = newWidth;
6076
6195
  }
6077
6196
  };
@@ -6096,11 +6215,23 @@
6096
6215
  };
6097
6216
  },
6098
6217
  render() {
6099
- const _ns = vue.inject("ns", {}), props = this.$props;
6218
+ const _ns = vue.inject("ns", {}), scaleTranslate = vue.inject("scaleTranslateManager", {}).scaleTranslate, props = this.$props;
6100
6219
  return vue.createVNode("div", {
6101
6220
  class: [ _ns.b("draggable-rect") ],
6102
6221
  style: (() => {
6103
- const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = this.rect, style = {
6222
+ const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = ((rect, scaleOffset) => {
6223
+ const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect, {scale: scale, x: x, y: y} = scaleOffset;
6224
+ return {
6225
+ startX: Math.ceil(startX * scale + x),
6226
+ startY: Math.ceil(startY * scale + y),
6227
+ rectWidth: Math.ceil(rectWidth * scale),
6228
+ rectHeight: Math.ceil(rectHeight * scale),
6229
+ canvasWidth: rect.canvasWidth,
6230
+ canvasHeight: rect.canvasHeight,
6231
+ originWidth: rect.originWidth,
6232
+ originHeight: rect.originHeight
6233
+ };
6234
+ })(this.rect, scaleTranslate.value), style = {
6104
6235
  top: startY + "px",
6105
6236
  left: startX + "px",
6106
6237
  width: rectWidth + "px",
@@ -6161,7 +6292,7 @@
6161
6292
  },
6162
6293
  emits: [ "change" ],
6163
6294
  setup(props, {emit: emit, expose: expose}) {
6164
- const ns = vue.inject("ns", {}), _emit = vue.inject("_emit", null), mainBasaeRef = vue.ref(), canvasMainRef = vue.ref(), canvasBaseRef = vue.ref(), canvasRectRef = vue.ref(), labels = vue.ref([]), drawBaseCanvas = vue.ref({}), formatLabelsType = () => {
6295
+ 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 = () => {
6165
6296
  const _labels = deepClone(labels.value);
6166
6297
  let yolo_label = [];
6167
6298
  return {
@@ -6223,16 +6354,18 @@
6223
6354
  return scale_rects;
6224
6355
  })(labels.value, canvasHeight);
6225
6356
  const {updateLabels: updateLabels, addDrawRect: addDrawRect, hitCanvasLabel: hitCanvasLabel} = (options => {
6226
- const {canvas: canvas, ctx: ctx, labels: labels, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight} = options, updateLabels = scaleOffset => {
6227
- scaleOffset && (canvas.width = canvasWidth, ctx.save(), ctx.translate(scaleOffset.x, scaleOffset.y),
6228
- ctx.scale(scaleOffset.scale, scaleOffset.scale)), ctx.clearRect(0, 0, canvasWidth, canvasHeight),
6357
+ const {canvas: canvas, ctx: ctx, labels: labels, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight, scaleOffset: scaleOffset} = options, updateLabels = () => {
6358
+ canvas.width = canvasWidth, scaleOffset.value && (ctx.save(), ctx.translate(scaleOffset.value.x, scaleOffset.value.y),
6359
+ ctx.scale(scaleOffset.value.scale, scaleOffset.value.scale)), ctx.clearRect(0, 0, canvasWidth, canvasHeight),
6229
6360
  ctx.drawImage(image, 0, 0, canvasWidth, canvasHeight);
6361
+ const scale = scaleOffset.value?.scale || 1, fontSize = 14 / scale, fontPadding = 6 / scale, lineWidth = 2 / scale;
6230
6362
  for (let i = 0; i < labels.length; i++) {
6231
6363
  const rect = labels[i], {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight, type: type} = rect, color = colors$1[type % colors$1.length];
6232
- if (ctx.font = "bold 14px serif", ctx.textBaseline = "top", ctx.save(), ctx.strokeStyle = color,
6233
- ctx.strokeRect(startX, startY, rectWidth, rectHeight), isValueExist(rect.typeName) || isValueExist(rect.type)) {
6364
+ if (ctx.font = `bold ${fontSize}px serif`, ctx.textBaseline = "top", ctx.save(),
6365
+ ctx.strokeStyle = color, ctx.lineWidth = lineWidth, ctx.strokeRect(startX, startY, rectWidth, rectHeight),
6366
+ isValueExist(rect.typeName) || isValueExist(rect.type)) {
6234
6367
  const text = rect.typeName || rect.type;
6235
- ctx.fillStyle = color, ctx.fillText(text, startX + 6, startY + 6);
6368
+ ctx.fillStyle = color, ctx.fillText(text, startX + fontPadding, startY + fontPadding);
6236
6369
  }
6237
6370
  ctx.restore();
6238
6371
  }
@@ -6240,8 +6373,10 @@
6240
6373
  return updateLabels(), {
6241
6374
  updateLabels: updateLabels,
6242
6375
  addDrawRect: (rect, color = "#f30635") => {
6243
- const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect;
6244
- ctx.save(), ctx.strokeStyle = color, ctx.strokeRect(startX, startY, rectWidth, rectHeight),
6376
+ const scale = scaleOffset.value?.scale || 1, {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect;
6377
+ ctx.save();
6378
+ const lineWidth = 2 / scale;
6379
+ ctx.lineWidth = lineWidth, ctx.strokeStyle = color, ctx.strokeRect(startX, startY, rectWidth, rectHeight),
6245
6380
  ctx.restore();
6246
6381
  },
6247
6382
  hitCanvasLabel: (x, y) => {
@@ -6265,7 +6400,8 @@
6265
6400
  canvasWidth: canvasWidth,
6266
6401
  canvasHeight: canvasHeight,
6267
6402
  labels: labels.value,
6268
- scaleFactor: scaleFactor
6403
+ scaleFactor: scaleFactor,
6404
+ scaleOffset: scaleTranslateManager.scaleTranslate
6269
6405
  });
6270
6406
  drawBaseCanvas.value.updateLabels = updateLabels, drawBaseCanvas.value.addDrawRect = addDrawRect,
6271
6407
  drawBaseCanvas.value.hitCanvasLabel = hitCanvasLabel;
@@ -6332,30 +6468,45 @@
6332
6468
  originWidth: originWidth,
6333
6469
  originHeight: originHeight
6334
6470
  }, ((rect, {endX: endX, endY: endY}) => {
6335
- activate_add_label.value = rect, drawBaseCanvas.value.addDrawRect(rect), updateContextmenuLabelFixed(endX, endY, rect);
6471
+ activate_add_label.value = rect;
6472
+ const newRect = ((rect, scaleOffset) => {
6473
+ const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect, {scale: scale, x: x, y: y} = scaleOffset;
6474
+ return {
6475
+ startX: Math.ceil((startX - x) / scale),
6476
+ startY: Math.ceil((startY - y) / scale),
6477
+ rectWidth: Math.ceil(rectWidth / scale),
6478
+ rectHeight: Math.ceil(rectHeight / scale),
6479
+ canvasWidth: rect.canvasWidth,
6480
+ canvasHeight: rect.canvasHeight,
6481
+ originWidth: rect.originWidth,
6482
+ originHeight: rect.originHeight
6483
+ };
6484
+ })(rect, scaleTranslateManager.scaleTranslate.value);
6485
+ drawBaseCanvas.value.addDrawRect(newRect), updateContextmenuLabelFixed(endX, endY, newRect);
6336
6486
  }), (() => {
6337
6487
  onCloseDraggableRectFixed();
6338
6488
  }));
6339
- drawBaseCanvas.value.clearCanvasRect = clearCanvas, drawBaseCanvas.value.removeEventAll = removeEventAll;
6489
+ drawBaseCanvas.value.clearCanvasRect = clearCanvas, drawBaseCanvas.value.removeEventAll = removeEventAll,
6490
+ canvasDragZoom.value = new CanvasSceneDragZoom(canvasBaseRef.value), canvasDragZoom.value.changeZoom((scaleOffset => {
6491
+ scaleTranslateManager.onChangeScaleTranslate(scaleOffset), drawBaseCanvas.value.updateLabels();
6492
+ }));
6340
6493
  }, image.onerror = () => {
6341
6494
  loadingImage.value = !1;
6342
6495
  };
6343
6496
  }
6344
6497
  canvasBaseRef.value.addEventListener("contextmenu", (e => {
6345
6498
  e.preventDefault();
6346
- const x = e.offsetX, y = e.offsetY, {hit_rect: hit_rect} = drawBaseCanvas.value.hitCanvasLabel(x, y);
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} = drawBaseCanvas.value.hitCanvasLabel(new_x, new_y);
6347
6500
  onCloseContentmenuLabel(), onCloseDraggableRectFixed(), hit_rect && vue.nextTick((() => {
6348
- updateContextmenuLabelFixed(x, y, hit_rect);
6501
+ updateContextmenuLabelFixed(offsetX, offsetY, hit_rect);
6349
6502
  }));
6350
6503
  })), canvasBaseRef.value.addEventListener("click", (e => {
6351
6504
  if (e.ctrlKey) return;
6352
- const x = e.offsetX, y = e.offsetY, {hit_rect: hit_rect, hit_index: hit_index, color: color} = drawBaseCanvas.value.hitCanvasLabel(x, y);
6505
+ 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);
6353
6506
  onCloseDraggableRectFixed(), onCloseContentmenuLabel(), hit_rect && vue.nextTick((() => {
6354
- updateDraggableRectFixed(x, y, hit_rect, hit_index, color);
6507
+ updateDraggableRectFixed(offsetX, offsetY, hit_rect, hit_index, color);
6355
6508
  }));
6356
6509
  }));
6357
- }, onWindowWheel = e => {
6358
- e.ctrlKey && e.preventDefault();
6359
6510
  };
6360
6511
  vue.onMounted((() => {
6361
6512
  vue.watch((() => props.rowInfo), (info => {
@@ -6373,11 +6524,9 @@
6373
6524
  const rowInfo = vue.toRaw(props.rowInfo);
6374
6525
  renderImageLabel(rowInfo);
6375
6526
  }
6376
- })), window.addEventListener("wheel", onWindowWheel, {
6377
- passive: !1
6378
- });
6527
+ }));
6379
6528
  })), vue.onUnmounted((() => {
6380
- drawBaseCanvas.value.removeEventAll?.(), window.removeEventListener("wheel", onWindowWheel);
6529
+ drawBaseCanvas.value.removeEventAll?.(), canvasDragZoom.value.destroy();
6381
6530
  }));
6382
6531
  const contextmenuLabelFixed = vue.ref({
6383
6532
  show: !1,
@@ -6464,6 +6613,9 @@
6464
6613
  const rowInfo = vue.toRaw(props.rowInfo);
6465
6614
  renderImageLabel(rowInfo);
6466
6615
  }));
6616
+ },
6617
+ resetScaleOffset: () => {
6618
+ canvasDragZoom.value.reset();
6467
6619
  }
6468
6620
  });
6469
6621
  return () => vue.createVNode(vue.Fragment, null, [ vue.createVNode(NextSpinLoading, {
@@ -6663,7 +6815,11 @@
6663
6815
  label_txt: label_txt
6664
6816
  }, (imageItem => {
6665
6817
  labelImages.value[activateNodeIndex.value] = imageItem || node, activateNodeIndex.value = index,
6666
- loading.value = !1;
6818
+ loading.value = !1, scaleTranslate.value = {
6819
+ scale: 1,
6820
+ x: 0,
6821
+ y: 0
6822
+ };
6667
6823
  }), (() => {
6668
6824
  loading.value = !1;
6669
6825
  })), !0);
@@ -6696,8 +6852,20 @@
6696
6852
  isFullscreen.value = val, updateMainContentHeight(), vue.nextTick((() => {
6697
6853
  canvasContextRef.value.rerenderImage();
6698
6854
  }));
6699
- };
6700
- expose({
6855
+ }, scaleTranslate = vue.ref({
6856
+ scale: 1,
6857
+ x: 0,
6858
+ y: 0
6859
+ });
6860
+ vue.provide("scaleTranslateManager", {
6861
+ scaleTranslate: scaleTranslate,
6862
+ onChangeScaleTranslate: val => {
6863
+ scaleTranslate.value = val;
6864
+ },
6865
+ onResetScaleTranslate: () => {
6866
+ canvasContextRef.value.resetScaleOffset();
6867
+ }
6868
+ }), expose({
6701
6869
  convertToLabel: convertToLabel,
6702
6870
  canvertToCanvas: canvertToCanvas
6703
6871
  });
@@ -6863,7 +7031,10 @@
6863
7031
  }, null) ]) ]);
6864
7032
  }
6865
7033
  });
6866
- const NextLabelimg = withInstall(Element$1), NextLabelimgPreview = withInstall(preview), isPointInCircle = (mouseX, mouseY, circleX, circleY, radius) => Math.sqrt(Math.pow(mouseX - circleX, 2) + Math.pow(mouseY - circleY, 2)) < radius, vertexesUnique = vertexes => Array.from(new Set(vertexes.map((item => JSON.stringify(item))))).map((item => JSON.parse(item))), {hexToRgba: hexToRgba} = useChangeColor(), colors = [ "#91cc75", "#fac858", "#ee6666", "#73c0de", "#3ba272", "#fc8452", "#9a60b4", "#ea7ccc" ];
7034
+ const NextLabelimg = withInstall(Element$1), NextLabelimgPreview = withInstall(preview), isPointInCircle = (mouseX, mouseY, circleX, circleY, radius) => Math.sqrt(Math.pow(mouseX - circleX, 2) + Math.pow(mouseY - circleY, 2)) < radius, vertexesUnique = vertexes => Array.from(new Set(vertexes.map((item => JSON.stringify(item))))).map((item => JSON.parse(item))), vertexesToScale = (vertexes, scaleX, scaleY, isMultiply = !0) => vertexes?.length ? vertexes.map((item => ((vertex, scaleX, scaleY, isMultiply = !0) => {
7035
+ const [x, y] = vertex;
7036
+ return isMultiply ? [ x * scaleX, y * scaleY ] : [ x / scaleX, y / scaleY ];
7037
+ })(item, scaleX, scaleY, isMultiply))) : [], {hexToRgba: hexToRgba} = useChangeColor(), colors = [ "#91cc75", "#fac858", "#ee6666", "#73c0de", "#3ba272", "#fc8452", "#9a60b4", "#ea7ccc" ];
6867
7038
  class CreatePolygonVertexes {
6868
7039
  canvas;
6869
7040
  ctx;
@@ -6919,9 +7090,9 @@
6919
7090
  canvasMouseDblclick(e) {
6920
7091
  e.stopPropagation(), this.isDrawing && (this.canvas.style.cursor = "unset", this.mouseOffset.x = e.offsetX,
6921
7092
  this.mouseOffset.y = e.offsetY, this.vertexes.push([ e.offsetX, e.offsetY ]), this.vertexes = vertexesUnique(this.vertexes)),
6922
- this.notifyDestryedListerers(), this.destroyed();
7093
+ this.notifyDestryedListerers(), this.destroy();
6923
7094
  }
6924
- destroyed() {
7095
+ destroy() {
6925
7096
  this.isDrawing = !1, this.vertexes = [], this.vertexesObservers = [], this.destroyedObservers = () => {
6926
7097
  this.canvas.removeEventListener("click", this.canvasMouseClick);
6927
7098
  }, this.canvas.removeEventListener("mousemove", this.canvasMousemove), this.canvas.removeEventListener("dblclick", this.canvasMouseDblclick);
@@ -6940,11 +7111,18 @@
6940
7111
  edgeCentreRadius;
6941
7112
  pointRecover;
6942
7113
  observers=[];
7114
+ editPolygonObserver;
6943
7115
  constructor(canvas, ctx) {
6944
7116
  this.canvas = canvas, this.ctx = ctx, this.vertexes = [], this.isEditing = !1, this.canClickEvent = !0,
6945
7117
  this.isMoveEditing = !1, this.pointVertexIndex = -1, this.pointCentreIndex = -1,
6946
7118
  this.vertexRadius = 8, this.edgeCentreRadius = 5, this.pointRecover = [];
6947
7119
  }
7120
+ notifyEditPolygonObserver() {
7121
+ this.editPolygonObserver?.(this.vertexes);
7122
+ }
7123
+ onEditPolygon(callback) {
7124
+ this.editPolygonObserver = callback;
7125
+ }
6948
7126
  drawPolygonPath(vertexes, mouseX, mouseY) {
6949
7127
  const ctx = this.ctx;
6950
7128
  if (!vertexes.length) return;
@@ -7049,7 +7227,7 @@
7049
7227
  this.pointVertexIndex > -1 && this.vertexes.splice(this.pointVertexIndex, 1, [ x, y ]),
7050
7228
  this.pointCentreIndex > -1 && this.vertexes.splice(this.pointCentreIndex, 1, [ x, y ]),
7051
7229
  this.isMoveEditing = !1, this.pointVertexIndex = -1, this.pointCentreIndex = -1,
7052
- this.drawPolygon(this.vertexes), this.notifyObservers();
7230
+ this.drawPolygon(this.vertexes), this.notifyObservers(), this.notifyEditPolygonObserver();
7053
7231
  }
7054
7232
  canvasMouseClick(e) {
7055
7233
  e.stopPropagation();
@@ -7058,7 +7236,8 @@
7058
7236
  const i = this.pointInVertexes(x, y);
7059
7237
  if (isValueExist(i)) {
7060
7238
  if (this.vertexes.length <= 3) return;
7061
- this.vertexes.splice(i, 1), this.drawPolygon(this.vertexes), this.notifyObservers();
7239
+ this.vertexes.splice(i, 1), this.drawPolygon(this.vertexes), this.notifyObservers(),
7240
+ this.notifyEditPolygonObserver();
7062
7241
  }
7063
7242
  }
7064
7243
  }
@@ -7069,7 +7248,7 @@
7069
7248
  this.pointCentreIndex > -1 && this.vertexes.splice(this.pointCentreIndex, 1, [ x, y ]),
7070
7249
  this.notifyObservers());
7071
7250
  }
7072
- destroyed() {
7251
+ destroy() {
7073
7252
  this.vertexes = [], this.observers = [], this.isEditing = !1, this.canvas.removeEventListener("mousedown", this.canvasMousedown),
7074
7253
  this.canvas.removeEventListener("mouseup", this.canvasMouseup), this.canvas.removeEventListener("click", this.canvasMouseClick),
7075
7254
  this.canvas.removeEventListener("mousemove", this.canvasMousemove);
@@ -7081,26 +7260,32 @@
7081
7260
  image;
7082
7261
  canvasWidth;
7083
7262
  canvasHeight;
7084
- paths;
7263
+ scaleOffset;
7264
+ labels;
7085
7265
  scaleX;
7086
7266
  scaleY;
7087
7267
  editDrawPolygon;
7088
7268
  createPolygonVertexes;
7089
7269
  editVertexes;
7090
7270
  editPolygonObservers=[];
7271
+ drawnPolygonObserver;
7091
7272
  constructor(options) {
7092
- const {canvas: canvas, ctx: ctx, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight, paths: paths, scaleX: scaleX, scaleY: scaleY} = options;
7273
+ const {canvas: canvas, ctx: ctx, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight, labels: labels, scaleX: scaleX, scaleY: scaleY, scaleOffset: scaleOffset} = options;
7093
7274
  this.canvas = canvas, this.ctx = ctx, this.image = image, this.canvasWidth = canvasWidth,
7094
- this.canvasHeight = canvasHeight, this.paths = paths || [], this.scaleX = scaleX || 1,
7095
- this.scaleY = scaleY || 1, this.editVertexes = [], this.render(), this.createPolygonVertexes = new CreatePolygonVertexes(canvas, ctx),
7096
- this.editDrawPolygon = new EditPolygonPath(canvas, ctx), this.createPolygonVertexes.vertexesChangeEventListener(((vertexes, mouseOffset) => {
7275
+ this.canvasHeight = canvasHeight, this.scaleOffset = scaleOffset, this.labels = labels || {},
7276
+ this.scaleX = scaleX || 1, this.scaleY = scaleY || 1, this.editVertexes = [], this.render(),
7277
+ this.createPolygonVertexes = new CreatePolygonVertexes(canvas, ctx), this.editDrawPolygon = new EditPolygonPath(canvas, ctx),
7278
+ this.createPolygonVertexes.vertexesChangeEventListener(((vertexes, mouseOffset) => {
7097
7279
  this.render(), this.editDrawPolygon.drawPolygon(vertexes, mouseOffset), this.editVertexes = vertexes,
7098
7280
  this.notifyObservers();
7099
7281
  })), this.createPolygonVertexes.onDestroyed((vertexes => {
7100
- this.render(), this.editDrawPolygon.drawPolygon(vertexes), this.editDrawPolygon.updatePolygon((vertexes => {
7282
+ this.editVertexes = vertexes, this.render(), this.editDrawPolygon.drawPolygon(vertexes),
7283
+ this.editDrawPolygon.updatePolygon((vertexes => {
7101
7284
  this.render(), this.editDrawPolygon.drawPolygon(vertexes), this.editVertexes = vertexes,
7102
7285
  this.notifyObservers();
7103
- }));
7286
+ })), this.editDrawPolygon.onEditPolygon((vertexes => {
7287
+ this.editVertexes = vertexes, this.notifyDrawnPolygonObservers();
7288
+ })), this.notifyDrawnPolygonObservers();
7104
7289
  }));
7105
7290
  }
7106
7291
  notifyObservers() {
@@ -7108,17 +7293,22 @@
7108
7293
  listener(this.editVertexes);
7109
7294
  }));
7110
7295
  }
7296
+ notifyDrawnPolygonObservers() {
7297
+ this.drawnPolygonObserver?.(this.editVertexes);
7298
+ }
7111
7299
  updatePolygon(callback) {
7112
7300
  this.editPolygonObservers.push(callback);
7113
7301
  }
7114
- drawPolygons(paths) {
7115
- const ctx = this.ctx;
7116
- ctx.scale(this.scaleX, this.scaleY);
7117
- for (let i = 0; i < paths.length; i++) {
7118
- const path = paths[i].path;
7302
+ onDrawnPolygon(callback) {
7303
+ this.drawnPolygonObserver = callback;
7304
+ }
7305
+ drawPolygons(shapes) {
7306
+ const ctx = this.ctx, {scale: scale} = this.scaleOffset.value, scaleX = this.scaleX, scaleY = this.scaleY;
7307
+ for (let i = 0; i < shapes.length; i++) {
7308
+ const item = shapes[i], path = vertexesToScale(item.points, scaleX, scaleY);
7119
7309
  if (!path.length) return;
7120
7310
  const color = colors[i % colors.length];
7121
- ctx.beginPath(), ctx.lineWidth = 2, ctx.strokeStyle = color, ctx.fillStyle = hexToRgba(color, .2);
7311
+ ctx.beginPath(), ctx.lineWidth = 2 / scale, ctx.strokeStyle = color, ctx.fillStyle = hexToRgba(color, .2);
7122
7312
  const startX = path[0][0], startY = path[0][1];
7123
7313
  ctx.moveTo(startX, startY);
7124
7314
  for (let i = 1; i < path.length; i++) {
@@ -7128,15 +7318,18 @@
7128
7318
  ctx.closePath(), ctx.stroke(), ctx.fill();
7129
7319
  }
7130
7320
  }
7131
- initCanvas=() => {
7321
+ drawCanvas=() => {
7132
7322
  this.ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight), this.ctx.drawImage(this.image, 0, 0, this.canvasWidth, this.canvasHeight),
7133
- this.ctx.save(), this.drawPolygons(this.paths), this.ctx.restore();
7323
+ this.ctx.save();
7324
+ const shapes = this.labels.shapes;
7325
+ this.drawPolygons(shapes), this.ctx.restore();
7134
7326
  };
7135
7327
  render=() => {
7136
- this.initCanvas();
7328
+ this.canvas.width = this.canvasWidth, this.scaleOffset.value && (this.ctx.translate(this.scaleOffset.value.x, this.scaleOffset.value.y),
7329
+ this.ctx.scale(this.scaleOffset.value.scale, this.scaleOffset.value.scale)), this.drawCanvas();
7137
7330
  };
7138
- destroyed() {
7139
- this.paths = [], this.editDrawPolygon.destroyed(), this.createPolygonVertexes.destroyed();
7331
+ destroy() {
7332
+ this.labels = {}, this.editDrawPolygon.destroy(), this.createPolygonVertexes.destroy();
7140
7333
  }
7141
7334
  }
7142
7335
  var CanvasContext = vue.defineComponent({
@@ -7154,9 +7347,9 @@
7154
7347
  default: () => ({})
7155
7348
  }
7156
7349
  },
7157
- emits: [ "editPolygon" ],
7350
+ emits: [ "editPolygon", "changePolygon" ],
7158
7351
  setup(props, {emit: emit, expose: expose}) {
7159
- const ns = vue.inject("ns", {}), mainBasaeRef = vue.ref(), canvasMainRef = vue.ref(), canvasBaseRef = vue.ref(), drawCanvas = vue.ref(), setContainerWidthHeight = (canvasWidth, canvasHeight) => {
7352
+ const ns = vue.inject("ns", {}), scaleTranslateManager = vue.inject("scaleTranslateManager", {}), mainBasaeRef = vue.ref(), canvasMainRef = vue.ref(), canvasBaseRef = vue.ref(), drawCanvas = vue.ref(), canvasDragZoom = vue.ref(), setContainerWidthHeight = (canvasWidth, canvasHeight) => {
7160
7353
  canvasMainRef.value.style.width = canvasWidth + "px", canvasMainRef.value.style.height = canvasHeight + "px",
7161
7354
  canvasBaseRef.value.width = canvasWidth, canvasBaseRef.value.height = canvasHeight,
7162
7355
  canvasBaseRef.value.style.width = canvasWidth + "px", canvasBaseRef.value.style.height = canvasHeight + "px";
@@ -7166,7 +7359,7 @@
7166
7359
  const image = new Image;
7167
7360
  image.src = rowInfo.imageSrc, loadingImage.value = !0, image.onload = () => {
7168
7361
  loadingImage.value = !1;
7169
- const {canvasWidth: canvasWidth, canvasHeight: canvasHeight, scaleFactor: scaleFactor, scaleX: scaleX, scaleY: scaleY} = (image => {
7362
+ const {canvasWidth: canvasWidth, canvasHeight: canvasHeight, scaleFactor: scaleFactor, scaleX: scaleX, scaleY: scaleY, originWidth: originWidth, originHeight: originHeight} = (image => {
7170
7363
  const clientWidth = mainBasaeRef.value?.elementInstance.clientWidth, clientHeight = mainBasaeRef.value?.elementInstance.clientHeight;
7171
7364
  let {width: width, height: height} = image, scaleFactor = 1;
7172
7365
  const aspect_ratio = width / height;
@@ -7186,7 +7379,9 @@
7186
7379
  canvasHeight: canvasHeight,
7187
7380
  scaleFactor: scaleFactor,
7188
7381
  scaleX: Number(scaleX),
7189
- scaleY: Number(scaleY)
7382
+ scaleY: Number(scaleY),
7383
+ originWidth: image.width,
7384
+ originHeight: image.height
7190
7385
  };
7191
7386
  })(image);
7192
7387
  image.style.width = canvasWidth + "px", image.style.height = canvasHeight + "px",
@@ -7197,15 +7392,25 @@
7197
7392
  canvasWidth: canvasWidth,
7198
7393
  canvasHeight: canvasHeight,
7199
7394
  scaleFactor: scaleFactor,
7200
- paths: rowInfo.labels,
7395
+ labels: rowInfo.labels,
7201
7396
  scaleX: scaleX,
7202
- scaleY: scaleY
7397
+ scaleY: scaleY,
7398
+ scaleOffset: scaleTranslateManager.scaleTranslate
7203
7399
  }), drawCanvas.value.updatePolygon((vertexes => {
7204
- emit("editPolygon", {
7400
+ emit("changePolygon", {
7205
7401
  vertexes: vertexes,
7206
7402
  canvasWidth: canvasWidth,
7207
7403
  canvasHeight: canvasHeight
7208
7404
  });
7405
+ })), drawCanvas.value.onDrawnPolygon((vertexes => {
7406
+ const new_vertexes = vertexesToScale(vertexes, scaleX, scaleY, !1);
7407
+ emit("editPolygon", {
7408
+ vertexes: new_vertexes,
7409
+ originWidth: originWidth,
7410
+ originHeight: originHeight
7411
+ });
7412
+ })), canvasDragZoom.value = new CanvasSceneDragZoom(canvasBaseRef.value), canvasDragZoom.value.changeZoom((scaleOffset => {
7413
+ scaleTranslateManager.onChangeScaleTranslate(scaleOffset), drawCanvas.value.render();
7209
7414
  }));
7210
7415
  }, image.onerror = () => {
7211
7416
  loadingImage.value = !1;
@@ -7226,6 +7431,8 @@
7226
7431
  renderImageLabel(rowInfo);
7227
7432
  }
7228
7433
  }));
7434
+ })), vue.onUnmounted((() => {
7435
+ drawCanvas.value.destroy(), canvasDragZoom.value.destroy();
7229
7436
  }));
7230
7437
  return expose({
7231
7438
  rerenderImage: () => {
@@ -7233,6 +7440,9 @@
7233
7440
  const rowInfo = vue.toRaw(props.rowInfo);
7234
7441
  renderImageLabel(rowInfo);
7235
7442
  }));
7443
+ },
7444
+ resetScaleOffset: () => {
7445
+ canvasDragZoom.value.reset();
7236
7446
  }
7237
7447
  }), () => vue.createVNode(vue.Fragment, null, [ vue.createVNode(NextSpinLoading, {
7238
7448
  ref: mainBasaeRef,
@@ -7268,7 +7478,7 @@
7268
7478
  },
7269
7479
  emits: [ "fullscreen", "save" ],
7270
7480
  setup(props, {emit: emit}) {
7271
- const _ns = vue.inject("ns", {}), {t: t} = useLocale(), switchFillscreen = val => {
7481
+ const _ns = vue.inject("ns", {}), scaleTranslateManager = vue.inject("scaleTranslateManager", {}), scaleTranslate = scaleTranslateManager.scaleTranslate, {t: t} = useLocale(), switchFillscreen = val => {
7272
7482
  emit("fullscreen", val), document.body.style.overflow = val ? "hidden" : "auto";
7273
7483
  };
7274
7484
  return () => vue.createVNode(vue.Fragment, null, [ vue.createVNode(vue.Fragment, null, [ vue.createVNode("ul", {
@@ -7349,7 +7559,28 @@
7349
7559
  class: "label-text"
7350
7560
  }, [ t("next.labelme.deletePolyton") ]) ]) ]), vue.createVNode("ul", {
7351
7561
  class: [ _ns.be("header", "tool") ]
7352
- }, [ props.imageLength ? vue.createVNode("li", null, [ vue.createVNode("span", null, [ vue.createTextVNode("第 "), props.imageIndex + 1, vue.createTextVNode(" 张") ]), vue.createVNode("em", {
7562
+ }, [ vue.createVNode("li", {
7563
+ class: "hover",
7564
+ onClick: () => scaleTranslateManager.onResetScaleTranslate()
7565
+ }, [ vue.createVNode("svg", {
7566
+ t: "1725840994827",
7567
+ class: "icon",
7568
+ viewBox: "0 0 1024 1024",
7569
+ version: "1.1",
7570
+ xmlns: "http://www.w3.org/2000/svg",
7571
+ "p-id": "6051",
7572
+ width: "18",
7573
+ height: "18"
7574
+ }, [ vue.createVNode("path", {
7575
+ 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",
7576
+ "p-id": "6052"
7577
+ }, null) ]), vue.createVNode("span", {
7578
+ style: "padding-left: 3px"
7579
+ }, [ 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", {
7580
+ style: "padding: 0 10px;"
7581
+ }, [ vue.createTextVNode("偏移量") ]), vue.createVNode("span", {
7582
+ style: "min-width: 120px; text-align: left;"
7583
+ }, [ 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", {
7353
7584
  style: "padding: 0 5px;"
7354
7585
  }, [ vue.createTextVNode("/") ]), vue.createVNode("span", null, [ vue.createTextVNode("共 "), props.imageLength, vue.createTextVNode(" 张") ]) ]) : null, vue.createVNode("li", {
7355
7586
  style: "margin-right: 30px;",
@@ -7441,7 +7672,7 @@
7441
7672
  default: () => []
7442
7673
  }
7443
7674
  },
7444
- emits: [ "change", "save", "edit-polygon", "prev-click", "next-click" ],
7675
+ emits: [ "change", "save", "edit-polygon", "change-polygon", "prev-click", "next-click" ],
7445
7676
  setup(props, {emit: emit, slots: slots}) {
7446
7677
  const _config = deepClone(defaultConfig), _options = vue.computed((() => {
7447
7678
  const cfg = vue.unref(props.options);
@@ -7501,14 +7732,29 @@
7501
7732
  isFullscreen.value = val, updateMainContentHeight(), vue.nextTick((() => {
7502
7733
  canvasContextRef.value.rerenderImage();
7503
7734
  }));
7504
- }, onEditPlygonChange = plygon => {
7505
- currentNode.value.labels = plygon, emit("edit-polygon", plygon);
7735
+ }, onChangePolygon = node => {
7736
+ currentNode.value.labels = node, emit("change-polygon", node);
7737
+ }, onEditPlygon = node => {
7738
+ currentNode.value.labels = node, emit("edit-polygon", node);
7506
7739
  }, onToolHeaderSave = () => {
7507
7740
  onChangeActivateNode(activateNodeIndex.value) || elementPlus.ElMessage({
7508
7741
  type: "info",
7509
7742
  message: t("next.labelimg.labelNoUpdate")
7510
7743
  });
7511
- };
7744
+ }, scaleTranslate = vue.ref({
7745
+ scale: 1,
7746
+ x: 0,
7747
+ y: 0
7748
+ });
7749
+ vue.provide("scaleTranslateManager", {
7750
+ scaleTranslate: scaleTranslate,
7751
+ onChangeScaleTranslate: val => {
7752
+ scaleTranslate.value = val;
7753
+ },
7754
+ onResetScaleTranslate: () => {
7755
+ canvasContextRef.value.resetScaleOffset();
7756
+ }
7757
+ });
7512
7758
  return () => vue.createVNode(vue.Fragment, null, [ vue.createVNode("div", {
7513
7759
  ref: layoutLabelRef,
7514
7760
  class: [ ns.b(), props.className, isFullscreen.value ? ns.b("fullscreen") : "" ],
@@ -7541,7 +7787,8 @@
7541
7787
  }, [ vue.createVNode(CanvasContext, {
7542
7788
  ref: canvasContextRef,
7543
7789
  rowInfo: currentNode.value,
7544
- onEditPolygon: onEditPlygonChange
7790
+ onEditPolygon: onEditPlygon,
7791
+ onChangePolygon: onChangePolygon
7545
7792
  }, null) ]) ]), vue.createVNode("footer", {
7546
7793
  ref: footerRef,
7547
7794
  class: [ ns.b("footer") ]
@@ -7647,7 +7894,7 @@
7647
7894
  })(app);
7648
7895
  };
7649
7896
  var index = {
7650
- version: "0.3.6",
7897
+ version: "0.3.8",
7651
7898
  install: install
7652
7899
  };
7653
7900
  exports.NextContainer = NextContainer, exports.NextCrudTable = NextCrudTable, exports.NextCrudTableVirtualized = NextCrudTableVirtualized,
@@ -7694,7 +7941,7 @@
7694
7941
  }), exports.useGetDerivedNamespace = useGetDerivedNamespace, exports.useLanguage = (locale, lang) => {
7695
7942
  const localeRef = vue.isRef(locale) ? locale : vue.ref(locale), nextLang = localeLang[lang] || localeLang["zh-cn"];
7696
7943
  localeRef.value.name = lang, localeRef.value.next = nextLang.next;
7697
- }, exports.useLocale = useLocale, exports.useNamespace = useNamespace, exports.version = "0.3.6",
7944
+ }, exports.useLocale = useLocale, exports.useNamespace = useNamespace, exports.version = "0.3.8",
7698
7945
  Object.defineProperty(exports, "__esModule", {
7699
7946
  value: !0
7700
7947
  });