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.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
 
@@ -4024,7 +4024,11 @@ var TableColumnOperations = defineComponent({
4024
4024
  const {operationsBtnPlain: operationsBtnPlain, operationsBtnText: operationsBtnText} = options;
4025
4025
  return operationsBtnText || operationsBtnPlain;
4026
4026
  })), renderContent = () => {
4027
- const btnText = options.operationsBtnText, btnPlain = options.operationsBtnPlain, btnSize = options.operationsBtnSize;
4027
+ const btnText = options.operationsBtnText, btnPlain = options.operationsBtnPlain, btnSize = options.operationsBtnSize, btnCfg = {
4028
+ text: btnText,
4029
+ plain: btnPlain,
4030
+ size: btnSize
4031
+ };
4028
4032
  return createVNode(ElTableColumn, {
4029
4033
  fixed: "right",
4030
4034
  label: t("next.table.operation"),
@@ -4032,10 +4036,9 @@ var TableColumnOperations = defineComponent({
4032
4036
  headerAlign: valueExist(options.operationsHeaderAlign, options.headerAlign),
4033
4037
  align: valueExist(options.operationsColumnAlign, options.cellAlign)
4034
4038
  }, {
4035
- default: scoped => createVNode(Fragment, null, [ slots["operation-column-prefix"]?.(scoped, {
4036
- text: btnText,
4037
- plain: btnPlain,
4038
- size: btnSize
4039
+ default: scoped => createVNode(Fragment, null, [ slots["operation-column-prefix"]?.({
4040
+ scoped: scoped,
4041
+ btn: btnCfg
4039
4042
  }), options.editBtn ? createVNode(ElTooltip, {
4040
4043
  enterable: !1,
4041
4044
  effect: "dark",
@@ -4115,10 +4118,9 @@ var TableColumnOperations = defineComponent({
4115
4118
  }),
4116
4119
  default: () => t("next.table.delete")
4117
4120
  }) ]
4118
- }) : null, slots["operation-column-suffix"]?.(scoped, {
4119
- text: btnText,
4120
- plain: btnPlain,
4121
- size: btnSize
4121
+ }) : null, slots["operation-column-suffix"]?.({
4122
+ scoped: scoped,
4123
+ btn: btnCfg
4122
4124
  }) ])
4123
4125
  });
4124
4126
  };
@@ -6024,7 +6026,7 @@ var ToolHeader = defineComponent({
6024
6026
  },
6025
6027
  emits: [ "fullscreen", "save" ],
6026
6028
  setup(props, {emit: emit}) {
6027
- const _ns = inject("ns", {}), {t: t} = useLocale(), switchFillscreen = val => {
6029
+ const _ns = inject("ns", {}), scaleTranslateManager = inject("scaleTranslateManager", {}), scaleTranslate = scaleTranslateManager.scaleTranslate, {t: t} = useLocale(), switchFillscreen = val => {
6028
6030
  emit("fullscreen", val), document.body.style.overflow = val ? "hidden" : "auto";
6029
6031
  };
6030
6032
  return () => createVNode(Fragment, null, [ createVNode(Fragment, null, [ createVNode("ul", {
@@ -6051,7 +6053,28 @@ var ToolHeader = defineComponent({
6051
6053
  style: "padding-left: 3px"
6052
6054
  }, [ t("next.labelimg.saveLabel") ]) ]) ]), createVNode("ul", {
6053
6055
  class: [ _ns.be("header", "tool") ]
6054
- }, [ props.imageLength ? createVNode("li", null, [ createVNode("span", null, [ createTextVNode("第 "), props.imageIndex + 1, createTextVNode(" 张") ]), createVNode("em", {
6056
+ }, [ createVNode("li", {
6057
+ class: "hover",
6058
+ onClick: () => scaleTranslateManager.onResetScaleTranslate()
6059
+ }, [ createVNode("svg", {
6060
+ t: "1725840994827",
6061
+ class: "icon",
6062
+ viewBox: "0 0 1024 1024",
6063
+ version: "1.1",
6064
+ xmlns: "http://www.w3.org/2000/svg",
6065
+ "p-id": "6051",
6066
+ width: "18",
6067
+ height: "18"
6068
+ }, [ createVNode("path", {
6069
+ 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",
6070
+ "p-id": "6052"
6071
+ }, null) ]), createVNode("span", {
6072
+ style: "padding-left: 3px"
6073
+ }, [ t("next.labelimg.zoomRestore") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("缩放比例") ]), createVNode("span", null, [ parseInt((100 * scaleTranslate.value.scale).toString()), createTextVNode("%") ]), createVNode("span", {
6074
+ style: "padding: 0 10px;"
6075
+ }, [ createTextVNode("偏移量") ]), createVNode("span", {
6076
+ style: "min-width: 120px; text-align: left;"
6077
+ }, [ createTextVNode("X: "), scaleTranslate.value.x, createTextVNode(", Y: "), scaleTranslate.value.y ]) ]), props.imageLength ? createVNode("li", null, [ createVNode("span", null, [ createTextVNode("第 "), props.imageIndex + 1, createTextVNode(" 张") ]), createVNode("em", {
6055
6078
  style: "padding: 0 5px;"
6056
6079
  }, [ createTextVNode("/") ]), createVNode("span", null, [ createTextVNode("共 "), props.imageLength, createTextVNode(" 张") ]) ]) : null, createVNode("li", {
6057
6080
  style: "margin-right: 30px;",
@@ -6072,7 +6095,7 @@ var ToolHeader = defineComponent({
6072
6095
  }) ]),
6073
6096
  default: () => createVNode("ul", {
6074
6097
  style: "font-size: 12px;white-space: nowrap;"
6075
- }, [ createVNode("li", null, [ createVNode("span", null, [ createTextVNode("W:") ]), createVNode("span", null, [ createTextVNode("鼠标移入图片中,长按W键,鼠标按下左键,移动鼠标开始绘制,鼠标抬起结束绘制") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("A:") ]), createVNode("span", null, [ createTextVNode("A键进入上一张图片进行标注") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("D:") ]), createVNode("span", null, [ createTextVNode("D键进入下一张图片进行标注") ]) ]) ])
6098
+ }, [ createVNode("li", null, [ createVNode("span", null, [ createTextVNode("W:") ]), createVNode("span", null, [ createTextVNode("鼠标移入图片中,长按W键,鼠标按下左键,移动鼠标开始绘制,鼠标抬起结束绘制") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("A:") ]), createVNode("span", null, [ createTextVNode("A键进入上一张图片进行标注") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("D:") ]), createVNode("span", null, [ createTextVNode("D键进入下一张图片进行标注") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("Ctrl+鼠标滚轮:") ]), createVNode("span", null, [ createTextVNode("长按Ctrl+鼠标滚轮对图片进行缩放") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("Ctrl+鼠标左键:") ]), createVNode("span", null, [ createTextVNode("长按Ctrl+鼠标左键对图片进行拖拽移动") ]) ]) ])
6076
6099
  }) ]), props.isFullscreen ? createVNode("li", {
6077
6100
  class: "hover",
6078
6101
  onClick: () => switchFillscreen(!1)
@@ -6220,6 +6243,101 @@ var ContextMenuLabel = defineComponent({
6220
6243
  }
6221
6244
  });
6222
6245
 
6246
+ class CanvasSceneDragZoom {
6247
+ canvas;
6248
+ canvasWidth;
6249
+ canvasHeight;
6250
+ ctx;
6251
+ scaleFactor=1;
6252
+ preScaleFactor=1;
6253
+ offset={
6254
+ x: 0,
6255
+ y: 0
6256
+ };
6257
+ preOffset={
6258
+ x: 0,
6259
+ y: 0
6260
+ };
6261
+ mousePositioin={
6262
+ x: 0,
6263
+ y: 0
6264
+ };
6265
+ maxScale=8;
6266
+ minScale=.5;
6267
+ scaleStep=.1;
6268
+ clickX=0;
6269
+ clickY=0;
6270
+ observers=[];
6271
+ constructor(canvas) {
6272
+ this.canvas = canvas, this.canvasWidth = canvas.width, this.canvasHeight = canvas.height,
6273
+ this.ctx = canvas.getContext("2d"), this.canvasMousedown = this.canvasMousedown.bind(this),
6274
+ this.canvasMousemove = this.canvasMousemove.bind(this), this.canvasMouseup = this.canvasMouseup.bind(this),
6275
+ this.canvas.addEventListener("mousedown", this.canvasMousedown), this.canvas.addEventListener("wheel", this.canvasMousewheel, {
6276
+ passive: !1
6277
+ }), window.addEventListener("wheel", this.onWindowWheel, {
6278
+ passive: !1
6279
+ });
6280
+ }
6281
+ notifyObservers(scale, offset) {
6282
+ this.observers.forEach((listener => {
6283
+ listener({
6284
+ scale: scale,
6285
+ ...offset
6286
+ });
6287
+ }));
6288
+ }
6289
+ changeZoom(callback) {
6290
+ this.observers.push(callback);
6291
+ }
6292
+ reset() {
6293
+ this.scaleFactor = 1, this.preScaleFactor = 1, this.offset = {
6294
+ x: 0,
6295
+ y: 0
6296
+ }, this.preOffset = {
6297
+ x: 0,
6298
+ y: 0
6299
+ }, this.mousePositioin = {
6300
+ x: 0,
6301
+ y: 0
6302
+ }, this.zoom();
6303
+ }
6304
+ render() {
6305
+ this.canvas.width = this.canvasWidth, this.notifyObservers(this.scaleFactor, this.offset);
6306
+ }
6307
+ zoom() {
6308
+ 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;
6309
+ this.offset.x = Math.ceil(offset_x), this.offset.y = Math.ceil(offset_y), this.render(),
6310
+ this.preScaleFactor = this.scaleFactor, this.preOffset.x = this.offset.x, this.preOffset.y = this.offset.y;
6311
+ }
6312
+ onWindowWheel=e => {
6313
+ e.ctrlKey && e.preventDefault();
6314
+ };
6315
+ canvasMousewheel=event => {
6316
+ event.preventDefault(), event.ctrlKey && (this.mousePositioin.x = event.offsetX,
6317
+ this.mousePositioin.y = event.offsetY, event.deltaY > 0 ? (this.scaleFactor = parseFloat((this.scaleFactor + this.scaleStep).toFixed(1)),
6318
+ this.scaleFactor > this.maxScale && (this.scaleFactor = this.maxScale)) : (this.scaleFactor = parseFloat((this.scaleFactor - this.scaleStep).toFixed(1)),
6319
+ this.scaleFactor < this.minScale && (this.scaleFactor = this.minScale)), this.zoom());
6320
+ };
6321
+ canvasMousedown(event) {
6322
+ event.preventDefault(), 0 === event.button && event.ctrlKey && (this.clickX = event.offsetX,
6323
+ this.clickY = event.offsetY, this.canvas.addEventListener("mousemove", this.canvasMousemove),
6324
+ this.canvas.addEventListener("mouseup", this.canvasMouseup));
6325
+ }
6326
+ canvasMousemove(event) {
6327
+ event.preventDefault(), event.ctrlKey && (this.offset.x = Math.ceil(this.preOffset.x + (event.offsetX - this.clickX)),
6328
+ this.offset.y = Math.ceil(this.preOffset.y + (event.offsetY - this.clickY)), this.render());
6329
+ }
6330
+ canvasMouseup(event) {
6331
+ event.preventDefault(), event.ctrlKey && (this.preOffset.x = this.offset.x, this.preOffset.y = this.offset.y,
6332
+ this.canvas.removeEventListener("mousemove", this.canvasMousemove), this.canvas.removeEventListener("mouseup", this.canvasMouseup));
6333
+ }
6334
+ destroy() {
6335
+ this.canvas.removeEventListener("mousedown", this.canvasMousedown), this.canvas.removeEventListener("mousemove", this.canvasMousemove),
6336
+ this.canvas.removeEventListener("mouseup", this.canvasMouseup), this.canvas.removeEventListener("wheel", this.canvasMousewheel),
6337
+ window.removeEventListener("wheel", this.onWindowWheel);
6338
+ }
6339
+ }
6340
+
6223
6341
  const {hexToRgb: hexToRgb} = useChangeColor();
6224
6342
 
6225
6343
  var DraggableRect = defineComponent({
@@ -6239,7 +6357,7 @@ var DraggableRect = defineComponent({
6239
6357
  },
6240
6358
  emits: [ "draggle-resize", "contextmenu" ],
6241
6359
  setup(props, {emit: emit}) {
6242
- const isDraggle = ref(!1), isResizeCorner = ref({
6360
+ const scaleTranslate = inject("scaleTranslateManager", {}).scaleTranslate, isDraggle = ref(!1), isResizeCorner = ref({
6243
6361
  topLeft: !1,
6244
6362
  topCenter: !1,
6245
6363
  topRight: !1,
@@ -6259,66 +6377,68 @@ var DraggableRect = defineComponent({
6259
6377
  isResizeCorner.value.rightCenter = !1, isResizeCorner.value.bottomLeft = !1, isResizeCorner.value.bottomCenter = !1,
6260
6378
  isResizeCorner.value.bottomRight = !1, emit("draggle-resize", rect.value);
6261
6379
  }, onMousemove = e => {
6380
+ 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);
6262
6381
  if (isDraggle.value) {
6263
- const newLeft = e.clientX - parentRect.left - draggleOffset.value.diff_x, newTop = e.clientY - parentRect.top - draggleOffset.value.diff_y;
6264
- rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6265
- rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6382
+ 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);
6383
+ rect.value.startX = Math.max(0, Math.min(offsetX, parentRect.width - rect.value.rectWidth)),
6384
+ rect.value.startY = Math.max(0, Math.min(offsetY, parentRect.height - rect.value.rectHeight));
6266
6385
  }
6267
6386
  if (isResizeCorner.value.bottomCenter) {
6268
- let newHeight = e.clientY - parentRect.top - rect.value.startY;
6269
- newHeight < 30 && (newHeight = 30), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6387
+ let newHeight = Math.floor((e.clientY - parentRect.top - startY) / scale);
6388
+ newHeight < min_size && (newHeight = min_size), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6270
6389
  rect.value.rectHeight = newHeight;
6271
6390
  }
6272
6391
  if (isResizeCorner.value.topCenter) {
6273
- let newTop = e.clientY - parentRect.top, newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6392
+ let newTop = Math.floor((e.clientY - parentRect.top - y) / scale), newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6274
6393
  if (newTop < 0) return;
6275
- if (newHeight < 30) return;
6394
+ if (newHeight < min_size) return;
6276
6395
  rect.value.rectHeight = newHeight, rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6277
6396
  }
6278
6397
  if (isResizeCorner.value.leftCenter) {
6279
- let newLeft = e.clientX - parentRect.left, newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6398
+ let newLeft = Math.floor((e.clientX - parentRect.left - x) / scale), newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6280
6399
  if (newLeft < 0) return;
6281
- if (newWidth < 30) return;
6400
+ if (newWidth < min_size) return;
6282
6401
  rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6283
6402
  rect.value.rectWidth = newWidth;
6284
6403
  }
6285
6404
  if (isResizeCorner.value.rightCenter) {
6286
- let newWidth = e.clientX - parentRect.left - rect.value.startX;
6287
- newWidth < 30 && (newWidth = 30), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6405
+ let newWidth = Math.floor((e.clientX - parentRect.left - startX) / scale);
6406
+ newWidth < min_size && (newWidth = min_size), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6288
6407
  rect.value.rectWidth = newWidth;
6289
6408
  }
6290
6409
  if (isResizeCorner.value.bottomRight) {
6291
- let newWidth = e.clientX - parentRect.left - rect.value.startX, newHeight = e.clientY - parentRect.top - rect.value.startY;
6292
- newWidth < 30 && (newWidth = 30), newHeight < 30 && (newHeight = 30), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6410
+ let newWidth = Math.floor((e.clientX - parentRect.left - startX) / scale), newHeight = Math.floor((e.clientY - parentRect.top - startY) / scale);
6411
+ newWidth < min_size && (newWidth = min_size), newHeight < min_size && (newHeight = min_size),
6412
+ newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6293
6413
  newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6294
6414
  rect.value.rectWidth = newWidth, rect.value.rectHeight = newHeight;
6295
6415
  }
6296
6416
  if (isResizeCorner.value.bottomLeft) {
6297
- let newLeft = e.clientX - parentRect.left, newWidth = rect.value.startX - newLeft + rect.value.rectWidth, newHeight = e.clientY - parentRect.top - rect.value.startY;
6417
+ 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);
6298
6418
  if (newLeft < 0) return;
6299
- if (newWidth < 30) return;
6300
- newHeight < 30 && (newHeight = 30), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6419
+ if (newWidth < min_size) return;
6420
+ newHeight < min_size && (newHeight = min_size), newHeight + rect.value.startY > parentRect.height && (newHeight = parentRect.height - rect.value.startY),
6301
6421
  rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6302
6422
  rect.value.rectWidth = newWidth, rect.value.rectHeight = newHeight;
6303
6423
  }
6304
6424
  if (isResizeCorner.value.topLeft) {
6305
- let newTop = e.clientY - parentRect.top, newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6425
+ let newTop = Math.floor((e.clientY - parentRect.top - y) / scale), newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6306
6426
  if (newTop < 0) return;
6307
- if (newHeight < 30) return;
6427
+ if (newHeight < min_size) return;
6308
6428
  rect.value.rectHeight = newHeight, rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6309
- let newLeft = e.clientX - parentRect.left, newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6429
+ let newLeft = Math.floor((e.clientX - parentRect.left - x) / scale), newWidth = rect.value.startX - newLeft + rect.value.rectWidth;
6310
6430
  if (newLeft < 0) return;
6311
- if (newWidth < 30) return;
6431
+ if (newWidth < min_size) return;
6312
6432
  rect.value.startX = Math.max(0, Math.min(newLeft, parentRect.width - rect.value.rectWidth)),
6313
6433
  rect.value.rectWidth = newWidth;
6314
6434
  }
6315
6435
  if (isResizeCorner.value.topRight) {
6316
- let newTop = e.clientY - parentRect.top, newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6436
+ let newTop = Math.floor((e.clientY - parentRect.top - y) / scale), newHeight = rect.value.startY - newTop + rect.value.rectHeight;
6317
6437
  if (newTop < 0) return;
6318
- if (newHeight < 30) return;
6438
+ if (newHeight < min_size) return;
6319
6439
  rect.value.rectHeight = newHeight, rect.value.startY = Math.max(0, Math.min(newTop, parentRect.height - rect.value.rectHeight));
6320
- let newWidth = e.clientX - parentRect.left - rect.value.startX;
6321
- newWidth < 30 && (newWidth = 30), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6440
+ let newWidth = Math.floor((e.clientX - parentRect.left - startX) / scale);
6441
+ newWidth < min_size && (newWidth = min_size), newWidth + rect.value.startX > parentRect.width && (newWidth = parentRect.width - rect.value.startX),
6322
6442
  rect.value.rectWidth = newWidth;
6323
6443
  }
6324
6444
  };
@@ -6343,11 +6463,23 @@ var DraggableRect = defineComponent({
6343
6463
  };
6344
6464
  },
6345
6465
  render() {
6346
- const _ns = inject("ns", {}), props = this.$props;
6466
+ const _ns = inject("ns", {}), scaleTranslate = inject("scaleTranslateManager", {}).scaleTranslate, props = this.$props;
6347
6467
  return createVNode("div", {
6348
6468
  class: [ _ns.b("draggable-rect") ],
6349
6469
  style: (() => {
6350
- const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = this.rect, style = {
6470
+ const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = ((rect, scaleOffset) => {
6471
+ const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect, {scale: scale, x: x, y: y} = scaleOffset;
6472
+ return {
6473
+ startX: Math.ceil(startX * scale + x),
6474
+ startY: Math.ceil(startY * scale + y),
6475
+ rectWidth: Math.ceil(rectWidth * scale),
6476
+ rectHeight: Math.ceil(rectHeight * scale),
6477
+ canvasWidth: rect.canvasWidth,
6478
+ canvasHeight: rect.canvasHeight,
6479
+ originWidth: rect.originWidth,
6480
+ originHeight: rect.originHeight
6481
+ };
6482
+ })(this.rect, scaleTranslate.value), style = {
6351
6483
  top: startY + "px",
6352
6484
  left: startX + "px",
6353
6485
  width: rectWidth + "px",
@@ -6408,7 +6540,7 @@ var DraggableRect = defineComponent({
6408
6540
  },
6409
6541
  emits: [ "change" ],
6410
6542
  setup(props, {emit: emit, expose: expose}) {
6411
- const ns = inject("ns", {}), _emit = inject("_emit", null), mainBasaeRef = ref(), canvasMainRef = ref(), canvasBaseRef = ref(), canvasRectRef = ref(), labels = ref([]), drawBaseCanvas = ref({}), formatLabelsType = () => {
6543
+ const ns = inject("ns", {}), _emit = inject("_emit", null), scaleTranslateManager = inject("scaleTranslateManager", {}), mainBasaeRef = ref(), canvasMainRef = ref(), canvasBaseRef = ref(), canvasRectRef = ref(), labels = ref([]), drawBaseCanvas = ref({}), canvasDragZoom = ref(), formatLabelsType = () => {
6412
6544
  const _labels = deepClone(labels.value);
6413
6545
  let yolo_label = [];
6414
6546
  return {
@@ -6470,16 +6602,18 @@ var DraggableRect = defineComponent({
6470
6602
  return scale_rects;
6471
6603
  })(labels.value, canvasHeight);
6472
6604
  const {updateLabels: updateLabels, addDrawRect: addDrawRect, hitCanvasLabel: hitCanvasLabel} = (options => {
6473
- const {canvas: canvas, ctx: ctx, labels: labels, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight} = options, updateLabels = scaleOffset => {
6474
- scaleOffset && (canvas.width = canvasWidth, ctx.save(), ctx.translate(scaleOffset.x, scaleOffset.y),
6475
- ctx.scale(scaleOffset.scale, scaleOffset.scale)), ctx.clearRect(0, 0, canvasWidth, canvasHeight),
6605
+ const {canvas: canvas, ctx: ctx, labels: labels, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight, scaleOffset: scaleOffset} = options, updateLabels = () => {
6606
+ canvas.width = canvasWidth, scaleOffset.value && (ctx.save(), ctx.translate(scaleOffset.value.x, scaleOffset.value.y),
6607
+ ctx.scale(scaleOffset.value.scale, scaleOffset.value.scale)), ctx.clearRect(0, 0, canvasWidth, canvasHeight),
6476
6608
  ctx.drawImage(image, 0, 0, canvasWidth, canvasHeight);
6609
+ const scale = scaleOffset.value?.scale || 1, fontSize = 14 / scale, fontPadding = 6 / scale, lineWidth = 2 / scale;
6477
6610
  for (let i = 0; i < labels.length; i++) {
6478
6611
  const rect = labels[i], {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight, type: type} = rect, color = colors$1[type % colors$1.length];
6479
- if (ctx.font = "bold 14px serif", ctx.textBaseline = "top", ctx.save(), ctx.strokeStyle = color,
6480
- ctx.strokeRect(startX, startY, rectWidth, rectHeight), isValueExist(rect.typeName) || isValueExist(rect.type)) {
6612
+ if (ctx.font = `bold ${fontSize}px serif`, ctx.textBaseline = "top", ctx.save(),
6613
+ ctx.strokeStyle = color, ctx.lineWidth = lineWidth, ctx.strokeRect(startX, startY, rectWidth, rectHeight),
6614
+ isValueExist(rect.typeName) || isValueExist(rect.type)) {
6481
6615
  const text = rect.typeName || rect.type;
6482
- ctx.fillStyle = color, ctx.fillText(text, startX + 6, startY + 6);
6616
+ ctx.fillStyle = color, ctx.fillText(text, startX + fontPadding, startY + fontPadding);
6483
6617
  }
6484
6618
  ctx.restore();
6485
6619
  }
@@ -6487,8 +6621,10 @@ var DraggableRect = defineComponent({
6487
6621
  return updateLabels(), {
6488
6622
  updateLabels: updateLabels,
6489
6623
  addDrawRect: (rect, color = "#f30635") => {
6490
- const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect;
6491
- ctx.save(), ctx.strokeStyle = color, ctx.strokeRect(startX, startY, rectWidth, rectHeight),
6624
+ const scale = scaleOffset.value?.scale || 1, {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect;
6625
+ ctx.save();
6626
+ const lineWidth = 2 / scale;
6627
+ ctx.lineWidth = lineWidth, ctx.strokeStyle = color, ctx.strokeRect(startX, startY, rectWidth, rectHeight),
6492
6628
  ctx.restore();
6493
6629
  },
6494
6630
  hitCanvasLabel: (x, y) => {
@@ -6512,7 +6648,8 @@ var DraggableRect = defineComponent({
6512
6648
  canvasWidth: canvasWidth,
6513
6649
  canvasHeight: canvasHeight,
6514
6650
  labels: labels.value,
6515
- scaleFactor: scaleFactor
6651
+ scaleFactor: scaleFactor,
6652
+ scaleOffset: scaleTranslateManager.scaleTranslate
6516
6653
  });
6517
6654
  drawBaseCanvas.value.updateLabels = updateLabels, drawBaseCanvas.value.addDrawRect = addDrawRect,
6518
6655
  drawBaseCanvas.value.hitCanvasLabel = hitCanvasLabel;
@@ -6579,30 +6716,45 @@ var DraggableRect = defineComponent({
6579
6716
  originWidth: originWidth,
6580
6717
  originHeight: originHeight
6581
6718
  }, ((rect, {endX: endX, endY: endY}) => {
6582
- activate_add_label.value = rect, drawBaseCanvas.value.addDrawRect(rect), updateContextmenuLabelFixed(endX, endY, rect);
6719
+ activate_add_label.value = rect;
6720
+ const newRect = ((rect, scaleOffset) => {
6721
+ const {startX: startX, startY: startY, rectWidth: rectWidth, rectHeight: rectHeight} = rect, {scale: scale, x: x, y: y} = scaleOffset;
6722
+ return {
6723
+ startX: Math.ceil((startX - x) / scale),
6724
+ startY: Math.ceil((startY - y) / scale),
6725
+ rectWidth: Math.ceil(rectWidth / scale),
6726
+ rectHeight: Math.ceil(rectHeight / scale),
6727
+ canvasWidth: rect.canvasWidth,
6728
+ canvasHeight: rect.canvasHeight,
6729
+ originWidth: rect.originWidth,
6730
+ originHeight: rect.originHeight
6731
+ };
6732
+ })(rect, scaleTranslateManager.scaleTranslate.value);
6733
+ drawBaseCanvas.value.addDrawRect(newRect), updateContextmenuLabelFixed(endX, endY, newRect);
6583
6734
  }), (() => {
6584
6735
  onCloseDraggableRectFixed();
6585
6736
  }));
6586
- drawBaseCanvas.value.clearCanvasRect = clearCanvas, drawBaseCanvas.value.removeEventAll = removeEventAll;
6737
+ drawBaseCanvas.value.clearCanvasRect = clearCanvas, drawBaseCanvas.value.removeEventAll = removeEventAll,
6738
+ canvasDragZoom.value = new CanvasSceneDragZoom(canvasBaseRef.value), canvasDragZoom.value.changeZoom((scaleOffset => {
6739
+ scaleTranslateManager.onChangeScaleTranslate(scaleOffset), drawBaseCanvas.value.updateLabels();
6740
+ }));
6587
6741
  }, image.onerror = () => {
6588
6742
  loadingImage.value = !1;
6589
6743
  };
6590
6744
  }
6591
6745
  canvasBaseRef.value.addEventListener("contextmenu", (e => {
6592
6746
  e.preventDefault();
6593
- const x = e.offsetX, y = e.offsetY, {hit_rect: hit_rect} = drawBaseCanvas.value.hitCanvasLabel(x, y);
6747
+ const offsetX = e.offsetX, offsetY = e.offsetY, {scale: scale, x: x, y: y} = scaleTranslateManager.scaleTranslate.value, new_x = Math.floor((offsetX - x) / scale), new_y = Math.floor((offsetY - y) / scale), {hit_rect: hit_rect} = drawBaseCanvas.value.hitCanvasLabel(new_x, new_y);
6594
6748
  onCloseContentmenuLabel(), onCloseDraggableRectFixed(), hit_rect && nextTick((() => {
6595
- updateContextmenuLabelFixed(x, y, hit_rect);
6749
+ updateContextmenuLabelFixed(offsetX, offsetY, hit_rect);
6596
6750
  }));
6597
6751
  })), canvasBaseRef.value.addEventListener("click", (e => {
6598
6752
  if (e.ctrlKey) return;
6599
- const x = e.offsetX, y = e.offsetY, {hit_rect: hit_rect, hit_index: hit_index, color: color} = drawBaseCanvas.value.hitCanvasLabel(x, y);
6753
+ 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);
6600
6754
  onCloseDraggableRectFixed(), onCloseContentmenuLabel(), hit_rect && nextTick((() => {
6601
- updateDraggableRectFixed(x, y, hit_rect, hit_index, color);
6755
+ updateDraggableRectFixed(offsetX, offsetY, hit_rect, hit_index, color);
6602
6756
  }));
6603
6757
  }));
6604
- }, onWindowWheel = e => {
6605
- e.ctrlKey && e.preventDefault();
6606
6758
  };
6607
6759
  onMounted((() => {
6608
6760
  watch((() => props.rowInfo), (info => {
@@ -6620,11 +6772,9 @@ var DraggableRect = defineComponent({
6620
6772
  const rowInfo = toRaw(props.rowInfo);
6621
6773
  renderImageLabel(rowInfo);
6622
6774
  }
6623
- })), window.addEventListener("wheel", onWindowWheel, {
6624
- passive: !1
6625
- });
6775
+ }));
6626
6776
  })), onUnmounted((() => {
6627
- drawBaseCanvas.value.removeEventAll?.(), window.removeEventListener("wheel", onWindowWheel);
6777
+ drawBaseCanvas.value.removeEventAll?.(), canvasDragZoom.value.destroy();
6628
6778
  }));
6629
6779
  const contextmenuLabelFixed = ref({
6630
6780
  show: !1,
@@ -6711,6 +6861,9 @@ var DraggableRect = defineComponent({
6711
6861
  const rowInfo = toRaw(props.rowInfo);
6712
6862
  renderImageLabel(rowInfo);
6713
6863
  }));
6864
+ },
6865
+ resetScaleOffset: () => {
6866
+ canvasDragZoom.value.reset();
6714
6867
  }
6715
6868
  });
6716
6869
  return () => createVNode(Fragment, null, [ createVNode(NextSpinLoading, {
@@ -6912,7 +7065,11 @@ var Element$1 = defineComponent({
6912
7065
  label_txt: label_txt
6913
7066
  }, (imageItem => {
6914
7067
  labelImages.value[activateNodeIndex.value] = imageItem || node, activateNodeIndex.value = index,
6915
- loading.value = !1;
7068
+ loading.value = !1, scaleTranslate.value = {
7069
+ scale: 1,
7070
+ x: 0,
7071
+ y: 0
7072
+ };
6916
7073
  }), (() => {
6917
7074
  loading.value = !1;
6918
7075
  })), !0);
@@ -6945,8 +7102,20 @@ var Element$1 = defineComponent({
6945
7102
  isFullscreen.value = val, updateMainContentHeight(), nextTick((() => {
6946
7103
  canvasContextRef.value.rerenderImage();
6947
7104
  }));
6948
- };
6949
- expose({
7105
+ }, scaleTranslate = ref({
7106
+ scale: 1,
7107
+ x: 0,
7108
+ y: 0
7109
+ });
7110
+ provide("scaleTranslateManager", {
7111
+ scaleTranslate: scaleTranslate,
7112
+ onChangeScaleTranslate: val => {
7113
+ scaleTranslate.value = val;
7114
+ },
7115
+ onResetScaleTranslate: () => {
7116
+ canvasContextRef.value.resetScaleOffset();
7117
+ }
7118
+ }), expose({
6950
7119
  convertToLabel: convertToLabel,
6951
7120
  canvertToCanvas: canvertToCanvas
6952
7121
  });
@@ -7115,7 +7284,10 @@ var preview = defineComponent({
7115
7284
  }
7116
7285
  });
7117
7286
 
7118
- 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" ];
7287
+ 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) => {
7288
+ const [x, y] = vertex;
7289
+ return isMultiply ? [ x * scaleX, y * scaleY ] : [ x / scaleX, y / scaleY ];
7290
+ })(item, scaleX, scaleY, isMultiply))) : [], {hexToRgba: hexToRgba} = useChangeColor(), colors = [ "#91cc75", "#fac858", "#ee6666", "#73c0de", "#3ba272", "#fc8452", "#9a60b4", "#ea7ccc" ];
7119
7291
 
7120
7292
  class CreatePolygonVertexes {
7121
7293
  canvas;
@@ -7172,9 +7344,9 @@ class CreatePolygonVertexes {
7172
7344
  canvasMouseDblclick(e) {
7173
7345
  e.stopPropagation(), this.isDrawing && (this.canvas.style.cursor = "unset", this.mouseOffset.x = e.offsetX,
7174
7346
  this.mouseOffset.y = e.offsetY, this.vertexes.push([ e.offsetX, e.offsetY ]), this.vertexes = vertexesUnique(this.vertexes)),
7175
- this.notifyDestryedListerers(), this.destroyed();
7347
+ this.notifyDestryedListerers(), this.destroy();
7176
7348
  }
7177
- destroyed() {
7349
+ destroy() {
7178
7350
  this.isDrawing = !1, this.vertexes = [], this.vertexesObservers = [], this.destroyedObservers = () => {
7179
7351
  this.canvas.removeEventListener("click", this.canvasMouseClick);
7180
7352
  }, this.canvas.removeEventListener("mousemove", this.canvasMousemove), this.canvas.removeEventListener("dblclick", this.canvasMouseDblclick);
@@ -7194,11 +7366,18 @@ class EditPolygonPath {
7194
7366
  edgeCentreRadius;
7195
7367
  pointRecover;
7196
7368
  observers=[];
7369
+ editPolygonObserver;
7197
7370
  constructor(canvas, ctx) {
7198
7371
  this.canvas = canvas, this.ctx = ctx, this.vertexes = [], this.isEditing = !1, this.canClickEvent = !0,
7199
7372
  this.isMoveEditing = !1, this.pointVertexIndex = -1, this.pointCentreIndex = -1,
7200
7373
  this.vertexRadius = 8, this.edgeCentreRadius = 5, this.pointRecover = [];
7201
7374
  }
7375
+ notifyEditPolygonObserver() {
7376
+ this.editPolygonObserver?.(this.vertexes);
7377
+ }
7378
+ onEditPolygon(callback) {
7379
+ this.editPolygonObserver = callback;
7380
+ }
7202
7381
  drawPolygonPath(vertexes, mouseX, mouseY) {
7203
7382
  const ctx = this.ctx;
7204
7383
  if (!vertexes.length) return;
@@ -7303,7 +7482,7 @@ class EditPolygonPath {
7303
7482
  this.pointVertexIndex > -1 && this.vertexes.splice(this.pointVertexIndex, 1, [ x, y ]),
7304
7483
  this.pointCentreIndex > -1 && this.vertexes.splice(this.pointCentreIndex, 1, [ x, y ]),
7305
7484
  this.isMoveEditing = !1, this.pointVertexIndex = -1, this.pointCentreIndex = -1,
7306
- this.drawPolygon(this.vertexes), this.notifyObservers();
7485
+ this.drawPolygon(this.vertexes), this.notifyObservers(), this.notifyEditPolygonObserver();
7307
7486
  }
7308
7487
  canvasMouseClick(e) {
7309
7488
  e.stopPropagation();
@@ -7312,7 +7491,8 @@ class EditPolygonPath {
7312
7491
  const i = this.pointInVertexes(x, y);
7313
7492
  if (isValueExist(i)) {
7314
7493
  if (this.vertexes.length <= 3) return;
7315
- this.vertexes.splice(i, 1), this.drawPolygon(this.vertexes), this.notifyObservers();
7494
+ this.vertexes.splice(i, 1), this.drawPolygon(this.vertexes), this.notifyObservers(),
7495
+ this.notifyEditPolygonObserver();
7316
7496
  }
7317
7497
  }
7318
7498
  }
@@ -7323,7 +7503,7 @@ class EditPolygonPath {
7323
7503
  this.pointCentreIndex > -1 && this.vertexes.splice(this.pointCentreIndex, 1, [ x, y ]),
7324
7504
  this.notifyObservers());
7325
7505
  }
7326
- destroyed() {
7506
+ destroy() {
7327
7507
  this.vertexes = [], this.observers = [], this.isEditing = !1, this.canvas.removeEventListener("mousedown", this.canvasMousedown),
7328
7508
  this.canvas.removeEventListener("mouseup", this.canvasMouseup), this.canvas.removeEventListener("click", this.canvasMouseClick),
7329
7509
  this.canvas.removeEventListener("mousemove", this.canvasMousemove);
@@ -7336,26 +7516,32 @@ class CreateDrawCanvas {
7336
7516
  image;
7337
7517
  canvasWidth;
7338
7518
  canvasHeight;
7339
- paths;
7519
+ scaleOffset;
7520
+ labels;
7340
7521
  scaleX;
7341
7522
  scaleY;
7342
7523
  editDrawPolygon;
7343
7524
  createPolygonVertexes;
7344
7525
  editVertexes;
7345
7526
  editPolygonObservers=[];
7527
+ drawnPolygonObserver;
7346
7528
  constructor(options) {
7347
- const {canvas: canvas, ctx: ctx, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight, paths: paths, scaleX: scaleX, scaleY: scaleY} = options;
7529
+ const {canvas: canvas, ctx: ctx, image: image, canvasWidth: canvasWidth, canvasHeight: canvasHeight, labels: labels, scaleX: scaleX, scaleY: scaleY, scaleOffset: scaleOffset} = options;
7348
7530
  this.canvas = canvas, this.ctx = ctx, this.image = image, this.canvasWidth = canvasWidth,
7349
- this.canvasHeight = canvasHeight, this.paths = paths || [], this.scaleX = scaleX || 1,
7350
- this.scaleY = scaleY || 1, this.editVertexes = [], this.render(), this.createPolygonVertexes = new CreatePolygonVertexes(canvas, ctx),
7351
- this.editDrawPolygon = new EditPolygonPath(canvas, ctx), this.createPolygonVertexes.vertexesChangeEventListener(((vertexes, mouseOffset) => {
7531
+ this.canvasHeight = canvasHeight, this.scaleOffset = scaleOffset, this.labels = labels || {},
7532
+ this.scaleX = scaleX || 1, this.scaleY = scaleY || 1, this.editVertexes = [], this.render(),
7533
+ this.createPolygonVertexes = new CreatePolygonVertexes(canvas, ctx), this.editDrawPolygon = new EditPolygonPath(canvas, ctx),
7534
+ this.createPolygonVertexes.vertexesChangeEventListener(((vertexes, mouseOffset) => {
7352
7535
  this.render(), this.editDrawPolygon.drawPolygon(vertexes, mouseOffset), this.editVertexes = vertexes,
7353
7536
  this.notifyObservers();
7354
7537
  })), this.createPolygonVertexes.onDestroyed((vertexes => {
7355
- this.render(), this.editDrawPolygon.drawPolygon(vertexes), this.editDrawPolygon.updatePolygon((vertexes => {
7538
+ this.editVertexes = vertexes, this.render(), this.editDrawPolygon.drawPolygon(vertexes),
7539
+ this.editDrawPolygon.updatePolygon((vertexes => {
7356
7540
  this.render(), this.editDrawPolygon.drawPolygon(vertexes), this.editVertexes = vertexes,
7357
7541
  this.notifyObservers();
7358
- }));
7542
+ })), this.editDrawPolygon.onEditPolygon((vertexes => {
7543
+ this.editVertexes = vertexes, this.notifyDrawnPolygonObservers();
7544
+ })), this.notifyDrawnPolygonObservers();
7359
7545
  }));
7360
7546
  }
7361
7547
  notifyObservers() {
@@ -7363,17 +7549,22 @@ class CreateDrawCanvas {
7363
7549
  listener(this.editVertexes);
7364
7550
  }));
7365
7551
  }
7552
+ notifyDrawnPolygonObservers() {
7553
+ this.drawnPolygonObserver?.(this.editVertexes);
7554
+ }
7366
7555
  updatePolygon(callback) {
7367
7556
  this.editPolygonObservers.push(callback);
7368
7557
  }
7369
- drawPolygons(paths) {
7370
- const ctx = this.ctx;
7371
- ctx.scale(this.scaleX, this.scaleY);
7372
- for (let i = 0; i < paths.length; i++) {
7373
- const path = paths[i].path;
7558
+ onDrawnPolygon(callback) {
7559
+ this.drawnPolygonObserver = callback;
7560
+ }
7561
+ drawPolygons(shapes) {
7562
+ const ctx = this.ctx, {scale: scale} = this.scaleOffset.value, scaleX = this.scaleX, scaleY = this.scaleY;
7563
+ for (let i = 0; i < shapes.length; i++) {
7564
+ const item = shapes[i], path = vertexesToScale(item.points, scaleX, scaleY);
7374
7565
  if (!path.length) return;
7375
7566
  const color = colors[i % colors.length];
7376
- ctx.beginPath(), ctx.lineWidth = 2, ctx.strokeStyle = color, ctx.fillStyle = hexToRgba(color, .2);
7567
+ ctx.beginPath(), ctx.lineWidth = 2 / scale, ctx.strokeStyle = color, ctx.fillStyle = hexToRgba(color, .2);
7377
7568
  const startX = path[0][0], startY = path[0][1];
7378
7569
  ctx.moveTo(startX, startY);
7379
7570
  for (let i = 1; i < path.length; i++) {
@@ -7383,15 +7574,18 @@ class CreateDrawCanvas {
7383
7574
  ctx.closePath(), ctx.stroke(), ctx.fill();
7384
7575
  }
7385
7576
  }
7386
- initCanvas=() => {
7577
+ drawCanvas=() => {
7387
7578
  this.ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight), this.ctx.drawImage(this.image, 0, 0, this.canvasWidth, this.canvasHeight),
7388
- this.ctx.save(), this.drawPolygons(this.paths), this.ctx.restore();
7579
+ this.ctx.save();
7580
+ const shapes = this.labels.shapes;
7581
+ this.drawPolygons(shapes), this.ctx.restore();
7389
7582
  };
7390
7583
  render=() => {
7391
- this.initCanvas();
7584
+ this.canvas.width = this.canvasWidth, this.scaleOffset.value && (this.ctx.translate(this.scaleOffset.value.x, this.scaleOffset.value.y),
7585
+ this.ctx.scale(this.scaleOffset.value.scale, this.scaleOffset.value.scale)), this.drawCanvas();
7392
7586
  };
7393
- destroyed() {
7394
- this.paths = [], this.editDrawPolygon.destroyed(), this.createPolygonVertexes.destroyed();
7587
+ destroy() {
7588
+ this.labels = {}, this.editDrawPolygon.destroy(), this.createPolygonVertexes.destroy();
7395
7589
  }
7396
7590
  }
7397
7591
 
@@ -7410,9 +7604,9 @@ var CanvasContext = defineComponent({
7410
7604
  default: () => ({})
7411
7605
  }
7412
7606
  },
7413
- emits: [ "editPolygon" ],
7607
+ emits: [ "editPolygon", "changePolygon" ],
7414
7608
  setup(props, {emit: emit, expose: expose}) {
7415
- const ns = inject("ns", {}), mainBasaeRef = ref(), canvasMainRef = ref(), canvasBaseRef = ref(), drawCanvas = ref(), setContainerWidthHeight = (canvasWidth, canvasHeight) => {
7609
+ const ns = inject("ns", {}), scaleTranslateManager = inject("scaleTranslateManager", {}), mainBasaeRef = ref(), canvasMainRef = ref(), canvasBaseRef = ref(), drawCanvas = ref(), canvasDragZoom = ref(), setContainerWidthHeight = (canvasWidth, canvasHeight) => {
7416
7610
  canvasMainRef.value.style.width = canvasWidth + "px", canvasMainRef.value.style.height = canvasHeight + "px",
7417
7611
  canvasBaseRef.value.width = canvasWidth, canvasBaseRef.value.height = canvasHeight,
7418
7612
  canvasBaseRef.value.style.width = canvasWidth + "px", canvasBaseRef.value.style.height = canvasHeight + "px";
@@ -7422,7 +7616,7 @@ var CanvasContext = defineComponent({
7422
7616
  const image = new Image;
7423
7617
  image.src = rowInfo.imageSrc, loadingImage.value = !0, image.onload = () => {
7424
7618
  loadingImage.value = !1;
7425
- const {canvasWidth: canvasWidth, canvasHeight: canvasHeight, scaleFactor: scaleFactor, scaleX: scaleX, scaleY: scaleY} = (image => {
7619
+ const {canvasWidth: canvasWidth, canvasHeight: canvasHeight, scaleFactor: scaleFactor, scaleX: scaleX, scaleY: scaleY, originWidth: originWidth, originHeight: originHeight} = (image => {
7426
7620
  const clientWidth = mainBasaeRef.value?.elementInstance.clientWidth, clientHeight = mainBasaeRef.value?.elementInstance.clientHeight;
7427
7621
  let {width: width, height: height} = image, scaleFactor = 1;
7428
7622
  const aspect_ratio = width / height;
@@ -7442,7 +7636,9 @@ var CanvasContext = defineComponent({
7442
7636
  canvasHeight: canvasHeight,
7443
7637
  scaleFactor: scaleFactor,
7444
7638
  scaleX: Number(scaleX),
7445
- scaleY: Number(scaleY)
7639
+ scaleY: Number(scaleY),
7640
+ originWidth: image.width,
7641
+ originHeight: image.height
7446
7642
  };
7447
7643
  })(image);
7448
7644
  image.style.width = canvasWidth + "px", image.style.height = canvasHeight + "px",
@@ -7453,15 +7649,25 @@ var CanvasContext = defineComponent({
7453
7649
  canvasWidth: canvasWidth,
7454
7650
  canvasHeight: canvasHeight,
7455
7651
  scaleFactor: scaleFactor,
7456
- paths: rowInfo.labels,
7652
+ labels: rowInfo.labels,
7457
7653
  scaleX: scaleX,
7458
- scaleY: scaleY
7654
+ scaleY: scaleY,
7655
+ scaleOffset: scaleTranslateManager.scaleTranslate
7459
7656
  }), drawCanvas.value.updatePolygon((vertexes => {
7460
- emit("editPolygon", {
7657
+ emit("changePolygon", {
7461
7658
  vertexes: vertexes,
7462
7659
  canvasWidth: canvasWidth,
7463
7660
  canvasHeight: canvasHeight
7464
7661
  });
7662
+ })), drawCanvas.value.onDrawnPolygon((vertexes => {
7663
+ const new_vertexes = vertexesToScale(vertexes, scaleX, scaleY, !1);
7664
+ emit("editPolygon", {
7665
+ vertexes: new_vertexes,
7666
+ originWidth: originWidth,
7667
+ originHeight: originHeight
7668
+ });
7669
+ })), canvasDragZoom.value = new CanvasSceneDragZoom(canvasBaseRef.value), canvasDragZoom.value.changeZoom((scaleOffset => {
7670
+ scaleTranslateManager.onChangeScaleTranslate(scaleOffset), drawCanvas.value.render();
7465
7671
  }));
7466
7672
  }, image.onerror = () => {
7467
7673
  loadingImage.value = !1;
@@ -7482,6 +7688,8 @@ var CanvasContext = defineComponent({
7482
7688
  renderImageLabel(rowInfo);
7483
7689
  }
7484
7690
  }));
7691
+ })), onUnmounted((() => {
7692
+ drawCanvas.value.destroy(), canvasDragZoom.value.destroy();
7485
7693
  }));
7486
7694
  return expose({
7487
7695
  rerenderImage: () => {
@@ -7489,6 +7697,9 @@ var CanvasContext = defineComponent({
7489
7697
  const rowInfo = toRaw(props.rowInfo);
7490
7698
  renderImageLabel(rowInfo);
7491
7699
  }));
7700
+ },
7701
+ resetScaleOffset: () => {
7702
+ canvasDragZoom.value.reset();
7492
7703
  }
7493
7704
  }), () => createVNode(Fragment, null, [ createVNode(NextSpinLoading, {
7494
7705
  ref: mainBasaeRef,
@@ -7524,7 +7735,7 @@ var CanvasContext = defineComponent({
7524
7735
  },
7525
7736
  emits: [ "fullscreen", "save" ],
7526
7737
  setup(props, {emit: emit}) {
7527
- const _ns = inject("ns", {}), {t: t} = useLocale(), switchFillscreen = val => {
7738
+ const _ns = inject("ns", {}), scaleTranslateManager = inject("scaleTranslateManager", {}), scaleTranslate = scaleTranslateManager.scaleTranslate, {t: t} = useLocale(), switchFillscreen = val => {
7528
7739
  emit("fullscreen", val), document.body.style.overflow = val ? "hidden" : "auto";
7529
7740
  };
7530
7741
  return () => createVNode(Fragment, null, [ createVNode(Fragment, null, [ createVNode("ul", {
@@ -7605,7 +7816,28 @@ var CanvasContext = defineComponent({
7605
7816
  class: "label-text"
7606
7817
  }, [ t("next.labelme.deletePolyton") ]) ]) ]), createVNode("ul", {
7607
7818
  class: [ _ns.be("header", "tool") ]
7608
- }, [ props.imageLength ? createVNode("li", null, [ createVNode("span", null, [ createTextVNode("第 "), props.imageIndex + 1, createTextVNode(" 张") ]), createVNode("em", {
7819
+ }, [ createVNode("li", {
7820
+ class: "hover",
7821
+ onClick: () => scaleTranslateManager.onResetScaleTranslate()
7822
+ }, [ createVNode("svg", {
7823
+ t: "1725840994827",
7824
+ class: "icon",
7825
+ viewBox: "0 0 1024 1024",
7826
+ version: "1.1",
7827
+ xmlns: "http://www.w3.org/2000/svg",
7828
+ "p-id": "6051",
7829
+ width: "18",
7830
+ height: "18"
7831
+ }, [ createVNode("path", {
7832
+ 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",
7833
+ "p-id": "6052"
7834
+ }, null) ]), createVNode("span", {
7835
+ style: "padding-left: 3px"
7836
+ }, [ t("next.labelimg.zoomRestore") ]) ]), createVNode("li", null, [ createVNode("span", null, [ createTextVNode("缩放比例") ]), createVNode("span", null, [ parseInt((100 * scaleTranslate.value.scale).toString()), createTextVNode("%") ]), createVNode("span", {
7837
+ style: "padding: 0 10px;"
7838
+ }, [ createTextVNode("偏移量") ]), createVNode("span", {
7839
+ style: "min-width: 120px; text-align: left;"
7840
+ }, [ createTextVNode("X: "), scaleTranslate.value.x, createTextVNode(", Y: "), scaleTranslate.value.y ]) ]), props.imageLength ? createVNode("li", null, [ createVNode("span", null, [ createTextVNode("第 "), props.imageIndex + 1, createTextVNode(" 张") ]), createVNode("em", {
7609
7841
  style: "padding: 0 5px;"
7610
7842
  }, [ createTextVNode("/") ]), createVNode("span", null, [ createTextVNode("共 "), props.imageLength, createTextVNode(" 张") ]) ]) : null, createVNode("li", {
7611
7843
  style: "margin-right: 30px;",
@@ -7699,7 +7931,7 @@ var Element = defineComponent({
7699
7931
  default: () => []
7700
7932
  }
7701
7933
  },
7702
- emits: [ "change", "save", "edit-polygon", "prev-click", "next-click" ],
7934
+ emits: [ "change", "save", "edit-polygon", "change-polygon", "prev-click", "next-click" ],
7703
7935
  setup(props, {emit: emit, slots: slots}) {
7704
7936
  const _config = deepClone(defaultConfig), _options = computed((() => {
7705
7937
  const cfg = unref(props.options);
@@ -7759,14 +7991,29 @@ var Element = defineComponent({
7759
7991
  isFullscreen.value = val, updateMainContentHeight(), nextTick((() => {
7760
7992
  canvasContextRef.value.rerenderImage();
7761
7993
  }));
7762
- }, onEditPlygonChange = plygon => {
7763
- currentNode.value.labels = plygon, emit("edit-polygon", plygon);
7994
+ }, onChangePolygon = node => {
7995
+ currentNode.value.labels = node, emit("change-polygon", node);
7996
+ }, onEditPlygon = node => {
7997
+ currentNode.value.labels = node, emit("edit-polygon", node);
7764
7998
  }, onToolHeaderSave = () => {
7765
7999
  onChangeActivateNode(activateNodeIndex.value) || ElMessage({
7766
8000
  type: "info",
7767
8001
  message: t("next.labelimg.labelNoUpdate")
7768
8002
  });
7769
- };
8003
+ }, scaleTranslate = ref({
8004
+ scale: 1,
8005
+ x: 0,
8006
+ y: 0
8007
+ });
8008
+ provide("scaleTranslateManager", {
8009
+ scaleTranslate: scaleTranslate,
8010
+ onChangeScaleTranslate: val => {
8011
+ scaleTranslate.value = val;
8012
+ },
8013
+ onResetScaleTranslate: () => {
8014
+ canvasContextRef.value.resetScaleOffset();
8015
+ }
8016
+ });
7770
8017
  return () => createVNode(Fragment, null, [ createVNode("div", {
7771
8018
  ref: layoutLabelRef,
7772
8019
  class: [ ns.b(), props.className, isFullscreen.value ? ns.b("fullscreen") : "" ],
@@ -7799,7 +8046,8 @@ var Element = defineComponent({
7799
8046
  }, [ createVNode(CanvasContext, {
7800
8047
  ref: canvasContextRef,
7801
8048
  rowInfo: currentNode.value,
7802
- onEditPolygon: onEditPlygonChange
8049
+ onEditPolygon: onEditPlygon,
8050
+ onChangePolygon: onChangePolygon
7803
8051
  }, null) ]) ]), createVNode("footer", {
7804
8052
  ref: footerRef,
7805
8053
  class: [ ns.b("footer") ]
@@ -7899,7 +8147,7 @@ const zoomDialog = app => {
7899
8147
  }));
7900
8148
  }
7901
8149
  });
7902
- }, version = "0.3.6", install = function(app) {
8150
+ }, version = "0.3.8", install = function(app) {
7903
8151
  Object.keys(components).forEach((key => {
7904
8152
  const component = components[key];
7905
8153
  app.component(component.name, component);
@@ -7909,7 +8157,7 @@ const zoomDialog = app => {
7909
8157
  };
7910
8158
 
7911
8159
  var index = {
7912
- version: "0.3.6",
8160
+ version: "0.3.8",
7913
8161
  install: install
7914
8162
  };
7915
8163