@labelbee/lb-annotation 1.8.0 → 1.9.0-alpha.2

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.
Files changed (96) hide show
  1. package/README.md +65 -0
  2. package/dist/index.js +20 -9
  3. package/dist/types/constant/tool.d.ts +3 -1
  4. package/dist/types/core/index.d.ts +24 -4
  5. package/dist/types/core/pointCloud/OrbitControls.d.ts +60 -0
  6. package/dist/types/core/pointCloud/PCDLoader.d.ts +11 -0
  7. package/dist/types/core/pointCloud/annotation.d.ts +47 -0
  8. package/dist/types/core/pointCloud/cache.d.ts +16 -0
  9. package/dist/types/core/pointCloud/index.d.ts +325 -0
  10. package/dist/types/core/scheduler.d.ts +71 -0
  11. package/dist/types/core/toolOperation/basicToolOperation.d.ts +20 -2
  12. package/dist/types/core/toolOperation/eventListener.d.ts +2 -2
  13. package/dist/types/core/toolOperation/pointCloud2dOperation.d.ts +80 -0
  14. package/dist/types/core/toolOperation/polygonOperation.d.ts +21 -7
  15. package/dist/types/core/toolOperation/segmentByRect.d.ts +31 -0
  16. package/dist/types/index.d.ts +9 -3
  17. package/dist/types/newCore/CanvasScheduler.d.ts +31 -0
  18. package/dist/types/newCore/index.d.ts +1 -0
  19. package/dist/types/utils/MathUtils.d.ts +6 -0
  20. package/dist/types/utils/tool/CommonToolUtils.d.ts +0 -13
  21. package/dist/types/utils/tool/EnhanceCommonToolUtils.d.ts +20 -0
  22. package/dist/types/utils/tool/PolygonUtils.d.ts +1 -0
  23. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -0
  24. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -0
  25. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -0
  26. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -0
  27. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -0
  28. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -0
  29. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -0
  30. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -0
  31. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -0
  32. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -0
  33. package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -0
  34. package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -0
  35. package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -0
  36. package/es/assets/attributeIcon/icon_editLV.svg.js +3 -0
  37. package/es/assets/attributeIcon/icon_editQING.svg.js +3 -0
  38. package/es/constant/annotation.js +68 -0
  39. package/es/constant/annotationTask.js +25 -0
  40. package/es/constant/defaultConfig.js +260 -0
  41. package/es/constant/keyCode.js +36 -0
  42. package/es/constant/style.js +67 -0
  43. package/es/constant/tool.js +183 -0
  44. package/es/core/index.js +145 -0
  45. package/es/core/pointCloud/OrbitControls.js +661 -0
  46. package/es/core/pointCloud/PCDLoader.js +238 -0
  47. package/es/core/pointCloud/annotation.js +98 -0
  48. package/es/core/pointCloud/cache.js +42 -0
  49. package/es/core/pointCloud/index.js +771 -0
  50. package/es/core/scheduler.js +184 -0
  51. package/es/core/toolOperation/LineToolOperation.js +1369 -0
  52. package/es/core/toolOperation/TextToolOperation.js +129 -0
  53. package/es/core/toolOperation/ViewOperation.js +410 -0
  54. package/es/core/toolOperation/basicToolOperation.js +817 -0
  55. package/es/core/toolOperation/checkOperation.js +206 -0
  56. package/es/core/toolOperation/eventListener.js +35 -0
  57. package/es/core/toolOperation/measureOperation.js +39 -0
  58. package/es/core/toolOperation/pointCloud2dOperation.js +197 -0
  59. package/es/core/toolOperation/pointOperation.js +603 -0
  60. package/es/core/toolOperation/polygonOperation.js +1201 -0
  61. package/es/core/toolOperation/rectOperation.js +1170 -0
  62. package/es/core/toolOperation/segmentByRect.js +172 -0
  63. package/es/core/toolOperation/tagOperation.js +215 -0
  64. package/es/core/toolOperation/textAttributeClass.js +201 -0
  65. package/es/index.js +25 -14
  66. package/es/locales/constants.js +21 -0
  67. package/es/locales/en_US/message.js +22 -0
  68. package/es/locales/index.js +17 -0
  69. package/es/locales/zh_CN/message.js +22 -0
  70. package/es/newCore/CanvasScheduler.js +31 -0
  71. package/es/utils/ActionsHistory.js +78 -0
  72. package/es/utils/ImgUtils.js +20 -0
  73. package/es/utils/MathUtils.js +283 -0
  74. package/es/utils/VectorUtils.js +23 -0
  75. package/es/utils/tool/AttributeUtils.js +196 -0
  76. package/es/utils/tool/AxisUtils.js +254 -0
  77. package/es/utils/tool/CanvasUtils.js +60 -0
  78. package/es/utils/tool/CommonToolUtils.js +172 -0
  79. package/es/utils/tool/CurrentOperation.js +35 -0
  80. package/es/utils/tool/DblClickEventListener.js +100 -0
  81. package/es/utils/tool/DrawUtils.js +424 -0
  82. package/es/utils/tool/EnhanceCommonToolUtils.js +39 -0
  83. package/es/utils/tool/ImgPosUtils.js +56 -0
  84. package/es/utils/tool/LineToolUtils.js +255 -0
  85. package/es/utils/tool/MarkerUtils.js +9 -0
  86. package/es/utils/tool/PolygonUtils.js +458 -0
  87. package/es/utils/tool/RectUtils.js +153 -0
  88. package/es/utils/tool/RenderDomClass.js +68 -0
  89. package/es/utils/tool/RenderDomUtils.js +29 -0
  90. package/es/utils/tool/StyleUtils.js +29 -0
  91. package/es/utils/tool/TagUtils.js +127 -0
  92. package/es/utils/tool/UnitUtils.js +10 -0
  93. package/es/utils/tool/ZoomUtils.js +70 -0
  94. package/es/utils/tool/polygonTool.js +126 -0
  95. package/es/utils/uuid.js +24 -0
  96. package/package.json +6 -4
package/es/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * sense-annotation v1.8.0
2
+ * sense-annotation v1.9.0-alpha.2
3
3
  * (c) 2020-2022
4
4
  * Released under the Apache-2.0 License.
5
- */import{polygon as St,difference as Hi,union as Ni}from"@turf/turf";import F,{isNumber as Wt,cloneDeep as Bi,isObject as Fi}from"lodash";import{i18n as Ct}from"@labelbee/lb-utils";import xe from"color-rgba";const $i=320;var pt;(function(r){r.PointCloud="pointCloudTool"})(pt||(pt={}));var bt;(function(r){r.VideoTextTool="videoTextTool",r.VideoTagTool="videoTagTool",r.VideoClipTool="videoClipTool"})(bt||(bt={}));var Vt;(function(r){r[r.Rect=0]="Rect",r[r.Tag=1]="Tag"})(Vt||(Vt={}));var L;(function(r){r.Rect="rectTool",r.Tag="tagTool",r.Point="pointTool",r.PointMarker="pointMarkerTool",r.Segmentation="segmentationTool",r.Filter="filterTool",r.Text="textTool",r.Polygon="polygonTool",r.Line="lineTool",r.LineMarker="lineMarkerTool",r.Empty="emptyTool",r.FolderTag="folderTagTool",r.RectTrack="rectTrackTool",r.Face="faceTool",r.ClientAttribute="clientAttributeTool",r.OCRRelation="OCRRelationTool"})(L||(L={}));var kt;(function(r){r.Check="check"})(kt||(kt={}));var jt;(function(r){r[r.nothing=0]="nothing",r[r.RectBG=1]="RectBG",r[r.showOrder=2]="showOrder"})(jt||(jt={}));const Zi={[L.Rect]:"\u62C9\u6846",[L.Tag]:"\u6807\u7B7E",[L.Point]:"\u6807\u70B9",[L.PointMarker]:"\u5217\u8868\u6807\u70B9",[L.Segmentation]:"\u524D\u666F\u5206\u5272",[L.Filter]:"\u7B5B\u9009",[L.Text]:"\u6587\u672C",[L.Polygon]:"\u591A\u8FB9\u5F62",[L.Line]:"\u7EBF\u6761",[L.LineMarker]:"\u5217\u8868\u7EBF\u6761",[L.FolderTag]:"\u6587\u4EF6\u5939\u6807\u7B7E",[L.RectTrack]:"\u62C9\u6846\u8DDF\u8E2A",[L.Face]:"\u4EBA\u8138106\u5DE5\u5177",[L.ClientAttribute]:"\u5BA2\u6237\u7AEF\u5C5E\u6027\u5DE5\u5177",[L.OCRRelation]:"OCR\u5173\u8054\u5173\u7CFB\u5DE5\u5177",[bt.VideoTextTool]:"\u89C6\u9891\u6587\u672C",[bt.VideoTagTool]:"\u89C6\u9891\u6807\u7B7E",[bt.VideoClipTool]:"\u89C6\u9891\u622A\u53D6",[pt.PointCloud]:"\u70B9\u4E91"};var Xt;(function(r){r[r.noDepend=1]="noDepend",r[r.dependOrigin=2]="dependOrigin",r[r.dependShape=3]="dependShape",r[r.dependLine=4]="dependLine",r[r.dependPolygon=5]="dependPolygon",r[r.dependPreShape=101]="dependPreShape",r[r.dependPreLine=102]="dependPreLine",r[r.dependPrePolygon=103]="dependPrePolygon"})(Xt||(Xt={}));var gt;(function(r){r.lc="leftClick",r.rc="rightClick",r.clc="ctrlLeftClick",r.crc="ctrlRightClick"})(gt||(gt={}));const Ui={leftClick:"\u9F20\u6807\u5DE6\u952E",rightClick:"\u9F20\u6807\u53F3\u952E",ctrlLeftClick:"ctrl + \u9F20\u6807\u5DE6\u952E",ctrlRightClick:"ctrl + \u9F20\u6807\u53F3\u952E"};var Yt;(function(r){r[r.Normal=1]="Normal",r[r.Modify=2]="Modify"})(Yt||(Yt={}));var T;(function(r){r[r.Line=0]="Line",r[r.Curve=1]="Curve"})(T||(T={}));var Ot;(function(r){r[r.SingleColor=0]="SingleColor",r[r.MultiColor=1]="MultiColor"})(Ot||(Ot={}));var Gt;(function(r){r[r.Form=1]="Form",r[r.Json=2]="Json"})(Gt||(Gt={}));var V;(function(r){r[r.Point=0]="Point",r[r.Line=1]="Line",r[r.Plane=2]="Plane"})(V||(V={}));var Kt;(function(r){r[r.None=0]="None",r[r.Drawing=1]="Drawing",r[r.Edit=2]="Edit"})(Kt||(Kt={}));var Jt;(function(r){r[r.Backward=0]="Backward",r[r.Forward=1]="Forward",r[r.JumpSkip=2]="JumpSkip",r[r.None=3]="None"})(Jt||(Jt={}));var qt;(function(r){r[r.Wait=0]="Wait",r[r.Pass=1]="Pass",r[r.Fail=2]="Fail",r[r.Loading=3]="Loading"})(qt||(qt={}));var X;(function(r){r[r.AnyString=0]="AnyString",r[r.Order=1]="Order",r[r.EnglishOnly=2]="EnglishOnly",r[r.NumberOnly=3]="NumberOnly",r[r.CustomFormat=4]="CustomFormat"})(X||(X={}));const zi={0:"\u4EFB\u610F\u5B57\u7B26",1:"\u5E8F\u53F7",2:"\u4EC5\u82F1\u6587",3:"\u4EC5\u6570\u5B57"},Qt=1e3,me=16,Ie=300,Mt="normal normal 500 14px Arial";var te;(function(r){r[r.ImgList=1e3]="ImgList",r[r.TrackPrediction=1001]="TrackPrediction",r[r.ImgSearch=1002]="ImgSearch"})(te||(te={}));const Wi={[pt.PointCloud]:"sensebeepc",[L.ClientAttribute]:"sensebeepc-EnumAttributeTool",[L.Face]:"sensebeepc-FacePointsLabellingTool",[L.OCRRelation]:"sensebeepc-OCRRelationTool"},Vi={[pt.PointCloud]:"\u70B9\u4E91\u5BA2\u6237\u7AEF",[L.ClientAttribute]:"\u5BA2\u6237\u7AEF\u5C5E\u6027\u5DE5\u5177",[L.Face]:"\u4EBA\u8138106\u70B9\u5DE5\u5177",[L.OCRRelation]:"OCR\u5173\u8054\u5173\u7CFB\u5DE5\u5177"},Y=16,yt=10;var Q;(function(r){r[r.Normal=0]="Normal",r[r.Rect=1]="Rect"})(Q||(Q={}));var ji=Object.freeze({__proto__:null,editStepWidth:$i,get EPointCloudName(){return pt},get EVideoToolName(){return bt},get EToolType(){return Vt},get EToolName(){return L},get ECheckModel(){return kt},get ERectPattern(){return jt},TOOL_NAME:Zi,get EDependPattern(){return Xt},get EFilterToolOperation(){return gt},OPERATION_LIST:Ui,get EAnnotationMode(){return Yt},get ELineTypes(){return T},get ELineColor(){return Ot},get ESelectedType(){return Gt},get EDragTarget(){return V},get EDrawPointPattern(){return Kt},get EPageOperator(){return Jt},get EAuditStatus(){return qt},get ETextType(){return X},TEXT_TYPE:zi,TEXT_ATTRIBUTE_MAX_LENGTH:Qt,TEXT_ATTRIBUTE_LINE_HEIGHT:me,DEFAULT_TEXT_MAX_WIDTH:Ie,DEFAULT_FONT:Mt,get EThumbnailOption(){return te},CLIENT_TOOL_HEAD_TYPE:Wi,CLIENT_TOOL_NAME:Vi,SEGMENT_NUMBER:Y,edgeAdsorptionScope:yt,get EPolygonPattern(){return Q}}),Xi=Object.defineProperty,Yi=Object.defineProperties,Gi=Object.getOwnPropertyDescriptors,we=Object.getOwnPropertySymbols,Ki=Object.prototype.hasOwnProperty,Ji=Object.prototype.propertyIsEnumerable,Le=(r,t,e)=>t in r?Xi(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,qi=(r,t)=>{for(var e in t||(t={}))Ki.call(t,e)&&Le(r,e,t[e]);if(we)for(var e of we(t))Ji.call(t,e)&&Le(r,e,t[e]);return r},Qi=(r,t)=>Yi(r,Gi(t));function ee(r,t,e,i=16){if(r.length<4)return r;const s=[],n=r.slice(0);let o,a,l,h,c,u,d,g,v,f,b,p,y;for(e?(n.unshift(r[r.length-1]),n.unshift(r[r.length-2]),n.unshift(r[r.length-1]),n.unshift(r[r.length-2]),n.push(r[0]),n.push(r[1])):(n.unshift(r[1]),n.unshift(r[0]),n.push(r[r.length-2]),n.push(r[r.length-1])),y=2;y<n.length-4;y+=2)for(l=(n[y+2]-n[y-2])*t,h=(n[y+4]-n[y-0])*t,c=(n[y+3]-n[y-1])*t,u=(n[y+5]-n[y+1])*t,p=0;p<=i;p++)b=p/i,d=2*Math.pow(b,3)-3*Math.pow(b,2)+1,g=-(2*Math.pow(b,3))+3*Math.pow(b,2),v=Math.pow(b,3)-2*Math.pow(b,2)+b,f=Math.pow(b,3)-Math.pow(b,2),o=d*n[y]+g*n[y+2]+v*l+f*h,a=d*n[y+1]+g*n[y+3]+v*c+f*u,s.push(o),s.push(a);const w=[];for(let D=0;D<s.length-1;D+=2)w.push({x:s[D],y:s[D+1]});if(e)for(let D=0;D<i+1;D++){const R=w.shift();w.push(R)}return w}const Et=(r,t=16)=>ee(r.reduce((e,i)=>[...e,i.x,i.y],[]),.5,!1,t);function Pe(r,t,e=T.Line){let i=0,s,n,o,a;t=[...t],e===T.Curve&&(t=ee(t.reduce((h,c)=>[...h,c.x,c.y],[]),.5,!0,Y)),[o]=t;const l=t.length;for(s=1;s<=l;s++)a=t[s%l],r.x>Math.min(o.x,a.x)&&r.x<=Math.max(o.x,a.x)&&r.y<=Math.max(o.y,a.y)&&o.x!==a.x&&(n=(r.x-o.x)*(a.y-o.y)/(a.x-o.x)+o.y,(o.y===a.y||r.y<=n)&&i++),o=a;return i%2!=0}function Ce(r,t=1){return r.map(e=>Qi(qi({},e),{x:e.x*t,y:e.y*t}))}var De=Math.pow;class xt{static add(t,e){return{x:t.x+e.x,y:t.y+e.y}}static getVector(t,e){return{x:e.x-t.x,y:e.y-t.y}}static len(t){return Math.sqrt(De(t.x,2)+De(t.y,2))}static dotProduct(t,e){return t.x*e.x+t.y+e.y}}class _e{static tanAPlusB(t,e){return(t+e)/(1-t*e)}static sinAPlusB(t,e,i,s){return s*t+e*i}static cosAPlusB(t,e,i,s){return e*s-t*i}}const mt=class{static getRotate(r){return r+90>=360?r+90-360:r+90}static getLineLength(r,t){return Math.sqrt(Math.pow(t.y-r.y,2)+Math.pow(t.x-r.x,2))}static getTextArea(r,t,e=Ie,i=Mt,s){if(typeof t!="string")return{width:0,height:0};const n=r.getContext("2d");n.font=i;let o=0;typeof s=="undefined"&&(s=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=r&&parseInt(window.getComputedStyle(r).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,l=t.split(`
6
- `);let h=0;for(let c=0;c<l.length;c++){const u=l[c].split("");let d="";for(let g=0;g<u.length;g++){const v=d+u[g],b=n.measureText(v).width;b>e&&g>0?(d=u[g],o+=s,h=e):(d=v,b>h&&(h=b))}c!==l.length-1&&(o+=s)}return{width:h,height:o+a,lineHeight:s,fontHeight:a}}static getLineCenterPoint(r){const[t,e]=r,i=xt.getVector(t,e);return{x:t.x+i.x/2,y:t.y+i.y/2}}static getPerpendicularLine(r){if(r.length!==2)return;const[t,e]=r,i={x:e.x+e.y-t.y,y:e.y-(e.x-t.x)};return[e,i]}static getPerpendicularFootOfLine(r,t){if(r.length!==2)return r;const e=this.getPerpendicularLine(r);if(!e)return r;const[i,s]=e;return this.getFootOfPerpendicular(t,i,s).footPoint}static getQuadrangleFromTriangle(r){if(r.length!==3)return r;const[t,e,i]=r,s={x:i.x+t.x-e.x,y:i.y+t.y-e.y};return[t,e,i,s]}static getRectPerpendicularOffset(r,t,e){const[i,s]=e,n=this.getFootOfPerpendicular(r,i,s).footPoint,o=this.getFootOfPerpendicular(t,i,s).footPoint,a={x:n.x-o.x,y:n.y-o.y},l=xt.add(t,a);return xt.getVector(r,l)}static getArrayIndex(r,t){return r<0?t+r:r>=t?r-t:r}static getPointListFromPointOffset(r,t,e){const i=this.getArrayIndex(t-1,r.length),s=this.getArrayIndex(t+1,r.length),n=this.getArrayIndex(t-2,r.length),o=[...r];o[t]=xt.add(o[t],e);const a=this.getFootOfPerpendicular(o[t],o[n],o[i]).footPoint,l=this.getFootOfPerpendicular(o[t],o[s],o[n]).footPoint;return o[i]=a,o[s]=l,o}static getRectCenterPoint(r){const[t,,e]=r;return{x:(t.x+e.x)/2,y:(t.y+e.y)/2}}static rotateRectPointList(r=5,t){const e=this.getRectCenterPoint(t),{PI:i}=Math,s=Math.sin(r*i/180),n=Math.cos(r*i/180);return t.map(o=>{const a=xt.getVector(e,o),l=xt.len(a),h=a.y/l,c=a.x/l;return{x:l*_e.cosAPlusB(h,c,s,n)+e.x,y:l*_e.sinAPlusB(h,c,s,n)+e.y}})}static getRectangleByRightAngle(r,t){if(t.length!==2)return t;const e=mt.getPerpendicularFootOfLine(t,r);return mt.getQuadrangleFromTriangle([...t,e])}};let P=mt;P.isInRange=(r,t)=>{const e=Math.min(...t),i=Math.max(...t),s=o=>o<=i&&o>=e;return(Array.isArray(r)?r:[r]).every(o=>s(o))},P.withinRange=(r,t)=>{const e=Math.min(...t),i=Math.max(...t);return r>i?i:r<e?e:r},P.calcViewportBoundaries=(r,t=!1,e=Y,i=1)=>{if(!r)return{top:0,bottom:0,left:0,right:0};const s=20/i,n=[],o=[];let a=r;t&&(a=Et(r,e)),a.forEach(({x:v,y:f})=>{n.push(v),o.push(f)});let l=Math.min(...n),h=Math.max(...n),c=Math.min(...o),u=Math.max(...o);const d=h-l,g=u-c;if(d<s){const v=(s-d)/2;l-=v,h+=v}if(g<s){const v=(s-g)/2;c-=v,u+=v}return{top:c,bottom:u,left:l,right:h}},P.getFootOfPerpendicular=(r,t,e,i=!1)=>{let s={x:0,y:0};const n=t.x-e.x,o=t.y-e.y;if(Math.abs(n)<1e-8&&Math.abs(o)<1e-8)return s=t,s;let a=(r.x-t.x)*(t.x-e.x)+(r.y-t.y)*(t.y-e.y);a/=n*n+o*o,s.x=t.x+a*n,s.y=t.y+a*o;const l=mt.getLineLength(r,s),h=2,c=Math.min(t.x,e.x),u=Math.max(t.x,e.x),d=Math.min(t.y,e.y),g=Math.max(t.y,e.y),v=!(mt.isInRange(r.x,[c,u])||mt.isInRange(r.y,[d,g])),f=r.x>u+h||r.x<c-h||r.y>g+h||r.y<d-h;return(i?v:f)?{footPoint:s,length:Infinity}:{footPoint:s,length:l}};const ts=61,es=40,is=40,ss=240;var Dt;(function(r){r[r.ANNOTATION=1]="ANNOTATION",r[r.QUALITY_INSPECTION=2]="QUALITY_INSPECTION",r[r.PRE_ANNOTATION=3]="PRE_ANNOTATION",r[r.MANUAL_CORRECTION=4]="MANUAL_CORRECTION"})(Dt||(Dt={}));const rs=1e3;var ie;(function(r){r[r.Backward=0]="Backward",r[r.Forward=1]="Forward",r[r.JumpSkip=2]="JumpSkip",r[r.None=3]="None"})(ie||(ie={}));var O;(function(r){r[r.Start=0]="Start",r[r.Stop=1]="Stop",r[r.Wait=2]="Wait",r[r.Move=3]="Move"})(O||(O={}));var q;(function(r){r[r.Point=0]="Point",r[r.Line=1]="Line",r[r.Plane=2]="Plane"})(q||(q={}));var G;(function(r){r[r.ascend=0]="ascend",r[r.descend=1]="descend"})(G||(G={}));var It;(function(r){r[r.Intelligence=0]="Intelligence",r[r.Linear=1]="Linear"})(It||(It={}));var at;(function(r){r.Zh="zh_CN",r.US="en_US"})(at||(at={}));var _t;(function(r){r[r.Clockwise=0]="Clockwise",r[r.Anticlockwise=1]="Anticlockwise"})(_t||(_t={}));const K={offsetX:-10,offsetY:-10},ft={shadowColor:"rgba(0,0,0,0.6)",shadowOffsetX:0,shadowOffsetY:2,shadowBlur:4},vt={x:8,y:26};var ns=Object.freeze({__proto__:null,headerHeight:ts,tipsHeight:es,footerHeight:is,sidebarWidth:ss,get EStepType(){return Dt},ANNOTATION_MAX_SIZE:rs,get EPageOperator(){return ie},get EDragStatus(){return O},get EDragTarget(){return q},get ESortDirection(){return G},get EGrowthMode(){return It},get ELang(){return at},get ERotateDirection(){return _t},DEFAULT_TEXT_OFFSET:K,DEFAULT_TEXT_SHADOW:ft,TEXT_ATTRIBUTE_OFFSET:vt}),os=Object.defineProperty,as=Object.defineProperties,ls=Object.getOwnPropertyDescriptors,Re=Object.getOwnPropertySymbols,hs=Object.prototype.hasOwnProperty,cs=Object.prototype.propertyIsEnumerable,Ae=(r,t,e)=>t in r?os(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,lt=(r,t)=>{for(var e in t||(t={}))hs.call(t,e)&&Ae(r,e,t[e]);if(Re)for(var e of Re(t))cs.call(t,e)&&Ae(r,e,t[e]);return r},ht=(r,t)=>as(r,ls(t));class Z{static composeResult(t,e,i,s,n){try{const o=JSON.parse(t),a=x.getCurrentStepInfo(e,s),{dataSourceStep:l}=a,h=`step_${a.step}`;if(Object.assign(o,n),o[h]){const c=o[h];return c.result?(c.result=i,JSON.stringify(o)):JSON.stringify(ht(lt({},o),{[h]:ht(lt({},o[h]),{result:i})}))}return JSON.stringify(ht(lt({},o),{[h]:{dataSourceStep:l,toolName:a.tool,result:i}}))}catch(o){return t}}static changeCoordinateByRotate(t,e,i){const{x:s,y:n,width:o,height:a}=t,l=I.changeCoordinateByRotate({x:s,y:n},e,i);switch(e%360){case 90:return ht(lt({},t),{x:l.x-a,y:l.y,width:a,height:o});case 180:return ht(lt({},t),{x:l.x-o,y:l.y-a});case 270:return ht(lt({},t),{x:l.x,y:l.y-o,width:a,height:o});default:return t}}static translateRect2Points(t){const{x:e,y:i,width:s,height:n}=t;return[{x:e,y:i},{x:e+s,y:i},{x:e+s,y:i+n},{x:e,y:i+n}]}static translatePoints2Rect(t,e){if(t.length!==4)return;const{x:i,y:s}=t[0],n=t[1].x-t[0].x,o=t[2].y-t[1].y;return ht(lt({},e),{x:i,y:s,width:n,height:o})}static getRectPointList(t,e=1){return[{x:t.x*e,y:t.y*e},{x:(t.x+t.width)*e,y:t.y*e},{x:(t.x+t.width)*e,y:(t.y+t.height)*e},{x:t.x*e,y:(t.y+t.height)*e}]}static getRectEdgeList(t,e=1){const i=this.getRectPointList(t,e),s=i.length;return i.map((n,o)=>({begin:n,end:i[(o+1)%s]}))}static isInRect(t,e,i=0,s=1){return t.x>=e.x*s-i&&t.x<=(e.x+e.width)*s+i&&t.y>=e.y*s-i&&t.y<=(e.y+e.height)*s+i}static getRectUnderZoom(t,e=1){const{x:i,y:s,width:n,height:o}=t;return ht(lt({},t),{x:i*e,y:s*e,width:n*e,height:o*e})}static isRectNotInPolygon(t,e){return this.getRectPointList(t).some(s=>!Pe(s,e))}}function J(r=8,t=62){const e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),i=[];let s;if(t=t||e.length,r)for(s=0;s<r;s++)i[s]=e[0|Math.random()*t];else{let n;for(i[8]=i[13]=i[18]=i[23]="-",i[14]="4",s=0;s<36;s++)i[s]||(n=0|Math.random()*16,i[s]=e[s===19?n&3|8:n])}return i.join("")}var ds=Object.defineProperty,Te=Object.getOwnPropertySymbols,us=Object.prototype.hasOwnProperty,gs=Object.prototype.propertyIsEnumerable,Se=(r,t,e)=>t in r?ds(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ke=(r,t)=>{for(var e in t||(t={}))us.call(t,e)&&Se(r,e,t[e]);if(Te)for(var e of Te(t))gs.call(t,e)&&Se(r,e,t[e]);return r};class Rt{static getTagKeyName(t,e){var i,s;if(!!e)return(s=(i=e.find(n=>n.value===t))==null?void 0:i.key)!=null?s:""}static getTagName([t="",e=""],i){if(!!i){for(const s of i)if(s.value===t){if(!s.subSelected)return console.error("\u6807\u7B7E\u89E3\u6790\u9519\u8BEF",t,e),"";for(const n of s.subSelected)if(n.value===e)return n.key}}}static getTagNameList(t,e){return Object.keys(t).length<=0?[]:Object.entries(t).reduce((i,s)=>{const[n,o]=s;if(o&&o.length>0){const a=o.split(";"),l={keyName:this.getTagKeyName(n,e),value:a.map(h=>this.getTagName([n,h],e))};return[...i,l]}return i},[]).filter(i=>i)}static getTagnameListWithoutConfig(t){return Object.keys(t).length<=0?[]:Object.entries(t).reduce((e,i)=>{const[s,n]=i,o=n.split(";"),a={keyName:s,value:o};return[...e,a]},[]).filter(e=>e)}static judgeResultIsInInputList(t,e,i){return!t||!e||!i?!1:i.filter(n=>{if(n.value===t&&n.subSelected){const o=e==null?void 0:e.split(";");return(n==null?void 0:n.subSelected.filter(a=>o.indexOf(a.value)>-1).length)>0}return!1}).length>0}static getDefaultResultByConfig(t){return t.reduce((e,i)=>(i.subSelected&&i.subSelected.forEach(s=>{var n;if(s.isDefault){const o=(n=e[i.value])!=null?n:"";let a=[];o.length>0&&(a=o.split(";")),a.push(s.value),e[i.value]=a.join(";")}}),e),{})}static getDefaultTagResult(t,e){const i=this.getDefaultResultByConfig(t);return e.length>0?e.map(s=>({id:J(),sourceID:s.id,result:ke({},i)})):[{id:J(),sourceID:"",result:ke({},i)}]}}var Oe='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#ccc"/></g></g></svg>',fs='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#ff2323"/></g></g></svg>',vs='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#ffe232"/></g></g></svg>',ps='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#01ff30"/></g></g></svg>',bs='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#00ffea"/></g></g></svg>',ys='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#0282fa"/></g></g></svg>',xs='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#800cf9"/></g></g></svg>',ms='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#ff88f7"/></g></g></svg>',Is='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#994217"/></g></g></svg>',ws='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#1f0bf9"/></g></g></svg>',Ls='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#3fe"/></g></g></svg>',Ps='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#33fe33"/></g></g></svg>',Cs='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#fdff37"/></g></g></svg>',Ds='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#f70efa"/></g></g></svg>',Me='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#f33"/></g></g></svg>';const Ee=Oe,_s=61,Rs=80,As=62,Ts=20,Ss=55,ks=55,Os=40,Ms=80,Es=240,Hs=320,Ns="rgba(102, 111, 255, 1)",wt=["rgba(128, 12, 249, 1)","rgba(0, 255, 48, 1)","rgba(255, 136, 247, 1)","rgba(255, 226, 50, 1)","rgba(153, 66, 23, 1)","rgba(2, 130, 250, 1)","rgba(255, 35, 35, 1)","rgba(0, 255, 234, 1)"],Ht=[Oe,xs,ps,ms,vs,Is,ys,fs,bs],He={1:ws,3:Ls,5:Ps,7:Cs,9:Ds},Bs="rgba(255, 51, 51, 1)",se="rgba(204, 204, 204, 1)",Fs={[gt.lc]:"rgba(153, 51, 255, 1)",[gt.rc]:"rgba(51, 153, 255, 1)",[gt.clc]:"rgba(46, 230, 46, 1)",[gt.crc]:"rgba(255, 51, 51, 1)"};var $s=Object.freeze({__proto__:null,HEADER_HEIGHT:_s,TAB_HEIGHT:Rs,SEARCH_HEIGHT:As,PADDING:Ts,TABLE_ROW_HEIGHT:Ss,PAGINATION_HEIGHT:ks,TIPS_HEIGHT:Os,FOOTER_HEIGHT:Ms,SIDERBAR_WIDTH:Es,EDIT_STEP_WIDTH:Hs,THEME_COLOR:Ns,COLORS_ARRAY:wt,ICON_ARRAY:Ht,BASE_ICON:He,INVALID_COLOR:Bs,NULL_COLOR:se,NULL_ICON:Ee,INVALID_ICON:Me,FILTER_TOOL_COLOR:Fs}),C;(function(r){r.NoRotateNotice="noRotateNotice",r.RectErrorSizeNotice="rectErrorSizeNotice",r.TextCheckNumberErrorNotice="textCheckNumberErrorNotice",r.TextCheckEnglishErrorNotice="textCheckEnglishErrorNotice",r.TextCheckCustomErrorNotice="textCheckCustomErrorNotice",r.UpperLimitErrorNotice="UpperLimitErrorNotice",r.LowerLimitErrorNotice="LowerLimitErrorNotice",r.InvalidImage="InvalidImage",r.DisableDelete="DisableDelete",r.ClearPartialData="ClearPartialData",r.MarkerFinish="MarkerFinish",r.LowerLimitPoint="LowerLimitPoint",r.NoRotateInDependence="noRotateInDependence",r.UnableToReannotation="unableToReannotation",r.ForbiddenCreationOutsideBoundary="ForbiddenCreationOutsideBoundary",r.SuccessfulEdgeAdsorption="SuccessfulEdgeAdsorption"})(C||(C={}));const Zs={[C.NoRotateNotice]:"This Image contains data and cannot be rotated",[C.RectErrorSizeNotice]:"The drawing frame size is smaller than the minimum drawing size",[C.TextCheckNumberErrorNotice]:"Please enter in number-only format",[C.TextCheckEnglishErrorNotice]:"Please enter in English only format",[C.TextCheckCustomErrorNotice]:"Please enter in the required format",[C.UpperLimitErrorNotice]:"The number of vertices is not more than",[C.LowerLimitErrorNotice]:"The number of vertices is not less than",[C.InvalidImage]:"Invalid image, please skip this image",[C.DisableDelete]:"Disable delete",[C.ClearPartialData]:"Clear partial data",[C.MarkerFinish]:"ListAnnotation is finished",[C.LowerLimitPoint]:"The maximum number of points has been reached",[C.NoRotateInDependence]:"Disallow rotation in dependent cases",[C.UnableToReannotation]:"Unabled to reannotation",[C.ForbiddenCreationOutsideBoundary]:"Fobid creation outside boundary",[C.SuccessfulEdgeAdsorption]:"Successful edge adsorption"},Us={[C.NoRotateNotice]:"\u672C\u56FE\u542B\u6709\u6570\u636E\uFF0C\u65E0\u6CD5\u8FDB\u884C\u65CB\u8F6C",[C.RectErrorSizeNotice]:"\u7ED8\u5236\u6846\u5C3A\u5BF8\u5C0F\u4E8E\u6700\u5C0F\u7ED8\u5236\u5C3A\u5BF8",[C.TextCheckNumberErrorNotice]:"\u8BF7\u6309\u4EC5\u6570\u5B57\u7684\u683C\u5F0F\u8F93\u5165",[C.TextCheckEnglishErrorNotice]:"\u8BF7\u6309\u4EC5\u82F1\u6587\u7684\u683C\u5F0F\u8F93\u5165",[C.TextCheckCustomErrorNotice]:"\u8BF7\u6309\u8981\u6C42\u7684\u683C\u5F0F\u8F93\u5165",[C.UpperLimitErrorNotice]:"\u9876\u70B9\u6570\u4E0D\u591A\u4E8E",[C.LowerLimitErrorNotice]:"\u9876\u70B9\u6570\u4E0D\u5C11\u4E8E",[C.InvalidImage]:"\u65E0\u6548\u56FE\u7247\uFF0C\u8BF7\u8DF3\u8FC7\u6B64\u56FE",[C.DisableDelete]:"\u8BE5\u6570\u636E\u7981\u6B62\u5220\u9664",[C.ClearPartialData]:"\u5B58\u5728\u90E8\u5206\u6570\u636E\u65E0\u6CD5\u6E05\u9664",[C.MarkerFinish]:"\u5217\u8868\u6807\u6CE8\u5DF2\u5B8C\u6210",[C.LowerLimitPoint]:"\u5DF2\u5230\u8FBE\u6807\u70B9\u6570\u91CF\u4E0A\u9650",[C.NoRotateInDependence]:"\u4F9D\u8D56\u60C5\u51B5\u4E0B\u65E0\u6CD5\u8FDB\u884C\u65CB\u8F6C",[C.UnableToReannotation]:"\u65E0\u6CD5\u8FDB\u884C\u7EED\u6807\u64CD\u4F5C",[C.ForbiddenCreationOutsideBoundary]:"\u8FB9\u754C\u5916\u7981\u6B62\u521B\u5EFA",[C.SuccessfulEdgeAdsorption]:"\u8FB9\u7F18\u5438\u9644\u6210\u529F"};class B{}B.getMessagesByLocale=(r,t)=>{switch(t){case at.US:return Zs[r];case at.Zh:default:return Us[r]}};var zs=Object.defineProperty,Ws=Object.defineProperties,Vs=Object.getOwnPropertyDescriptors,Ne=Object.getOwnPropertySymbols,js=Object.prototype.hasOwnProperty,Xs=Object.prototype.propertyIsEnumerable,Be=(r,t,e)=>t in r?zs(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Fe=(r,t)=>{for(var e in t||(t={}))js.call(t,e)&&Be(r,e,t[e]);if(Ne)for(var e of Ne(t))Xs.call(t,e)&&Be(r,e,t[e]);return r},$e=(r,t)=>Ws(r,Vs(t));const Ys="^[0-9]+$",Gs="^[A-Za-z]+$";class S{static getAttributeIcon(t,e,i=!0){var s;const n=e.findIndex(l=>l.value===t);let o=(s=Ht[n%Ht.length])!=null?s:Ee;i||(o=Me),o="";const a=new Image;return a.src=o,a}static checkString(t,e){let i="";switch(t){case X.Order:case X.NumberOnly:i=Ys;break;case X.EnglishOnly:i=Gs;break;case X.CustomFormat:i=e;break}return i}static checkTextAttibute(t,e){if(t===void 0||t==="")return!0;try{return new RegExp(e).test(t)}catch(i){return!1}}static getAttributeShowText(t,e=[]){var i,s;try{const n=e.findIndex(o=>o.value===t);return(s=(i=e[n])==null?void 0:i.key)!=null?s:t}catch(n){return t}}static getAttributeIndex(t,e){try{const i=e.findIndex(s=>s.value===t);return i>=8?i%8:i}catch(i){return-1}}static getAttributeColor(t,e){try{const i=this.getAttributeIndex(t,e);return i===-1?se:wt[i%wt.length]}catch(i){return se}}static getTextAttribute(t,e){try{if(e===X.Order){const i=t.map(n=>parseInt(n.textAttribute,10)).filter(n=>Wt(n)&&n<Number.MAX_SAFE_INTEGER&&n>=0);return i.sort((n,o)=>n-o),`${(i.pop()||0)+1}`}return""}catch(i){return""}}static textChange(t,e,i){return i.map(s=>s.id===e?$e(Fe({},s),{textAttribute:t}):s)}static getErrorNotice(t,e){switch(t){case X.Order:case X.NumberOnly:return B.getMessagesByLocale(C.TextCheckNumberErrorNotice,e);case X.EnglishOnly:return B.getMessagesByLocale(C.TextCheckEnglishErrorNotice,e);case X.CustomFormat:return B.getMessagesByLocale(C.TextCheckCustomErrorNotice,e);default:return""}}static textAttributeValidate(t,e,i){try{return new RegExp(this.checkString(t,e)).test(i)}catch(s){}}static checkTextAttribute(t,e,i,s){let n=!1;return i.forEach(o=>{(o==null?void 0:o.textAttribute)===void 0||(o==null?void 0:o.textAttribute)===""||(s?o.id===s:!0)&&!this.textAttributeValidate(t,e,o.textAttribute)&&(n=!0)}),!!n}static changeTextAttributeInLog(t,e){return t==null?void 0:t.map(i=>i==null?void 0:i.map(s=>{if((e==null?void 0:e.findIndex(n=>(n==null?void 0:n.id)===(s==null?void 0:s.id)))>-1){const n=e==null?void 0:e.find(o=>(o==null?void 0:o.id)===(s==null?void 0:s.id));return $e(Fe({},s),{textAttribute:n==null?void 0:n.textAttribute})}return s}))}static getTextIconSvg(t="",e,i=!1,s){if(i===!0){const n=(e==null?void 0:e.findIndex(o=>(o==null?void 0:o.value)===t))%wt.length+1;return Ht[n]}return s}static getAttributeByKeycode(t,e){var i;let s;return P.isInRange(t,[48,57])&&(s=t-48),P.isInRange(t,[96,105])&&(s=t-96),s===0?"":s?(i=e[s-1])==null?void 0:i.value:void 0}}class Nt{static deg2rad(t){return t*Math.PI/180}static rad2deg(t){return t*180/Math.PI}}var Ks=Object.defineProperty,Js=Object.defineProperties,qs=Object.getOwnPropertyDescriptors,Ze=Object.getOwnPropertySymbols,Qs=Object.prototype.hasOwnProperty,tr=Object.prototype.propertyIsEnumerable,Ue=(r,t,e)=>t in r?Ks(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,er=(r,t)=>{for(var e in t||(t={}))Qs.call(t,e)&&Ue(r,e,t[e]);if(Ze)for(var e of Ze(t))tr.call(t,e)&&Ue(r,e,t[e]);return r},ir=(r,t)=>Js(r,qs(t));const sr=1,rr={x:0,y:0},nr=0,tt="";class m{static drawLine(t,e,i,s={}){const n=t.getContext("2d"),{color:o=tt,thickness:a=1,lineCap:l="round"}=s;n.save(),n.strokeStyle=o,n.lineWidth=a,n.lineCap=l,n.beginPath(),n.moveTo(e.x,e.y),n.lineTo(i.x+1,i.y+1),n.stroke(),n.restore()}static drawRect(t,e,i={}){const s=t.getContext("2d"),{color:n=tt,thickness:o=1,lineCap:a="round",hiddenText:l=!1,lineDash:h}=i;if(s.save(),s.strokeStyle=n,s.lineWidth=o,s.lineCap=a,Array.isArray(h)&&s.setLineDash(h),s.fillStyle=n,s.strokeRect(e.x,e.y,e.width,e.height),l===!1){let c="";if(e.attribute&&(c=`${c} ${e.attribute}`),this.drawText(t,{x:e.x,y:e.y-5},c),e.textAttribute){const d=`${~~e.width} * ${~~e.height}`.length*7,g=0,v=Math.max(20,e.width-d);this.drawText(t,{x:e.x,y:e.y+e.height+20+g},e.textAttribute,{textMaxWidth:v})}}s.restore()}static drawRectWithFill(t,e,i={}){const s=t.getContext("2d"),{color:n=tt}=i;s.save(),s.fillStyle=n,s.fillRect(e.x,e.y,e.width,e.height),s.restore()}static drawTagByDom(t,e,i){const s=t;if(!((e==null?void 0:e.length)>0))return;const n=document.createElement("div");return n.innerHTML=e,n.setAttribute("id",i),s==null||s.appendChild(n),n}static drawTag(t,e){var i;const s=t==null?void 0:t.parentNode,n=window.self.document.getElementById("tagToolTag");if(n&&s&&s.contains(n)&&(s==null||s.removeChild(n)),!((e==null?void 0:e.length)>0))return;const o=document.createElement("div");return o.innerHTML=(i=e.reduce((a,l)=>`${a}${l.keyName}: ${l.value.join(" \u3001 ")}
7
- `,""))!=null?i:"",o.setAttribute("id","tagToolTag"),s==null||s.appendChild(o),o}static drawLineWithPointList(t,e,i={}){if(e.length<2)return;const s=t.getContext("2d"),{color:n=tt,thickness:o=1,lineCap:a="round",lineType:l=T.Line,lineDash:h,hoverEdgeIndex:c}=i;s.save(),(()=>{s.strokeStyle=n,s.lineWidth=o,s.lineCap=a,Array.isArray(h)?s.setLineDash(h):s.setLineDash([])})(),l===T.Curve?(c!==void 0&&c>-1&&e.push(e[0]),e=_.createSmoothCurvePointsFromPointList([...e],Y),c!==void 0&&c>-1&&(e=e.slice((Y+1)*c,(Y+1)*(c+1)))):c!==void 0&&c>-1&&(e=[...e,e[0]],e=e.slice(c,c+2));const d=[];s.beginPath(),s.moveTo(e[0].x,e[0].y);for(let f=0;f<e.length-1;f++)e[f].specialEdge&&d.push({i1:f,i2:f+1}),s.lineTo(e[f+1].x,e[f+1].y);s.stroke(),s.save(),s.lineWidth=o*.8,s.lineCap="butt",s.strokeStyle="white",s.setLineDash([3,3]),d.forEach(f=>{const b=e[f.i1],p=e[f.i2];s.beginPath(),s.moveTo(b.x,b.y),s.lineTo(p.x,p.y),s.stroke()}),s.restore();const g=4,v=2;return e.forEach(f=>{f.specialPoint&&(this.drawSpecialPoint(t,f,g+v,n),this.drawSpecialPoint(t,f,g,"white"))}),s.restore(),e}static drawCircle(t,e,i,s={}){const n=t.getContext("2d"),{startAngleDeg:o=0,endAngleDeg:a=360,thickness:l=1,color:h=tt,fill:c=tt}=s,u=Nt.deg2rad(o),d=Nt.deg2rad(a);n.save(),n.beginPath(),n.strokeStyle=h,n.fillStyle=c,n.lineWidth=l,n.arc(e.x,e.y,i,u,d,!1),n.stroke(),c&&n.fill(),n.closePath(),n.restore()}static drawCircleWithFill(t,e,i=3,s={}){const n=t.getContext("2d"),{color:o=tt}=s;n.save();const a=Nt.deg2rad(0),l=Nt.deg2rad(360);n.fillStyle=o,n.beginPath(),n.arc(e.x,e.y,i,a,l,!1),n.fill(),n.restore()}static drawSpecialPoint(t,e,i=6,s){const n=t.getContext("2d"),{x:o,y:a}=e;n.save(),n.beginPath(),n.fillStyle=s;const l=i*1.5,h=l*Math.sqrt(3)/2,c=l/2;n.moveTo(o,a-l),n.lineTo(o-h,a+c),n.lineTo(o+h,a+c),n.closePath(),n.fill(),n.restore()}static drawPolygon(t,e,i={}){const{isClose:s=!1,lineType:n=T.Line}=i;return s===!0&&(e=[...e,e[0]]),n===T.Curve&&(e=_.createSmoothCurvePointsFromPointList([...e])),this.drawLineWithPointList(t,e,ir(er({},i),{lineType:T.Line})),e}static drawPolygonWithFill(t,e,i={}){if(e.length<2)return;const s=t.getContext("2d"),{color:n=tt,lineType:o=T.Line}=i;s.save(),s.fillStyle=n,s.beginPath(),o===T.Curve&&(e=_.createSmoothCurvePointsFromPointList([...e,e[0]]));const[a,...l]=e;return s.moveTo(a.x,a.y),l.forEach(h=>{s.lineTo(h.x,h.y)}),s.fill(),s.restore(),e}static drawPolygonWithFillAndLine(t,e,i={}){const{strokeColor:s,fillColor:n,thickness:o,lineCap:a,isClose:l,lineType:h}=i,c=this.drawPolygon(t,e,{color:s,thickness:o,lineCap:a,isClose:l,lineType:h});return this.drawPolygonWithFill(t,e,{color:n,lineType:h}),c}static drawPolygonWithKeyPoint(t,e,i={}){const{pointColor:s="white",strokeColor:n}=i,o=this.drawPolygon(t,e,i);return o.forEach(a=>{this.drawCircleWithFill(t,a,4,{color:n}),this.drawCircleWithFill(t,a,3,{color:s})}),o}static drawSelectedPolygonWithFillAndLine(t,e,i={}){const{pointColor:s="white",strokeColor:n}=i,o=this.drawPolygonWithFillAndLine(t,e,i);return o.forEach(a=>{this.drawCircleWithFill(t,a,4,{color:n}),this.drawCircleWithFill(t,a,3,{color:s})}),o}static drawText(t,e,i,s={}){if(!i)return;const n=t.getContext("2d"),{color:o=tt,font:a=Mt,shadowColor:l="",shadowBlur:h=0,shadowOffsetX:c=0,shadowOffsetY:u=0,textMaxWidth:d=164,offsetX:g=0,offsetY:v=0,textAlign:f="start",lineHeight:b}=s;n.save(),n.textAlign=f,n.fillStyle=o!=null?o:"white",n.font=a,n.shadowColor=l,n.shadowOffsetX=c,n.shadowOffsetY=u,n.shadowBlur=h,this.wrapText(t,`${i}`,e.x+g,e.y+v,d,b),n.restore()}static wrapText(t,e,i,s,n,o){if(typeof e!="string"||typeof i!="number"||typeof s!="number")return;const a=t.getContext("2d");typeof n=="undefined"&&(n=t&&t.width||300),typeof o=="undefined"&&(o=t&&parseInt(window.getComputedStyle(t).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const l=e.split(`
8
- `);for(let h=0;h<l.length;h++){const c=l[h].split("");let u="";for(let d=0;d<c.length;d++){const g=u+c[d],f=a.measureText(g).width;n||(n=300),f>n&&d>0?(a.fillText(u,i,s),u=c[d],s+=o):u=g}a.fillText(u,i,s),s+=o}}static drawArrow(t,e,i,s={}){const{color:n=tt,thickness:o=1,lineCap:a="round",theta:l=30,headLen:h=10}=s,c=Math.atan2(e.y-i.y,e.x-i.x)*180/Math.PI,u=(c+l)*Math.PI/180,d=(c-l)*Math.PI/180,g=h*Math.cos(u),v=h*Math.sin(u),f=h*Math.cos(d),b=h*Math.sin(d);t.save(),t.strokeStyle=n,t.lineWidth=o,t.lineCap=a,t.beginPath(),t.moveTo(i.x+g,i.y+v),t.lineTo(i.x,i.y),t.lineTo(i.x+f,i.y+b),t.stroke(),t.restore()}static drawArrowByCanvas(t,e,i,s={}){const n=t.getContext("2d");this.drawArrow(n,e,i,s)}}m.drawImg=(r,t,e={})=>{const i=r.getContext("2d"),{zoom:s=sr,currentPos:n=rr,rotate:o=nr,imgAttribute:a}=e;switch(i.save(),o){case 0:i.translate(n.x,n.y);break;case 90:i.translate(n.x+t.height*s,n.y),i.rotate(90*Math.PI/180);break;case 180:i.translate(n.x+t.width*s,n.y+t.height*s),i.rotate(Math.PI);break;case 270:i.translate(n.x,n.y+t.width*s),i.rotate(270*Math.PI/180);break;default:i.translate(n.x,n.y);break}if(a){const{contrast:l,saturation:h,brightness:c}=a;i.filter=`saturate(${h+100}%) contrast(${l+100}%) brightness(${c+100}%)`}i.drawImage(t,0,0,t.width*s,t.height*s),i.restore()};class et{static getStrokeAndFill(t,e=!0,i={}){const{isSelected:s=!1,isHover:n=!1}=i;return s?{stroke:e?t.validSelected.stroke:t.invalidSelected.stroke,fill:e?t.validSelected.fill:t.invalidSelected.fill}:n?{stroke:e?t.validHover.stroke:t.invalidHover.stroke,fill:e?t.validHover.fill:t.invalidHover.fill}:{stroke:e?t.valid.stroke:t.invalid.stroke,fill:e?t.valid.fill:t.invalid.fill}}static getStyle2String(t){if(!!t)return Object.entries(t).reduce((e,i)=>`${e} ${i[0]}: ${i[1]};`,"")}}class st{static getMousePositionOnCanvasFromEvent(t,e){if(e&&t){const i=e.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}return null}static getClientRect(t){if(t){const e=t.getBoundingClientRect();return{x:e.left,y:e.top,width:e.width,height:e.height}}return null}static getSize(t){if(t){const e=t.getBoundingClientRect();return{width:e.width,height:e.height}}return null}static inViewPort(t,e){return t?P.isInRange(t.x,[e.left,e.right])&&P.isInRange(t.y,[e.top,e.bottom]):!1}}st.getViewPort=(r,t,e)=>{const{width:i,height:s}=r,{x:n,y:o}=t,a=(0-o)/e,l=(0-n)/e,h=a+s/e,c=l+i/e;return{top:a,bottom:h,left:l,right:c}},st.getPixelRatio=r=>{if(!r||!window)return 1;const t=r.backingStorePixelRatio||r.webkitBackingStorePixelRatio||r.mozBackingStorePixelRatio||r.msBackingStorePixelRatio||r.oBackingStorePixelRatio||r.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/t};const ze={showConfirm:!1,skipWhileNoDependencies:!1,drawOutsideTarget:!1,copyBackwardResult:!1,minWidth:1,minHeight:1,isShowOrder:!1,filterData:["valid","invalid"],attributeConfigurable:!1,attributeList:[],textConfigurable:!1,textCheckType:0,customFormat:""},or={showConfirm:!1,skipWhileNoDependencies:!1,inputList:[{key:"\u7C7B\u522B1",value:"class1",isMulti:!1,subSelected:[{key:"\u9009\u98791",value:"option1",isDefault:!1},{key:"\u9009\u98792",value:"option1-2",isDefault:!1}]},{key:"\u7C7B\u522B2",value:"class-AH",isMulti:!0,subSelected:[{key:"\u9009\u98792-1",value:"option2-1",isDefault:!1},{key:"\u9009\u98792-2",value:"option2-2",isDefault:!1},{key:"\u9009\u98792-3",value:"option2-3",isDefault:!1}]},{key:"\u7C7B\u522B3",value:"class-0P",isMulti:!1,subSelected:[{key:"\u9009\u98793-1",value:"option3-1",isMulti:!1},{key:"\u9009\u98793-2",value:"option3-2",isDefault:!1},{key:"\u9009\u98793-3",value:"option3-3",isDefault:!1}]}]},ar={lineType:0,lineColor:0,edgeAdsorption:!1,outOfTarget:!0,copyBackwardResult:!1,isShowOrder:!1,attributeConfigurable:!1,attributeList:[{key:"\u7C7B\u522B1",value:"\u7C7B\u522B1"},{key:"\u7C7B\u522Bao",value:"class-ao"},{key:"\u7C7B\u522BM1",value:"class-M1"},{key:"\u7C7B\u522BCm",value:"class-Cm"},{key:"\u7C7B\u522Bc3",value:"class-c3"},{key:"\u7C7B\u522Ba0",value:"class-a0"},{key:"\u7C7B\u522Bu7",value:"class-u7"},{key:"\u7C7B\u522BZb",value:"class-Zb"},{key:"\u7C7B\u522Bzi",value:"class-zi"}],textConfigurable:!1,textCheckType:2,customFormat:"",showConfirm:!1,lowerLimitPointNum:2,upperLimitPointNum:"",preReferenceStep:0,skipWhileNoDependencies:!1,filterData:["valid","invalid"]},lr={showConfirm:!1,skipWhileNoDependencies:!1,enableTextRecognition:!1,recognitionMode:"general",configList:[{label:"\u6587\u672C",key:"text",required:!1,default:"",maxLength:1e3}],filterData:["valid","invalid"]},hr={lineType:0,lineColor:0,lowerLimitPointNum:3,edgeAdsorption:!1,drawOutsideTarget:!1,copyBackwardResult:!1,isShowOrder:!1,attributeConfigurable:!1,attributeList:[],textConfigurable:!0,textCheckType:0,customFormat:""},We=r=>r==="lineTool"?ar:r==="rectTool"?ze:r==="tagTool"?or:r==="textTool"?lr:r==="polygonTool"?hr:ze,Ve={toolColor:{1:{valid:{stroke:"rgba(0,0,255,0.50)",fill:"rgba(0,0,255,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.80)"},validSelected:{stroke:"rgba(0,15,255,1.00)",fill:"rgba(0,15,255,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,0.60)",fill:"rgba(255,0,0,0.24)"},validHover:{stroke:"rgba(0,15,255,0.80)",fill:"rgba(0,15,255,0.64)"},invalidHover:{stroke:"rgba(255,0,0,0.50)",fill:"rgba(255,0,0,0.40)"}},3:{valid:{stroke:"rgba(0,255,255,0.50)",fill:"rgba(0,255,255,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.80)"},validSelected:{stroke:"rgba(0,212,255,1.00)",fill:"rgba(0,212,255,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,0.60)",fill:"rgba(255,0,0,0.24)"},validHover:{stroke:"rgba(0,212,255,0.80)",fill:"rgba(0,212,255,0.64)"},invalidHover:{stroke:"rgba(255,0,0,0.50)",fill:"rgba(255,0,0,0.40)"}},5:{valid:{stroke:"rgba(0,255,0,0.50)",fill:"rgba(0,255,0,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.80)"},validSelected:{stroke:"rgba(149,255,1.00)",fill:"rgba(149,255,0,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,0.60)",fill:"rgba(255,0,0,0.24)"},validHover:{stroke:"rgba(149,255,0,0.80)",fill:"rgba(149,255,0,0.64)"},invalidHover:{stroke:"rgba(255,0,0,0.50)",fill:"rgba(255,0,0,0.40)"}},7:{valid:{stroke:"rgba(255,255,0,0.50)",fill:"rgba(255,255,0,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.80)"},validSelected:{stroke:"rgba(255,230,102,1.00)",fill:"rgba(255,213,0,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,0.60)",fill:"rgba(255,0,0,0.24)"},validHover:{stroke:"rgba(255,230,102,0.80)",fill:"rgba(255,230,102,0.64)"},invalidHover:{stroke:"rgba(255,0,0,0.50)",fill:"rgba(255,0,0,0.40)"}},9:{valid:{stroke:"rgba(255,0,255,0.50)",fill:"rgba(255,0,255,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.80)"},validSelected:{stroke:"rgba(230,102,255,1.00)",fill:"rgba(213,0,255,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,0.60)",fill:"rgba(255,0,0,0.24)"},validHover:{stroke:"rgba(230,102,255,0.80)",fill:"rgba(230,102,255,0.64)"},invalidHover:{stroke:"rgba(255,0,0,0.50)",fill:"rgba(255,0,0,0.40)"}}},attributeColor:[{valid:{stroke:"rgba(204,204,204,1.00)",fill:"rgba(204,204,204,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(204,204,204,1.00)",fill:"rgba(204,204,204,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(204,204,204,1.00)",fill:"rgba(204,204,204,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(153,51,255,1.00)",fill:"rgba(153,51,255,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(153,51,255,1.00)",fill:"rgba(153,51,255,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(153,51,255,1.00)",fill:"rgba(153,51,255,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(51,254,51,1.00)",fill:"rgba(51,254,51,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(51,254,51,1.00)",fill:"rgba(51,254,51,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(51,254,51,1.00)",fill:"rgba(51,254,51,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(255,51,255,1.00)",fill:"rgba(255,51,255,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(255,51,255,1.00)",fill:"rgba(255,51,255,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(255,51,255,1.00)",fill:"rgba(255,51,255,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(204,255,51,1.00)",fill:"rgba(204,255,51,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(204,255,51,1.00)",fill:"rgba(204,255,51,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(204,255,51,1.00)",fill:"rgba(204,255,51,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(51,153,255,1.00)",fill:"rgba(51,153,255,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(51,153,255,1.00)",fill:"rgba(51,153,255,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(51,153,255,1.00)",fill:"rgba(51,153,255,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(255,153,51,1.00)",fill:"rgba(255,153,51,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(255,153,51,1.00)",fill:"rgba(255,153,51,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(255,153,51,1.00)",fill:"rgba(255,153,51,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(51,255,238,1.00)",fill:"rgba(51,255,238,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(51,255,238,1.00)",fill:"rgba(51,255,238,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(51,255,238,1.00)",fill:"rgba(51,255,238,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(255,221,51,1.00)",fill:"rgba(255,221,51,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(255,221,51,1.00)",fill:"rgba(255,221,51,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(255,221,51,1.00)",fill:"rgba(255,221,51,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}}],lineColor:{1:"rgba(102, 111, 255, 1 )",3:"rgba(102, 230, 255, 1)",5:"rgba(191, 255, 102, 1)",7:"rgba(255, 230, 102, 1)",9:"rgba(230, 102, 255, 1)"},attributeLineColor:["rgba(204, 204, 204, 1)","rgba(153, 51, 255, 1)","rgba(51, 254, 51, 1)","rgba(255, 51, 255, 1)","rgba(204, 255, 51, 1)","rgba(51, 153, 255, 1)","rgba(255, 153, 51, 1)","rgba(51, 255, 238, 1)","rgba(255, 221, 51, 1)"],color:1,width:2,opacity:9};var cr=Object.defineProperty,dr=Object.defineProperties,ur=Object.getOwnPropertyDescriptors,je=Object.getOwnPropertySymbols,gr=Object.prototype.hasOwnProperty,fr=Object.prototype.propertyIsEnumerable,Xe=(r,t,e)=>t in r?cr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ye=(r,t)=>{for(var e in t||(t={}))gr.call(t,e)&&Xe(r,e,t[e]);if(je)for(var e of je(t))fr.call(t,e)&&Xe(r,e,t[e]);return r},Ge=(r,t)=>dr(r,ur(t)),Ke;(function(r){r[r.Create=0]="Create",r[r.Active=1]="Active",r[r.Edit=1]="Edit",r[r.None=2]="None"})(Ke||(Ke={}));var Je;(function(r){r.ActiveArea="#B3B8FF"})(Je||(Je={}));const qe=16,vr=3,U=class{static isInLine(r,t,e,i=3){const{length:s}=P.getFootOfPerpendicular(r,t,e);return s<i}};let M=U;M.setSpecialEdgeStyle=r=>{r.lineCap="butt",r.setLineDash([10,10])},M.setReferenceCtx=r=>{r.lineCap="butt",r.setLineDash([6])},M.calcOptimalIntersection=(r,t,e,i,s)=>{let n,o=Infinity,a;if(r.find((h,c)=>{if(c===0)return;const u=U.isInLine(t.pointA,h,r[c-1]),d=U.isInLine(t.pointB,h,r[c-1]);return u&&d}))return{point:e};if(r.forEach((h,c)=>{if(c===0)return;const u={pointA:r[c-1],pointB:h},d=U.lineIntersection(t,u);if(d&&t){const{onLine2:g,onLine1:v,x:f,y:b}=d,p=U.calcDistance(e,d);if(U.isOnLine(t.pointB.x,t.pointB.y,h.x,h.y,r[c-1].x,r[c-1].y)){if(U.calcDistance(e,d)<i/s){const D=t.pointB,{footPoint:R,length:E}=P.getFootOfPerpendicular(D,u.pointA,u.pointB,!0);if(E!==void 0){const H=U.calcDistance(u.pointA,R),k=U.calcDistance(u.pointB,R);a={point:R,minDistance:E},E===Infinity&&(a.point=H>k?u.pointB:u.pointA)}}return}p<o&&g&&v&&(o=p,n={x:f,y:b})}}),n)return{point:n,minDistance:o};if(a)return a},M.lineIntersection=(r,t)=>{let e=!1,i=!1;const s=U.getAxisDiff(r),n=U.getAxisDiff(t),o=n.y*s.x-n.x*s.y;if(o===0)return!1;let a=r.pointA.y-t.pointA.y,l=r.pointA.x-t.pointA.x;const h=(t.pointB.x-t.pointA.x)*a-(t.pointB.y-t.pointA.y)*l,c=(r.pointB.x-r.pointA.x)*a-(r.pointB.y-r.pointA.y)*l;a=h/o,l=c/o,a>0&&a<1&&(e=!0),l>0&&l<1&&(i=!0);const u=r.pointA.x+a*(r.pointB.x-r.pointA.x),d=r.pointA.y+a*(r.pointB.y-r.pointA.y);return{x:u,y:d,onLine1:e,onLine2:i}},M.getAxisDiff=r=>({x:r.pointB.x-r.pointA.x,y:r.pointB.y-r.pointA.y}),M.calcDistance=(r,t)=>Math.sqrt(Math.pow(Math.abs(r.x-t.x),2)+Math.pow(Math.abs(r.y-t.y),2)),M.drawCurveLine=(r,t,e,i=!0,s=!1,n)=>{const o=Et(t,qe);r.save(),r.lineCap="round",r.lineJoin="round",r.strokeStyle=e.color,i&&(r.lineWidth=e.lineWidth),s&&U.setReferenceCtx(r),t.forEach((a,l)=>{const h=a==null?void 0:a.specialEdge,c=o.splice(0,qe+1);r.save(),r.beginPath(),n===l&&(r.lineWidth=4),c.forEach(({x:u,y:d},g)=>{const v=g>0?"lineTo":"moveTo";h&&U.setSpecialEdgeStyle(r),r[v](u,d)}),r.stroke(),r.restore()}),r.restore()},M.calcTwoPointDistance=(r,t)=>Math.sqrt(Math.pow(r.x-t.x,2)+Math.pow(r.y-t.y,2)),M.pointOverTarget=(r,t,e,i,s,n,o,a,l,h)=>{const c=r;if(!t)return r;if(e===L.Polygon){const u=U.getPolygonPointList(i,s);if(u.length===0||_.isInPolygon(r,u))return c;const g=u.concat(u[0]).map(y=>l(y)),v=l(t),f=l(r),b={pointA:v,pointB:f},p=U.calcOptimalIntersection(g,b,v,o,a);if(p){const y=h(p==null?void 0:p.point);c.x=y.x,c.y=y.y}else return t;return c}if(e===L.Rect){const{x:u,y:d,width:g,height:v}=i;return c.x=P.withinRange(c.x,[u,u+g]),c.y=P.withinRange(c.y,[d,d+v]),c}return c.x=P.withinRange(c.x,[0,n.width]),c.y=P.withinRange(c.y,[0,n.height]),c},M.getPolygonPointList=(r,t)=>{const{pointList:e}=r,{lineType:i}=t;return i===T.Line?e:_.createSmoothCurvePoints(e.reduce((s,n)=>[...s,n.x,n.y],[]),.5,!0,20)},M.isOnLine=(r,t,e,i,s,n)=>Math.abs((a=>(i-t)/(e-r)*(a-r)+t)(s)-n)<1e-6&&s>=r&&s<=e,M.inArea=({top:r,left:t,right:e,bottom:i},{x:s,y:n})=>n>=r&&n<=i&&s>=t&&s<=e,M.getVHPoint=(r,t,e,i)=>{const s=U.getAngle(r,e);return Math.abs(s)<45?Ge(Ye({},t),{y:i.y}):Ge(Ye({},t),{x:i.x})},M.getAngle=(r,t)=>{const e=t.x-r.x,i=t.y-r.y;return 360*Math.atan(i/e)/(2*Math.PI)};var re;(function(r){r[r.A=65]="A",r[r.B=66]="B",r[r.C=67]="C",r[r.D=68]="D",r[r.E=69]="E",r[r.F=70]="F",r[r.G=71]="G",r[r.H=72]="H",r[r.L=76]="L",r[r.R=82]="R",r[r.Z=90]="Z",r[r.W=87]="W",r[r.X=88]="X",r[r.Y=89]="Y",r[r.S=83]="S",r[r.Q=81]="Q",r[r.Delete=46]="Delete",r[r.F11=122]="F11",r[r.Space=32]="Space",r[r.Esc=27]="Esc",r[r.Left=37]="Left",r[r.Up=38]="Up",r[r.Right=39]="Right",r[r.Down=40]="Down",r[r.Enter=13]="Enter",r[r.Ctrl=17]="Ctrl",r[r.Alt=18]="Alt",r[r.Shift=16]="Shift",r[r.Tab=9]="Tab",r[r.BackSpace=8]="BackSpace"})(re||(re={}));var A=re,pr=Object.freeze({__proto__:null,default:A});class ne{constructor(t){this.record=[],this.recordIndex=-1,this.minRecordIndex=-1,this.emitHistoryChanged=()=>{this.historyChanged&&(this.constructor.name==="ActionsHistory"?!0:this.record.length>0)&&this.historyChanged(this.undoEnabled,this.redoEnabled)},this.historyChanged=t}get undoEnabled(){return this.recordIndex>this.minRecordIndex}get redoEnabled(){return this.recordIndex<this.record.length-1}pushHistory(t){if(this.recordIndex!==this.record.length-1){const e=this.record.slice(0,Math.min(this.recordIndex+1,this.record.length));this.record=e}this.record.push(F.cloneDeepWith(t)),this.recordIndex+=1,this.emitHistoryChanged()}updateHistory(t){this.record[this.recordIndex]=F.cloneDeep(t)}applyAttribute(t,e,i){t&&this.record.forEach(s=>{const n=s.find(o=>o.id===t);n&&(n[e]=i)})}undo(){if(this.undoEnabled)return this.recordIndex-=1,this.emitHistoryChanged(),F.cloneDeep(this.record[this.recordIndex])||[]}redo(){if(this.redoEnabled)return this.recordIndex+=1,this.emitHistoryChanged(),F.cloneDeep(this.record[this.recordIndex])}init(){this.record=[[]],this.recordIndex=0,this.emitHistoryChanged()}empty(){this.record=[],this.recordIndex=-1,this.emitHistoryChanged()}initRecord(t,e=!1){const i=t.length>0||e;this.record=i?[F.cloneDeep(t)]:[],this.minRecordIndex=i?0:-1,this.recordIndex=0}}class Qe{constructor(t,e){this.rcTime=0,this.mouseDownTime=0,this.onMouseDown=()=>{this.mouseDownTime=new Date().getTime()},this.dom=t,this.isDoubleClick=!1,this.delay=e}getRcTime(){return this.rcTime}getCoord(t){return{x:t.clientX,y:t.clientY}}removeEvent(){!this.dom||(this.dom.removeEventListener("mouseup",this.mouseUp),this.dom.removeEventListener("mousemove",this.mouseMove),this.dom.removeEventListener("dblclick",this.dblclick),this.dom.removeEventListener("mousedown",this.onMouseDown))}addEvent(t,e,i,s){!this.dom||(this.removeEvent(),this.mouseUp=n=>{const o=new Date().getTime(),a=s?s(n):!0;if(o-this.mouseDownTime>this.delay||a!==!0){t(n);return}if(n.button===2)if(this.rcTime===0)setTimeout(()=>{this.rcTime=0},this.delay),this.rcTime=o;else{o-this.rcTime<this.delay&&(i(n),clearTimeout(this.setTimeFun),this.cacheFunction=void 0),this.rcTime=0;return}this.setTimeFun&&clearTimeout(this.setTimeFun),this.clickCoord=this.getCoord(n),this.cacheFunction=()=>t(n),this.setTimeFun=setTimeout(()=>{if(this.isDoubleClick){this.isDoubleClick=!1;return}this.cacheFunction(),this.clickCoord=void 0},this.delay)},this.mouseMove=n=>{const o=this.getCoord(n);this.clickCoord&&!I.getIsInScope(o,this.clickCoord,10)&&(this.cacheFunction&&this.cacheFunction(),this.clickCoord=void 0,this.cacheFunction=null,clearTimeout(this.setTimeFun))},this.dblclick=n=>{this.isDoubleClick=!0,this.clickCoord=void 0,e(n)},this.dom.addEventListener("mouseup",this.mouseUp),this.dom.addEventListener("mousemove",this.mouseMove),this.dom.addEventListener("dblclick",this.dblclick),this.dom.addEventListener("mousedown",this.onMouseDown))}clearRightDblClick(){this.rcTime=0}}class ti{static getInitImgPos(t,e,i=0,s=1,n=!1){(i===90||i===270)&&(e={width:e.height,height:e.width});const o=t.width*s/e.width,a=t.height*s/e.height;let l=n?1:Math.min(o,a);const h={x:(t.width-e.width*l)/2,y:(t.height-e.height*l)/2},c=e.width*l,u=e.height*l;return n&&(l=1),{zoom:l,currentPos:h,imgInfo:{width:c,height:u}}}static getBasicRecPos(t,e,i,s=.9,n=1,o=!1){if(e&&t){const{x:a,y:l,height:h,width:c}=e;let u=i.height/h;c/h>i.width/i.height&&(u=i.width/c);const d=o?1:u*s*n,g={x:i.width/2,y:i.height/2},v={x:(a+c/2)*d,y:(l+h/2)*d};return{currentPos:{x:g.x-v.x,y:g.y-v.y},innerZoom:d}}return!1}}class br{static renderInvalidPage(t,e,i){const s=document.createElement("div");return s.setAttribute("style",`
5
+ */import{polygon as Jt,difference as an,union as ln}from"@turf/turf";import j,{isObject as hn,isNumber as ve,cloneDeep as cn}from"lodash";import{i18n as yt,MatrixUtils as me,PointCloudUtils as qt,PerspectiveShiftUtils as _t,EPerspectiveView as nt}from"@labelbee/lb-utils";import gi from"color-rgba";import*as C from"three";import{Loader as dn,FileLoader as un,LoaderUtils as gn,BufferGeometry as fn,Float32BufferAttribute as ye,PointsMaterial as pn,Points as vn,EventDispatcher as mn,Vector3 as wt,MOUSE as kt,TOUCH as Mt,Quaternion as fi,Spherical as pi,Vector2 as dt}from"three";const yn=320;var Et;(function(r){r.PointCloud="pointCloudTool"})(Et||(Et={}));var Bt;(function(r){r.VideoTextTool="videoTextTool",r.VideoTagTool="videoTagTool",r.VideoClipTool="videoClipTool"})(Bt||(Bt={}));var be;(function(r){r[r.Rect=0]="Rect",r[r.Tag=1]="Tag"})(be||(be={}));var D;(function(r){r.Rect="rectTool",r.Tag="tagTool",r.Point="pointTool",r.PointMarker="pointMarkerTool",r.Segmentation="segmentationTool",r.Filter="filterTool",r.Text="textTool",r.Polygon="polygonTool",r.Line="lineTool",r.LineMarker="lineMarkerTool",r.Empty="emptyTool",r.FolderTag="folderTagTool",r.RectTrack="rectTrackTool",r.Face="faceTool",r.ClientAttribute="clientAttributeTool",r.OCRRelation="OCRRelationTool",r.SegmentByRect="segmentByRectTool"})(D||(D={}));var Qt;(function(r){r.Check="check"})(Qt||(Qt={}));var xe;(function(r){r[r.nothing=0]="nothing",r[r.RectBG=1]="RectBG",r[r.showOrder=2]="showOrder"})(xe||(xe={}));const bn={[D.Rect]:"\u62C9\u6846",[D.Tag]:"\u6807\u7B7E",[D.Point]:"\u6807\u70B9",[D.PointMarker]:"\u5217\u8868\u6807\u70B9",[D.Segmentation]:"\u524D\u666F\u5206\u5272",[D.Filter]:"\u7B5B\u9009",[D.Text]:"\u6587\u672C",[D.Polygon]:"\u591A\u8FB9\u5F62",[D.Line]:"\u7EBF\u6761",[D.LineMarker]:"\u5217\u8868\u7EBF\u6761",[D.FolderTag]:"\u6587\u4EF6\u5939\u6807\u7B7E",[D.RectTrack]:"\u62C9\u6846\u8DDF\u8E2A",[D.Face]:"\u4EBA\u8138106\u5DE5\u5177",[D.ClientAttribute]:"\u5BA2\u6237\u7AEF\u5C5E\u6027\u5DE5\u5177",[D.OCRRelation]:"OCR\u5173\u8054\u5173\u7CFB\u5DE5\u5177",[D.SegmentByRect]:"\u7B97\u6CD5\u5206\u5272\u8F85\u52A9\u5DE5\u5177",[Bt.VideoTextTool]:"\u89C6\u9891\u6587\u672C",[Bt.VideoTagTool]:"\u89C6\u9891\u6807\u7B7E",[Bt.VideoClipTool]:"\u89C6\u9891\u622A\u53D6",[Et.PointCloud]:"\u70B9\u4E91"};var we;(function(r){r[r.noDepend=1]="noDepend",r[r.dependOrigin=2]="dependOrigin",r[r.dependShape=3]="dependShape",r[r.dependLine=4]="dependLine",r[r.dependPolygon=5]="dependPolygon",r[r.dependPreShape=101]="dependPreShape",r[r.dependPreLine=102]="dependPreLine",r[r.dependPrePolygon=103]="dependPrePolygon"})(we||(we={}));var Rt;(function(r){r.lc="leftClick",r.rc="rightClick",r.clc="ctrlLeftClick",r.crc="ctrlRightClick"})(Rt||(Rt={}));const xn={leftClick:"\u9F20\u6807\u5DE6\u952E",rightClick:"\u9F20\u6807\u53F3\u952E",ctrlLeftClick:"ctrl + \u9F20\u6807\u5DE6\u952E",ctrlRightClick:"ctrl + \u9F20\u6807\u53F3\u952E"};var Pe;(function(r){r[r.Normal=1]="Normal",r[r.Modify=2]="Modify"})(Pe||(Pe={}));var k;(function(r){r[r.Line=0]="Line",r[r.Curve=1]="Curve"})(k||(k={}));var te;(function(r){r[r.SingleColor=0]="SingleColor",r[r.MultiColor=1]="MultiColor"})(te||(te={}));var Ie;(function(r){r[r.Form=1]="Form",r[r.Json=2]="Json"})(Ie||(Ie={}));var G;(function(r){r[r.Point=0]="Point",r[r.Line=1]="Line",r[r.Plane=2]="Plane"})(G||(G={}));var Le;(function(r){r[r.None=0]="None",r[r.Drawing=1]="Drawing",r[r.Edit=2]="Edit"})(Le||(Le={}));var Ce;(function(r){r[r.Backward=0]="Backward",r[r.Forward=1]="Forward",r[r.JumpSkip=2]="JumpSkip",r[r.None=3]="None"})(Ce||(Ce={}));var De;(function(r){r[r.Wait=0]="Wait",r[r.Pass=1]="Pass",r[r.Fail=2]="Fail",r[r.Loading=3]="Loading"})(De||(De={}));var Q;(function(r){r[r.AnyString=0]="AnyString",r[r.Order=1]="Order",r[r.EnglishOnly=2]="EnglishOnly",r[r.NumberOnly=3]="NumberOnly",r[r.CustomFormat=4]="CustomFormat"})(Q||(Q={}));const wn={0:"\u4EFB\u610F\u5B57\u7B26",1:"\u5E8F\u53F7",2:"\u4EC5\u82F1\u6587",3:"\u4EC5\u6570\u5B57"},_e=1e3,vi=16,mi=300,ee="normal normal 500 14px Arial";var Re;(function(r){r[r.ImgList=1e3]="ImgList",r[r.TrackPrediction=1001]="TrackPrediction",r[r.ImgSearch=1002]="ImgSearch"})(Re||(Re={}));const Pn={[Et.PointCloud]:"sensebeepc",[D.ClientAttribute]:"sensebeepc-EnumAttributeTool",[D.Face]:"sensebeepc-FacePointsLabellingTool",[D.OCRRelation]:"sensebeepc-OCRRelationTool"},In={[Et.PointCloud]:"\u70B9\u4E91\u5BA2\u6237\u7AEF",[D.ClientAttribute]:"\u5BA2\u6237\u7AEF\u5C5E\u6027\u5DE5\u5177",[D.Face]:"\u4EBA\u8138106\u70B9\u5DE5\u5177",[D.OCRRelation]:"OCR\u5173\u8054\u5173\u7CFB\u5DE5\u5177"},tt=16,Nt=10;var et;(function(r){r[r.Normal=0]="Normal",r[r.Rect=1]="Rect"})(et||(et={}));var Ln=Object.freeze({__proto__:null,editStepWidth:yn,get EPointCloudName(){return Et},get EVideoToolName(){return Bt},get EToolType(){return be},get EToolName(){return D},get ECheckModel(){return Qt},get ERectPattern(){return xe},TOOL_NAME:bn,get EDependPattern(){return we},get EFilterToolOperation(){return Rt},OPERATION_LIST:xn,get EAnnotationMode(){return Pe},get ELineTypes(){return k},get ELineColor(){return te},get ESelectedType(){return Ie},get EDragTarget(){return G},get EDrawPointPattern(){return Le},get EPageOperator(){return Ce},get EAuditStatus(){return De},get ETextType(){return Q},TEXT_TYPE:wn,TEXT_ATTRIBUTE_MAX_LENGTH:_e,TEXT_ATTRIBUTE_LINE_HEIGHT:vi,DEFAULT_TEXT_MAX_WIDTH:mi,DEFAULT_FONT:ee,get EThumbnailOption(){return Re},CLIENT_TOOL_HEAD_TYPE:Pn,CLIENT_TOOL_NAME:In,SEGMENT_NUMBER:tt,edgeAdsorptionScope:Nt,get EPolygonPattern(){return et}}),Cn=Object.defineProperty,Dn=Object.defineProperties,_n=Object.getOwnPropertyDescriptors,yi=Object.getOwnPropertySymbols,Rn=Object.prototype.hasOwnProperty,An=Object.prototype.propertyIsEnumerable,bi=(r,t,e)=>t in r?Cn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Tn=(r,t)=>{for(var e in t||(t={}))Rn.call(t,e)&&bi(r,e,t[e]);if(yi)for(var e of yi(t))An.call(t,e)&&bi(r,e,t[e]);return r},Sn=(r,t)=>Dn(r,_n(t));function Ae(r,t=.5,e=!1,i=16){if(r.length<4)return r;const s=[],n=r.slice(0);let o,a,l,h,c,u,d,g,p,f,v,y,b;for(e?(n.unshift(r[r.length-1]),n.unshift(r[r.length-2]),n.unshift(r[r.length-1]),n.unshift(r[r.length-2]),n.push(r[0]),n.push(r[1])):(n.unshift(r[1]),n.unshift(r[0]),n.push(r[r.length-2]),n.push(r[r.length-1])),b=2;b<n.length-4;b+=2)for(l=(n[b+2]-n[b-2])*t,h=(n[b+4]-n[b-0])*t,c=(n[b+3]-n[b-1])*t,u=(n[b+5]-n[b+1])*t,y=0;y<=i;y++)v=y/i,d=2*Math.pow(v,3)-3*Math.pow(v,2)+1,g=-(2*Math.pow(v,3))+3*Math.pow(v,2),p=Math.pow(v,3)-2*Math.pow(v,2)+v,f=Math.pow(v,3)-Math.pow(v,2),o=d*n[b]+g*n[b+2]+p*l+f*h,a=d*n[b+1]+g*n[b+3]+p*c+f*u,s.push(o),s.push(a);const w=[];for(let A=0;A<s.length-1;A+=2)w.push({x:s[A],y:s[A+1]});if(e)for(let A=0;A<i+1;A++){const P=w.shift();w.push(P)}return w}const ie=(r,t=16)=>Ae(r.reduce((e,i)=>[...e,i.x,i.y],[]),.5,!1,t);function Ut(r,t,e=k.Line){let i=0,s,n,o,a;t=[...t],e===k.Curve&&(t=Ae(t.reduce((h,c)=>[...h,c.x,c.y],[]),.5,!0,tt)),[o]=t;const l=t.length;for(s=1;s<=l;s++)a=t[s%l],r.x>Math.min(o.x,a.x)&&r.x<=Math.max(o.x,a.x)&&r.y<=Math.max(o.y,a.y)&&o.x!==a.x&&(n=(r.x-o.x)*(a.y-o.y)/(a.x-o.x)+o.y,(o.y===a.y||r.y<=n)&&i++),o=a;return i%2!=0}function xi(r,t=1){return r.map(e=>Sn(Tn({},e),{x:e.x*t,y:e.y*t}))}var wi=Math.pow;class Ht{static add(t,e){return{x:t.x+e.x,y:t.y+e.y}}static getVector(t,e){return{x:e.x-t.x,y:e.y-t.y}}static len(t){return Math.sqrt(wi(t.x,2)+wi(t.y,2))}static dotProduct(t,e){return t.x*e.x+t.y+e.y}}class Pi{static tanAPlusB(t,e){return(t+e)/(1-t*e)}static sinAPlusB(t,e,i,s){return s*t+e*i}static cosAPlusB(t,e,i,s){return e*s-t*i}}const Ft=class{static getRotate(r){return r+90>=360?r+90-360:r+90}static getLineLength(r,t){return Math.sqrt(Math.pow(t.y-r.y,2)+Math.pow(t.x-r.x,2))}static getTextArea(r,t,e=mi,i=ee,s){if(typeof t!="string")return{width:0,height:0};const n=r.getContext("2d");n.font=i;let o=0;typeof s=="undefined"&&(s=r&&parseInt(window.getComputedStyle(r).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=r&&parseInt(window.getComputedStyle(r).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,l=t.split(`
6
+ `);let h=0;for(let c=0;c<l.length;c++){const u=l[c].split("");let d="";for(let g=0;g<u.length;g++){const p=d+u[g],v=n.measureText(p).width;v>e&&g>0?(d=u[g],o+=s,h=e):(d=p,v>h&&(h=v))}c!==l.length-1&&(o+=s)}return{width:h,height:o+a,lineHeight:s,fontHeight:a}}static getLineCenterPoint(r){const[t,e]=r,i=Ht.getVector(t,e);return{x:t.x+i.x/2,y:t.y+i.y/2}}static getPerpendicularLine(r){if(r.length!==2)return;const[t,e]=r,i={x:e.x+e.y-t.y,y:e.y-(e.x-t.x)};return[e,i]}static getPerpendicularFootOfLine(r,t){if(r.length!==2)return r;const e=this.getPerpendicularLine(r);if(!e)return r;const[i,s]=e;return this.getFootOfPerpendicular(t,i,s).footPoint}static getQuadrangleFromTriangle(r){if(r.length!==3)return r;const[t,e,i]=r,s={x:i.x+t.x-e.x,y:i.y+t.y-e.y};return[t,e,i,s]}static getRectPerpendicularOffset(r,t,e){const[i,s]=e,n=this.getFootOfPerpendicular(r,i,s).footPoint,o=this.getFootOfPerpendicular(t,i,s).footPoint,a={x:n.x-o.x,y:n.y-o.y},l=Ht.add(t,a);return Ht.getVector(r,l)}static getArrayIndex(r,t){return r<0?t+r:r>=t?r-t:r}static getPointListFromPointOffset(r,t,e){const i=this.getArrayIndex(t-1,r.length),s=this.getArrayIndex(t+1,r.length),n=this.getArrayIndex(t-2,r.length),o=[...r];o[t]=Ht.add(o[t],e);const a=this.getFootOfPerpendicular(o[t],o[n],o[i]).footPoint,l=this.getFootOfPerpendicular(o[t],o[s],o[n]).footPoint;return o[i]=a,o[s]=l,o}static getRectCenterPoint(r){const[t,,e]=r;return{x:(t.x+e.x)/2,y:(t.y+e.y)/2}}static rotateRectPointList(r=5,t){const e=this.getRectCenterPoint(t),{PI:i}=Math,s=Math.sin(r*i/180),n=Math.cos(r*i/180);return t.map(o=>{const a=Ht.getVector(e,o),l=Ht.len(a),h=a.y/l,c=a.x/l;return{x:l*Pi.cosAPlusB(h,c,s,n)+e.x,y:l*Pi.sinAPlusB(h,c,s,n)+e.y}})}static getRectangleByRightAngle(r,t){if(t.length!==2)return t;const e=Ft.getPerpendicularFootOfLine(t,r);return Ft.getQuadrangleFromTriangle([...t,e])}static getRadiusFromQuadrangle(r){const[,t,e]=r,i=e.y-t.y,s=t.x-e.x,n=this.getLineLength(t,e),o=i/n,a=Math.acos(o);return s>0?-a:a}};let _=Ft;_.isInRange=(r,t)=>{const e=Math.min(...t),i=Math.max(...t),s=o=>o<=i&&o>=e;return(Array.isArray(r)?r:[r]).every(o=>s(o))},_.withinRange=(r,t)=>{const e=Math.min(...t),i=Math.max(...t);return r>i?i:r<e?e:r},_.calcViewportBoundaries=(r,t=!1,e=tt,i=1)=>{if(!r)return{top:0,bottom:0,left:0,right:0};const s=20/i,n=[],o=[];let a=r;t&&(a=ie(r,e)),a.forEach(({x:p,y:f})=>{n.push(p),o.push(f)});let l=Math.min(...n),h=Math.max(...n),c=Math.min(...o),u=Math.max(...o);const d=h-l,g=u-c;if(d<s){const p=(s-d)/2;l-=p,h+=p}if(g<s){const p=(s-g)/2;c-=p,u+=p}return{top:c,bottom:u,left:l,right:h}},_.getFootOfPerpendicular=(r,t,e,i=!1)=>{let s={x:0,y:0};const n=t.x-e.x,o=t.y-e.y;if(Math.abs(n)<1e-8&&Math.abs(o)<1e-8)return s=t,s;let a=(r.x-t.x)*(t.x-e.x)+(r.y-t.y)*(t.y-e.y);a/=n*n+o*o,s.x=t.x+a*n,s.y=t.y+a*o;const l=Ft.getLineLength(r,s),h=2,c=Math.min(t.x,e.x),u=Math.max(t.x,e.x),d=Math.min(t.y,e.y),g=Math.max(t.y,e.y),p=!(Ft.isInRange(r.x,[c,u])||Ft.isInRange(r.y,[d,g])),f=r.x>u+h||r.x<c-h||r.y>g+h||r.y<d-h;return(i?p:f)?{footPoint:s,length:Infinity}:{footPoint:s,length:l}};const On=61,kn=40,Mn=40,En=240;var Vt;(function(r){r[r.ANNOTATION=1]="ANNOTATION",r[r.QUALITY_INSPECTION=2]="QUALITY_INSPECTION",r[r.PRE_ANNOTATION=3]="PRE_ANNOTATION",r[r.MANUAL_CORRECTION=4]="MANUAL_CORRECTION"})(Vt||(Vt={}));const Bn=1e3;var Te;(function(r){r[r.Backward=0]="Backward",r[r.Forward=1]="Forward",r[r.JumpSkip=2]="JumpSkip",r[r.None=3]="None"})(Te||(Te={}));var E;(function(r){r[r.Start=0]="Start",r[r.Stop=1]="Stop",r[r.Wait=2]="Wait",r[r.Move=3]="Move"})(E||(E={}));var ct;(function(r){r[r.Point=0]="Point",r[r.Line=1]="Line",r[r.Plane=2]="Plane"})(ct||(ct={}));var q;(function(r){r[r.ascend=0]="ascend",r[r.descend=1]="descend"})(q||(q={}));var zt;(function(r){r[r.Intelligence=0]="Intelligence",r[r.Linear=1]="Linear"})(zt||(zt={}));var Pt;(function(r){r.Zh="zh_CN",r.US="en_US"})(Pt||(Pt={}));var jt;(function(r){r[r.Clockwise=0]="Clockwise",r[r.Anticlockwise=1]="Anticlockwise"})(jt||(jt={}));const rt={offsetX:-10,offsetY:-10},At={shadowColor:"rgba(0,0,0,0.6)",shadowOffsetX:0,shadowOffsetY:2,shadowBlur:4},Tt={x:8,y:26};var Nn=Object.freeze({__proto__:null,headerHeight:On,tipsHeight:kn,footerHeight:Mn,sidebarWidth:En,get EStepType(){return Vt},ANNOTATION_MAX_SIZE:Bn,get EPageOperator(){return Te},get EDragStatus(){return E},get EDragTarget(){return ct},get ESortDirection(){return q},get EGrowthMode(){return zt},get ELang(){return Pt},get ERotateDirection(){return jt},DEFAULT_TEXT_OFFSET:rt,DEFAULT_TEXT_SHADOW:At,TEXT_ATTRIBUTE_OFFSET:Tt}),Hn=Object.defineProperty,Fn=Object.defineProperties,zn=Object.getOwnPropertyDescriptors,Ii=Object.getOwnPropertySymbols,$n=Object.prototype.hasOwnProperty,Zn=Object.prototype.propertyIsEnumerable,Li=(r,t,e)=>t in r?Hn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ci=(r,t)=>{for(var e in t||(t={}))$n.call(t,e)&&Li(r,e,t[e]);if(Ii)for(var e of Ii(t))Zn.call(t,e)&&Li(r,e,t[e]);return r},Un=(r,t)=>Fn(r,zn(t));class x{static getStepInfo(t,e){return e==null?void 0:e.filter(i=>i.step===t)[0]}static getCurrentStepInfo(t,e){const i=this.getStepInfo(t,e);return i&&(i.type===Vt.QUALITY_INSPECTION||i.type===Vt.MANUAL_CORRECTION)?this.getCurrentStepInfo(i.dataSourceStep,e):i}static getMaxOrder(t){let e=0;return t.forEach(i=>{i.order&&i.order>e&&(e=i.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:i,type:s}=e;if(!i||!s)return!0;let n=!0;return(e.isContentEditable||i==="TEXTAREA"||(i==="INPUT"&&s!=="radio"||i==="TEXTAREA")&&!e.readOnly)&&(n=!1),n}static getNextSelectedRectID(t,e=q.ascend,i){let s=1;e===q.descend&&(s=-1);const n=t.sort((l,h)=>l.x-h.x==0?l.y-h.y:s*(l.x-h.x)),o=n.findIndex(l=>l.id===i),a=n.length;return n[(o+1)%a]}static getNextSelectedRectIDByEvent(t,e,i){const s=e.shiftKey?q.descend:q.ascend;return this.getNextSelectedRectID(t,s,i)}static getRenderResultList(t,e,i=[],s){let n;return[t.filter(a=>s&&s===(a==null?void 0:a.id)?(n=a,!1):!(i.length>0&&!i.includes(a==null?void 0:a.attribute)||this.isDifferSourceID(a==null?void 0:a.sourceID,e))),n]}static getSourceID(t){var e;const i="";return t&&(e=t==null?void 0:t.id)!=null?e:i}static findAllLine(t,e=!0){const i=[],s=[...t];s.length>=3&&e===!0&&s.push(Ci({},s[0]));for(let n=0;n<s.length;n++)s[n+1]&&i.push({point1:s[n],point2:s[n+1],pointIndex:n});return i}static translateSourceID(t){return(t===void 0||t===0||t==="0")&&(t=""),t}static isDifferSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`!=`${e}`}static isSameSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`==`${e}`}static getNextMarker(t,e=[],i){if((e==null?void 0:e.length)===0)return;let s=e.map((n,o)=>Un(Ci({},n),{index:o}));if(typeof i=="number"&&i>0){const n=e[i];if(n&&t.every(o=>o.label!==n.value))return{label:n.value,index:i};s=[...s.slice(i,e.length),...s.slice(0,i)]}for(let n=0;n<s.length;n++)if(!t.some(o=>o.label===s[n].value))return{label:s[n].value,index:s[n].index}}static getCurrentMarkerIndex(t,e=[]){return e.findIndex(i=>t===i.value)}}x.jsonParser=(r,t={})=>{try{return typeof r=="string"?JSON.parse(r):hn(r)?r:t}catch(e){return t}};var Vn=Object.defineProperty,jn=Object.defineProperties,Wn=Object.getOwnPropertyDescriptors,Di=Object.getOwnPropertySymbols,Xn=Object.prototype.hasOwnProperty,Yn=Object.prototype.propertyIsEnumerable,_i=(r,t,e)=>t in r?Vn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ri=(r,t)=>{for(var e in t||(t={}))Xn.call(t,e)&&_i(r,e,t[e]);if(Di)for(var e of Di(t))Yn.call(t,e)&&_i(r,e,t[e]);return r},Ai=(r,t)=>jn(r,Wn(t)),Ti;(function(r){r[r.Create=0]="Create",r[r.Active=1]="Active",r[r.Edit=1]="Edit",r[r.None=2]="None"})(Ti||(Ti={}));var Si;(function(r){r.ActiveArea="#B3B8FF"})(Si||(Si={}));const Oi=16,Kn=3,X=class{static isInLine(r,t,e,i=3){const{length:s}=_.getFootOfPerpendicular(r,t,e);return s<i}};let B=X;B.setSpecialEdgeStyle=r=>{r.lineCap="butt",r.setLineDash([10,10])},B.setReferenceCtx=r=>{r.lineCap="butt",r.setLineDash([6])},B.calcOptimalIntersection=(r,t,e,i,s)=>{let n,o=Infinity,a;if(r.find((h,c)=>{if(c===0)return;const u=X.isInLine(t.pointA,h,r[c-1]),d=X.isInLine(t.pointB,h,r[c-1]);return u&&d}))return{point:e};if(r.forEach((h,c)=>{if(c===0)return;const u={pointA:r[c-1],pointB:h},d=X.lineIntersection(t,u);if(d&&t){const{onLine2:g,onLine1:p,x:f,y:v}=d,y=X.calcDistance(e,d);if(X.isOnLine(t.pointB.x,t.pointB.y,h.x,h.y,r[c-1].x,r[c-1].y)){if(X.calcDistance(e,d)<i/s){const A=t.pointB,{footPoint:P,length:N}=_.getFootOfPerpendicular(A,u.pointA,u.pointB,!0);if(N!==void 0){const z=X.calcDistance(u.pointA,P),H=X.calcDistance(u.pointB,P);a={point:P,minDistance:N},N===Infinity&&(a.point=z>H?u.pointB:u.pointA)}}return}y<o&&g&&p&&(o=y,n={x:f,y:v})}}),n)return{point:n,minDistance:o};if(a)return a},B.lineIntersection=(r,t)=>{let e=!1,i=!1;const s=X.getAxisDiff(r),n=X.getAxisDiff(t),o=n.y*s.x-n.x*s.y;if(o===0)return!1;let a=r.pointA.y-t.pointA.y,l=r.pointA.x-t.pointA.x;const h=(t.pointB.x-t.pointA.x)*a-(t.pointB.y-t.pointA.y)*l,c=(r.pointB.x-r.pointA.x)*a-(r.pointB.y-r.pointA.y)*l;a=h/o,l=c/o,a>0&&a<1&&(e=!0),l>0&&l<1&&(i=!0);const u=r.pointA.x+a*(r.pointB.x-r.pointA.x),d=r.pointA.y+a*(r.pointB.y-r.pointA.y);return{x:u,y:d,onLine1:e,onLine2:i}},B.getAxisDiff=r=>({x:r.pointB.x-r.pointA.x,y:r.pointB.y-r.pointA.y}),B.calcDistance=(r,t)=>Math.sqrt(Math.pow(Math.abs(r.x-t.x),2)+Math.pow(Math.abs(r.y-t.y),2)),B.drawCurveLine=(r,t,e,i=!0,s=!1,n)=>{const o=ie(t,Oi);r.save(),r.lineCap="round",r.lineJoin="round",r.strokeStyle=e.color,i&&(r.lineWidth=e.lineWidth),s&&X.setReferenceCtx(r),t.forEach((a,l)=>{const h=a==null?void 0:a.specialEdge,c=o.splice(0,Oi+1);r.save(),r.beginPath(),n===l&&(r.lineWidth=4),c.forEach(({x:u,y:d},g)=>{const p=g>0?"lineTo":"moveTo";h&&X.setSpecialEdgeStyle(r),r[p](u,d)}),r.stroke(),r.restore()}),r.restore()},B.calcTwoPointDistance=(r,t)=>Math.sqrt(Math.pow(r.x-t.x,2)+Math.pow(r.y-t.y,2)),B.pointOverTarget=(r,t,e,i,s,n,o,a,l,h)=>{const c=r;if(!t)return r;if(e===D.Polygon){const u=X.getPolygonPointList(i,s);if(u.length===0||S.isInPolygon(r,u))return c;const g=u.concat(u[0]).map(b=>l(b)),p=l(t),f=l(r),v={pointA:p,pointB:f},y=X.calcOptimalIntersection(g,v,p,o,a);if(y){const b=h(y==null?void 0:y.point);c.x=b.x,c.y=b.y}else return t;return c}if(e===D.Rect){const{x:u,y:d,width:g,height:p}=i;return c.x=_.withinRange(c.x,[u,u+g]),c.y=_.withinRange(c.y,[d,d+p]),c}return c.x=_.withinRange(c.x,[0,n.width]),c.y=_.withinRange(c.y,[0,n.height]),c},B.getPolygonPointList=(r,t)=>{const{pointList:e}=r,{lineType:i}=t;return i===k.Line?e:S.createSmoothCurvePoints(e.reduce((s,n)=>[...s,n.x,n.y],[]),.5,!0,20)},B.isOnLine=(r,t,e,i,s,n)=>Math.abs((a=>(i-t)/(e-r)*(a-r)+t)(s)-n)<1e-6&&s>=r&&s<=e,B.inArea=({top:r,left:t,right:e,bottom:i},{x:s,y:n})=>n>=r&&n<=i&&s>=t&&s<=e,B.getVHPoint=(r,t,e,i)=>{const s=X.getAngle(r,e);return Math.abs(s)<45?Ai(Ri({},t),{y:i.y}):Ai(Ri({},t),{x:i.x})},B.getAngle=(r,t)=>{const e=t.x-r.x,i=t.y-r.y;return 360*Math.atan(i/e)/(2*Math.PI)};var Gn=Object.defineProperty,ki=Object.getOwnPropertySymbols,Jn=Object.prototype.hasOwnProperty,qn=Object.prototype.propertyIsEnumerable,Mi=(r,t,e)=>t in r?Gn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Se=(r,t)=>{for(var e in t||(t={}))Jn.call(t,e)&&Mi(r,e,t[e]);if(ki)for(var e of ki(t))qn.call(t,e)&&Mi(r,e,t[e]);return r};class S{static getHoverPolygonID(t,e,i=3,s=k.Line){let n="",o=Infinity;const a=I.axisArea(t,i);return e.forEach(l=>{l.pointList&&a.forEach(h=>{const c=this.calcPolygonSize(l.pointList);this.isInPolygon(h,l.pointList,s)&&c<o&&(n=l.id,o=c)})}),n}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,i=t.reduce((s,n,o,a)=>{const l=a[(o+1)%e];return s+n.x*l.y-l.x*n.y},0);return Math.abs(i)/2}static isInPolygon(t,e,i=k.Line){let s=0,n,o,a,l;e=[...e],i===k.Curve&&(e=this.createSmoothCurvePoints(e.reduce((c,u)=>[...c,u.x,u.y],[]),.5,!0,20)),[a]=e;const h=e.length;for(n=1;n<=h;n++)l=e[n%h],t.x>Math.min(a.x,l.x)&&t.x<=Math.max(a.x,l.x)&&t.y<=Math.max(a.y,l.y)&&a.x!==l.x&&(o=(t.x-a.x)*(l.y-a.y)/(l.x-a.x)+a.y,(a.y===l.y||t.y<=o)&&s++),a=l;return s%2!=0}static createSmoothCurvePointsFromPointList(t,e=tt){return this.createSmoothCurvePoints(t.reduce((s,n)=>[...s,n.x,n.y],[]),.5,!1,e).map((s,n)=>{var o;const a=n/(tt+1),l=Math.floor(a),h=(o=t[l])!=null?o:{};return Se(l===a?Se({},h):{specialEdge:h.specialEdge},s)})}static createSmoothCurvePoints(t,e=.5,i=!1,s=tt){if(t.length<4)return t;const n=[],o=t.slice(0);let a,l,h,c,u,d,g,p,f,v,y,b,w;for(i?(o.unshift(t[t.length-1]),o.unshift(t[t.length-2]),o.unshift(t[t.length-1]),o.unshift(t[t.length-2]),o.push(t[0]),o.push(t[1])):(o.unshift(t[1]),o.unshift(t[0]),o.push(t[t.length-2]),o.push(t[t.length-1])),w=2;w<o.length-4;w+=2)for(h=(o[w+2]-o[w-2])*e,c=(o[w+4]-o[w-0])*e,u=(o[w+3]-o[w-1])*e,d=(o[w+5]-o[w+1])*e,b=0;b<=s;b++)y=b/s,g=2*Math.pow(y,3)-3*Math.pow(y,2)+1,p=-(2*Math.pow(y,3))+3*Math.pow(y,2),f=Math.pow(y,3)-2*Math.pow(y,2)+y,v=Math.pow(y,3)-Math.pow(y,2),a=g*o[w]+p*o[w+2]+f*h+v*c,l=g*o[w+1]+p*o[w+3]+f*u+v*d,n.push(a),n.push(l);const A=[];for(let P=0;P<n.length-1;P+=2)A.push({x:n[P],y:n[P+1]});if(i)for(let P=0;P<s+1;P++){const N=A.shift();A.push(N)}return A}static getPolygonByID(t,e){return t.find(i=>i.id===e)}static getPolygonByIDs(t,e){if(e&&(e==null?void 0:e.length)>0)return t.filter(i=>e.includes(i.id))}static getHoverEdgeIndex(t,e,i=k.Line,s=3){let n=[...e];i===k.Curve?n=this.createSmoothCurvePoints(e.reduce((l,h)=>[...l,h.x,h.y],[]),.5,!0,tt):i===k.Line&&n.push(n[0]);let o=-1,a=s;for(let l=0;l<n.length-1;l++){const{length:h}=_.getFootOfPerpendicular(t,n[l],n[l+1]);h<a&&(o=l,a=h)}return o===-1?-1:i===k.Curve?Math.floor(o/tt):o}static getClosestPoint(t,e,i=k.Line,s=3,n){var o;let a=!1;const l=(o=n==null?void 0:n.isClose)!=null?o:!0;let h="",c=-1,u=Infinity,d=t;const g=20;let p=!1;return e.forEach(f=>{if(!p&&!!f.pointList)switch(i){case k.Line:x.findAllLine(f.pointList,l).forEach((y,b)=>{if(p)return;let{length:w,footPoint:A}=_.getFootOfPerpendicular(t,y.point1,y.point2);const P=_.getLineLength(y.point1,t),N=_.getLineLength(y.point2,t);P<s*2&&(A=y.point1,w=P,p=!0),N<s*2&&(A=y.point2,w=N,p=!0),w<u&&w<s&&(h=f.id,c=b,u=w,d=A,a=!0)});break;case k.Curve:{const v=this.createSmoothCurvePoints(f.pointList.reduce((y,b)=>[...y,b.x,b.y],[]),.5,l,g);for(let y=0;y<v.length-1;y++){const{length:b,footPoint:w}=_.getFootOfPerpendicular(t,v[y],v[y+1]);b<u&&b<s&&(h=f.id,c=Math.floor(y/(g+1)),u=b,d=w,a=!0)}}break}}),{dropFoot:d,closestEdgeIndex:c,closestPolygonID:h,hasClosed:a}}static isPointListInPolygon(t,e,i=k.Line){return t.every(s=>this.isInPolygon(s,e,i))}static isPointListOutSidePolygon(t,e,i=k.Line){return t.some(s=>!this.isInPolygon(s,e,i))}static getPolygonArea(t){let e=0;for(let i=0,s=t.length;i<s;i++){const n=t[i].x,o=t[i===t.length-1?0:i+1].y,a=t[i===t.length-1?0:i+1].x,l=t[i].y;e+=n*o*.5,e-=a*l*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,i){let s=1;return t===jt.Anticlockwise&&(s=-1),s*=e,_.rotateRectPointList(s,i)}static deletePolygonLastPoint(t,e,i,s){return i===s.length-1?t:[...t,{x:e[0],y:e[1]}]}static concatBeginAndEnd(t){return t.length<1?t:[...t,t[0]]}static segmentPolygonByPolygon(t,e){var i,s;try{let n=Jt([[...S.concatBeginAndEnd(t.map(a=>[a.x,a.y]))]]);return e.forEach(a=>{const l=Jt([[...S.concatBeginAndEnd(a.pointList.map(c=>[c.x,c.y]))]]),h=an(n,l);h&&(n=h)}),((s=(i=n==null?void 0:n.geometry)==null?void 0:i.coordinates.map(a=>{var l;return((l=n==null?void 0:n.geometry)==null?void 0:l.type)==="MultiPolygon"?a[0].reduce(S.deletePolygonLastPoint,[]):a.reduce(S.deletePolygonLastPoint,[])}))!=null?s:[]).reduce((a,l)=>{const h=l.length,c=l.filter((u,d)=>{const g=(d+1)%h;return!I.getIsInScope(u,l[g],1)});return c.length<3?a:[...a,c]},[])}catch(n){console.error(n)}}static getPolygonPointList(t,e){const i=e.find(s=>s.id===t);return i&&i.pointList&&i.pointList.length>0?i.pointList:[]}static getWrapPolygonIndex(t,e){return e.findIndex(i=>S.isPointListInPolygon(t,i.pointList))}static clipPolygonFromWrapPolygon(t,e){const i=S.isPolygonClosewise(e),s=S.isPolygonClosewise(t),n=S.getClosePointDistanceFromPolygon(t[0],e),o=e[n];let a=[...e.slice(0,n),o,...t,t[0],...e.slice(n,e.length)];return i===s&&(a=[...e.slice(0,n),o,t[0],...t.reverse(),...e.slice(n,e.length)]),a}static isPolygonClosewise(t){const e=t.length;let i,s,n,o=0,a;if(e<3)return 0;for(i=0;i<e;i++)s=(i+1)%e,n=(i+2)%e,a=(t[s].x-t[i].x)*(t[n].y-t[s].y),a-=(t[s].y-t[i].y)*(t[n].x-t[s].x),a<0?o--:a>0&&o++;return o>0?1:o<0?-1:0}static getClosePointDistanceFromPolygon(t,e){let i=Number.MAX_SAFE_INTEGER,s=-1;return e.forEach((n,o)=>{const a=B.calcDistance(t,n);a<i&&(i=a,s=o)}),s}static combinePolygonWithPolygon(t,e){var i,s;try{const n=Jt([[...S.concatBeginAndEnd(t.pointList.map(c=>[c.x,c.y]))]]),o=Jt([[...S.concatBeginAndEnd(e.pointList.map(c=>[c.x,c.y]))]]),a=ln(n,o),l=[],h=t;if(((s=(i=a==null?void 0:a.geometry)==null?void 0:i.coordinates)==null?void 0:s.length)===1){l.push(e.id);const c=a==null?void 0:a.geometry.coordinates.map(u=>{var d;return((d=a==null?void 0:a.geometry)==null?void 0:d.type)==="MultiPolygon"?u[0].reduce(S.deletePolygonLastPoint,[]):u.reduce(S.deletePolygonLastPoint,[])})[0];h.pointList=c}return{newPolygon:h,unionList:l}}catch(n){console.error(n)}}}var Qn=Object.defineProperty,tr=Object.defineProperties,er=Object.getOwnPropertyDescriptors,Ei=Object.getOwnPropertySymbols,ir=Object.prototype.hasOwnProperty,sr=Object.prototype.propertyIsEnumerable,Bi=(r,t,e)=>t in r?Qn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Oe=(r,t)=>{for(var e in t||(t={}))ir.call(t,e)&&Bi(r,e,t[e]);if(Ei)for(var e of Ei(t))sr.call(t,e)&&Bi(r,e,t[e]);return r},ke=(r,t)=>tr(r,er(t));class I{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,s,n,o){return typeof s=="boolean"&&!s&&(n&&o?(t.x-e.x>(n.x+n.width)*o&&(t.x=(n.x+n.width)*o+e.x),t.x-e.x<n.x*o&&(t.x=n.x*o+e.x),t.y-e.y>(n.y+n.height)*o&&(t.y=(n.y+n.height)*o+e.y),t.y-e.y<n.y*o&&(t.y=n.y*o+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:s,height:n}=i,{x:o,y:a}=t;switch(e%360){case 90:return{x:n-a,y:o};case 180:return{x:s-o,y:n-a};case 270:return{x:a,y:s-o};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return ke(Oe({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return ke(Oe({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t.map(s=>this.changePointByZoom(s,e,i))}static axisArea(t,e=3){const{x:i,y:s}=t,n=[];for(let o=i-e;o<i+e;o+=e/3)for(let a=s-e;a<s+e;a+=e/3)n.push({x:o,y:a});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let s=-1;for(let n=0;n<e.length;n++){const o=e[n];this.getIsInScope(t,o,i)&&(s=n)}return s}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class nr{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===D.Polygon}get isDependRect(){return this.dependToolName===D.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:s,width:n,height:o}=e;return{x:_.withinRange(t.x,[i,i+n]),y:_.withinRange(t.y,[s,s+o])}}getPolygonPointList(t,e){return t===k.Curve?S.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const s=this.getRenderCoord(e),n=this.getRenderCoord(t),o={pointA:s,pointB:n};return B.calcOptimalIntersection(i,o,s,Kn,this.zoom)}coordInsidePolygon(t,e,i,s){const{pointList:n}=i,o=s==null?void 0:s.lineType;if(n.length===0)return t;const a=this.getPolygonPointList(o,n);if(S.isInPolygon(t,a))return t;const h=a.concat(a[0]).map(u=>this.getRenderCoord(u)),c=this.getIntersection(t,e,h);return c?this.getAbsCoord(c==null?void 0:c.point):t}coordInsideImage(t){return this.coordInsideRect(t,ke(Oe({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],a=[i,i+n];return _.isInRange(t.x,o)&&_.isInRange(t.y,a)}return _.isInRange(t.x,[0,this.basicImgInfo.width])&&_.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return S.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}var rr=Object.defineProperty,or=Object.defineProperties,ar=Object.getOwnPropertyDescriptors,Ni=Object.getOwnPropertySymbols,lr=Object.prototype.hasOwnProperty,hr=Object.prototype.propertyIsEnumerable,Hi=(r,t,e)=>t in r?rr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,It=(r,t)=>{for(var e in t||(t={}))lr.call(t,e)&&Hi(r,e,t[e]);if(Ni)for(var e of Ni(t))hr.call(t,e)&&Hi(r,e,t[e]);return r},Lt=(r,t)=>or(r,ar(t));class Y{static composeResult(t,e,i,s,n){try{const o=JSON.parse(t),a=x.getCurrentStepInfo(e,s),{dataSourceStep:l}=a,h=`step_${a.step}`;if(Object.assign(o,n),o[h]){const c=o[h];return c.result?(c.result=i,JSON.stringify(o)):JSON.stringify(Lt(It({},o),{[h]:Lt(It({},o[h]),{result:i})}))}return JSON.stringify(Lt(It({},o),{[h]:{dataSourceStep:l,toolName:a.tool,result:i}}))}catch(o){return t}}static changeCoordinateByRotate(t,e,i){const{x:s,y:n,width:o,height:a}=t,l=I.changeCoordinateByRotate({x:s,y:n},e,i);switch(e%360){case 90:return Lt(It({},t),{x:l.x-a,y:l.y,width:a,height:o});case 180:return Lt(It({},t),{x:l.x-o,y:l.y-a});case 270:return Lt(It({},t),{x:l.x,y:l.y-o,width:a,height:o});default:return t}}static translateRect2Points(t){const{x:e,y:i,width:s,height:n}=t;return[{x:e,y:i},{x:e+s,y:i},{x:e+s,y:i+n},{x:e,y:i+n}]}static translatePoints2Rect(t,e){if(t.length!==4)return;const{x:i,y:s}=t[0],n=t[1].x-t[0].x,o=t[2].y-t[1].y;return Lt(It({},e),{x:i,y:s,width:n,height:o})}static getRectPointList(t,e=1){return[{x:t.x*e,y:t.y*e},{x:(t.x+t.width)*e,y:t.y*e},{x:(t.x+t.width)*e,y:(t.y+t.height)*e},{x:t.x*e,y:(t.y+t.height)*e}]}static getRectEdgeList(t,e=1){const i=this.getRectPointList(t,e),s=i.length;return i.map((n,o)=>({begin:n,end:i[(o+1)%s]}))}static isInRect(t,e,i=0,s=1){return t.x>=e.x*s-i&&t.x<=(e.x+e.width)*s+i&&t.y>=e.y*s-i&&t.y<=(e.y+e.height)*s+i}static getRectUnderZoom(t,e=1){const{x:i,y:s,width:n,height:o}=t;return Lt(It({},t),{x:i*e,y:s*e,width:n*e,height:o*e})}static isRectNotInPolygon(t,e){return this.getRectPointList(t).some(s=>!Ut(s,e))}}var Me;(function(r){r[r.A=65]="A",r[r.B=66]="B",r[r.C=67]="C",r[r.D=68]="D",r[r.E=69]="E",r[r.F=70]="F",r[r.G=71]="G",r[r.H=72]="H",r[r.L=76]="L",r[r.R=82]="R",r[r.Z=90]="Z",r[r.W=87]="W",r[r.X=88]="X",r[r.Y=89]="Y",r[r.S=83]="S",r[r.Q=81]="Q",r[r.Delete=46]="Delete",r[r.F11=122]="F11",r[r.Space=32]="Space",r[r.Esc=27]="Esc",r[r.Left=37]="Left",r[r.Up=38]="Up",r[r.Right=39]="Right",r[r.Down=40]="Down",r[r.Enter=13]="Enter",r[r.Ctrl=17]="Ctrl",r[r.Alt=18]="Alt",r[r.Shift=16]="Shift",r[r.Tab=9]="Tab",r[r.BackSpace=8]="BackSpace"})(Me||(Me={}));var O=Me,cr=Object.freeze({__proto__:null,default:O}),R;(function(r){r.NoRotateNotice="noRotateNotice",r.RectErrorSizeNotice="rectErrorSizeNotice",r.TextCheckNumberErrorNotice="textCheckNumberErrorNotice",r.TextCheckEnglishErrorNotice="textCheckEnglishErrorNotice",r.TextCheckCustomErrorNotice="textCheckCustomErrorNotice",r.UpperLimitErrorNotice="UpperLimitErrorNotice",r.LowerLimitErrorNotice="LowerLimitErrorNotice",r.InvalidImage="InvalidImage",r.DisableDelete="DisableDelete",r.ClearPartialData="ClearPartialData",r.MarkerFinish="MarkerFinish",r.LowerLimitPoint="LowerLimitPoint",r.NoRotateInDependence="noRotateInDependence",r.UnableToReannotation="unableToReannotation",r.ForbiddenCreationOutsideBoundary="ForbiddenCreationOutsideBoundary",r.SuccessfulEdgeAdsorption="SuccessfulEdgeAdsorption"})(R||(R={}));const dr={[R.NoRotateNotice]:"This Image contains data and cannot be rotated",[R.RectErrorSizeNotice]:"The drawing frame size is smaller than the minimum drawing size",[R.TextCheckNumberErrorNotice]:"Please enter in number-only format",[R.TextCheckEnglishErrorNotice]:"Please enter in English only format",[R.TextCheckCustomErrorNotice]:"Please enter in the required format",[R.UpperLimitErrorNotice]:"The number of vertices is not more than",[R.LowerLimitErrorNotice]:"The number of vertices is not less than",[R.InvalidImage]:"Invalid image, please skip this image",[R.DisableDelete]:"Disable delete",[R.ClearPartialData]:"Clear partial data",[R.MarkerFinish]:"ListAnnotation is finished",[R.LowerLimitPoint]:"The maximum number of points has been reached",[R.NoRotateInDependence]:"Disallow rotation in dependent cases",[R.UnableToReannotation]:"Unabled to reannotation",[R.ForbiddenCreationOutsideBoundary]:"Fobid creation outside boundary",[R.SuccessfulEdgeAdsorption]:"Successful edge adsorption"},ur={[R.NoRotateNotice]:"\u672C\u56FE\u542B\u6709\u6570\u636E\uFF0C\u65E0\u6CD5\u8FDB\u884C\u65CB\u8F6C",[R.RectErrorSizeNotice]:"\u7ED8\u5236\u6846\u5C3A\u5BF8\u5C0F\u4E8E\u6700\u5C0F\u7ED8\u5236\u5C3A\u5BF8",[R.TextCheckNumberErrorNotice]:"\u8BF7\u6309\u4EC5\u6570\u5B57\u7684\u683C\u5F0F\u8F93\u5165",[R.TextCheckEnglishErrorNotice]:"\u8BF7\u6309\u4EC5\u82F1\u6587\u7684\u683C\u5F0F\u8F93\u5165",[R.TextCheckCustomErrorNotice]:"\u8BF7\u6309\u8981\u6C42\u7684\u683C\u5F0F\u8F93\u5165",[R.UpperLimitErrorNotice]:"\u9876\u70B9\u6570\u4E0D\u591A\u4E8E",[R.LowerLimitErrorNotice]:"\u9876\u70B9\u6570\u4E0D\u5C11\u4E8E",[R.InvalidImage]:"\u65E0\u6548\u56FE\u7247\uFF0C\u8BF7\u8DF3\u8FC7\u6B64\u56FE",[R.DisableDelete]:"\u8BE5\u6570\u636E\u7981\u6B62\u5220\u9664",[R.ClearPartialData]:"\u5B58\u5728\u90E8\u5206\u6570\u636E\u65E0\u6CD5\u6E05\u9664",[R.MarkerFinish]:"\u5217\u8868\u6807\u6CE8\u5DF2\u5B8C\u6210",[R.LowerLimitPoint]:"\u5DF2\u5230\u8FBE\u6807\u70B9\u6570\u91CF\u4E0A\u9650",[R.NoRotateInDependence]:"\u4F9D\u8D56\u60C5\u51B5\u4E0B\u65E0\u6CD5\u8FDB\u884C\u65CB\u8F6C",[R.UnableToReannotation]:"\u65E0\u6CD5\u8FDB\u884C\u7EED\u6807\u64CD\u4F5C",[R.ForbiddenCreationOutsideBoundary]:"\u8FB9\u754C\u5916\u7981\u6B62\u521B\u5EFA",[R.SuccessfulEdgeAdsorption]:"\u8FB9\u7F18\u5438\u9644\u6210\u529F"};class Z{}Z.getMessagesByLocale=(r,t)=>{switch(t){case Pt.US:return dr[r];case Pt.Zh:default:return ur[r]}};var Fi='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#ccc"/></g></g></svg>',gr='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#ff2323"/></g></g></svg>',fr='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#ffe232"/></g></g></svg>',pr='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#01ff30"/></g></g></svg>',vr='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#00ffea"/></g></g></svg>',mr='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#0282fa"/></g></g></svg>',yr='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#800cf9"/></g></g></svg>',br='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#ff88f7"/></g></g></svg>',xr='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#994217"/></g></g></svg>',wr='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#1f0bf9"/></g></g></svg>',Pr='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#3fe"/></g></g></svg>',Ir='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#33fe33"/></g></g></svg>',Lr='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#fdff37"/></g></g></svg>',Cr='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#f70efa"/></g></g></svg>',zi='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16"><defs><clipPath id="a"><path d="M0,0H16V-16H0Z" fill="none"/></clipPath><clipPath id="b"><path d="M13.75-2.937H2.25a.5.5,0,0,0-.5.5v.563a.125.125,0,0,0,.125.125h12.25a.125.125,0,0,0,.125-.125v-.562A.5.5,0,0,0,13.75-2.937ZM4.027-4.25a.632.632,0,0,0,.094-.008l2.628-.461a.153.153,0,0,0,.083-.044l6.623-6.623a.156.156,0,0,0,0-.22l-2.6-2.6a.155.155,0,0,0-.111-.045.155.155,0,0,0-.111.045L4.012-7.581a.159.159,0,0,0-.044.083L3.508-4.87a.524.524,0,0,0,.147.466.529.529,0,0,0,.372.155Z" fill="none"/></clipPath></defs><g transform="translate(0 16)"><g clip-path="url(#a)"><path d="M-5-21H21V5H-5Z" fill="rgba(0,0,0,0)"/></g><g clip-path="url(#b)"><path d="M-3.25-19.25h22.5V3.25H-3.25Z" fill="#f33"/></g></g></svg>';const $i=Fi,Dr=61,_r=80,Rr=62,Ar=20,Tr=55,Sr=55,Or=40,kr=80,Mr=240,Er=320,Br="rgba(102, 111, 255, 1)",$t=["rgba(128, 12, 249, 1)","rgba(0, 255, 48, 1)","rgba(255, 136, 247, 1)","rgba(255, 226, 50, 1)","rgba(153, 66, 23, 1)","rgba(2, 130, 250, 1)","rgba(255, 35, 35, 1)","rgba(0, 255, 234, 1)"],se=[Fi,yr,pr,br,fr,xr,mr,gr,vr],Zi={1:wr,3:Pr,5:Ir,7:Lr,9:Cr},Nr="rgba(255, 51, 51, 1)",Ee="rgba(204, 204, 204, 1)",Hr={[Rt.lc]:"rgba(153, 51, 255, 1)",[Rt.rc]:"rgba(51, 153, 255, 1)",[Rt.clc]:"rgba(46, 230, 46, 1)",[Rt.crc]:"rgba(255, 51, 51, 1)"};var Fr=Object.freeze({__proto__:null,HEADER_HEIGHT:Dr,TAB_HEIGHT:_r,SEARCH_HEIGHT:Rr,PADDING:Ar,TABLE_ROW_HEIGHT:Tr,PAGINATION_HEIGHT:Sr,TIPS_HEIGHT:Or,FOOTER_HEIGHT:kr,SIDERBAR_WIDTH:Mr,EDIT_STEP_WIDTH:Er,THEME_COLOR:Br,COLORS_ARRAY:$t,ICON_ARRAY:se,BASE_ICON:Zi,INVALID_COLOR:Nr,NULL_COLOR:Ee,NULL_ICON:$i,INVALID_ICON:zi,FILTER_TOOL_COLOR:Hr}),zr=Object.defineProperty,$r=Object.defineProperties,Zr=Object.getOwnPropertyDescriptors,Ui=Object.getOwnPropertySymbols,Ur=Object.prototype.hasOwnProperty,Vr=Object.prototype.propertyIsEnumerable,Vi=(r,t,e)=>t in r?zr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ji=(r,t)=>{for(var e in t||(t={}))Ur.call(t,e)&&Vi(r,e,t[e]);if(Ui)for(var e of Ui(t))Vr.call(t,e)&&Vi(r,e,t[e]);return r},Wi=(r,t)=>$r(r,Zr(t));const jr="^[0-9]+$",Wr="^[A-Za-z]+$";class M{static getAttributeIcon(t,e,i=!0){var s;const n=e.findIndex(l=>l.value===t);let o=(s=se[n%se.length])!=null?s:$i;i||(o=zi),o="";const a=new Image;return a.src=o,a}static checkString(t,e){let i="";switch(t){case Q.Order:case Q.NumberOnly:i=jr;break;case Q.EnglishOnly:i=Wr;break;case Q.CustomFormat:i=e;break}return i}static checkTextAttibute(t,e){if(t===void 0||t==="")return!0;try{return new RegExp(e).test(t)}catch(i){return!1}}static getAttributeShowText(t,e=[]){var i,s;try{const n=e.findIndex(o=>o.value===t);return(s=(i=e[n])==null?void 0:i.key)!=null?s:t}catch(n){return t}}static getAttributeIndex(t,e){try{const i=e.findIndex(s=>s.value===t);return i>=8?i%8:i}catch(i){return-1}}static getAttributeColor(t,e){try{const i=this.getAttributeIndex(t,e);return i===-1?Ee:$t[i%$t.length]}catch(i){return Ee}}static getTextAttribute(t,e){try{if(e===Q.Order){const i=t.map(n=>parseInt(n.textAttribute,10)).filter(n=>ve(n)&&n<Number.MAX_SAFE_INTEGER&&n>=0);return i.sort((n,o)=>n-o),`${(i.pop()||0)+1}`}return""}catch(i){return""}}static textChange(t,e,i){return i.map(s=>s.id===e?Wi(ji({},s),{textAttribute:t}):s)}static getErrorNotice(t,e){switch(t){case Q.Order:case Q.NumberOnly:return Z.getMessagesByLocale(R.TextCheckNumberErrorNotice,e);case Q.EnglishOnly:return Z.getMessagesByLocale(R.TextCheckEnglishErrorNotice,e);case Q.CustomFormat:return Z.getMessagesByLocale(R.TextCheckCustomErrorNotice,e);default:return""}}static textAttributeValidate(t,e,i){try{return new RegExp(this.checkString(t,e)).test(i)}catch(s){}}static checkTextAttribute(t,e,i,s){let n=!1;return i.forEach(o=>{(o==null?void 0:o.textAttribute)===void 0||(o==null?void 0:o.textAttribute)===""||(s?o.id===s:!0)&&!this.textAttributeValidate(t,e,o.textAttribute)&&(n=!0)}),!!n}static changeTextAttributeInLog(t,e){return t==null?void 0:t.map(i=>i==null?void 0:i.map(s=>{if((e==null?void 0:e.findIndex(n=>(n==null?void 0:n.id)===(s==null?void 0:s.id)))>-1){const n=e==null?void 0:e.find(o=>(o==null?void 0:o.id)===(s==null?void 0:s.id));return Wi(ji({},s),{textAttribute:n==null?void 0:n.textAttribute})}return s}))}static getTextIconSvg(t="",e,i=!1,s){if(i===!0){const n=(e==null?void 0:e.findIndex(o=>(o==null?void 0:o.value)===t))%$t.length+1;return se[n]}return s}static getAttributeByKeycode(t,e){var i;let s;return _.isInRange(t,[48,57])&&(s=t-48),_.isInRange(t,[96,105])&&(s=t-96),s===0?"":s?(i=e[s-1])==null?void 0:i.value:void 0}}class bt{static getMousePositionOnCanvasFromEvent(t,e){if(e&&t){const i=e.getBoundingClientRect();return{x:t.clientX-i.left,y:t.clientY-i.top}}return null}static getClientRect(t){if(t){const e=t.getBoundingClientRect();return{x:e.left,y:e.top,width:e.width,height:e.height}}return null}static getSize(t){if(t){const e=t.getBoundingClientRect();return{width:e.width,height:e.height}}return null}static inViewPort(t,e){return t?_.isInRange(t.x,[e.left,e.right])&&_.isInRange(t.y,[e.top,e.bottom]):!1}}bt.getViewPort=(r,t,e)=>{const{width:i,height:s}=r,{x:n,y:o}=t,a=(0-o)/e,l=(0-n)/e,h=a+s/e,c=l+i/e;return{top:a,bottom:h,left:l,right:c}},bt.getPixelRatio=r=>{if(!r||!window)return 1;const t=r.backingStorePixelRatio||r.webkitBackingStorePixelRatio||r.mozBackingStorePixelRatio||r.msBackingStorePixelRatio||r.oBackingStorePixelRatio||r.backingStorePixelRatio||1;return(window.devicePixelRatio||1)/t};class Wt{static deg2rad(t){return t*Math.PI/180}static rad2deg(t){return t*180/Math.PI}}var Xr=Object.defineProperty,Yr=Object.defineProperties,Kr=Object.getOwnPropertyDescriptors,Xi=Object.getOwnPropertySymbols,Gr=Object.prototype.hasOwnProperty,Jr=Object.prototype.propertyIsEnumerable,Yi=(r,t,e)=>t in r?Xr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,qr=(r,t)=>{for(var e in t||(t={}))Gr.call(t,e)&&Yi(r,e,t[e]);if(Xi)for(var e of Xi(t))Jr.call(t,e)&&Yi(r,e,t[e]);return r},Qr=(r,t)=>Yr(r,Kr(t));const to=1,eo={x:0,y:0},io=0,ut="";class L{static drawLine(t,e,i,s={}){const n=t.getContext("2d"),{color:o=ut,thickness:a=1,lineCap:l="round"}=s;n.save(),n.strokeStyle=o,n.lineWidth=a,n.lineCap=l,n.beginPath(),n.moveTo(e.x,e.y),n.lineTo(i.x+1,i.y+1),n.stroke(),n.restore()}static drawRect(t,e,i={}){const s=t.getContext("2d"),{color:n=ut,thickness:o=1,lineCap:a="round",hiddenText:l=!1,lineDash:h}=i;if(s.save(),s.strokeStyle=n,s.lineWidth=o,s.lineCap=a,Array.isArray(h)&&s.setLineDash(h),s.fillStyle=n,s.strokeRect(e.x,e.y,e.width,e.height),l===!1){let c="";if(e.attribute&&(c=`${c} ${e.attribute}`),this.drawText(t,{x:e.x,y:e.y-5},c),e.textAttribute){const d=`${~~e.width} * ${~~e.height}`.length*7,g=0,p=Math.max(20,e.width-d);this.drawText(t,{x:e.x,y:e.y+e.height+20+g},e.textAttribute,{textMaxWidth:p})}}s.restore()}static drawRectWithFill(t,e,i={}){const s=t.getContext("2d"),{color:n=ut}=i;s.save(),s.fillStyle=n,s.fillRect(e.x,e.y,e.width,e.height),s.restore()}static drawTagByDom(t,e,i){const s=t;if(!((e==null?void 0:e.length)>0))return;const n=document.createElement("div");return n.innerHTML=e,n.setAttribute("id",i),s==null||s.appendChild(n),n}static drawTag(t,e){var i;const s=t==null?void 0:t.parentNode,n=window.self.document.getElementById("tagToolTag");if(n&&s&&s.contains(n)&&(s==null||s.removeChild(n)),!((e==null?void 0:e.length)>0))return;const o=document.createElement("div");return o.innerHTML=(i=e.reduce((a,l)=>`${a}${l.keyName}: ${l.value.join(" \u3001 ")}
7
+ `,""))!=null?i:"",o.setAttribute("id","tagToolTag"),s==null||s.appendChild(o),o}static drawLineWithPointList(t,e,i={}){if(e.length<2)return;const s=t.getContext("2d"),{color:n=ut,thickness:o=1,lineCap:a="round",lineType:l=k.Line,lineDash:h,hoverEdgeIndex:c}=i;s.save(),(()=>{s.strokeStyle=n,s.lineWidth=o,s.lineCap=a,Array.isArray(h)?s.setLineDash(h):s.setLineDash([])})(),l===k.Curve?(c!==void 0&&c>-1&&e.push(e[0]),e=S.createSmoothCurvePointsFromPointList([...e],tt),c!==void 0&&c>-1&&(e=e.slice((tt+1)*c,(tt+1)*(c+1)))):c!==void 0&&c>-1&&(e=[...e,e[0]],e=e.slice(c,c+2));const d=[];s.beginPath(),s.moveTo(e[0].x,e[0].y);for(let f=0;f<e.length-1;f++)e[f].specialEdge&&d.push({i1:f,i2:f+1}),s.lineTo(e[f+1].x,e[f+1].y);s.stroke(),s.save(),s.lineWidth=o*.8,s.lineCap="butt",s.strokeStyle="white",s.setLineDash([3,3]),d.forEach(f=>{const v=e[f.i1],y=e[f.i2];s.beginPath(),s.moveTo(v.x,v.y),s.lineTo(y.x,y.y),s.stroke()}),s.restore();const g=4,p=2;return e.forEach(f=>{f.specialPoint&&(this.drawSpecialPoint(t,f,g+p,n),this.drawSpecialPoint(t,f,g,"white"))}),s.restore(),e}static drawCircle(t,e,i,s={}){const n=t.getContext("2d"),{startAngleDeg:o=0,endAngleDeg:a=360,thickness:l=1,color:h=ut,fill:c=ut}=s,u=Wt.deg2rad(o),d=Wt.deg2rad(a);n.save(),n.beginPath(),n.strokeStyle=h,n.fillStyle=c,n.lineWidth=l,n.arc(e.x,e.y,i,u,d,!1),n.stroke(),c&&n.fill(),n.closePath(),n.restore()}static drawCircleWithFill(t,e,i=3,s={}){const n=t.getContext("2d"),{color:o=ut}=s;n.save();const a=Wt.deg2rad(0),l=Wt.deg2rad(360);n.fillStyle=o,n.beginPath(),n.arc(e.x,e.y,i,a,l,!1),n.fill(),n.restore()}static drawSpecialPoint(t,e,i=6,s){const n=t.getContext("2d"),{x:o,y:a}=e;n.save(),n.beginPath(),n.fillStyle=s;const l=i*1.5,h=l*Math.sqrt(3)/2,c=l/2;n.moveTo(o,a-l),n.lineTo(o-h,a+c),n.lineTo(o+h,a+c),n.closePath(),n.fill(),n.restore()}static drawPolygon(t,e,i={}){const{isClose:s=!1,lineType:n=k.Line}=i;return s===!0&&(e=[...e,e[0]]),n===k.Curve&&(e=S.createSmoothCurvePointsFromPointList([...e])),this.drawLineWithPointList(t,e,Qr(qr({},i),{lineType:k.Line})),e}static drawPolygonWithFill(t,e,i={}){if(e.length<2)return;const s=t.getContext("2d"),{color:n=ut,lineType:o=k.Line}=i;s.save(),s.fillStyle=n,s.beginPath(),o===k.Curve&&(e=S.createSmoothCurvePointsFromPointList([...e,e[0]]));const[a,...l]=e;return s.moveTo(a.x,a.y),l.forEach(h=>{s.lineTo(h.x,h.y)}),s.fill(),s.restore(),e}static drawPolygonWithFillAndLine(t,e,i={}){const{strokeColor:s,fillColor:n,thickness:o,lineCap:a,isClose:l,lineType:h}=i,c=this.drawPolygon(t,e,{color:s,thickness:o,lineCap:a,isClose:l,lineType:h});return this.drawPolygonWithFill(t,e,{color:n,lineType:h}),c}static drawPolygonWithKeyPoint(t,e,i={}){const{pointColor:s="white",strokeColor:n}=i,o=this.drawPolygon(t,e,i);return o.forEach(a=>{this.drawCircleWithFill(t,a,4,{color:n}),this.drawCircleWithFill(t,a,3,{color:s})}),o}static drawSelectedPolygonWithFillAndLine(t,e,i={}){const{pointColor:s="white",strokeColor:n}=i,o=this.drawPolygonWithFillAndLine(t,e,i);return o.forEach(a=>{this.drawCircleWithFill(t,a,4,{color:n}),this.drawCircleWithFill(t,a,3,{color:s})}),o}static drawText(t,e,i,s={}){if(!i)return;const n=t.getContext("2d"),{color:o=ut,font:a=ee,shadowColor:l="",shadowBlur:h=0,shadowOffsetX:c=0,shadowOffsetY:u=0,textMaxWidth:d=164,offsetX:g=0,offsetY:p=0,textAlign:f="start",lineHeight:v}=s;n.save(),n.textAlign=f,n.fillStyle=o!=null?o:"white",n.font=a,n.shadowColor=l,n.shadowOffsetX=c,n.shadowOffsetY=u,n.shadowBlur=h,this.wrapText(t,`${i}`,e.x+g,e.y+p,d,v),n.restore()}static wrapText(t,e,i,s,n,o){if(typeof e!="string"||typeof i!="number"||typeof s!="number")return;const a=t.getContext("2d");typeof n=="undefined"&&(n=t&&t.width||300),typeof o=="undefined"&&(o=t&&parseInt(window.getComputedStyle(t).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const l=e.split(`
8
+ `);for(let h=0;h<l.length;h++){const c=l[h].split("");let u="";for(let d=0;d<c.length;d++){const g=u+c[d],f=a.measureText(g).width;n||(n=300),f>n&&d>0?(a.fillText(u,i,s),u=c[d],s+=o):u=g}a.fillText(u,i,s),s+=o}}static drawArrow(t,e,i,s={}){const{color:n=ut,thickness:o=1,lineCap:a="round",theta:l=30,headLen:h=10}=s,c=Math.atan2(e.y-i.y,e.x-i.x)*180/Math.PI,u=(c+l)*Math.PI/180,d=(c-l)*Math.PI/180,g=h*Math.cos(u),p=h*Math.sin(u),f=h*Math.cos(d),v=h*Math.sin(d);t.save(),t.strokeStyle=n,t.lineWidth=o,t.lineCap=a,t.beginPath(),t.moveTo(i.x+g,i.y+p),t.lineTo(i.x,i.y),t.lineTo(i.x+f,i.y+v),t.stroke(),t.restore()}static drawArrowByCanvas(t,e,i,s={}){const n=t.getContext("2d");this.drawArrow(n,e,i,s)}}L.drawImg=(r,t,e={})=>{const i=r.getContext("2d"),{zoom:s=to,currentPos:n=eo,rotate:o=io,imgAttribute:a}=e;switch(i.save(),o){case 0:i.translate(n.x,n.y);break;case 90:i.translate(n.x+t.height*s,n.y),i.rotate(90*Math.PI/180);break;case 180:i.translate(n.x+t.width*s,n.y+t.height*s),i.rotate(Math.PI);break;case 270:i.translate(n.x,n.y+t.width*s),i.rotate(270*Math.PI/180);break;default:i.translate(n.x,n.y);break}if(a){const{contrast:l,saturation:h,brightness:c}=a;i.filter=`saturate(${h+100}%) contrast(${l+100}%) brightness(${c+100}%)`}i.drawImage(t,0,0,t.width*s,t.height*s),i.restore()};class Be{static getMarkerShowText(t,e=[]){return M.getAttributeShowText(t,e)}}function it(r=8,t=62){const e="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),i=[];let s;if(t=t||e.length,r)for(s=0;s<r;s++)i[s]=e[0|Math.random()*t];else{let n;for(i[8]=i[13]=i[18]=i[23]="-",i[14]="4",s=0;s<36;s++)i[s]||(n=0|Math.random()*16,i[s]=e[s===19?n&3|8:n])}return i.join("")}const Ki={showConfirm:!1,skipWhileNoDependencies:!1,drawOutsideTarget:!1,copyBackwardResult:!1,minWidth:1,minHeight:1,isShowOrder:!1,filterData:["valid","invalid"],attributeConfigurable:!1,attributeList:[],textConfigurable:!1,textCheckType:0,customFormat:""},so={showConfirm:!1,skipWhileNoDependencies:!1,inputList:[{key:"\u7C7B\u522B1",value:"class1",isMulti:!1,subSelected:[{key:"\u9009\u98791",value:"option1",isDefault:!1},{key:"\u9009\u98792",value:"option1-2",isDefault:!1}]},{key:"\u7C7B\u522B2",value:"class-AH",isMulti:!0,subSelected:[{key:"\u9009\u98792-1",value:"option2-1",isDefault:!1},{key:"\u9009\u98792-2",value:"option2-2",isDefault:!1},{key:"\u9009\u98792-3",value:"option2-3",isDefault:!1}]},{key:"\u7C7B\u522B3",value:"class-0P",isMulti:!1,subSelected:[{key:"\u9009\u98793-1",value:"option3-1",isMulti:!1},{key:"\u9009\u98793-2",value:"option3-2",isDefault:!1},{key:"\u9009\u98793-3",value:"option3-3",isDefault:!1}]}]},no={lineType:0,lineColor:0,edgeAdsorption:!1,outOfTarget:!0,copyBackwardResult:!1,isShowOrder:!1,attributeConfigurable:!1,attributeList:[{key:"\u7C7B\u522B1",value:"\u7C7B\u522B1"},{key:"\u7C7B\u522Bao",value:"class-ao"},{key:"\u7C7B\u522BM1",value:"class-M1"},{key:"\u7C7B\u522BCm",value:"class-Cm"},{key:"\u7C7B\u522Bc3",value:"class-c3"},{key:"\u7C7B\u522Ba0",value:"class-a0"},{key:"\u7C7B\u522Bu7",value:"class-u7"},{key:"\u7C7B\u522BZb",value:"class-Zb"},{key:"\u7C7B\u522Bzi",value:"class-zi"}],textConfigurable:!1,textCheckType:2,customFormat:"",showConfirm:!1,lowerLimitPointNum:2,upperLimitPointNum:"",preReferenceStep:0,skipWhileNoDependencies:!1,filterData:["valid","invalid"]},ro={showConfirm:!1,skipWhileNoDependencies:!1,enableTextRecognition:!1,recognitionMode:"general",configList:[{label:"\u6587\u672C",key:"text",required:!1,default:"",maxLength:1e3}],filterData:["valid","invalid"]},oo={lineType:0,lineColor:0,lowerLimitPointNum:3,edgeAdsorption:!1,drawOutsideTarget:!1,copyBackwardResult:!1,isShowOrder:!1,attributeConfigurable:!1,attributeList:[],textConfigurable:!0,textCheckType:0,customFormat:""},Ne=r=>r==="lineTool"?no:r==="rectTool"?Ki:r==="tagTool"?so:r==="textTool"?ro:r==="polygonTool"?oo:Ki,He={toolColor:{1:{valid:{stroke:"rgba(0,0,255,0.50)",fill:"rgba(0,0,255,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.80)"},validSelected:{stroke:"rgba(0,15,255,1.00)",fill:"rgba(0,15,255,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,0.60)",fill:"rgba(255,0,0,0.24)"},validHover:{stroke:"rgba(0,15,255,0.80)",fill:"rgba(0,15,255,0.64)"},invalidHover:{stroke:"rgba(255,0,0,0.50)",fill:"rgba(255,0,0,0.40)"}},3:{valid:{stroke:"rgba(0,255,255,0.50)",fill:"rgba(0,255,255,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.80)"},validSelected:{stroke:"rgba(0,212,255,1.00)",fill:"rgba(0,212,255,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,0.60)",fill:"rgba(255,0,0,0.24)"},validHover:{stroke:"rgba(0,212,255,0.80)",fill:"rgba(0,212,255,0.64)"},invalidHover:{stroke:"rgba(255,0,0,0.50)",fill:"rgba(255,0,0,0.40)"}},5:{valid:{stroke:"rgba(0,255,0,0.50)",fill:"rgba(0,255,0,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.80)"},validSelected:{stroke:"rgba(149,255,1.00)",fill:"rgba(149,255,0,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,0.60)",fill:"rgba(255,0,0,0.24)"},validHover:{stroke:"rgba(149,255,0,0.80)",fill:"rgba(149,255,0,0.64)"},invalidHover:{stroke:"rgba(255,0,0,0.50)",fill:"rgba(255,0,0,0.40)"}},7:{valid:{stroke:"rgba(255,255,0,0.50)",fill:"rgba(255,255,0,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.80)"},validSelected:{stroke:"rgba(255,230,102,1.00)",fill:"rgba(255,213,0,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,0.60)",fill:"rgba(255,0,0,0.24)"},validHover:{stroke:"rgba(255,230,102,0.80)",fill:"rgba(255,230,102,0.64)"},invalidHover:{stroke:"rgba(255,0,0,0.50)",fill:"rgba(255,0,0,0.40)"}},9:{valid:{stroke:"rgba(255,0,255,0.50)",fill:"rgba(255,0,255,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.80)"},validSelected:{stroke:"rgba(230,102,255,1.00)",fill:"rgba(213,0,255,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,0.60)",fill:"rgba(255,0,0,0.24)"},validHover:{stroke:"rgba(230,102,255,0.80)",fill:"rgba(230,102,255,0.64)"},invalidHover:{stroke:"rgba(255,0,0,0.50)",fill:"rgba(255,0,0,0.40)"}}},attributeColor:[{valid:{stroke:"rgba(204,204,204,1.00)",fill:"rgba(204,204,204,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(204,204,204,1.00)",fill:"rgba(204,204,204,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(204,204,204,1.00)",fill:"rgba(204,204,204,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(153,51,255,1.00)",fill:"rgba(153,51,255,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(153,51,255,1.00)",fill:"rgba(153,51,255,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(153,51,255,1.00)",fill:"rgba(153,51,255,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(51,254,51,1.00)",fill:"rgba(51,254,51,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(51,254,51,1.00)",fill:"rgba(51,254,51,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(51,254,51,1.00)",fill:"rgba(51,254,51,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(255,51,255,1.00)",fill:"rgba(255,51,255,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(255,51,255,1.00)",fill:"rgba(255,51,255,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(255,51,255,1.00)",fill:"rgba(255,51,255,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(204,255,51,1.00)",fill:"rgba(204,255,51,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(204,255,51,1.00)",fill:"rgba(204,255,51,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(204,255,51,1.00)",fill:"rgba(204,255,51,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(51,153,255,1.00)",fill:"rgba(51,153,255,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(51,153,255,1.00)",fill:"rgba(51,153,255,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(51,153,255,1.00)",fill:"rgba(51,153,255,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(255,153,51,1.00)",fill:"rgba(255,153,51,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(255,153,51,1.00)",fill:"rgba(255,153,51,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(255,153,51,1.00)",fill:"rgba(255,153,51,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(51,255,238,1.00)",fill:"rgba(51,255,238,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(51,255,238,1.00)",fill:"rgba(51,255,238,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(51,255,238,1.00)",fill:"rgba(51,255,238,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}},{valid:{stroke:"rgba(255,221,51,1.00)",fill:"rgba(255,221,51,0.40)"},invalid:{stroke:"rgba(255,153,102,1.00)",fill:"rgba(255,153,102,0.40)"},validSelected:{stroke:"rgba(255,221,51,1.00)",fill:"rgba(255,221,51,0.80)"},invalidSelected:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"},validHover:{stroke:"rgba(255,221,51,1.00)",fill:"rgba(255,221,51,0.80)"},invalidHover:{stroke:"rgba(255,0,0,1.00)",fill:"rgba(255,0,0,0.80)"}}],lineColor:{1:"rgba(102, 111, 255, 1 )",3:"rgba(102, 230, 255, 1)",5:"rgba(191, 255, 102, 1)",7:"rgba(255, 230, 102, 1)",9:"rgba(230, 102, 255, 1)"},attributeLineColor:["rgba(204, 204, 204, 1)","rgba(153, 51, 255, 1)","rgba(51, 254, 51, 1)","rgba(255, 51, 255, 1)","rgba(204, 255, 51, 1)","rgba(51, 153, 255, 1)","rgba(255, 153, 51, 1)","rgba(51, 255, 238, 1)","rgba(255, 221, 51, 1)"],color:1,width:2,opacity:9};class Fe{constructor(t){this.record=[],this.recordIndex=-1,this.minRecordIndex=-1,this.emitHistoryChanged=()=>{this.historyChanged&&(this.constructor.name==="ActionsHistory"?!0:this.record.length>0)&&this.historyChanged(this.undoEnabled,this.redoEnabled)},this.historyChanged=t}get undoEnabled(){return this.recordIndex>this.minRecordIndex}get redoEnabled(){return this.recordIndex<this.record.length-1}pushHistory(t){if(this.recordIndex!==this.record.length-1){const e=this.record.slice(0,Math.min(this.recordIndex+1,this.record.length));this.record=e}this.record.push(j.cloneDeepWith(t)),this.recordIndex+=1,this.emitHistoryChanged()}updateHistory(t){this.record[this.recordIndex]=j.cloneDeep(t)}applyAttribute(t,e,i){t&&this.record.forEach(s=>{const n=s.find(o=>o.id===t);n&&(n[e]=i)})}undo(){if(this.undoEnabled)return this.recordIndex-=1,this.emitHistoryChanged(),j.cloneDeep(this.record[this.recordIndex])||[]}redo(){if(this.redoEnabled)return this.recordIndex+=1,this.emitHistoryChanged(),j.cloneDeep(this.record[this.recordIndex])}init(){this.record=[[]],this.recordIndex=0,this.emitHistoryChanged()}empty(){this.record=[],this.recordIndex=-1,this.emitHistoryChanged()}initRecord(t,e=!1){const i=t.length>0||e;this.record=i?[j.cloneDeep(t)]:[],this.minRecordIndex=i?0:-1,this.recordIndex=0}}class Gi{constructor(t,e){this.rcTime=0,this.mouseDownTime=0,this.onMouseDown=()=>{this.mouseDownTime=new Date().getTime()},this.dom=t,this.isDoubleClick=!1,this.delay=e}getRcTime(){return this.rcTime}getCoord(t){return{x:t.clientX,y:t.clientY}}removeEvent(){!this.dom||(this.dom.removeEventListener("mouseup",this.mouseUp),this.dom.removeEventListener("mousemove",this.mouseMove),this.dom.removeEventListener("dblclick",this.dblclick),this.dom.removeEventListener("mousedown",this.onMouseDown))}addEvent(t,e,i,s){!this.dom||(this.removeEvent(),this.mouseUp=n=>{const o=new Date().getTime(),a=s?s(n):!0;if(o-this.mouseDownTime>this.delay||a!==!0){t(n);return}if(n.button===2)if(this.rcTime===0)setTimeout(()=>{this.rcTime=0},this.delay),this.rcTime=o;else{o-this.rcTime<this.delay&&(i(n),clearTimeout(this.setTimeFun),this.cacheFunction=void 0),this.rcTime=0;return}this.setTimeFun&&clearTimeout(this.setTimeFun),this.clickCoord=this.getCoord(n),this.cacheFunction=()=>t(n),this.setTimeFun=setTimeout(()=>{if(this.isDoubleClick){this.isDoubleClick=!1;return}this.cacheFunction(),this.clickCoord=void 0},this.delay)},this.mouseMove=n=>{const o=this.getCoord(n);this.clickCoord&&!I.getIsInScope(o,this.clickCoord,10)&&(this.cacheFunction&&this.cacheFunction(),this.clickCoord=void 0,this.cacheFunction=null,clearTimeout(this.setTimeFun))},this.dblclick=n=>{this.isDoubleClick=!0,this.clickCoord=void 0,e(n)},this.dom.addEventListener("mouseup",this.mouseUp),this.dom.addEventListener("mousemove",this.mouseMove),this.dom.addEventListener("dblclick",this.dblclick),this.dom.addEventListener("mousedown",this.onMouseDown))}clearRightDblClick(){this.rcTime=0}}class Ji{static getInitImgPos(t,e,i=0,s=1,n=!1){(i===90||i===270)&&(e={width:e.height,height:e.width});const o=t.width*s/e.width,a=t.height*s/e.height;let l=n?1:Math.min(o,a);const h={x:(t.width-e.width*l)/2,y:(t.height-e.height*l)/2},c=e.width*l,u=e.height*l;return n&&(l=1),{zoom:l,currentPos:h,imgInfo:{width:c,height:u}}}static getBasicRecPos(t,e,i,s=.9,n=1,o=!1){if(e&&t){const{x:a,y:l,height:h,width:c}=e;let u=i.height/h;c/h>i.width/i.height&&(u=i.width/c);const d=o?1:u*s*n,g={x:i.width/2,y:i.height/2},p={x:(a+c/2)*d,y:(l+h/2)*d};return{currentPos:{x:g.x-p.x,y:g.y-p.y},innerZoom:d}}return!1}}class ao{static renderInvalidPage(t,e,i){const s=document.createElement("div");return s.setAttribute("style",`
9
9
  position: absolute;
10
10
  left: 0px;
11
11
  top: 0px;
@@ -20,8 +20,8 @@
20
20
  font-size: 30px;
21
21
  opacity: 0.7;
22
22
  z-index: 30;
23
- `),s.innerHTML=B.getMessagesByLocale(C.InvalidImage,i),t.appendChild(s),s}}const ct=[1,5,10,20,30,50,80,100].concat(Array.from({length:9}).map((r,t)=>(t+2)*100));class Bt{}Bt.zoomChanged=(r,t,e=It.Linear)=>{switch(e){case It.Intelligence:{const i=Math.max(...ct),s=Math.min(...ct),n=ct.slice(0,ct.length).findIndex((a,l)=>r>=a&&(r<ct[l+1]||a===i));let o;if(n===-1)r>=s&&r<=i?o=t?i:s:o=t?s:r;else{const a=t?n+1:n-(ct.includes(r)?1:0);o=ct[P.withinRange(a,[0,ct.length-1])]}return o}default:{const i=t?2:1/2;return r*i}}},Bt.wheelChangePos=(r,t,e,i,s={})=>{const{zoom:n=1,innerZoom:o=1,basicZoom:a=1,zoomMax:l=1e3,rotate:h=0}=s,{x:c,y:u}=i,d=parseFloat((n+1/10).toFixed(1))/5;if(r&&t){let{width:g,height:v}=r;[90,270].includes(h)&&(g=r.height,v=r.width);const f=g*o,b=v*o,p=t.x-c,y=t.y-u,w=p/f,D=y/b;let R=n+e*d;R=P.withinRange(R,[a,l]);const E=g*R*w,H=v*R*D,k=c+(p-E),W=u+(y-H);return{zoom:R,currentPos:{x:k,y:W},imgInfo:{width:g*R,height:v*R},ratio:d}}return null};class yr{constructor(){this._events=new Map}on(t,e){const i=this._events.get(t)||[];i.some(s=>s===e)||this._events.set(t,i.concat(e))}singleOn(t,e){this._events.set(t,[e])}emit(t,...e){const i=this._events.get(t);i&&i.forEach(s=>{s&&s(...e)})}unbind(t,e){const i=this._events.get(t);i&&this._events.set(t,i.filter(s=>s!==e))}unbindAll(t){this._events.delete(t)}}var xr=Object.defineProperty,mr=Object.defineProperties,Ir=Object.getOwnPropertyDescriptors,ei=Object.getOwnPropertySymbols,wr=Object.prototype.hasOwnProperty,Lr=Object.prototype.propertyIsEnumerable,ii=(r,t,e)=>t in r?xr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,si=(r,t)=>{for(var e in t||(t={}))wr.call(t,e)&&ii(r,e,t[e]);if(ei)for(var e of ei(t))Lr.call(t,e)&&ii(r,e,t[e]);return r},Pr=(r,t)=>mr(r,Ir(t)),Cr=(r,t,e)=>new Promise((i,s)=>{var n=l=>{try{a(e.next(l))}catch(h){s(h)}},o=l=>{try{a(e.throw(l))}catch(h){s(h)}},a=l=>l.done?i(l.value):Promise.resolve(l.value).then(n,o);a((e=e.apply(r,t)).next())});const Ft={min:.2,max:1e3,ratio:.4};class rt extends yr{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.initImgPos=()=>Cr(this,null,function*(){var u,d;if(!this.imgNode)return;const g=(u=this._imgAttribute)==null?void 0:u.zoomRatio,v=(d=this._imgAttribute)==null?void 0:d.isOriginalSize,{currentPos:f,imgInfo:b,zoom:p}=ti.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,g,v);this.setCurrentPos(f),this.currentPosStorage=f,this.imgInfo=b,this.setZoom(p),this.innerZoom=p,this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",p)}),this.getCurrentPos=u=>{const{_firstClickCoordinate:d,currentPosStorage:g}=this;try{let v;return d&&g?v={y:g.y+u.y-d.y,x:g.x+u.x-d.x}:v={x:0,y:0},v}catch(v){return console.error(v),{x:0,y:0}}},this.wheelChangePos=(u,d,g)=>{const{currentPos:v,imgNode:f}=this;if(!f){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&d===-1)return;const b=Bt.wheelChangePos(f,u,d,v,{zoom:g||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:Ft.max,rotate:this.rotate});if(!b)return;const{currentPos:p,ratio:y,zoom:w,imgInfo:D}=b;this.innerZoom=w,this.setZoom(w),this.setCurrentPos(p),this.currentPosStorage=p,this.imgInfo=D,Ft.ratio=y,this.emit("renderZoom",w,v)},this.zoomChanged=(u,d=It.Linear)=>{const g=Bt.zoomChanged(this.zoom,u,d);this.wheelChangePos(this.getGetCenterCoordinate(),g>this.zoom?1:-1,g),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||m.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute})};var e,i,s,n,o,a,l,h,c;this.container=t.container,this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size),this.imgNode=t.imgNode,this.isImgError=!t.imgNode,this.basicImgInfo={width:(i=(e=t.imgNode)==null?void 0:e.width)!=null?i:0,height:(n=(s=t.imgNode)==null?void 0:s.height)!=null?n:0,valid:!0,rotate:0},this.forbidOperation=(o=t.forbidOperation)!=null?o:!1,this.forbidBasicResultRender=(a=t.forbidBasicResultRender)!=null?a:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.style={strokeColor:wt[4],fillColor:wt[4],strokeWidth:2,opacity:1},this.attributeLockList=[],this.history=new ne,this.style=(l=t.style)!=null?l:{},this._imgAttribute=(h=t.imgAttribute)!=null?h:{},this.isHidden=!1,this.dragStatus=O.Wait,this.defaultAttribute=(c=t==null?void 0:t.defaultAttribute)!=null?c:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=at.Zh,this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new Qe(this.container,200),this.coordUtils=new ln(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo)}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?e:0}get valid(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?e:!0}get baseIcon(){return He[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}updatePosition(t){const{zoom:e,currentPos:i}=t;this.setZoom(e),this.setCurrentPos(i),this.currentPosStorage=i,this.innerZoom=e,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}get forbidMouseOperation(){return this.forbidOperation||this.valid===!1}get pixelRatio(){var t;return st.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}createCanvas(t){var e,i;const s=document.createElement("canvas"),n=this.pixelRatio;s.width=t.width*n,s.height=t.height*n,s.style.width=`${t.width}px`,s.style.height=`${t.height}px`,s.style.left="0",s.style.top="0",s.style.zIndex="0",this.basicCanvas=s;const o=document.createElement("canvas");o.style.position="absolute",o.style.left="0",o.style.top="0",o.style.zIndex="10",o.style.width=`${t.width}px`,o.style.height=`${t.height}px`,o.width=t.width*n,o.height=t.height*n,this.container.hasChildNodes()?(this.container.insertBefore(o,this.container.childNodes[0]),this.container.insertBefore(s,this.container.childNodes[0])):(this.container.appendChild(s),this.container.appendChild(o)),this.canvas=o,this.container.style.cursor=this.defaultCursor,(e=this.ctx)==null||e.scale(n,n),(i=this.basicCtx)==null||i.scale(n,n)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,e={}){this.imgNode=t,this.setBasicImgInfo(si({width:t.width,height:t.height,valid:!0,rotate:0},e)),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof e.valid=="boolean"&&this.setValid(e.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}getCoordinateUnderZoom(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left-this.currentPos.x,y:t.clientY-e.top-this.currentPos.y}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:e,imgNode:i,_imgAttribute:s,imgInfo:n,dependToolName:o}=this;if(t&&i&&o){let a=t;switch(o){case L.Polygon:case L.Line:{if(t.pointList){const h=P.calcViewportBoundaries(t.pointList);a={x:h.left,y:h.top,width:h.right-h.left,height:h.bottom-h.top}}break}}const l=ti.getBasicRecPos(i,a,e,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);l&&(this.setCurrentPos(l.currentPos),this.currentPosStorage=this.currentPos,this.imgInfo=Pr(si({},n),{width:n.width/this.innerZoom*l.innerZoom,height:n.height/this.innerZoom*l.innerZoom}),this.innerZoom=l.innerZoom,this.setZoom(l.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=e,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);this.isShowCursor&&(this.coord=e);try{if(!e||!Wt(e==null?void 0:e.x)||!Wt(e==null?void 0:e.y))throw new Error("coord error");if(this.coord=e,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const i=this.getCurrentPos(e);this.setCurrentPos(i),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:i,zoom:this.zoom})}this.render()}catch(i){console.error(i)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const e=new Date().getTime(),i=this.getCoordinate(t);if(e-this.startTime>1e3||this.isSpaceKey===!0||M.calcTwoPointDistance(i,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===A.Alt&&t.preventDefault(),t.keyCode){case A.Space:this.isSpaceKey=!0;break;case A.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case A.Space:this.isSpaceKey=!1;break}}onWheel(t,e=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const i=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let n=0;s>0&&this.zoom>Ft.min&&(n=-1),s<0&&this.zoom<Ft.max&&(n=1),this.wheelChangePos(i,n),this.emit("dependRender"),e&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(e=>(e=this.style.lineColor[0])!=null?e:"")()){if(!this.ctx||this.forbidCursorLine)return;const{x:e,y:i}=this.coord;m.drawLine(this.canvas,{x:0,y:i},{x:1e4,y:i},{color:t}),m.drawLine(this.canvas,{x:e,y:0},{x:e,y:1e4},{color:t}),m.drawCircleWithFill(this.canvas,{x:e,y:i},1,{color:"white"})}setSize(t){var e;this.size=t,this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((e=this.basicImgInfo)==null?void 0:e.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const e=this._imgAttribute;if(this._imgAttribute=t,(e==null?void 0:e.zoomRatio)!==t.zoomRatio||e.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,e){this.dependToolName=t,this.coordUtils.setDependInfo(t,e)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=x.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",B.getMessagesByLocale(C.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",B.getMessagesByLocale(C.NoRotateNotice,this.lang)),!1;const t=P.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",e=this.config){var i;if((e==null?void 0:e.attributeConfigurable)===!0&&this.style.attributeColor){const o=S.getAttributeIndex(t,(i=e.attributeList)!=null?i:[])+1;return this.style.attributeColor[o]}const{color:s,toolColor:n}=this.style;return n?n[s]:Ve.toolColor["1"]}getLineColor(t=""){var e,i,s;if(((e=this.config)==null?void 0:e.attributeConfigurable)===!0){const a=S.getAttributeIndex(t,(s=(i=this.config)==null?void 0:i.attributeList)!=null?s:[])+1;return this.style.attributeLineColor?this.style.attributeLineColor[a]:""}const{color:n,lineColor:o}=this.style;return n&&o?o[n]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=br.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case L.Rect:{m.drawRect(this.basicCanvas,I.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case L.Polygon:{m.drawPolygonWithFillAndLine(this.basicCanvas,I.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case L.Line:{m.drawLineWithPointList(this.basicCanvas,I.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}var Dr=Object.defineProperty,ri=Object.getOwnPropertySymbols,_r=Object.prototype.hasOwnProperty,Rr=Object.prototype.propertyIsEnumerable,ni=(r,t,e)=>t in r?Dr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,oi=(r,t)=>{for(var e in t||(t={}))_r.call(t,e)&&ni(r,e,t[e]);if(ri)for(var e of ri(t))Rr.call(t,e)&&ni(r,e,t[e]);return r};const ai={x:8,y:26},Ar=2;class Tr extends rt{constructor(t){super(t);this.getHoverRectID=e=>{var i,s;const n=this.getCoordinateUnderZoom(e),o=(s=(i=this.resultList.find(a=>a.toolName===L.Rect))==null?void 0:i.result)!=null?s:[];if(o.length>0){const a=o.filter(l=>Z.isInRect(n,l,Ar,this.zoom));if(a.length===0)return"";if(a.length===1)return a[0].id;if(a.length>1)return a.map(h=>({size:h.width*h.height,id:h.id})).sort((h,c)=>h.size-c.size)[0].id}return""},this.resultList=[],this.hoverID=[],this.fillID=[],this.render=this.render.bind(this),this.drawPolygon=this.drawPolygon.bind(this),this.drawRect=this.drawRect.bind(this),this.drawTag=this.drawTag.bind(this),this.setShowDefaultCursor(!0),this.forbidOperation=!0}onMouseDown(t){var e,i;if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const s=this.mouseHoverID,n=(i=(e=this.resultList.find(o=>o.toolName===L.Rect))==null?void 0:e.result)!=null?i:[];if(t.button===0){let o=[s],a=!0;s&&n.find(l=>l.id===s&&(l==null?void 0:l.isSelected))&&(a=!1),s||(o=n.map(l=>l.id),a=!1),this.emit("setSelectedID",o,a),this.render()}}updateRotate(){}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,i=this.getHoverRectID(t);if(e!==i){this.mouseHoverID=i;let s=[i];i||(s=[]),this.emit("setHoverID",s),this.render()}}setResult(t){this.resultList=Bi(t),this.render()}drawPolygon(t,e){t==null||t.forEach(i=>{var s,n,o,a,l;const h=this.getColor(i.attribute,e),c=et.getStrokeAndFill(h,i.valid);let u=(n=(s=this.style)==null?void 0:s.width)!=null?n:2;this.hoverID.includes(i.id)?(u=4,m.drawPolygonWithFillAndLine(this.canvas,I.changePointListByZoom(i.pointList,this.zoom,this.currentPos),{fillColor:c.fill,strokeColor:c.stroke,pointColor:"white",thickness:u,lineCap:"round",isClose:!0,lineType:e==null?void 0:e.lineType})):m.drawPolygon(this.canvas,I.changePointListByZoom(i.pointList,this.zoom,this.currentPos),{color:c.fill,lineType:(o=this.config)==null?void 0:o.lineType,thickness:u,isClose:!0});let d=`${(l=S.getAttributeShowText(i.attribute,(a=e==null?void 0:e.attributeList)!=null?a:[]))!=null?l:""}`;(e==null?void 0:e.isShowOrder)&&(i==null?void 0:i.order)>0&&(d=`${i.order} ${d}`),m.drawText(this.canvas,I.changePointByZoom(i.pointList[0],this.zoom,this.currentPos),d,oi({color:c.stroke},K));const g=I.changePointListByZoom(i.pointList||[],this.zoom,this.currentPos),v=g[g.length-1];m.drawText(this.canvas,{x:v.x+ai.x,y:v.y+ai.y},i==null?void 0:i.textAttribute,oi({color:c.stroke},K))})}drawRect(t,e){t==null||t.forEach(i=>{let s=1;this.hoverID.includes(i.id)&&(s=3);const n=this.getColor(i.attribute,e),o=I.changeRectByZoom(i,this.zoom,this.currentPos);m.drawRect(this.canvas,o,{color:(i==null?void 0:i.valid)?n.valid.stroke:n.invalid.stroke,thickness:s}),this.fillID.includes(i.id)&&m.drawRectWithFill(this.canvas,o,{color:(i==null?void 0:i.valid)?n.valid.fill:n.invalid.fill})})}drawTag(t,e){const i=t.reduce((s,n)=>[...s,...(e==null?void 0:e.inputList)?Rt.getTagNameList(n.result,e.inputList):Rt.getTagnameListWithoutConfig(n.result)],[]);m.drawTag(this.canvas,i)}setHoverID(t){this.hoverID=t,this.render()}setFillID(t){this.fillID=t,this.render()}render(){var t;super.render(),(t=this.resultList)==null||t.forEach(e=>{switch(e==null?void 0:e.toolName){case L.Rect:this.drawRect(e.result,x.jsonParser(e.config));break;case L.Polygon:this.drawPolygon(e.result,x.jsonParser(e.config));break;case L.Tag:this.drawTag(e.result,x.jsonParser(e.config));break}})}exportData(){return[[],{}]}}const oe=30,ae=164;class $t{constructor(t){this.textKeyDown=l=>{switch(l.stopPropagation(),l.keyCode){case A.Enter:this.submitTextarea(),this.appendToContainer();break}};const{container:e,icon:i,color:s,getCurrentSelectedData:n,updateSelectedTextAttribute:o}=t,a=t.width||ae;this.container=e,this.getCurrentSelectedData=n,this.updateSelectedTextAttribute=o,this._textAttributeDOM=this.initTextAttributeDOM(),this._iconDOM=this.initIconDOM(i),this._textDOM=this.initTextDOM(a,me),this._textareaDOM=this.initTextareaDOM(a,s),this.appendToContainer()}get isExit(){return this._textAttributeDOM?this.container.contains(this._textAttributeDOM):!1}get isExitTextareaDOM(){return this._textareaDOM?this.container.contains(this._textareaDOM):!1}updateIcon(t){this._iconDOM&&(this._iconDOM.innerHTML=t)}appendToContainer(){!this._textAttributeDOM||!this._textDOM||!this._iconDOM||(this.container.appendChild(this._textAttributeDOM),this._textAttributeDOM.appendChild(this._textDOM),this._textAttributeDOM.appendChild(this._iconDOM))}initTextAttributeDOM(){const t=document.createElement("div");return t.setAttribute("id","textArea"),t}initTextDOM(t,e){const i=document.createElement("span");return i.setAttribute("style",`
24
- width: ${Math.max(t,oe)}px;
23
+ `),s.innerHTML=Z.getMessagesByLocale(R.InvalidImage,i),t.appendChild(s),s}}const Ct=[1,5,10,20,30,50,80,100].concat(Array.from({length:9}).map((r,t)=>(t+2)*100));class ne{}ne.zoomChanged=(r,t,e=zt.Linear)=>{switch(e){case zt.Intelligence:{const i=Math.max(...Ct),s=Math.min(...Ct),n=Ct.slice(0,Ct.length).findIndex((a,l)=>r>=a&&(r<Ct[l+1]||a===i));let o;if(n===-1)r>=s&&r<=i?o=t?i:s:o=t?s:r;else{const a=t?n+1:n-(Ct.includes(r)?1:0);o=Ct[_.withinRange(a,[0,Ct.length-1])]}return o}default:{const i=t?2:1/2;return r*i}}},ne.wheelChangePos=(r,t,e,i,s={})=>{const{zoom:n=1,innerZoom:o=1,basicZoom:a=1,zoomMax:l=1e3,rotate:h=0}=s,{x:c,y:u}=i,d=parseFloat((n+1/10).toFixed(1))/5;if(r&&t){let{width:g,height:p}=r;[90,270].includes(h)&&(g=r.height,p=r.width);const f=g*o,v=p*o,y=t.x-c,b=t.y-u,w=y/f,A=b/v;let P=n+e*d;P=_.withinRange(P,[a,l]);const N=g*P*w,z=p*P*A,H=c+(y-N),F=u+(b-z);return{zoom:P,currentPos:{x:H,y:F},imgInfo:{width:g*P,height:p*P},ratio:d}}return null};class lo{constructor(){this._events=new Map}on(t,e){const i=this._events.get(t)||[];i.some(s=>s===e)||this._events.set(t,i.concat(e))}singleOn(t,e){this._events.set(t,[e])}emit(t,...e){const i=this._events.get(t);i&&i.forEach(s=>{s&&s(...e)})}unbind(t,e){const i=this._events.get(t);i&&this._events.set(t,i.filter(s=>s!==e))}unbindAll(t){this._events.delete(t)}}var ho=Object.defineProperty,co=Object.defineProperties,uo=Object.getOwnPropertyDescriptors,qi=Object.getOwnPropertySymbols,go=Object.prototype.hasOwnProperty,fo=Object.prototype.propertyIsEnumerable,Qi=(r,t,e)=>t in r?ho(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ts=(r,t)=>{for(var e in t||(t={}))go.call(t,e)&&Qi(r,e,t[e]);if(qi)for(var e of qi(t))fo.call(t,e)&&Qi(r,e,t[e]);return r},po=(r,t)=>co(r,uo(t)),vo=(r,t,e)=>new Promise((i,s)=>{var n=l=>{try{a(e.next(l))}catch(h){s(h)}},o=l=>{try{a(e.throw(l))}catch(h){s(h)}},a=l=>l.done?i(l.value):Promise.resolve(l.value).then(n,o);a((e=e.apply(r,t)).next())});const re={min:.2,max:1e3,ratio:.4};class gt extends lo{constructor(t){super();this.isDrag=!1,this.isSpaceKey=!1,this.innerZoom=1,this.basicZoom=.01,this.isSpaceClick=!1,this.isDragStart=!1,this.startTime=0,this.initImgPos=()=>vo(this,null,function*(){var u,d;if(!this.imgNode)return;const g=(u=this._imgAttribute)==null?void 0:u.zoomRatio,p=(d=this._imgAttribute)==null?void 0:d.isOriginalSize,{currentPos:f,imgInfo:v,zoom:y}=Ji.getInitImgPos(this.size,{width:this.imgNode.width,height:this.imgNode.height},this.rotate,g,p);this.setCurrentPos(f),this.currentPosStorage=f,this.setImgInfo(v),this.setZoom(y),this.render(),this.renderBasicCanvas(),this.emit("dependRender"),this.emit("renderZoom",y,f,v)}),this.getCurrentPos=u=>{const{_firstClickCoordinate:d,currentPosStorage:g}=this;try{let p;return d&&g?p={y:g.y+u.y-d.y,x:g.x+u.x-d.x}:p={x:0,y:0},p}catch(p){return console.error(p),{x:0,y:0}}},this.wheelChangePos=(u,d,g)=>{const{currentPos:p,imgNode:f}=this;if(!f){console.error("unable to load image");return}if(this.zoom===this.basicZoom&&d===-1)return;const v=ne.wheelChangePos(f,u,d,p,{zoom:g||this.zoom,innerZoom:this.innerZoom,basicZoom:this.basicZoom,zoomMax:re.max,rotate:this.rotate});if(!v)return;const{currentPos:y,ratio:b,zoom:w,imgInfo:A}=v;this.setZoom(w),this.setCurrentPos(y),this.currentPosStorage=y,this.setImgInfo(A),re.ratio=b,this.emit("renderZoom",w,y,A)},this.zoomChanged=(u,d=zt.Linear)=>{const g=ne.zoomChanged(this.zoom,u,d);this.wheelChangePos(this.getGetCenterCoordinate(),g>this.zoom?1:-1,g),this.render(),this.renderBasicCanvas()},this.zoomChangeOnCenter=u=>{this.wheelChangePos(this.getGetCenterCoordinate(),0,u),this.render(),this.renderBasicCanvas()},this.drawImg=()=>{!this.imgNode||this.hiddenImg===!0||L.drawImg(this.basicCanvas,this.imgNode,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate,imgAttribute:this._imgAttribute})};var e,i,s,n,o,a,l,h,c;this.container=t.container,this.showDefaultCursor=t.showDefaultCursor||!1,this.destroyCanvas(),this.createCanvas(t.size,t.isAppend),this.imgNode=t.imgNode,this.isImgError=!t.imgNode,this.basicImgInfo={width:(i=(e=t.imgNode)==null?void 0:e.width)!=null?i:0,height:(n=(s=t.imgNode)==null?void 0:s.height)!=null?n:0,valid:!0,rotate:0},this.forbidOperation=(o=t.forbidOperation)!=null?o:!1,this.forbidBasicResultRender=(a=t.forbidBasicResultRender)!=null?a:!1,this.size=t.size,this.currentPos={x:0,y:0},this.zoom=1,this.coord={x:-1,y:-1},this.currentPosStorage={x:0,y:0},this.isShowCursor=!1,this.style={strokeColor:$t[4],fillColor:$t[4],strokeWidth:2,opacity:1},this.attributeLockList=[],this.history=new Fe,this.style=(l=t.style)!=null?l:{},this._imgAttribute=(h=t.imgAttribute)!=null?h:{},this.isHidden=!1,this.dragStatus=E.Wait,this.defaultAttribute=(c=t==null?void 0:t.defaultAttribute)!=null?c:"",this.forbidCursorLine=!!t.forbidCursorLine,this.lang=Pt.Zh,this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseLeave=this.onMouseLeave.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onKeyDown=this.onKeyDown.bind(this),this.onKeyUp=this.onKeyUp.bind(this),this.onWheel=this.onWheel.bind(this),this.onLeftDblClick=this.onLeftDblClick.bind(this),this.onRightDblClick=this.onRightDblClick.bind(this),this.onClick=this.onClick.bind(this),this.clearImgDrag=this.clearImgDrag.bind(this),this.dblClickListener=new Gi(this.container,200),this.coordUtils=new nr(this),this.coordUtils.setBasicImgInfo(this.basicImgInfo),this.hiddenImg=t.hiddenImg||!1}onContextmenu(t){t.preventDefault()}get ctx(){var t;return this._ctx||((t=this.canvas)==null?void 0:t.getContext("2d"))}get basicCtx(){var t;return(t=this.basicCanvas)==null?void 0:t.getContext("2d")}get rotate(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.rotate)!=null?e:0}get valid(){var t,e;return(e=(t=this.basicImgInfo)==null?void 0:t.valid)!=null?e:!0}get baseIcon(){return Zi[this.style.color]}get defaultCursor(){return this.showDefaultCursor?"default":"none"}get dataList(){return[]}get hasMarkerConfig(){return this.config.markerConfigurable===!0&&this.config.markerList&&this.config.markerList.length>0}setZoom(t){this.zoom=t,this.innerZoom=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setCurrentPos(t){this.currentPos=t,this.coordUtils.setZoomAndCurrentPos(this.zoom,this.currentPos)}setReferenceData(t){this.referenceData=t}setImgInfo(t){this.imgInfo=t}updatePosition(t){const{zoom:e,currentPos:i}=t;this.setZoom(e),this.setCurrentPos(i),this.currentPosStorage=i,this.renderBasicCanvas(),this.render()}setLang(t){this.lang=t}setShowDefaultCursor(t){this.showDefaultCursor=t,this.container.style.cursor=this.defaultCursor}get forbidMouseOperation(){return!1}get pixelRatio(){var t;return bt.getPixelRatio((t=this.canvas)==null?void 0:t.getContext("2d"))}init(){this.eventUnbinding(),this.initPosition(),this.eventBinding(),this.render(),this.renderBasicCanvas()}destroy(){this.destroyCanvas(),this.eventUnbinding()}createCanvas(t,e=!0){var i,s;const n=document.createElement("canvas"),o=this.pixelRatio;n.width=t.width*o,n.height=t.height*o,n.style.width=`${t.width}px`,n.style.height=`${t.height}px`,n.style.left="0",n.style.top="0",n.style.zIndex="0",this.basicCanvas=n;const a=document.createElement("canvas");a.style.position="absolute",a.style.left="0",a.style.top="0",a.style.zIndex="10",a.style.width=`${t.width}px`,a.style.height=`${t.height}px`,a.width=t.width*o,a.height=t.height*o,e&&(this.container.hasChildNodes()?(this.container.insertBefore(a,this.container.childNodes[0]),this.container.insertBefore(n,this.container.childNodes[0])):(this.container.appendChild(n),this.container.appendChild(a))),this.canvas=a,this.container.style.cursor=this.defaultCursor,(i=this.ctx)==null||i.scale(o,o),(s=this.basicCtx)==null||s.scale(o,o)}destroyCanvas(){this.canvas&&this.container.contains(this.canvas)&&this.container.removeChild(this.canvas),this.basicCanvas&&this.container.contains(this.basicCanvas)&&this.container.removeChild(this.basicCanvas),this.clearInvalidPage(),this.clearImgDrag()}setStyle(t){this.style=t,this.render()}setImgNode(t,e={}){this.imgNode=t,this.setBasicImgInfo(ts({width:t.width,height:t.height,valid:!0,rotate:0},e)),this.isImgError===!0&&(this.isImgError=!1,this.emit("changeAnnotationShow")),typeof e.valid=="boolean"&&this.setValid(e.valid),this.initImgPos(),this.render(),this.renderBasicCanvas()}setErrorImg(){const t=this.isImgError;this.isImgError=!0,this.imgNode=void 0,this.setBasicImgInfo({width:0,height:0,valid:!0,rotate:0}),t===!1&&this.emit("changeAnnotationShow")}setBasicImgInfo(t){this.basicImgInfo=t,this.coordUtils.setBasicImgInfo(t)}setForbidOperation(t){this.forbidOperation=t,this.setShowDefaultCursor(!0),this.render()}setForbidCursorLine(t){this.forbidCursorLine=t,this.render()}setIsHidden(t){this.isHidden=t,this.emit("hiddenChange")}setIsShowOrder(t){this.config.isShowOrder=t,this.render()}getCoordinate(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}getCoordinateUnderZoom(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left-this.currentPos.x,y:t.clientY-e.top-this.currentPos.y}}getGetCenterCoordinate(){return{x:this.size.width/2,y:this.size.height/2}}initPosition(){if(this.basicResult&&this.imgInfo){const{basicResult:t,size:e,imgNode:i,_imgAttribute:s,imgInfo:n,dependToolName:o}=this;if(t&&i&&o){let a=t;switch(o){case D.Polygon:case D.Line:{if(t.pointList){const h=_.calcViewportBoundaries(t.pointList);a={x:h.left,y:h.top,width:h.right-h.left,height:h.bottom-h.top}}break}}const l=Ji.getBasicRecPos(i,a,e,void 0,s==null?void 0:s.zoomRatio,s==null?void 0:s.isOriginalSize);l&&(this.setCurrentPos(l.currentPos),this.currentPosStorage=this.currentPos,this.setImgInfo(po(ts({},n),{width:n.width/this.innerZoom*l.innerZoom,height:n.height/this.innerZoom*l.innerZoom})),this.setZoom(l.innerZoom),this.render(),this.renderBasicCanvas())}}else this.initImgPos()}undo(){this.history.undo()}redo(){this.history.redo()}clearCanvas(){var t;(t=this.ctx)==null||t.clearRect(0,0,this.size.width,this.size.height)}clearBasicCanvas(){var t;(t=this.basicCtx)==null||t.clearRect(0,0,this.size.width,this.size.height)}eventBinding(){this.dblClickListener.addEvent(()=>{},this.onLeftDblClick,this.onRightDblClick),this.container.addEventListener("mousedown",this.onMouseDown),this.container.addEventListener("mousemove",this.onMouseMove),this.container.addEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseleave",this.onMouseLeave),this.container.addEventListener("click",this.onClick),this.container.addEventListener("wheel",this.onWheel),document.addEventListener("keydown",this.onKeyDown),document.addEventListener("keyup",this.onKeyUp),window.parent.document.addEventListener("contextmenu",this.onContextmenu,!1)}eventUnbinding(){this.container.removeEventListener("mousedown",this.onMouseDown),this.container.removeEventListener("mousemove",this.onMouseMove),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.removeEventListener("mouseleave",this.onMouseLeave),this.container.removeEventListener("wheel",this.onWheel),this.container.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeyDown),document.removeEventListener("keyup",this.onKeyUp),window.parent.document.removeEventListener("contextmenu",this.onContextmenu,!1),this.dblClickListener.removeEvent()}clearImgDrag(){this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime=0,this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1}clearCursorLine(){this.coord={x:-1,y:-1}}onMouseDown(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);(this.isSpaceKey&&t.button===0||t.button===2)&&(t.stopPropagation(),this._firstClickCoordinate=e,this.currentPosStorage=this.currentPos,this.isSpaceClick=!0,this.isDragStart=!0,this.startTime=new Date().getTime())}onMouseMove(t){if(!this.canvas||this.isImgError)return!0;const e=this.getCoordinate(t);this.isShowCursor&&(this.coord=e);try{if(!e||!ve(e==null?void 0:e.x)||!ve(e==null?void 0:e.y))throw new Error("coord error");if(this.coord=e,(this.isSpaceClick||this.isDragStart)&&this._firstClickCoordinate){const i=this.getCurrentPos(e);this.setCurrentPos(i),this.isDrag=!0,this.container.style.cursor="grabbing",this.forbidCursorLine=!0,this.renderBasicCanvas(),this.emit("dependRender"),this.emit("dragMove",{currentPos:i,zoom:this.zoom,imgInfo:this.imgInfo})}this.render()}catch(i){console.error(i)}}onMouseUp(t){if(!this.canvas||this.isImgError)return!0;if(this.container.style.cursor=this.defaultCursor,this.forbidCursorLine=!1,this.isDrag=!1,this.isDragStart=!1,this.isSpaceClick=!1,this.startTime!==0&&this._firstClickCoordinate){const e=new Date().getTime(),i=this.getCoordinate(t);if(e-this.startTime>1e3||this.isSpaceKey===!0||B.calcTwoPointDistance(i,this._firstClickCoordinate)>10)return t.stopPropagation(),this.startTime=0,this.render(),!0}this.startTime=0,this.render()}onMouseLeave(){this.clearImgDrag()}onClick(t){}onLeftDblClick(t){}onRightDblClick(t){this.clearImgDrag()}onKeyDown(t){switch(t.keyCode===O.Alt&&t.preventDefault(),t.keyCode){case O.Space:this.isSpaceKey=!0;break;case O.Z:if(t.ctrlKey)return t.shiftKey?this.redo():this.undo(),!1;break}return!0}onKeyUp(t){switch(t.keyCode){case O.Space:this.isSpaceKey=!1;break}}exportCustomData(){return{}}onWheel(t,e=!0){if(!this.imgNode||!this.coord)return;t.preventDefault(),t.stopPropagation();const i=this.getCoordinate(t),s=t.deltaY||t.wheelDelta;let n=0;s>0&&this.zoom>re.min&&(n=-1),s<0&&this.zoom<re.max&&(n=1),this.wheelChangePos(i,n),this.emit("dependRender"),e&&this.render(),this.renderBasicCanvas()}renderCursorLine(t=(e=>(e=this.style.lineColor[0])!=null?e:"")()){if(!this.ctx||this.forbidCursorLine||this.forbidOperation)return;const{x:e,y:i}=this.coord;L.drawLine(this.canvas,{x:0,y:i},{x:1e4,y:i},{color:t}),L.drawLine(this.canvas,{x:e,y:0},{x:e,y:1e4},{color:t}),L.drawCircleWithFill(this.canvas,{x:e,y:i},1,{color:"white"})}setSize(t){var e;this.size=t,this.container.contains(this.canvas)&&(this.destroyCanvas(),this.createCanvas(t),this.eventUnbinding(),this.init(),((e=this.basicImgInfo)==null?void 0:e.valid)===!1&&this.renderInvalidPage())}setImgAttribute(t){const e=this._imgAttribute;if(this._imgAttribute=t,(e==null?void 0:e.zoomRatio)!==t.zoomRatio||e.isOriginalSize!==t.isOriginalSize){this.initImgPos();return}this.renderBasicCanvas(),this.render()}clearResult(t){}setValid(t){this.basicImgInfo.valid=t,t===!1?(this.renderInvalidPage(),this.clearResult(!1)):this.clearInvalidPage()}setRotate(t){this.basicImgInfo.rotate=t}setBasicResult(t){this.basicResult=t,this.coordUtils.setBasicResult(t),this.initPosition(),this.emit("dependRender")}setDependName(t,e){this.dependToolName=t,this.coordUtils.setDependInfo(t,e)}setAttributeLockList(t){this.attributeLockList=t,this.render()}setConfig(t){this.config=x.jsonParser(t)}setDataInjectionAtCreation(t){this.dataInjectionAtCreation=t}setRenderEnhance(t){this.renderEnhance=t}setCustomRenderStyle(t){this.customRenderStyle=t}updateRotate(){if(this.dependToolName)return this.emit("messageInfo",Z.getMessagesByLocale(R.NoRotateInDependence,this.lang)),!1;if(this.dataList.length>0)return this.emit("messageInfo",Z.getMessagesByLocale(R.NoRotateNotice,this.lang)),!1;const t=_.getRotate(this.basicImgInfo.rotate);this.basicImgInfo.rotate=t,this.initImgPos(),this.emit("updateResult")}getColor(t="",e=this.config){var i;if((e==null?void 0:e.attributeConfigurable)===!0&&this.style.attributeColor){const o=M.getAttributeIndex(t,(i=e.attributeList)!=null?i:[])+1;return this.style.attributeColor[o]}const{color:s,toolColor:n}=this.style;return n?n[s]:He.toolColor["1"]}getLineColor(t=""){var e,i,s;if(((e=this.config)==null?void 0:e.attributeConfigurable)===!0){const a=M.getAttributeIndex(t,(s=(i=this.config)==null?void 0:i.attributeList)!=null?s:[])+1;return this.style.attributeLineColor?this.style.attributeLineColor[a]:""}const{color:n,lineColor:o}=this.style;return n&&o?o[n]:""}clearInvalidPage(){this._invalidDOM&&this.container&&this.container.contains(this._invalidDOM)&&(this.container.removeChild(this._invalidDOM),this._invalidDOM=void 0)}renderInvalidPage(){!this.container||this._invalidDOM||(this._invalidDOM=ao.renderInvalidPage(this.container,this.size,this.lang))}renderBasicCanvas(){if(!this.basicCanvas)return;this.clearBasicCanvas(),this.drawImg();const t=3;if(!this.forbidBasicResultRender&&this.basicResult&&this.dependToolName)switch(this.dependToolName){case D.Rect:{L.drawRect(this.basicCanvas,I.changeRectByZoom(this.basicResult,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}case D.Polygon:{L.drawPolygonWithFillAndLine(this.basicCanvas,I.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{fillColor:"transparent",strokeColor:"rgba(204,204,204,1.00)",isClose:!0,thickness:t});break}case D.Line:{L.drawLineWithPointList(this.basicCanvas,I.changePointListByZoom(this.basicResult.pointList,this.zoom,this.currentPos),{color:"rgba(204,204,204,1.00)",thickness:t});break}}}render(){!this.canvas||!this.ctx||!this.imgNode||this.clearCanvas()}changeStyle(t=this.defaultAttribute){this.emit("changeStyle",{attribute:t})}}const ze=30,$e=164;class oe{constructor(t){this.textKeyDown=l=>{switch(l.stopPropagation(),l.keyCode){case O.Enter:this.submitTextarea(),this.appendToContainer();break}};const{container:e,icon:i,color:s,getCurrentSelectedData:n,updateSelectedTextAttribute:o}=t,a=t.width||$e;this.container=e,this.getCurrentSelectedData=n,this.updateSelectedTextAttribute=o,this._textAttributeDOM=this.initTextAttributeDOM(),this._iconDOM=this.initIconDOM(i),this._textDOM=this.initTextDOM(a,vi),this._textareaDOM=this.initTextareaDOM(a,s),this.appendToContainer()}get isExit(){return this._textAttributeDOM?this.container.contains(this._textAttributeDOM):!1}get isExitTextareaDOM(){return this._textareaDOM?this.container.contains(this._textareaDOM):!1}updateIcon(t){this._iconDOM&&(this._iconDOM.innerHTML=t)}appendToContainer(){!this._textAttributeDOM||!this._textDOM||!this._iconDOM||(this.container.appendChild(this._textAttributeDOM),this._textAttributeDOM.appendChild(this._textDOM),this._textAttributeDOM.appendChild(this._iconDOM))}initTextAttributeDOM(){const t=document.createElement("div");return t.setAttribute("id","textArea"),t}initTextDOM(t,e){const i=document.createElement("span");return i.setAttribute("style",`
24
+ width: ${Math.max(t,ze)}px;
25
25
  line-height: ${e}px;
26
26
  word-break: break-all;
27
27
  white-space: pre-line;
@@ -39,7 +39,7 @@
39
39
  outline: none;
40
40
  resize: none;
41
41
  width: ${Math.max(t,30)}px;
42
- `),i.setAttribute("maxLength",`${Qt}`),i}removeTextDOM(){!this._textAttributeDOM||this._textDOM&&this._textAttributeDOM.removeChild(this._textDOM)}removeIconDOM(){!this._textAttributeDOM||this._iconDOM&&this._textAttributeDOM.removeChild(this._iconDOM)}removeTextareaDOM(){var t,e;this._textareaDOM&&this._textAttributeDOM&&((t=this._textAttributeDOM)==null?void 0:t.contains(this._textareaDOM))&&((e=this._textAttributeDOM)==null||e.removeChild(this._textareaDOM))}submitTextarea(){var t;this._textareaDOM&&(this.updateSelectedTextAttribute((t=this._textareaDOM)==null?void 0:t.value),this.removeTextareaDOM(),this.clearTextAttribute())}clearTextAttribute(){this._textAttributeDOM&&this.container.contains(this._textAttributeDOM)&&this.container.removeChild(this._textAttributeDOM)}renderTextarea(){if(!this._textAttributeDOM||!this._textareaDOM)return;const t=this.getCurrentSelectedData();if(!t)return;const{width:e=ae,textAttribute:i,color:s}=t;this._textareaDOM.value=`${i}`,this._textareaDOM.setAttribute("style",`
42
+ `),i.setAttribute("maxLength",`${_e}`),i}removeTextDOM(){!this._textAttributeDOM||this._textDOM&&this._textAttributeDOM.removeChild(this._textDOM)}removeIconDOM(){!this._textAttributeDOM||this._iconDOM&&this._textAttributeDOM.removeChild(this._iconDOM)}removeTextareaDOM(){var t,e;this._textareaDOM&&this._textAttributeDOM&&((t=this._textAttributeDOM)==null?void 0:t.contains(this._textareaDOM))&&((e=this._textAttributeDOM)==null||e.removeChild(this._textareaDOM))}submitTextarea(){var t;this._textareaDOM&&(this.updateSelectedTextAttribute((t=this._textareaDOM)==null?void 0:t.value),this.removeTextareaDOM(),this.clearTextAttribute())}clearTextAttribute(){this._textAttributeDOM&&this.container.contains(this._textAttributeDOM)&&this.container.removeChild(this._textAttributeDOM)}renderTextarea(){if(!this._textAttributeDOM||!this._textareaDOM)return;const t=this.getCurrentSelectedData();if(!t)return;const{width:e=$e,textAttribute:i,color:s}=t;this._textareaDOM.value=`${i}`,this._textareaDOM.setAttribute("style",`
43
43
  background-color: rgba(0,0,0,0.4);
44
44
  border-radius: 5px;
45
45
  border-color: ${s};
@@ -48,15 +48,15 @@
48
48
  font-style: italic;
49
49
  font-weight: 900;
50
50
  text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.6);
51
- width: ${Math.max(e,oe)}px;
52
- `),this._textareaDOM.setAttribute("maxLength",`${Qt}`),this._textAttributeDOM.appendChild(this._textareaDOM),this.removeIconDOM(),this.removeTextDOM(),this._textareaDOM.focus(),this._textareaDOM.addEventListener("keydown",this.textKeyDown)}update(t,e){var i;const{left:s,top:n,color:o,width:a=ae}=e,l=Math.max(a,oe);(i=this._textAttributeDOM)==null||i.setAttribute("style",`
51
+ width: ${Math.max(e,ze)}px;
52
+ `),this._textareaDOM.setAttribute("maxLength",`${_e}`),this._textAttributeDOM.appendChild(this._textareaDOM),this.removeIconDOM(),this.removeTextDOM(),this._textareaDOM.focus(),this._textareaDOM.addEventListener("keydown",this.textKeyDown)}update(t,e){var i;const{left:s,top:n,color:o,width:a=$e}=e,l=Math.max(a,ze);(i=this._textAttributeDOM)==null||i.setAttribute("style",`
53
53
  position: absolute;
54
54
  width: ${l}px;
55
55
  font-size: 14px;
56
56
  left:${s}px;
57
57
  top: ${n}px;
58
58
  color: ${o};
59
- `),this._textDOM&&(this._textDOM.innerHTML=`${t}`),this._textareaDOM&&(this._textareaDOM.style.width=`${l}px`,this._textareaDOM.style.borderColor=`${o}`)}changeSelected(){this.isExitTextareaDOM&&this.submitTextarea()}}var Sr=Object.defineProperty,kr=Object.defineProperties,Or=Object.getOwnPropertyDescriptors,li=Object.getOwnPropertySymbols,Mr=Object.prototype.hasOwnProperty,Er=Object.prototype.propertyIsEnumerable,hi=(r,t,e)=>t in r?Sr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,j=(r,t)=>{for(var e in t||(t={}))Mr.call(t,e)&&hi(r,e,t[e]);if(li)for(var e of li(t))Er.call(t,e)&&hi(r,e,t[e]);return r},it=(r,t)=>kr(r,Or(t));const ci=164;class di extends rt{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(S.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.config=x.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new ne,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=Q.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return _.getPolygonByID(this.polygonList,this.selectedID)}get polygonListUnderZoom(){return this.polygonList.map(t=>it(j({},t),{pointList:I.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t){var e;((e=this.drawingPointList)==null?void 0:e.length)>0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=x.getRenderResultList(this.polygonList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=x.getRenderResultList(this.polygonList,x.getSourceID(this.basicResult),[]);return t}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?j(j({},i),t):i)}rotatePolygon(t=1,e=_t.Clockwise,i=this.selectedID){if(!i)return;const s=_.getPolygonByID(this.polygonList,i);if(!s)return;const n=_.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:n},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo)return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${B.getMessagesByLocale(C.UpperLimitErrorNotice,this.lang)}${e}`);return}this.setSelectedID("");const s=this.getCoordinateUnderZoom(t),n=I.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(I.returnClosePointIndex(n,I.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:a}=_.getClosestPoint(n,this.polygonListUnderZoom,this.config.lineType,yt),l=I.changePointByZoom(a&&t.altKey===!1&&i?a:n,1/this.zoom);if(this.pattern===Q.Rect&&this.drawingPointList.length===2){const h=P.getRectangleByRightAngle(l,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${B.getMessagesByLocale(C.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(l),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.setSelectedID(void 0),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=O.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.setSelectedID(void 0)}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>i.id===t?it(j({},i),{valid:!i.valid}):i);this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;if(e<3&&(e=3),this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}const i=x.getSourceID(this.basicResult),s=[...this.polygonList];if(this.editPolygonID){const n=s.find(o=>o.id===this.editPolygonID);if(!n)return;n.pointList=this.drawingPointList,this.editPolygonID=""}else{const n=J(8,62);let o={id:n,sourceID:i,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:x.getMaxOrder(s.filter(a=>x.isSameSourceID(a.sourceID,i)))+1};if(this.config.textConfigurable){let a="";a=S.getTextAttribute(this.polygonList.filter(l=>x.isSameSourceID(l.sourceID,i)),this.config.textCheckType),o=it(j({},o),{textAttribute:a})}this.pattern===Q.Rect&&t===!0&&(o=it(j({},o),{isRect:!0})),s.push(o),this.setSelectedIdAfterAddingDrawing(n)}this.setPolygonList(s),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(s)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.setSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(n=>it(j({},n),{pointList:I.changePointListByZoom(n.pointList,this.zoom)}));return _.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),n=I.changePointListByZoom(i.pointList,this.zoom);return _.getHoverEdgeIndex(s,n,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=I.changePointListByZoom(e.pointList,this.zoom);return I.returnClosePointIndex(i,s)}deletePolygon(t){var e;!t||(this.setPolygonList(this.polygonList.filter(i=>i.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render())}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${B.getMessagesByLocale(C.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${B.getMessagesByLocale(C.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.setSelectedID(""),this.render()}}onTabKeyDown(t){if(t.preventDefault(),this.drawingPointList.length>0)return;let e=G.ascend;t.shiftKey&&(e=G.descend);const[i,s]=x.getRenderResultList(this.polygonList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let n=[...i];s&&(n=[...n,s]);const o=st.getViewPort(this.canvas,this.currentPos,this.zoom),a=n.map(h=>{var c,u,d,g;return it(j({},h),{x:(u=(c=h.pointList[0])==null?void 0:c.x)!=null?u:0,y:(g=(d=h.pointList[0])==null?void 0:d.y)!=null?g:0})}).filter(h=>st.inViewPort({x:h.x,y:h.y},o)),l=x.getNextSelectedRectID(a,e,this.selectedID);if(l){this.setSelectedID(l.id);const{selectedPolygon:h}=this;h&&this.setDefaultAttribute(h.attribute)}this.render()}onKeyDown(t){if(!x.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case A.Space:this.spaceKeydown();break;case A.Esc:this.drawingPointList=[],this.editPolygonID="";break;case A.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case A.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case A.Delete:this.deletePolygon(this.selectedID),this.render();break;case A.Ctrl:this.isCtrl=!0;break;case A.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case A.Tab:{this.onTabKeyDown(t);break}case A.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=S.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case A.Ctrl:this.isCtrl=!1;break;case A.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:t}=this;t&&this.setDefaultAttribute(t.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;const{dropFoot:s}=_.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,yt);if(!s)return;const{upperLimitPointNum:n}=this.config;if(n&&i.pointList.length>=n){this.emit("messageInfo",`${B.getMessagesByLocale(C.UpperLimitErrorNotice,this.lang)}${n}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,I.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,n=this.getCoordinateUnderZoom(t);let o=[0],a=q.Plane;this.dragStatus=O.Start;const l=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);return l>-1?(a=q.Point,o=[l]):h>-1&&this.hoverEdgeIndex>-1&&(a=q.Line,o=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:n,dragTarget:a,initPointList:s,changePointIndex:o},!0}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==T.Line)return;const e=_.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(o=>o.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=_.getWrapPolygonIndex(e,i);let n=[...this.polygonList];if(s===-1){const o=_.segmentPolygonByPolygon(e,i);if(!o)return;const a=o.shift();if(!a)return;let l="",h=!0;const c=x.getSourceID(this.basicResult);let u="";n=this.polygonList.map(d=>{var g,v;return d.id===this.selectedID?(l=d.attribute,h=(g=d==null?void 0:d.valid)!=null?g:!0,u=(v=d==null?void 0:d.textAttribute)!=null?v:"",it(j({},d),{pointList:a})):d}),o.length>0&&o.forEach((d,g)=>{n.push({sourceID:c,id:J(8,62),pointList:d,valid:h,order:x.getMaxOrder(this.currentShowList)+1+g,attribute:l,textAttribute:u})})}else n[s].pointList=_.clipPolygonFromWrapPolygon(e,n[s].pointList),n=n.filter(o=>o.id!==this.selectedID);this.setPolygonList(n),this.history.pushHistory(n),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",Ct.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==T.Line){this.emit("messageInfo",Ct.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),n=this.currentShowList.find(h=>h.id===i);if(!n||!s)return;const o=_.combinePolygonWithPolygon(s,n);if(!o)return;const{newPolygon:a,unionList:l}=o;if(l.length===1&&a){const h=this.polygonList.filter(c=>!l.includes(c.id)).map(c=>c.id===this.selectedID?a:c);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",Ct.t("CombineSuccess"))}else this.emit("messageInfo",Ct.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let a=!1;switch(this.dependToolName){case L.Rect:{a=t.filter(l=>!Z.isInRect(l,this.basicResult)).length>0;break}case L.Polygon:{a=_.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return a}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:n}=P.calcViewportBoundaries(I.changePointListByZoom(t,this.zoom)),o=1e-5;return e<0||i<0||s>this.imgInfo.width+o||n>this.imgInfo.height+o}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{selectedPolygon:e}=this;let i=e==null?void 0:e.pointList;if(!i)return;const{initPointList:s,dragStartCoord:n,dragTarget:o,changePointIndex:a}=this.dragInfo,l=this.getCoordinateUnderZoom(t);let h={x:(l.x-n.x)/this.zoom,y:(l.y-n.y)/this.zoom};if(this.pattern===Q.Rect&&(e==null?void 0:e.isRect)===!0&&a&&[q.Line].includes(o)){const u=P.getArrayIndex(a[0]-2,4),d=P.getArrayIndex(a[0]-1,4),g=[s[u],s[d]];h=P.getRectPerpendicularOffset(n,l,g)}switch(this.dragStatus=O.Move,o){case q.Plane:i=i.map((u,d)=>it(j({},u),{x:s[d].x+h.x,y:s[d].y+h.y}));break;case q.Point:case q.Line:i=i.map((u,d)=>a&&a.includes(d)?it(j({},u),{x:s[d].x+h.x,y:s[d].y+h.y}):u);break}if(this.pattern===Q.Rect&&(e==null?void 0:e.isRect)===!0&&o===q.Point&&a&&(i=P.getPointListFromPointOffset(s,a[0],h)),this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i))return;const c=this.polygonList.map(u=>{if(u.id===this.selectedID){const d=it(j({},u),{pointList:i});return u.isRect===!0&&this.pattern===Q.Normal&&Object.assign(d,{isRect:!1}),d}return u});this.setPolygonList(c),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const n=this.getHoverID(t);this.hoverID!==n&&(this.hoverID=n,this.render())}leftMouseUp(t){const e=this.getHoverID(t);if(this.drawingPointList.length===0&&t.ctrlKey===!0&&e){this.setPolygonValidAndRender(e);return}this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===O.Move){this.dragInfo=void 0,this.dragStatus=O.Wait,this.history.pushHistory(this.polygonList),this.emit("updateResult");return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp();break}}this.render()}}dragMouseUp(){this.dragStatus===O.Start&&(this.dragInfo=void 0,this.dragStatus=O.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return S.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:ci,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;S.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",S.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(S.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:n,textAttribute:o}=e,{x:a,y:l}=i[i.length-1],h=ci,c=I.getOffsetCoordinate({x:a,y:l},this.currentPos,this.zoom),u=this.getColor(s),d=n?u==null?void 0:u.valid.stroke:u==null?void 0:u.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new $t({width:h,container:this.container,icon:this.getTextIconSvg(s),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${o}`,{left:c.x,top:c.y,color:d,width:h})}renderPolygon(){var t,e,i,s,n,o,a,l,h;if(this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(d=>{var g,v,f,b,p;if([this.selectedID,this.editPolygonID].includes(d.id))return;const{textAttribute:y,attribute:w}=d,D=this.getColor(w),R=et.getStrokeAndFill(D,d.valid),E=I.changePointListByZoom(d.pointList||[],this.zoom,this.currentPos);m.drawPolygonWithFillAndLine(this.canvas,E,{fillColor:R.fill,strokeColor:R.stroke,pointColor:"white",thickness:(v=(g=this.style)==null?void 0:g.width)!=null?v:2,lineCap:"round",isClose:!0,lineType:(f=this.config)==null?void 0:f.lineType});let H=`${(b=S.getAttributeShowText(w,this.config.attributeList))!=null?b:""}`;((p=this.config)==null?void 0:p.isShowOrder)&&(d==null?void 0:d.order)>0&&(H=`${d.order} ${H}`),m.drawText(this.canvas,E[0],H,j({color:R.stroke},K));const k=E[E.length-1];m.drawText(this.canvas,{x:k.x+vt.x,y:k.y+vt.y},y,j({color:R.stroke},K))})),this.hoverID&&this.hoverID!==this.editPolygonID){const d=this.polygonList.find(g=>g.id===this.hoverID&&g.id!==this.selectedID);if(d){let g="";const v=this.getColor(d.attribute);d.valid?g=v.validHover.fill:g=et.getStrokeAndFill(v,!1,{isHover:!0}).fill,m.drawPolygonWithFill(this.canvas,I.changePointListByZoom(d.pointList,this.zoom,this.currentPos),{color:g,lineType:(e=this.config)==null?void 0:e.lineType})}}if(this.selectedID){const d=this.selectedPolygon;if(d){const g=this.getColor(d.attribute),v=et.getStrokeAndFill(g,d.valid,{isSelected:!0});m.drawSelectedPolygonWithFillAndLine(this.canvas,I.changePointListByZoom(d.pointList,this.zoom,this.currentPos),{fillColor:v.fill,strokeColor:v.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(i=this.config)==null?void 0:i.lineType});let f=`${(s=S.getAttributeShowText(d.attribute,this.config.attributeList))!=null?s:""}`;((n=this.config)==null?void 0:n.isShowOrder)&&(d==null?void 0:d.order)>0&&(f=`${d.order} ${f}`),m.drawText(this.canvas,I.changePointByZoom(d.pointList[0],this.zoom,this.currentPos),f,j({color:v.stroke},K)),this.renderTextAttribute()}}const c=this.getColor(this.defaultAttribute),u=et.getStrokeAndFill(c,!this.isCtrl);if(((o=this.drawingPointList)==null?void 0:o.length)>0){let d=[...this.drawingPointList],g=I.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===Q.Rect&&d.length===2)d=P.getRectangleByRightAngle(g,d);else{if(((a=this.config)==null?void 0:a.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:v}=_.getClosestPoint(g,this.polygonList,(l=this.config)==null?void 0:l.lineType,yt/this.zoom);v&&(g=v)}d.push(g)}m.drawSelectedPolygonWithFillAndLine(this.canvas,I.changePointListByZoom(d,this.zoom,this.currentPos),{fillColor:u.fill,strokeColor:u.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const d=this.selectedPolygon;if(!d)return;const g=et.getStrokeAndFill(c,d.valid,{isSelected:!0}),v=d==null?void 0:d.pointList[this.hoverPointIndex];if(v){const{x:f,y:b}=I.changePointByZoom(v,this.zoom,this.currentPos);m.drawCircleWithFill(this.canvas,{x:f,y:b},5,{color:g.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const d=this.selectedPolygon;if(!d)return;const g=et.getStrokeAndFill(c,d.valid,{isSelected:!0});m.drawLineWithPointList(this.canvas,I.changePointListByZoom(d.pointList,this.zoom,this.currentPos),{color:g.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(h=this.config)==null?void 0:h.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,n=186,o=32;m.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:n,height:o},{color:"black"}),m.drawText(this.canvas,{x:e,y:i},Ct.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:n/2+s,offsetY:-(o/2+s/2)}),m.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.setSelectedID(""),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.setSelectedID(""),this.setPolygonList(t),this.render())}}class ui extends rt{constructor(t){super(t);this.getInitResultList=(e,i)=>!(e===0||e===void 0)&&i.length===0?[]:Rt.getDefaultTagResult(this.config.inputList,i),this.setLabel=(e,i)=>{var s,n;if(this.isImgError||!this.basicResult&&this.dependToolName)return;const o=this.config.inputList;if(!o[e])return;const{subSelected:a}=o[e];if(e<o.length&&o[e].subSelected&&a&&i<a.length){const l=o[e].value;let h=(s=a[i])==null?void 0:s.value;const c=(n=o[e])==null?void 0:n.isMulti,u=this.tagResult.filter(d=>{const g=`${d.sourceID}`;return x.isSameSourceID(g,this.sourceID)})[0];if(u){let d=0;const{result:g}=u;u.sourceID===0&&(u.sourceID="0");for(const v in u.result)if(v===o[e].value){if(d++,c===!0){const f=g[v].split(";").filter(p=>p!==""),b=f.indexOf(h);b===-1?f.push(h):f.splice(b,1),h=f.join(";")}h===""?Object.keys(g).length===1?this.tagResult=this.tagResult.filter(f=>{const b=`${f.sourceID}`;return x.isDifferSourceID(b,this.sourceID)}):Object.keys(g).length>1&&delete g[v]:g[v]=h}d===0&&Object.assign(u.result,{[l]:h})}else this.tagResult=[{sourceID:this.sourceID,id:J(8,62),result:{[l]:h}}];this.render()}},this.clearResult=(e=!0,i)=>{i?this.tagResult=this.tagResult.map(s=>((s==null?void 0:s.result[i])&&delete s.result[i],s)):this.tagResult=[],this.render()},this.config=x.jsonParser(t.config),this.tagResult=[],this.labelSelectedList=[],this.setShowDefaultCursor(!0)}destroy(){this.clearTag(),super.destroy()}setResult(t){this.tagResult=t,this.render()}get currentPageResult(){return[this.currentTagResult]}get currentTagResult(){var t;return(t=this.tagResult.filter(e=>{const i=`${e.sourceID}`;return x.isSameSourceID(i,this.sourceID)})[0])!=null?t:{}}get sourceID(){return x.getSourceID(this.basicResult)}onKeyDown(t){if(!x.hotkeyFilter(t))return;let{keyCode:e}=t;if(e&&(e<=57&&e>=49||e<=105&&e>=97)){if(e>57?e-=97:e-=49,this.config.inputList.length===1){this.labelSelectedList=[0,e],this.setLabel(0,e),setTimeout(()=>{this.labelSelectedList=[],this.render()},500);return}this.labelSelectedList.length===1?(this.labelSelectedList=[this.labelSelectedList[0],e],this.setLabel(this.labelSelectedList[0],e),setTimeout(()=>{this.labelSelectedList=[],this.render()},500)):(this.labelSelectedList=[e],this.emit("expend"))}}clearTag(){var t;const e=(t=this.canvas)==null?void 0:t.parentNode,i=window.self.document.getElementById("tagToolTag");i&&e&&e.contains(i)&&(e==null||e.removeChild(i))}renderTag(){var t,e,i,s,n,o;if(this.clearTag(),!(((t=this.tagResult)==null?void 0:t.length)>0))return;const a=document.createElement("div"),l=Rt.getTagNameList((i=(e=this.currentTagResult)==null?void 0:e.result)!=null?i:{},this.config.inputList);a.innerHTML=(s=l.reduce((h,c)=>`${h}${c.keyName}: ${c.value.join(" \u3001 ")}
59
+ `),this._textDOM&&(this._textDOM.innerHTML=`${t}`),this._textareaDOM&&(this._textareaDOM.style.width=`${l}px`,this._textareaDOM.style.borderColor=`${o}`)}changeSelected(){this.isExitTextareaDOM&&this.submitTextarea()}}var mo=Object.defineProperty,yo=Object.defineProperties,bo=Object.getOwnPropertyDescriptors,es=Object.getOwnPropertySymbols,xo=Object.prototype.hasOwnProperty,wo=Object.prototype.propertyIsEnumerable,is=(r,t,e)=>t in r?mo(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,$=(r,t)=>{for(var e in t||(t={}))xo.call(t,e)&&is(r,e,t[e]);if(es)for(var e of es(t))wo.call(t,e)&&is(r,e,t[e]);return r},K=(r,t)=>yo(r,bo(t));const Xt=6;class ae extends gt{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(n=>n.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),s=Xt,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&Y.isInRect(i,a,s,this.zoom))return a.id}const o=n.filter(a=>Y.isInRect(i,a,s,this.zoom));if(o.length===0)return"";if(o.length===1)return o[0].id;if(o.length>1)return o.map(l=>({size:l.width*l.height,id:l.id})).sort((l,h)=>l.size-h.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(M.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=x.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=x.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=x.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRect(){return this.rectList.find(t=>t.id===this.selectedRectID)}get selectedID(){return this.selectedRectID}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=x.getRenderResultList(this.rectList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=x.getRenderResultList(this.rectList,x.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=x.getRenderResultList(t,x.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t){var e,i;const s=this.selectedRectID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedRectID=t,this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributInstance&&t){let e=t;M.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",M.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?K($({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?I.returnClosePointIndex(this.getCoordinateUnderZoom(t),Y.getRectPointList(this.selectedRect,this.zoom),Xt+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,s=Y.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let o=0;o<s.length;o++){const a=s[o],{length:l}=_.getFootOfPerpendicular(n,a.begin,a.end);l<Xt+10&&(e=o)}return e}getTextIconSvg(t=""){return M.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t),s=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!(!s||t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){if(this.getHoverRectPointIndex(t)>-1){const n=G.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:s},this.dragStatus=E.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=G.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:s},this.dragStatus=E.Start;return}}if(i===this.selectedRectID&&!this.drawingRect){const n=G.Plane;this.dragInfo={dragStartCoord:e,dragTarget:n,firstRect:s,startTime:+new Date},this.dragStatus=E.Start}}}onDragMove(t){var e,i,s,n,o,a;if(!this.dragInfo)return;this.dragStatus=E.Move;const l=Y.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:h,y:c,width:u,height:d}=l,g={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};let p=this.rectList.filter(f=>f.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case G.Plane:p=K($({},p),{x:h+g.x,y:c+g.y,width:u,height:d});break;case G.Point:{let f=h,v=c,y=u,b=d;switch(this.hoverRectPointIndex){case 0:{f=u-g.x<0?h+u:h+g.x,v=d-g.y<0?c+d:c+g.y,y=Math.abs(g.x-u),b=Math.abs(g.y-d);break}case 1:{f=u+g.x>0?h:h+u+g.x,v=d-g.y<0?c+d:c+g.y,y=Math.abs(u+g.x),b=Math.abs(d-g.y);break}case 2:{f=u+g.x>0?h:h+u+g.x,v=d+g.y>0?c:c+d+g.y,y=Math.abs(u+g.x),b=d+g.y>0?d+g.y:Math.abs(d+g.y);break}case 3:{f=u-g.x<0?h+u:h+g.x,v=d+g.y>0?c:c+d+g.y,y=Math.abs(g.x-u),b=d+g.y>0?d+g.y:Math.abs(d+g.y);break}default:return}p=K($({},p),{x:f,y:v,width:y,height:b})}break;case G.Line:{let f=h,v=c,y=u,b=d;switch(this.hoverRectEdgeIndex){case 0:{v=d-g.y<0?c+d:c+g.y,b=Math.abs(g.y-d);break}case 1:{f=u+g.x>0?h:h+u+g.x,y=Math.abs(u+g.x);break}case 2:{v=d+g.y>0?c:c+d+g.y,b=d+g.y>0?d+g.y:Math.abs(d+g.y);break}case 3:{f=u-g.x<0?h+u:h+g.x,y=Math.abs(g.x-u);break}default:return}p=K($({},p),{x:f,y:v,width:y,height:b});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&Y.isRectNotInPolygon(p,xi(this.basicResult.pointList,this.zoom)))return;const f=this.basicResult.x*this.zoom,v=this.basicResult.y*this.zoom,y=this.basicResult.width*this.zoom,b=this.basicResult.height*this.zoom;if(this.dragInfo.dragTarget!==G.Plane&&(p.x<f-.01||p.y<v-.01||p.width>f+y-p.x+.01||p.height>v+b-p.y+.01))return;if(p.x<f&&(p.x=f),p.y<v&&(p.y=v),p.width>f+y-p.x)switch(this.dragInfo.dragTarget){case G.Plane:p.x=f+y-u;break;case G.Point:case G.Line:g.x>0&&g.y>0&&(p.width=f+y-p.x);break;default:return}if(p.height>v+b-p.y)switch(this.dragInfo.dragTarget){case G.Plane:p.y=v+b-d;break}}else if(p.x<0&&(p.x=0),p.y<0&&(p.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){case G.Plane:p.x+p.width>((s=this.imgInfo)==null?void 0:s.width)&&(p.x=this.imgInfo.width-u),p.y+p.height>((n=this.imgInfo)==null?void 0:n.height)&&(p.y=this.imgInfo.height-d);break;default:if(p.x+p.width>((o=this.imgInfo)==null?void 0:o.width)+.01||p.y+p.height>((a=this.imgInfo)==null?void 0:a.height)+.01)return}}this.setRectList(this.rectList.map(f=>f.id===p.id?Y.getRectUnderZoom(p,1/this.zoom):f)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const s=this.getCoordinateUnderZoom(t),n=I.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.selectedRectID&&this.dragInfo){this.onDragMove(n);return}if(this.selectedRectID){const l=this.getHoverRectPointIndex(t);if(l!==this.hoverRectPointIndex){this.hoverRectPointIndex=l,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const h=this.getHoverRectEdgeIndex(t);if(h!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=h,this.render();return}}}const o=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=o,o!==a&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:l,y:h}=this.firstClickCoord,{width:c,height:u}=this.drawingRect;if(c=Math.abs(l-n.x),u=Math.abs(h-n.y),n.x<l&&(l=n.x),n.y<h&&(h=n.y),this.config.drawOutsideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&Y.isRectNotInPolygon(K($({},this.drawingRect),{x:l,y:h,width:c,height:u}),xi(this.basicResult.pointList,this.zoom)))return;n.x<0&&(c=Math.abs(this.firstClickCoord.x),l=0),n.y<0&&(u=Math.abs(this.firstClickCoord.y),h=0),this.imgInfo&&(l+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-l)),h+u>this.imgInfo.height&&(u=Math.abs(this.imgInfo.height-h)))}this.drawingRect=K($({},this.drawingRect),{x:l,y:h,width:c,height:u}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?K($({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const i=this.getCoordinateUnderZoom(t),s=I.changeDrawOutsideTarget(i,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(s.x<0&&(s.x=0),s.y<0&&(s.y=0)),this.drawingRect=K($({},s),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:it(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const n=x.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(n)this.drawingRect&&(this.drawingRect=K($({},this.drawingRect),{label:n.label})),this.markerIndex=n.index,this.emit("markIndexChange");else{this.emit("messageInfo",Z.getMessagesByLocale(R.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let n="";n=M.getTextAttribute(this.rectList.filter(o=>x.isSameSourceID(o.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=K($({},this.drawingRect),{textAttribute:n}))}if(Object.assign(this.drawingRect,{order:x.getMaxOrder(this.rectList.filter(n=>x.isSameSourceID(n.sourceID,e)))+1}),this.firstClickCoord=$({},s),this.firstCurrentPos=$({},this.currentPos),this.dataInjectionAtCreation){const n=this.dataInjectionAtCreation(this.drawingRect);n&&Object.assign(this.drawingRect,n)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",Z.getMessagesByLocale(R.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=E.Wait,this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=E.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:s}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,s/=this.zoom,[...this.rectList,K($({},this.drawingRect),{x:t,y:e,width:i,height:s})]}rightMouseUp(t){const e=this.getHoverRectID(t),i=this.rectList.find(n=>n.id===e),{selectedRectID:s}=this;if(this.setSelectedRectID(void 0),i&&this.setDefaultAttribute(i.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(s!==e&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(e),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const n=x.getCurrentMarkerIndex(i.label,this.config.markerList);n>=0&&(this.setMarkerIndex(n),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===E.Move){this.dragInfo=void 0,this.dragStatus=E.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=x.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selectedRectID&&this.selectedRectID===e&&this.deleteRect(e)}onKeyDown(t){if(!x.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case O.Ctrl:this.drawingRect&&(this.drawingRect=K($({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case O.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case O.Z:this.setIsHidden(!this.isHidden),this.render();break;case O.Delete:this.deleteRect(this.selectedRectID);break;case O.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=q.ascend;t.shiftKey&&(i=q.descend);const[s,n]=x.getRenderResultList(this.rectList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);let o=[...s];n&&(o=[...o,n]);const a=bt.getViewPort(this.canvas,this.currentPos,this.zoom);o=o.filter(h=>bt.inViewPort({x:h.x,y:h.y},a));const l=x.getNextSelectedRectID(o,i,this.selectedRectID);l&&(this.setSelectedRectID(l.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(l.attribute));break}default:{if(this.config.attributeConfigurable){const i=M.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case O.Ctrl:this.drawingRect&&(this.drawingRect=K($({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,s;this.drawingRect&&this.firstClickCoord&&(i=Y.getRectUnderZoom(this.drawingRect,1/e),s=I.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&s&&(this.drawingRect=Y.getRectUnderZoom(i,this.zoom),this.firstClickCoord=I.changePointByZoom(s,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.customRenderStyle&&this.customRenderStyle(t);if(e)return e;const i=this.getColor(t.attribute);let s,n;return t.valid===!1?(s=i==null?void 0:i.invalid.stroke,n=i==null?void 0:i.invalid.fill):(s=i==null?void 0:i.valid.stroke,n=i==null?void 0:i.valid.fill),{strokeColor:s,fillColor:n,textColor:s,toolColor:i}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:s,width:n,height:o,attribute:a,valid:l}=e,h=n*this.zoom*.6,c=I.getOffsetCoordinate({x:i,y:s+o},this.currentPos,this.zoom),u=this.getColor(a),d=l?u==null?void 0:u.valid.stroke:u==null?void 0:u.invalid.stroke,g=4;this._textAttributInstance||(this._textAttributInstance=new oe({width:h,container:this.container,icon:this.getTextIconSvg(a),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${e.textAttribute}`,{left:c.x,top:c.y+g,color:d,width:h})}renderSelectedRect(t){const{selectedRect:e}=this;if(!this.ctx||!t||!e)return;const{ctx:i}=this;let s=10;const n=Y.getRectPointList(e),o=n.length,a=this.getColor(t.attribute);n.forEach((l,h)=>{var c,u;if(i.save(),i.moveTo(l.x,l.y),i.beginPath(),this.hoverRectPointIndex===h?s=Xt+6:s=Xt,t.valid===!1?(i.strokeStyle=a==null?void 0:a.invalid.stroke,i.fillStyle=a==null?void 0:a.invalid.stroke):(i.strokeStyle=a==null?void 0:a.valid.stroke,i.fillStyle=a==null?void 0:a.valid.stroke),i.arc(l.x*this.zoom+this.currentPos.x,l.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),i.fill(),this.hoverRectEdgeIndex===h){i.beginPath(),i.lineWidth=10;const d=this.getColor(t.attribute),g=t.valid===!1?(c=d==null?void 0:d.invalid)==null?void 0:c.stroke:(u=d==null?void 0:d.valid)==null?void 0:u.stroke;i.strokeStyle=g,i.moveTo(n[h].x*this.zoom+this.currentPos.x,n[h].y*this.zoom+this.currentPos.y),i.lineTo(n[(h+1)%o].x*this.zoom+this.currentPos.x,n[(h+1)%o].y*this.zoom+this.currentPos.y),i.stroke()}i.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var s,n,o,a;if(this.ctx&&t){const{ctx:l,style:h}=this,{hiddenText:c=!1}=h;l.save();const{strokeColor:u,fillColor:d,textColor:g}=this.getRenderStyle(t);l.font="lighter 14px Arial";let p="";((s=this.config)==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(p=`${t.order}`),t.label&&this.hasMarkerConfig&&(p=`${x.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${Be.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(p=`${p} ${M.getAttributeShowText(t.attribute,(n=this.config)==null?void 0:n.attributeList)}`);const f=I.changeRectByZoom(t,i?e:this.zoom,this.currentPos);c||L.drawText(this.canvas,{x:f.x,y:f.y-6},p,K($({color:u,font:"normal normal 900 14px SourceHanSansCN-Regular"},At),{textMaxWidth:300}));const v=(a=(o=this.style)==null?void 0:o.width)!=null?a:2;(t.id===this.hoverRectID||t.id===this.selectedRectID)&&L.drawRectWithFill(this.canvas,f,{color:d}),L.drawRect(this.canvas,f,{color:u,thickness:v,hiddenText:!0}),l.restore();let y=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(y=`${Math.round(t.width/this.zoom)} * ${Math.round(f.height/this.zoom)}`);const b=y.length*7;if(c||L.drawText(this.canvas,{x:f.x+f.width-b,y:f.y+f.height+15},y,$({color:g,font:"normal normal 600 14px Arial"},At)),!c&&t.textAttribute&&t.id!==this.selectedRectID){const w=0,A=Math.max(20,f.width-b);L.drawText(this.canvas,{x:f.x,y:f.y+f.height+20+w},t.textAttribute,$({color:g,font:"italic normal 900 14px Arial",textMaxWidth:A},At))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,s]=x.getRenderResultList(this.rectList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);this.isHidden||i==null||i.forEach(n=>{this.renderDrawingRect(n),e.staticRender&&e.staticRender(this.canvas,I.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),s&&(this.renderDrawingRect(s),this.renderSelectedRect(s),e.selectedRender&&e.selectedRender(this.canvas,I.changeRectByZoom(s,this.zoom,this.currentPos),this.getRenderStyle(s)))}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,I.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedRect:i}=this;if(i&&(this.setRectList(this.rectList.map(s=>s.id===this.selectedID?K($({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=K($({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=E.Wait,this.setSelectedRectID(void 0)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",Z.getMessagesByLocale(R.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(s=>s.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",Z.getMessagesByLocale(R.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(s=>s.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}var Po=Object.defineProperty,ss=Object.getOwnPropertySymbols,Io=Object.prototype.hasOwnProperty,Lo=Object.prototype.propertyIsEnumerable,ns=(r,t,e)=>t in r?Po(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,rs=(r,t)=>{for(var e in t||(t={}))Io.call(t,e)&&ns(r,e,t[e]);if(ss)for(var e of ss(t))Lo.call(t,e)&&ns(r,e,t[e]);return r};class Yt{static getTagKeyName(t,e){var i,s;if(!!e)return(s=(i=e.find(n=>n.value===t))==null?void 0:i.key)!=null?s:""}static getTagName([t="",e=""],i){if(!!i){for(const s of i)if(s.value===t){if(!s.subSelected)return console.error("\u6807\u7B7E\u89E3\u6790\u9519\u8BEF",t,e),"";for(const n of s.subSelected)if(n.value===e)return n.key}}}static getTagNameList(t,e){return Object.keys(t).length<=0?[]:Object.entries(t).reduce((i,s)=>{const[n,o]=s;if(o&&o.length>0){const a=o.split(";"),l={keyName:this.getTagKeyName(n,e),value:a.map(h=>this.getTagName([n,h],e))};return[...i,l]}return i},[]).filter(i=>i)}static getTagnameListWithoutConfig(t){return Object.keys(t).length<=0?[]:Object.entries(t).reduce((e,i)=>{const[s,n]=i,o=n.split(";"),a={keyName:s,value:o};return[...e,a]},[]).filter(e=>e)}static judgeResultIsInInputList(t,e,i){return!t||!e||!i?!1:i.filter(n=>{if(n.value===t&&n.subSelected){const o=e==null?void 0:e.split(";");return(n==null?void 0:n.subSelected.filter(a=>o.indexOf(a.value)>-1).length)>0}return!1}).length>0}static getDefaultResultByConfig(t){return t.reduce((e,i)=>(i.subSelected&&i.subSelected.forEach(s=>{var n;if(s.isDefault){const o=(n=e[i.value])!=null?n:"";let a=[];o.length>0&&(a=o.split(";")),a.push(s.value),e[i.value]=a.join(";")}}),e),{})}static getDefaultTagResult(t,e){const i=this.getDefaultResultByConfig(t);return e.length>0?e.map(s=>({id:it(),sourceID:s.id,result:rs({},i)})):[{id:it(),sourceID:"",result:rs({},i)}]}}class os extends gt{constructor(t){super(t);this.getInitResultList=(e,i)=>!(e===0||e===void 0)&&i.length===0?[]:Yt.getDefaultTagResult(this.config.inputList,i),this.setLabel=(e,i)=>{var s,n;if(this.isImgError||!this.basicResult&&this.dependToolName)return;const o=this.config.inputList;if(!o[e])return;const{subSelected:a}=o[e];if(e<o.length&&o[e].subSelected&&a&&i<a.length){const l=o[e].value;let h=(s=a[i])==null?void 0:s.value;const c=(n=o[e])==null?void 0:n.isMulti,u=this.tagResult.filter(d=>{const g=`${d.sourceID}`;return x.isSameSourceID(g,this.sourceID)})[0];if(u){let d=0;const{result:g}=u;u.sourceID===0&&(u.sourceID="0");for(const p in u.result)if(p===o[e].value){if(d++,c===!0){const f=g[p].split(";").filter(y=>y!==""),v=f.indexOf(h);v===-1?f.push(h):f.splice(v,1),h=f.join(";")}h===""?Object.keys(g).length===1?this.tagResult=this.tagResult.filter(f=>{const v=`${f.sourceID}`;return x.isDifferSourceID(v,this.sourceID)}):Object.keys(g).length>1&&delete g[p]:g[p]=h}d===0&&Object.assign(u.result,{[l]:h})}else this.tagResult=[{sourceID:this.sourceID,id:it(8,62),result:{[l]:h}}];this.render()}},this.clearResult=(e=!0,i)=>{i?this.tagResult=this.tagResult.map(s=>((s==null?void 0:s.result[i])&&delete s.result[i],s)):this.tagResult=[],this.render()},this.config=x.jsonParser(t.config),this.tagResult=[],this.labelSelectedList=[],this.setShowDefaultCursor(!0)}destroy(){this.clearTag(),super.destroy()}setResult(t){this.tagResult=t,this.render()}get currentPageResult(){return[this.currentTagResult]}get currentTagResult(){var t;return(t=this.tagResult.filter(e=>{const i=`${e.sourceID}`;return x.isSameSourceID(i,this.sourceID)})[0])!=null?t:{}}get sourceID(){return x.getSourceID(this.basicResult)}onKeyDown(t){if(!x.hotkeyFilter(t))return;let{keyCode:e}=t;if(e&&(e<=57&&e>=49||e<=105&&e>=97)){if(e>57?e-=97:e-=49,this.config.inputList.length===1){this.labelSelectedList=[0,e],this.setLabel(0,e),setTimeout(()=>{this.labelSelectedList=[],this.render()},500);return}this.labelSelectedList.length===1?(this.labelSelectedList=[this.labelSelectedList[0],e],this.setLabel(this.labelSelectedList[0],e),setTimeout(()=>{this.labelSelectedList=[],this.render()},500)):(this.labelSelectedList=[e],this.emit("expend"))}}clearTag(){var t;const e=(t=this.canvas)==null?void 0:t.parentNode,i=window.self.document.getElementById("tagToolTag");i&&e&&e.contains(i)&&(e==null||e.removeChild(i))}renderTag(){var t,e,i,s,n,o;if(this.clearTag(),!(((t=this.tagResult)==null?void 0:t.length)>0))return;const a=document.createElement("div"),l=Yt.getTagNameList((i=(e=this.currentTagResult)==null?void 0:e.result)!=null?i:{},this.config.inputList);a.innerHTML=(s=l.reduce((h,c)=>`${h}${c.keyName}: ${c.value.join(" \u3001 ")}
60
60
  `,""))!=null?s:"",a.setAttribute("id","tagToolTag"),a.setAttribute("style",`
61
61
  position: absolute;
62
62
  top: 0;
@@ -74,7 +74,7 @@
74
74
  background: rgba(102, 111, 255, 1);
75
75
  opacity: 0.6;
76
76
  clear: both;
77
- `),(o=(n=this.canvas)==null?void 0:n.parentNode)==null||o.appendChild(a)}render(){this.renderTag(),super.render(),this.emit("render")}exportData(){let{tagResult:t}=this;return this.isImgError&&(t=[]),[t,this.basicImgInfo]}}var Hr=Object.defineProperty,Nr=Object.defineProperties,Br=Object.getOwnPropertyDescriptors,gi=Object.getOwnPropertySymbols,Fr=Object.prototype.hasOwnProperty,$r=Object.prototype.propertyIsEnumerable,fi=(r,t,e)=>t in r?Hr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,le=(r,t)=>{for(var e in t||(t={}))Fr.call(t,e)&&fi(r,e,t[e]);if(gi)for(var e of gi(t))$r.call(t,e)&&fi(r,e,t[e]);return r},he=(r,t)=>Nr(r,Br(t)),vi;(function(r){r[r.Create=0]="Create",r[r.Active=1]="Active",r[r.None=2]="None"})(vi||(vi={}));const nt=16,Zt={x:0,y:20},ce=3,Ut=5,Zr=2;class pi extends rt{constructor(t){super(t);this.drawActivatedLine=(e,i,s)=>{const n=F.cloneDeep(this.activeLine);if(!n||n.length===0)return;const o=this.isActiveLineValid();let a;const l=this.selectedID?this.lineList.find(c=>c.id===this.selectedID):void 0;l?a=l.order:a=this.nextOrder();const h=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!o});n.map(c=>Object.assign(c,this.coordUtils.getRenderCoord(c))),this.updateActiveArea(),this.drawLine(n,e,h,!0,!0),this.drawLineNumber(n[0],a,h,"",this.defaultAttribute,o),e&&this.isCreate&&this.arc(e,ce,h),this.cursor&&!this.selectedPoint&&!s&&!this.isShift&&this.arc(this.cursor,Ut,h)},this.drawHoverPoint=e=>{if(!this.isMousedown&&e&&this.isLineSelected){const i=this.getPointList(this.activeLine),s=this.activeLine.find(o=>M.calcDistance(this.coordUtils.getRenderCoord(o),e)<=Ut);let n;!s&&this.activeLine&&(n=this.findNearestPoint(i,e)),this.hoverPointID=s?s.id:void 0,this.cursor=s||n==null?void 0:n.point}},this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(e,i,s,n=!0,o=!1,a)=>{const l=Et(i,nt);e.save(),e.lineCap="round",e.lineJoin="round",e.strokeStyle=s.color,n&&(e.lineWidth=s.lineWidth),o&&M.setReferenceCtx(e),i.forEach(({specialEdge:h},c)=>{const u=l.splice(0,nt+1);e.save(),e.beginPath(),a===c&&(e.lineWidth=4),u.forEach(({x:d,y:g},v)=>{const f=v>0?"lineTo":"moveTo";h&&M.setSpecialEdgeStyle(e),e[f](d,g)}),e.stroke(),e.restore()}),e.restore()},this.drawLine=(e,i,s,n=!1,o=!1)=>{const a=i?e.concat(i):e,l={color:s,lineWidth:o?1:this.lineStyle.lineWidth};this.isCurve?M.drawCurveLine(this.ctx,a,l,!n,this.isReference,o?this.hoverLineSegmentIndex:-1):this.drawStraightLine(a,l,o),n&&e.forEach(h=>{var c,u;const d=h.id,g=d&&[this.hoverPointID,(c=this.selectedPoint)==null?void 0:c.id].includes(d)?Ut:ce;this.arc(h,g,s),[this.hoverPointID,(u=this.selectedPoint)==null?void 0:u.id].includes(d)||this.arc(h,Zr,"white")})},this.drawStraightLine=(e,i,s=!1)=>{const{ctx:n}=this;n&&(n.save(),n.lineCap="round",n.lineJoin="round",n.strokeStyle=i.color,n.lineWidth=i.lineWidth,this.isReference&&M.setReferenceCtx(n),e.forEach((o,a)=>{if(n.beginPath(),a>0){const l=e[a-1];n.save(),(l==null?void 0:l.specialEdge)&&M.setSpecialEdgeStyle(n),s&&this.hoverLineSegmentIndex+1===a&&(n.lineWidth=4),n.moveTo(l.x,l.y),n.lineTo(o.x,o.y),n.stroke(),n.restore()}}),n.restore())},this.drawLines=()=>{try{const e=F.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;e.forEach(i=>{if(i.id!==this.selectedID&&i.pointList){i.pointList.map(l=>Object.assign(l,this.coordUtils.getRenderCoord(l)));const{order:s,label:n}=i,o=s,a=i&&this.getLineColorByAttribute(i);this.drawLine(i.pointList,void 0,a,!1),this.drawLineNumber(i.pointList[0],o,a,n,i.attribute,i.valid),i.id!==this.textEditingID&&this.drawLineTextAttribute(i.pointList[1],a,i==null?void 0:i.textAttribute)}})}catch(e){console.error(e,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=e=>{super.render(),this.drawLines(),this.drawActivatedLine(e,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(e,i)=>{var s;if(!Array.isArray(this.activeLine))return!1;((s=this.activeLine)==null?void 0:s.every(o=>this.isInBasicPolygon({x:o.x+e,y:o.y+i})))&&(this.lineDragging=!0,this.moveActiveArea(e,i))},this.moveLineInRectRange=(e,i,s,n)=>{if(this.activeArea===void 0)return;const{top:o,left:a,right:l,bottom:h}=this.activeArea,c=[a,l].map(b=>F.isNumber(b)?b+e:0),u=[o,h].map(b=>F.isNumber(b)?b+i:0),d=a>=0&&l&&P.isInRange(c,s),g=o>=0&&h&&P.isInRange(u,n),v=d?e:0,f=g?i:0;this.lineDragging=!0,this.moveActiveArea(v,f)},this.onRightClick=e=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(e),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const e=this.lineList.find(s=>s.id===this.selectedID),i=e==null?void 0:e.attribute;typeof i=="string"&&(this.defaultAttribute=i,this.updateAttribute(i),this.render())}},this.onLeftClick=e=>{const i=this.getCoordinate(e),{lineDragging:s}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&e.ctrlKey){const o=this.findHoverLine(i);o&&this.setInvalidLine(o.id);return}if(this.isLinePointsExceed())return;const n=this.getNextPoint(e,i);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(n);return}if(this.isActive){if(s)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(n);return}if(e.shiftKey){this.updateLineSegmentSpecial(i);return}if(this.coordsInsideActiveArea&&e.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=e=>{if(super.onKeyUp(e),this.isShift=!1,this.hoverLineSegmentIndex=-1,e.keyCode===A.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(e.keyCode===A.Delete){this.deleteLine();return}if(e.keyCode===A.F){this.setInvalidLine(this.selectedID);return}if(e.keyCode===A.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(e)},this.onRightDblClick=e=>{super.onRightDblClick(e);const i=this.getCoordinate(e);if(this.isActive){const s=this.findHoveredPoint(i);if(s){this.deleteSelectedLinePoint(s.id);return}this.deleteSelectedLine(i)}},this.setReference=e=>{this.isReference=e},this.pointsWithinRange=e=>!(this.lowerLimitPointNum&&e<this.lowerLimitPointNum||this.upperLimitPointNum&&e>this.upperLimitPointNum),this.setLineList=e=>{const i=e.length!==this.lineListLen;this.lineList=e,i&&this.emit("updatePageNumber")},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(e),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(t.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new ne,this.dependToolConfig={lineType:T.Line}}get isLineSelected(){return this.selectedID&&this.activeLine}get selectedLinePoints(){return this.activeLine?this.getPointList(this.activeLine):[]}get isCreate(){return this.status===0}get isActive(){return this.status===1}get isNone(){return this.status===2}get isCurve(){return this.config.lineType===T.Curve}get isMultipleColor(){return this.config.lineColor===Ot.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===L.Polygon}get isDependRect(){return this.dependToolName===L.Rect}get isCurrentAttributeLocked(){return this.attributeLockList.includes(this.defaultAttribute)}get attributeFilteredLines(){return this.attributeLockList.length>0?this.lineList.filter(t=>this.attributeLockList.includes((t==null?void 0:t.attribute)||"")):this.lineList}get enableOutOfTarget(){return this.config.enableOutOfTarget}get showOrder(){return this.config.showOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const t=st.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(e=>{var i;return(i=e==null?void 0:e.pointList)==null?void 0:i.some(s=>st.inViewPort(s,t))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var t,e;return(e=(t=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:""}get currentPageResult(){return this.lineList}updateStatus(t,e=!1){if(t!==this.status){if(e){let i="";this.textCheckType===X.Order&&this.isTextConfigurable&&(i=S.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",i)}this.status=t,this.lineStatusChanged()}}isInBasicPolygon(t){var e,i;return Pe(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:t}=this.basicResult,{lineType:e}=this.dependToolConfig;return e===T.Curve?ee(t.reduce((i,s)=>[...i,s.x,s.y],[]),.5,!0,20):t}getNextCoordByRenderCoord(t){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(t))}getNextCoordByAbsCoord(t){var e;const i=(e=this.activeLine)==null?void 0:e.slice(-1)[0];return i?this.coordUtils.getNextCoordByDependTool(t,i):t}pointInLine(t,e,i){return t.filter(s=>s).length<2?!1:t.some((s,n)=>{if(n===0)return!1;const o=this.coordUtils.getRenderCoord(t[n-1]),a=this.coordUtils.getRenderCoord(s);return M.isInLine(e,o,a,i)})}arc(t,e=ce,i){var s,n,o,a,l,h;if(this.ctx){const{x:c,y:u}=t;(s=this.ctx)==null||s.save(),(n=this.ctx)==null||n.beginPath(),this.ctx.fillStyle=i||this.lineStyle.color,(o=this.ctx)==null||o.arc(c,u,e,0,360),(a=this.ctx)==null||a.closePath(),(l=this.ctx)==null||l.fill(),(h=this.ctx)==null||h.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:t,left:e,right:i,bottom:s}=this.activeArea,{x:n,y:o}=this.coordUtils.getRenderCoord({x:e,y:t});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(n,o,(i-e)*this.zoom,(s-t)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}addLinePoint(t){var e,i,s,n;this.arc(t),(e=this.activeLine)==null||e.push(he(le({},t),{id:J()})),((i=this.activeLine)==null?void 0:i.length)===1?(s=this.actionsHistory)==null||s.initRecord(this.activeLine):(n=this.actionsHistory)==null||n.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(t,e=!1){this.updateStatus(0,e),this.addLinePoint(t)}isActiveLineValid(){var t;return this.selectedID?(t=this.lineList.find(e=>e.id===this.selectedID))==null?void 0:t.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(t,e=!1){return et.getStrokeAndFill(this.getColor(t.attribute),t.valid,{isSelected:e}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?P.calcViewportBoundaries(this.activeLine,this.isCurve,nt,this.zoom):void 0}drawLineNumber(t,e=1,i,s="",n,o=!0){var a,l,h;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let c=this.showOrder?e.toString():`${s}`;if(this.attributeConfigurable){const u=n?(h=(l=(a=this.attributeList)==null?void 0:a.find(d=>d.value===n))==null?void 0:l.key)!=null?h:n:"";c=[c,`${!o&&u?"\u65E0\u6548":""}${u}`].filter(d=>d).join("_")}this.drawText(t,c,i)}}drawLineTextAttribute(t,e,i){if(t&&i)return this.drawText(t,i,e,200)}drawText(t,e,i,s){var n,o;this.ctx&&((n=this.ctx)==null||n.save(),this.ctx.font="italic bold 14px SourceHanSansCN-Regular",this.ctx.fillStyle=i,this.ctx.strokeStyle=i,this.ctx.shadowColor="rgba(0, 0, 0, 0.6)",this.ctx.shadowOffsetY=2,this.ctx.shadowBlur=4,s?m.wrapText(this.canvas,e,t.x-Zt.x,t.y-Zt.y,s):this.ctx.fillText(e,t.x-Zt.x,t.y-Zt.y),(o=this.ctx)==null||o.restore())}moveActiveArea(t,e){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+e,bottom:this.activeArea.bottom+e,right:this.activeArea.right+t,left:this.activeArea.left+t})),this.activeLine&&(this.activeLine.map(i=>Object.assign(i,{x:i.x+t,y:i.y+e})),this.updateLines())}findHoveredPoint(t){if(!!this.activeLine)return this.activeLine.find(e=>{const i=this.coordUtils.getRenderCoord(e);return M.calcDistance(i,t)<=Ut})}findHoverLine(t){return F.cloneDeep(this.lineList).reverse().find(({pointList:i})=>{const s=i?this.getPointList(i):[],n=this.getLineWidthScope();return s.some((o,a)=>{if(a===0)return!1;const l=this.coordUtils.getRenderCoord(o),h=this.coordUtils.getRenderCoord(s[a-1]);return M.isInLine(t,l,h,n)})})}getAdsorptionPoint(t){let e,i,s;return F.cloneDeep(this.lineList).reverse().forEach(({pointList:n,id:o})=>{if(o===this.selectedID||!n||(n==null?void 0:n.length)<2)return;const a=this.findNearestPoint(n,t);if(a){if(a.minDistance===0){e=a.point;return}(i===void 0||a.minDistance<i)&&(e=a.point,i=a.minDistance)}}),s||e}findNearestPoint(t,e,i=7){let s;const n=i;for(let o=1;o<=t.length-1;o++){const a=this.coordUtils.getRenderCoord(t[o]),l=this.coordUtils.getRenderCoord(t[o-1]),{length:h,footPoint:c}=P.getFootOfPerpendicular(e,a,l),u=M.calcTwoPointDistance(a,e),d=M.calcTwoPointDistance(l,e);if(u<=i*2){s=a,i=0;break}if(d<=i*2){s=l,i=0;break}h<i&&(s=c,i=h)}return s?{point:s,minDistance:n}:void 0}getPointList(t){return this.isCurve?Et(t,nt):t}moveSelectedLine(t){const e=(t.x-this.prevAxis.x)/this.zoom,i=(t.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(e,i);return}if(this.isDependPolygon){this.moveLineInPolygon(e,i);return}let s=[0,this.imageSize.width],n=[0,this.imageSize.height];if(this.isDependRect){const{x:o,y:a,width:l,height:h}=this.basicResult;s=[o,o+l],n=[a,a+h]}this.moveLineInRectRange(e,i,s,n)}moveSelectPoint(t){if(!this.selectedPoint)return;const e=t.x-this.prevAxis.x,i=t.y-this.prevAxis.y,s=(this.selectedPoint?this.selectedPoint.x:0)+e/this.zoom,n=(this.selectedPoint?this.selectedPoint.y:0)+i/this.zoom,o={x:s,y:n};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(o)),this.updateLines(),this.render()}getCoordByConfig(t,e){var i;const s=!!t.shiftKey,n=t.altKey;if(((i=this.activeLine)==null?void 0:i.length)>0&&s){const o=this.activeLine.slice(-1)[0];return M.getVHPoint(o,e,this.coordUtils.getAbsCoord(e),this.coordUtils.getRenderCoord(o))}return this.edgeAdsorptionEnabled&&!n?this.getAdsorptionPoint(e):e}getNextPoint(t,e){const i=this.getCoordByConfig(t,e)||e;return this.enableOutOfTarget?i:this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(t){const e=this.getCoordinate(t),i=t.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(t,e);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!t.altKey)){const s=this.getAdsorptionPoint(e);s&&this.arc(s)}if(this.isActive){if(this.isMousedown&&i){if(this.selectedPoint){this.moveSelectPoint(e);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(e),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(e),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);this.mouseMoveHandler(t),this.prevAxis=e}setActiveArea(t,e=!1){const i=this.findHoverLine(t);if(i){const s=this.lineList.findIndex(a=>a.id===(i==null?void 0:i.id)),n=P.calcViewportBoundaries((i==null?void 0:i.pointList)||[],this.isCurve,nt,this.zoom),o=this.lineList[s];this.updateStatus(1),this.setActiveLine(o.pointList),this.setSelectedLineID(o.id),this.activeArea=n,this.updateLineAttributes(o)}else e&&this.setNoneStatus();this.render()}setActiveLineByID(t){const e=this.lineList.find(i=>i.id===t);if(e){const i=P.calcViewportBoundaries((e==null?void 0:e.pointList)||[],this.isCurve,nt,this.zoom);this.updateStatus(1),this.setActiveLine(e.pointList),this.setSelectedLineID(e.id),this.activeArea=i,this.updateLineAttributes(e)}this.render()}setActiveLine(t){this.activeLine=t?F.cloneDeep(t):void 0}historyChanged(t){const e=`${t}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[e]){const i=this.actionsHistory&&this.actionsHistory[t]();this.setActiveLine(i),this.render()}return}if(this.history&&this.history[e]){const i=this.history[t](),s=i==null?void 0:i.find(n=>n.id===this.selectedID);this.lineList=i,this.selectedID&&s?this.setActiveLine(s==null?void 0:s.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],a=[i,i+n];return P.isInRange(t.x,o)&&P.isInRange(t.y,a)}return P.isInRange(t.x,[0,this.imageSize.width])&&P.isInRange(t.y,[0,this.imageSize.height])}getPointInsertIndex(t,e){if(t&&this.activeLine){const i=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((s,n)=>{if(n>0){const o=this.activeLine?this.activeLine[n-1]:void 0,a=this.isCurve?i.slice((n-1)*(nt+1),n*(nt+1)):[o,s];return this.pointInLine(a,t,e||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var t;return this.activeLine&&((t=this.activeLine)==null?void 0:t.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(t){const e=this.getPointInsertIndex(t,2)-1;if(e>-1){const i=this.activeLine[e];i.specialEdge=!i.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var t;const e=this.getPointInsertIndex(this.cursor),i=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&e>-1&&i&&(this.activeLine.splice(e,0,he(le({},this.coordUtils.getAbsCoord(this.cursor)),{id:J()})),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);if(this.isMousedown=!0,this.prevAxis=e,t.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(e),this.coordsInsideActiveArea=this.isActive&&this.activeArea?M.inArea(this.activeArea,this.coordUtils.getAbsCoord(e)):!1,this.lineDragging=!1}lineHasChanged(){const t=this.lineList.find(e=>e.id===this.selectedID);return t?JSON.stringify(t.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const t=this.lineList.find(e=>e.id===this.selectedID);t&&(t.pointList=F.cloneDeep(this.activeLine),this.emit("dataUpdated",this.lineList))}onMouseUp(t){const e=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo){e();return}t.which===1&&this.onLeftClick(t),t.which===3&&this.onRightClick(t),e()}isTextValid(t){return S.textAttributeValidate(this.textCheckType,this.customFormat,t)}createLineData(){const t=J(),e={pointList:F.cloneDeep(this.activeLine),id:t,valid:this.isLineValid,order:this.nextOrder()};return e.attribute=this.defaultAttribute,e}stopLineCreating(t=!0){var e,i,s,n;const o=this.selectedID?!0:!!this.isTextConfigurable;let a;if(t){if(this.selectedID){const l=this.lineList.find(h=>h.id===this.selectedID);a=this.selectedID,l&&(l.pointList=F.cloneWith(this.activeLine),F.isEqual(l.pointList,(e=this.history)==null?void 0:e.pushHistory(this.lineList))||(i=this.history)==null||i.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const l=this.createLineData();a=l.id,this.setLineList([...this.lineList,l]),(s=this.history)==null||s.pushHistory(this.lineList)}}o?this.setActiveStatus(a):this.setNoneStatus(),(n=this.actionsHistory)==null||n.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(t){const e=t?this.lineList.find(i=>i.id===t):void 0;if(e){const i=e==null?void 0:e.pointList;this.updateStatus(1),this.setActiveLine(i),this.setSelectedLineID(t)}else this.setNoneStatus()}setNoneStatus(t=!0){t&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(t,e){this.isShift=e!=null?e:t.keyCode===A.Shift}continueToEdit(){var t;this.updateStatus(0),this.cursor=void 0,(t=this.actionsHistory)==null||t.pushHistory(this.activeLine),this.render()}setInvalidLineOnCreating(t){if(this.selectedID&&t.keyCode!==A.Ctrl||!this.isCreate)return;const e=!t.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,e,!1):this.isLineValid=e}onKeyDown(t){if(super.onKeyDown(t),this.setKeyDownStatus(t),t.keyCode===A.Z&&!t.ctrlKey&&this.toggleIsHide(),t.keyCode===A.Shift&&this.render(),t.keyCode===A.Tab){t.preventDefault(),this.selectToNextLine(t);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(t),this.config.attributeConfigurable){const e=S.getAttributeByKeycode(t.keyCode,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}selectToNextLine(t){const e=x.getNextSelectedRectIDByEvent(this.viewPortLines.map(i=>{var s,n,o,a;return he(le({},i),{x:(n=(s=i.pointList[0])==null?void 0:s.x)!=null?n:0,y:(a=(o=i.pointList[0])==null?void 0:o.y)!=null?a:0})}),t,this.selectedID);e&&this.setActiveLineByID(e.id)}keyboardEventWhileLineCreating(t){!this.isCreate||(t.keyCode===A.Ctrl&&this.setInvalidLineOnCreating(t),[A.Shift,A.Alt].includes(t.keyCode)&&this.renderNextPoint(t,this.prevAxis))}renderNextPoint(t,e){const i=this.coordUtils.getRenderCoord(this.getNextPoint(t,e));this.render(i)}deleteSelectedLine(t){const e=P.calcViewportBoundaries(this.activeLine,this.isCurve,nt,this.zoom);M.inArea(e,this.coordUtils.getAbsCoord(t))&&this.deleteLine()}deleteSelectedLinePoint(t){var e;this.pointsWithinRange(this.activeLine.length-1)&&t&&(this.setActiveLine(this.activeLine.filter(s=>s.id!==t)),this.updateLines(),(e=this.history)==null||e.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var t;this.lineList=this.lineList.filter(e=>e.id!==this.selectedID),(t=this.history)==null||t.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(t,e,i=!0){var s;const n=this.lineList.find(o=>o.id===t);n&&(n.valid=e!==void 0?e:!n.valid,(s=this.history)==null||s.pushHistory(this.lineList),i&&this.render())}empty(){var t,e;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(t=this.actionsHistory)==null||t.empty(),(e=this.history)==null||e.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(t){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)))}setTextAttribute(t){var e;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",t),(e=this.history)==null||e.applyAttribute(this.selectedID,"textAttribute",t))}setLineAttribute(t,e,i){const s=i||this.selectedID;if(s){const n=this.lineList.find(o=>o.id===s);n&&(n[t]=e)}this.render()}updateAttribute(t){this.emit("updateAttribute",t)}updateLineAttributes(t){var e;if(this.attributeConfigurable&&t){const i=(t==null?void 0:t.attribute)||"";this.defaultAttribute=i,this.updateAttribute(i)}if(this.isTextConfigurable&&t){const i=(t==null?void 0:t.textAttribute)||"";this.updateTextAttribute(i)}(e=this.history)==null||e.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(t){if(this.selectedID){const e=this.lineList.find(i=>i.id===this.selectedID);e&&(e.textAttribute=t)}this.emit("updateText",t)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(t){this.textEditingID=t,this.render()}setSelectedLineID(t){var e,i;if(this.selectedID===t)return;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}attributeLockListChange(t){this.attributeLockList=t,this.render()}setResult(t){this.setNoneStatus(),this.setLineList(t),this.render()}setConfig(t){super.setConfig(t)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(t=""){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var t,e;const i=this.isActiveLineValid(),s=this.defaultAttribute,n=this.getColor(s),o=i?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,a=(e=(t=this.lineList.find(l=>l.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:"";return{color:o,textAttribute:a}}renderTextAttribute(){var t,e,i,s;if(!this.ctx||!this.activeLine||((t=this.activeLine)==null?void 0:t.length)<2||this.isCreate)return;const n=this.isActiveLineValid(),o=this.defaultAttribute,{x:a,y:l}=this.activeLine[1],h=this.coordUtils.getRenderCoord({x:a,y:l}),c=this.getColor(o),u=n?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,d=(i=(e=this.lineList.find(g=>g.id===this.selectedID))==null?void 0:e.textAttribute)!=null?i:"";this._textAttributeInstance||(this._textAttributeInstance=new $t({container:this.container,icon:this.getTextIconSvg(o),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((s=this._textAttributeInstance)==null?void 0:s.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${d}`,{left:h.x,top:h.y,color:u}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(o))}getTextIconSvg(t=""){return S.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;!S.textAttributeValidate(this.config.textCheckType,"",e)&&(this.emit("messageError",S.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setTextAttribute(e),this.emit("updateTextAttribute"),this.render()}}}class de{static getMarkerShowText(t,e=[]){return S.getAttributeShowText(t,e)}}var Ur=Object.defineProperty,zr=Object.defineProperties,Wr=Object.getOwnPropertyDescriptors,bi=Object.getOwnPropertySymbols,Vr=Object.prototype.hasOwnProperty,jr=Object.prototype.propertyIsEnumerable,yi=Math.pow,xi=(r,t,e)=>t in r?Ur(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,zt=(r,t)=>{for(var e in t||(t={}))Vr.call(t,e)&&xi(r,e,t[e]);if(bi)for(var e of bi(t))jr.call(t,e)&&xi(r,e,t[e]);return r},ue=(r,t)=>zr(r,Wr(t));const mi=200;class Ii extends rt{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(n=>n.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(S.textChange(e,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=e=>{const i=I.changePointByZoom(e,this.zoom);return this.pointList.some(s=>{const n=I.changePointByZoom(s,this.zoom);return P.getLineLength(n,i)<.2})},this.config=x.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=x.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=x.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.pointList.forEach(s=>{s.id===i&&(s.attribute=t)}),this.history.pushHistory(this.pointList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return S.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=O.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.createPoint(t),this.render();return}return this.hoverID===this.selectedID&&t.button===0&&(this.dragStatus=O.Start),this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===O.Start||this.dragStatus===O.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===O.Move&&this.history.pushHistory(this.pointList),this.dragStatus=O.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=O.Move;const s=this.getCoordinateUnderZoom(t),n=I.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),o=this.drawOutsideTarget?I.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):I.changePointByZoom(n,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===L.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!_.isInPolygon(o,this.basicResult.pointList)||(this.pointList.forEach(a=>{a.id===this.selectedID&&(a.x=o.x,a.y=o.y)}),this.render())}onKeyDown(t){if(!x.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case A.Delete:this.deletePoint();break;case A.Tab:{this.onTabKeyDown(t);break}case A.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=S.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,n;if(!this.imgInfo)return;const{upperLimit:o}=this.config;if(o&&this.currentPageResult.length>=o){this.emit("messageInfo",`${B.getMessagesByLocale(C.LowerLimitPoint,this.lang)}`);return}const a=x.getSourceID(this.basicResult),l=this.getCoordinateUnderZoom(t);let h=I.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[L.Polygon,L.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const g=((i=this.referenceData)==null?void 0:i.toolName)===L.Polygon,{dropFoot:v,hasClosed:f}=_.getClosestPoint(h,this.referenceData.result,(n=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?n:T.Line,yt/this.zoom,{isClose:g});v&&(h=v),f&&this.emit("messageSuccess",`${B.getMessagesByLocale(C.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let d=!1;switch(this.dependToolName){case L.Rect:{d=!Z.isInRect(h,this.basicResult);break}case L.Polygon:{d=!_.isInPolygon(h,this.basicResult.pointList);break}}if(d)return}if(l.x<0||l.y<0||l.x>this.imgInfo.width||l.y>this.imgInfo.height)return}if(this.isMinDistance(h))return;let c=ue(zt({},h),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:J(8,62),sourceID:a,textAttribute:"",order:x.getMaxOrder(this.pointList.filter(d=>x.isSameSourceID(d.sourceID,a)))+1});if(this.config.textConfigurable){let d="";d=S.getTextAttribute(this.pointList.filter(g=>x.isSameSourceID(g.sourceID,a)),this.config.textCheckType),c=ue(zt({},c),{textAttribute:d})}if(this.hasMarkerConfig){const d=x.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(d)c=ue(zt({},c),{label:d.label}),this.markerIndex=d.index,this.emit("markIndexChange");else{this.emit("messageInfo",B.getMessagesByLocale(C.MarkerFinish,this.lang));return}}this.hoverID=c.id;const u=[...this.pointList,c];this.setPointList(u),this.history.pushHistory(u),this.setSelectedID(c.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(yi(t.x-e.x,2)+yi(t.y-e.y,2))}getHoverId(){var t;const e=I.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}rightMouseUp(){if(this.selectedID===this.hoverID){const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=x.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===O.Move||this.dragStatus===O.Start)return;let e=G.ascend;t.shiftKey&&(e=G.descend);const[i,s]=x.getRenderResultList(this.pointList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let n=[...i];s&&(n=[...n,s]);const o=x.getNextSelectedRectID(n,e,this.selectedID);o&&this.setSelectedID(o.id)}get currentPageResult(){const[t]=x.getRenderResultList(this.pointList,x.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=x.getRenderResultList(t,x.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedID&&(this.setPointList(this.pointList.filter(e=>e.id!==this.selectedID)),this.history.pushHistory(this.pointList),(t=this._textAttributInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===O.Move||this.dragStatus===O.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(n=>n.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(n=>n.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=O.Wait,{width:mi*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;S.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",S.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(S.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(g=>g.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:n,attribute:o,valid:a}=i,l=mi*this.zoom*.6,h=I.getOffsetCoordinate({x:s,y:n},this.currentPos,this.zoom),c=this.getColor(o),u=a?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,d=4;this._textAttributInstance||(this._textAttributInstance=new $t({width:l,container:this.container,icon:this.getTextIconSvg(o),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((e=this._textAttributInstance)==null?void 0:e.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${i.textAttribute}`,{left:h.x,top:h.y+d,color:u,width:l})}renderPoint(t){var e,i,s;const{textAttribute:n="",attribute:o}=t,a=t.id===this.selectedID,l=this.getColor(o),h=I.changePointByZoom(t,this.zoom,this.currentPos),{width:c=2,hiddenText:u=!1}=this.style,d=et.getStrokeAndFill(l,t.valid,{isSelected:a||t.id===this.hoverID});m.drawCircle(this.canvas,h,c,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:d.stroke,fill:d.fill});let g="";(((e=this.config)==null?void 0:e.isShowOrder)||((i=this.config)==null?void 0:i.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(g=`${t.order}`),t.label&&this.hasMarkerConfig&&(g=`${x.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${de.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(g=`${g} ${S.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`),u||m.drawText(this.canvas,{x:h.x+c/2,y:h.y-c-4},g,{textAlign:"center",color:d.stroke}),a?this.renderTextAttribute():u||m.drawText(this.canvas,{x:h.x+c,y:h.y+c+24},n,zt({color:d.stroke},K))}renderPointList(){const[t,e]=x.getRenderResultList(this.pointList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let n=I.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const o=((t=this.referenceData)==null?void 0:t.toolName)===L.Polygon,{dropFoot:a}=_.getClosestPoint(n,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:T.Line,yt/this.zoom,{isClose:o});a&&n!==a&&n!==a&&(n=a,m.drawCircle(this.canvas,I.changePointByZoom(n,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),m.drawCircle(this.canvas,I.changePointByZoom(n,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderPointList(),this.renderTop())}}class wi extends rt{constructor(t){super(t);this.getSingleResult=e=>{const i={};return this.config.configList.length>0&&this.config.configList.forEach(s=>{var n;i[s.key]=(n=s.default)!=null?n:""}),{value:i,id:J(),sourceID:e!=null?e:x.getSourceID()}},this.getInitResultList=(e,i)=>e>0?i.map(s=>this.getSingleResult(s.id)):[this.getSingleResult()],this.textList=[],this.setShowDefaultCursor(!0),this.setConfig(t.config),this.initTextDisplayContainer()}get dataList(){return this.textList}get textValueContainerID(){return"textValueContainer"}get textValueContainer(){return document.getElementById(this.textValueContainerID)}get currentPageResult(){return this.textList}setResult(t){var e;this.textList=t,this.toggleTextContainerVisible(!0);const i=(e=this.textList[0])==null?void 0:e.value;i&&Object.keys(i).forEach(s=>{this.renderText(s,i[s])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!i)}updateTextValue(t,e){this.textList[0].value[t]=e,this.renderText(t,e),this.emit("valueUpdated")}renderText(t,e){const i=document.getElementById(`textKey${t}`);i&&(i.innerText=e)}getTextDomID(t){return`textKey${t}`}initTextDisplayContainer(){const t=document.createElement("div"),e={position:"absolute",right:"0",top:"0","z-index":"20","max-width":"20%","font-family":"SourceHanSansCN-Regular",background:"rgb(102, 230, 255)",color:"white","word-break":"break-all","line-height":"24px","white-space":"pre-wrap","max-height":"80%","overflow-y":"auto",opacity:"0.6"};t.setAttribute("style",Object.keys(e).reduce((i,s)=>(i+=`${s}: ${e[s]};`,i),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(i=>{const s=document.createElement("div"),n=document.createElement("div"),o=document.createElement("div");s.setAttribute("style","padding: 8px 16px"),n.innerText=`${i.key}:`,o.innerText="",o.setAttribute("id",this.getTextDomID(i.key)),s.appendChild(n),s.appendChild(o),t.appendChild(s)}),this.container.appendChild(t)}exportData(){return[this.textList,this.basicImgInfo]}destroyCanvas(){super.destroyCanvas(),this.textValueContainer&&this.container.removeChild(this.textValueContainer)}onKeyDown(t){super.onKeyDown(t),t.keyCode===A.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const e=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=e}}}var Xr=Object.defineProperty,Yr=Object.defineProperties,Gr=Object.getOwnPropertyDescriptors,Li=Object.getOwnPropertySymbols,Kr=Object.prototype.hasOwnProperty,Jr=Object.prototype.propertyIsEnumerable,Pi=(r,t,e)=>t in r?Xr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ci=(r,t)=>{for(var e in t||(t={}))Kr.call(t,e)&&Pi(r,e,t[e]);if(Li)for(var e of Li(t))Jr.call(t,e)&&Pi(r,e,t[e]);return r},qr=(r,t)=>Yr(r,Gr(t));class x{static getStepInfo(t,e){return e==null?void 0:e.filter(i=>i.step===t)[0]}static getCurrentStepInfo(t,e){const i=this.getStepInfo(t,e);return i&&(i.type===Dt.QUALITY_INSPECTION||i.type===Dt.MANUAL_CORRECTION)?this.getCurrentStepInfo(i.dataSourceStep,e):i}static getMaxOrder(t){let e=0;return t.forEach(i=>{i.order&&i.order>e&&(e=i.order)}),e}static hotkeyFilter(t){const e=t.target||t.srcElement;if(!e)return!0;const{tagName:i,type:s}=e;if(!i||!s)return!0;let n=!0;return(e.isContentEditable||i==="TEXTAREA"||(i==="INPUT"&&s!=="radio"||i==="TEXTAREA")&&!e.readOnly)&&(n=!1),n}static getCurrentOperation(t){switch(t){case L.Rect:case L.RectTrack:return pe;case L.Tag:return ui;case L.Polygon:return di;case kt.Check:return Tr;case L.Line:return pi;case L.Point:return Ii;case L.Text:return wi;default:throw new Error("not match tool")}}static getNextSelectedRectID(t,e=G.ascend,i){let s=1;e===G.descend&&(s=-1);const n=t.sort((l,h)=>l.x-h.x==0?l.y-h.y:s*(l.x-h.x)),o=n.findIndex(l=>l.id===i),a=n.length;return n[(o+1)%a]}static getNextSelectedRectIDByEvent(t,e,i){const s=e.shiftKey?G.descend:G.ascend;return this.getNextSelectedRectID(t,s,i)}static getRenderResultList(t,e,i=[],s){let n;return[t.filter(a=>s&&s===(a==null?void 0:a.id)?(n=a,!1):!(i.length>0&&!i.includes(a==null?void 0:a.attribute)||this.isDifferSourceID(a==null?void 0:a.sourceID,e))),n]}static getSourceID(t){var e;const i="";return t&&(e=t==null?void 0:t.id)!=null?e:i}static findAllLine(t,e=!0){const i=[],s=[...t];s.length>=3&&e===!0&&s.push(Ci({},s[0]));for(let n=0;n<s.length;n++)s[n+1]&&i.push({point1:s[n],point2:s[n+1],pointIndex:n});return i}static translateSourceID(t){return(t===void 0||t===0||t==="0")&&(t=""),t}static isDifferSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`!=`${e}`}static isSameSourceID(t,e){return t=this.translateSourceID(t),e=this.translateSourceID(e),`${t}`==`${e}`}static getNextMarker(t,e=[],i){if((e==null?void 0:e.length)===0)return;let s=e.map((n,o)=>qr(Ci({},n),{index:o}));if(typeof i=="number"&&i>0){const n=e[i];if(n&&t.every(o=>o.label!==n.value))return{label:n.value,index:i};s=[...s.slice(i,e.length),...s.slice(0,i)]}for(let n=0;n<s.length;n++)if(!t.some(o=>o.label===s[n].value))return{label:s[n].value,index:s[n].index}}static getCurrentMarkerIndex(t,e=[]){return e.findIndex(i=>t===i.value)}}x.jsonParser=(r,t={})=>{try{return typeof r=="string"?JSON.parse(r):Fi(r)?r:t}catch(e){return t}};var Qr=Object.defineProperty,Di=Object.getOwnPropertySymbols,tn=Object.prototype.hasOwnProperty,en=Object.prototype.propertyIsEnumerable,_i=(r,t,e)=>t in r?Qr(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ge=(r,t)=>{for(var e in t||(t={}))tn.call(t,e)&&_i(r,e,t[e]);if(Di)for(var e of Di(t))en.call(t,e)&&_i(r,e,t[e]);return r};class _{static getHoverPolygonID(t,e,i=3,s=T.Line){let n="",o=Infinity;const a=I.axisArea(t,i);return e.forEach(l=>{l.pointList&&a.forEach(h=>{const c=this.calcPolygonSize(l.pointList);this.isInPolygon(h,l.pointList,s)&&c<o&&(n=l.id,o=c)})}),n}static calcPolygonSize(t=[]){if((t==null?void 0:t.length)<=2)return 0;const e=t.length,i=t.reduce((s,n,o,a)=>{const l=a[(o+1)%e];return s+n.x*l.y-l.x*n.y},0);return Math.abs(i)/2}static isInPolygon(t,e,i=T.Line){let s=0,n,o,a,l;e=[...e],i===T.Curve&&(e=this.createSmoothCurvePoints(e.reduce((c,u)=>[...c,u.x,u.y],[]),.5,!0,20)),[a]=e;const h=e.length;for(n=1;n<=h;n++)l=e[n%h],t.x>Math.min(a.x,l.x)&&t.x<=Math.max(a.x,l.x)&&t.y<=Math.max(a.y,l.y)&&a.x!==l.x&&(o=(t.x-a.x)*(l.y-a.y)/(l.x-a.x)+a.y,(a.y===l.y||t.y<=o)&&s++),a=l;return s%2!=0}static createSmoothCurvePointsFromPointList(t,e=Y){return this.createSmoothCurvePoints(t.reduce((s,n)=>[...s,n.x,n.y],[]),.5,!1,e).map((s,n)=>{var o;const a=n/(Y+1),l=Math.floor(a),h=(o=t[l])!=null?o:{};return ge(l===a?ge({},h):{specialEdge:h.specialEdge},s)})}static createSmoothCurvePoints(t,e=.5,i=!1,s=Y){if(t.length<4)return t;const n=[],o=t.slice(0);let a,l,h,c,u,d,g,v,f,b,p,y,w;for(i?(o.unshift(t[t.length-1]),o.unshift(t[t.length-2]),o.unshift(t[t.length-1]),o.unshift(t[t.length-2]),o.push(t[0]),o.push(t[1])):(o.unshift(t[1]),o.unshift(t[0]),o.push(t[t.length-2]),o.push(t[t.length-1])),w=2;w<o.length-4;w+=2)for(h=(o[w+2]-o[w-2])*e,c=(o[w+4]-o[w-0])*e,u=(o[w+3]-o[w-1])*e,d=(o[w+5]-o[w+1])*e,y=0;y<=s;y++)p=y/s,g=2*Math.pow(p,3)-3*Math.pow(p,2)+1,v=-(2*Math.pow(p,3))+3*Math.pow(p,2),f=Math.pow(p,3)-2*Math.pow(p,2)+p,b=Math.pow(p,3)-Math.pow(p,2),a=g*o[w]+v*o[w+2]+f*h+b*c,l=g*o[w+1]+v*o[w+3]+f*u+b*d,n.push(a),n.push(l);const D=[];for(let R=0;R<n.length-1;R+=2)D.push({x:n[R],y:n[R+1]});if(i)for(let R=0;R<s+1;R++){const E=D.shift();D.push(E)}return D}static getPolygonByID(t,e){return t.find(i=>i.id===e)}static getHoverEdgeIndex(t,e,i=T.Line,s=3){let n=[...e];i===T.Curve?n=this.createSmoothCurvePoints(e.reduce((l,h)=>[...l,h.x,h.y],[]),.5,!0,Y):i===T.Line&&n.push(n[0]);let o=-1,a=s;for(let l=0;l<n.length-1;l++){const{length:h}=P.getFootOfPerpendicular(t,n[l],n[l+1]);h<a&&(o=l,a=h)}return o===-1?-1:i===T.Curve?Math.floor(o/Y):o}static getClosestPoint(t,e,i=T.Line,s=3,n){var o;let a=!1;const l=(o=n==null?void 0:n.isClose)!=null?o:!0;let h="",c=-1,u=Infinity,d=t;const g=20;let v=!1;return e.forEach(f=>{if(!v&&!!f.pointList)switch(i){case T.Line:x.findAllLine(f.pointList,l).forEach((p,y)=>{if(v)return;let{length:w,footPoint:D}=P.getFootOfPerpendicular(t,p.point1,p.point2);const R=P.getLineLength(p.point1,t),E=P.getLineLength(p.point2,t);R<s*2&&(D=p.point1,w=R,v=!0),E<s*2&&(D=p.point2,w=E,v=!0),w<u&&w<s&&(h=f.id,c=y,u=w,d=D,a=!0)});break;case T.Curve:{const b=this.createSmoothCurvePoints(f.pointList.reduce((p,y)=>[...p,y.x,y.y],[]),.5,l,g);for(let p=0;p<b.length-1;p++){const{length:y,footPoint:w}=P.getFootOfPerpendicular(t,b[p],b[p+1]);y<u&&y<s&&(h=f.id,c=Math.floor(p/(g+1)),u=y,d=w,a=!0)}}break}}),{dropFoot:d,closestEdgeIndex:c,closestPolygonID:h,hasClosed:a}}static isPointListInPolygon(t,e,i=T.Line){return t.every(s=>this.isInPolygon(s,e,i))}static isPointListOutSidePolygon(t,e,i=T.Line){return t.some(s=>!this.isInPolygon(s,e,i))}static getPolygonArea(t){let e=0;for(let i=0,s=t.length;i<s;i++){const n=t[i].x,o=t[i===t.length-1?0:i+1].y,a=t[i===t.length-1?0:i+1].x,l=t[i].y;e+=n*o*.5,e-=a*l*.5}return Math.abs(e)}static updatePolygonByRotate(t,e=1,i){let s=1;return t===_t.Anticlockwise&&(s=-1),s*=e,P.rotateRectPointList(s,i)}static deletePolygonLastPoint(t,e,i,s){return i===s.length-1?t:[...t,{x:e[0],y:e[1]}]}static concatBeginAndEnd(t){return t.length<1?t:[...t,t[0]]}static segmentPolygonByPolygon(t,e){var i,s;try{let n=St([[..._.concatBeginAndEnd(t.map(a=>[a.x,a.y]))]]);return e.forEach(a=>{const l=St([[..._.concatBeginAndEnd(a.pointList.map(c=>[c.x,c.y]))]]),h=Hi(n,l);h&&(n=h)}),((s=(i=n==null?void 0:n.geometry)==null?void 0:i.coordinates.map(a=>{var l;return((l=n==null?void 0:n.geometry)==null?void 0:l.type)==="MultiPolygon"?a[0].reduce(_.deletePolygonLastPoint,[]):a.reduce(_.deletePolygonLastPoint,[])}))!=null?s:[]).reduce((a,l)=>{const h=l.length,c=l.filter((u,d)=>{const g=(d+1)%h;return!I.getIsInScope(u,l[g],1)});return c.length<3?a:[...a,c]},[])}catch(n){console.error(n)}}static getPolygonPointList(t,e){const i=e.find(s=>s.id===t);return i&&i.pointList&&i.pointList.length>0?i.pointList:[]}static getWrapPolygonIndex(t,e){return e.findIndex(i=>_.isPointListInPolygon(t,i.pointList))}static clipPolygonFromWrapPolygon(t,e){const i=_.isPolygonClosewise(e),s=_.isPolygonClosewise(t),n=_.getClosePointDistanceFromPolygon(t[0],e),o=e[n];let a=[...e.slice(0,n),o,...t,t[0],...e.slice(n,e.length)];return i===s&&(a=[...e.slice(0,n),o,t[0],...t.reverse(),...e.slice(n,e.length)]),a}static isPolygonClosewise(t){const e=t.length;let i,s,n,o=0,a;if(e<3)return 0;for(i=0;i<e;i++)s=(i+1)%e,n=(i+2)%e,a=(t[s].x-t[i].x)*(t[n].y-t[s].y),a-=(t[s].y-t[i].y)*(t[n].x-t[s].x),a<0?o--:a>0&&o++;return o>0?1:o<0?-1:0}static getClosePointDistanceFromPolygon(t,e){let i=Number.MAX_SAFE_INTEGER,s=-1;return e.forEach((n,o)=>{const a=M.calcDistance(t,n);a<i&&(i=a,s=o)}),s}static combinePolygonWithPolygon(t,e){var i,s;try{const n=St([[..._.concatBeginAndEnd(t.pointList.map(c=>[c.x,c.y]))]]),o=St([[..._.concatBeginAndEnd(e.pointList.map(c=>[c.x,c.y]))]]),a=Ni(n,o),l=[],h=t;if(((s=(i=a==null?void 0:a.geometry)==null?void 0:i.coordinates)==null?void 0:s.length)===1){l.push(e.id);const c=a==null?void 0:a.geometry.coordinates.map(u=>{var d;return((d=a==null?void 0:a.geometry)==null?void 0:d.type)==="MultiPolygon"?u[0].reduce(_.deletePolygonLastPoint,[]):u.reduce(_.deletePolygonLastPoint,[])})[0];h.pointList=c}return{newPolygon:h,unionList:l}}catch(n){console.error(n)}}}var sn=Object.defineProperty,rn=Object.defineProperties,nn=Object.getOwnPropertyDescriptors,Ri=Object.getOwnPropertySymbols,on=Object.prototype.hasOwnProperty,an=Object.prototype.propertyIsEnumerable,Ai=(r,t,e)=>t in r?sn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,fe=(r,t)=>{for(var e in t||(t={}))on.call(t,e)&&Ai(r,e,t[e]);if(Ri)for(var e of Ri(t))an.call(t,e)&&Ai(r,e,t[e]);return r},ve=(r,t)=>rn(r,nn(t));class I{static getOffsetCoordinate(t,e,i){return{x:t.x*i+e.x,y:t.y*i+e.y}}static changeDrawOutsideTarget(t,e,i,s,n,o){return typeof s=="boolean"&&!s&&(n&&o?(t.x-e.x>(n.x+n.width)*o&&(t.x=(n.x+n.width)*o+e.x),t.x-e.x<n.x*o&&(t.x=n.x*o+e.x),t.y-e.y>(n.y+n.height)*o&&(t.y=(n.y+n.height)*o+e.y),t.y-e.y<n.y*o&&(t.y=n.y*o+e.y)):(t.x-e.x>i.width&&(t.x=i.width+e.x),t.x-e.x<0&&(t.x=e.x),t.y-e.y>i.height&&(t.y=i.height+e.y),t.y-e.y<0&&(t.y=e.y))),t}static changeCoordinateByRotate(t,e,i){const{width:s,height:n}=i,{x:o,y:a}=t;switch(e%360){case 90:return{x:n-a,y:o};case 180:return{x:s-o,y:n-a};case 270:return{x:a,y:s-o};default:return t}}static changeRectByZoom(t,e,i={x:0,y:0}){return ve(fe({},t),{x:t.x*e+i.x,y:t.y*e+i.y,width:t.width*e,height:t.height*e})}static changePointByZoom(t,e,i={x:0,y:0}){return ve(fe({},t),{x:t.x*e+i.x,y:t.y*e+i.y})}static changePointListByZoom(t,e,i={x:0,y:0}){return t.map(s=>this.changePointByZoom(s,e,i))}static axisArea(t,e=3){const{x:i,y:s}=t,n=[];for(let o=i-e;o<i+e;o+=e/3)for(let a=s-e;a<s+e;a+=e/3)n.push({x:o,y:a});return n}static getOriginCoordinateWithOffsetCoordinate(t,e=1,i={x:0,y:0}){return{x:(t.x-i.x)/e,y:(t.y-i.y)/e}}static returnClosePointIndex(t,e,i=3){let s=-1;for(let n=0;n<e.length;n++){const o=e[n];this.getIsInScope(t,o,i)&&(s=n)}return s}static getIsInScope(t,e,i){return Math.abs(t.x-e.x)<i&&Math.abs(t.y-e.y)<i}}class ln{constructor(t){this.currentPos=t.currentPos,this.zoom=t.zoom,this.basicImgInfo=t.basicImgInfo,this.dependToolName=""}get isDependPolygon(){return this.dependToolName===L.Polygon}get isDependRect(){return this.dependToolName===L.Rect}get isDependOriginalImage(){return this.dependToolName===""}getAbsCoord(t){return{x:(t.x-this.currentPos.x)/this.zoom,y:(t.y-this.currentPos.y)/this.zoom}}getRenderCoord(t){return{x:t.x*this.zoom+this.currentPos.x,y:t.y*this.zoom+this.currentPos.y}}coordInsideRect(t,e){const{x:i,y:s,width:n,height:o}=e;return{x:P.withinRange(t.x,[i,i+n]),y:P.withinRange(t.y,[s,s+o])}}getPolygonPointList(t,e){return t===T.Curve?_.createSmoothCurvePointsFromPointList(e):e}getIntersection(t,e,i){const s=this.getRenderCoord(e),n=this.getRenderCoord(t),o={pointA:s,pointB:n};return M.calcOptimalIntersection(i,o,s,vr,this.zoom)}coordInsidePolygon(t,e,i,s){const{pointList:n}=i,o=s==null?void 0:s.lineType;if(n.length===0)return t;const a=this.getPolygonPointList(o,n);if(_.isInPolygon(t,a))return t;const h=a.concat(a[0]).map(u=>this.getRenderCoord(u)),c=this.getIntersection(t,e,h);return c?this.getAbsCoord(c==null?void 0:c.point):t}coordInsideImage(t){return this.coordInsideRect(t,ve(fe({},this.basicImgInfo),{x:0,y:0}))}getNextCoordByDependTool(t,e){if(this.isDependRect)return this.coordInsideRect(t,this.basicResult);if(this.isDependPolygon)return this.coordInsidePolygon(t,e,this.basicResult,this.dependToolConfig);if(this.isDependOriginalImage)return this.coordInsideImage(t)}setDependInfo(t,e){this.dependToolName=t!=null?t:"",this.dependToolConfig=t?e:void 0}setBasicImgInfo(t){this.basicImgInfo=t}setBasicResult(t){this.basicResult=t}setZoomAndCurrentPos(t,e){this.zoom=t,this.currentPos=e}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],a=[i,i+n];return P.isInRange(t.x,o)&&P.isInRange(t.y,a)}return P.isInRange(t.x,[0,this.basicImgInfo.width])&&P.isInRange(t.y,[0,this.basicImgInfo.height])}isInBasicPolygon(t){var e,i;return _.isInPolygon(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}}var hn=Object.defineProperty,cn=Object.defineProperties,dn=Object.getOwnPropertyDescriptors,Ti=Object.getOwnPropertySymbols,un=Object.prototype.hasOwnProperty,gn=Object.prototype.propertyIsEnumerable,Si=(r,t,e)=>t in r?hn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,N=(r,t)=>{for(var e in t||(t={}))un.call(t,e)&&Si(r,e,t[e]);if(Ti)for(var e of Ti(t))gn.call(t,e)&&Si(r,e,t[e]);return r},z=(r,t)=>cn(r,dn(t));const At=6;class pe extends rt{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(n=>n.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.getHoverRectID=e=>{const i=this.getCoordinateUnderZoom(e),s=At,{currentShowList:n}=this;if(n.length>0){if(this.selectedRectID){const{selectedRect:a}=this;if(a&&Z.isInRect(i,a,s,this.zoom))return a.id}const o=n.filter(a=>Z.isInRect(i,a,s,this.zoom));if(o.length===0)return"";if(o.length===1)return o[0].id;if(o.length>1)return o.map(l=>({size:l.width*l.height,id:l.id})).sort((l,h)=>l.size-h.size)[0].id}return""},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedRectID||(this.setRectList(S.textChange(e,this.selectedRectID,this.rectList),!0),this.emit("selectedChange"),this.render())},this.drawOutSideTarget=t.drawOutSideTarget||!1,this.rectList=[],this.isFlow=!0,this.config=x.jsonParser(t.config),this.hoverRectEdgeIndex=-1,this.hoverRectPointIndex=-1,this.markerIndex=0,this.setStyle(t.style),this.createNewDrawingRect=this.createNewDrawingRect.bind(this),this.getDrawingRectWithRectList=this.getDrawingRectWithRectList.bind(this),this.setSelectedIdAfterAddingDrawingRect=this.setSelectedIdAfterAddingDrawingRect.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedRectTextAttribute=this.updateSelectedRectTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}setResult(t){if(this.clearActiveStatus(),this.setRectList(t),this.hasMarkerConfig){const e=x.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndex(e.index)}this.render()}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}setConfig(t,e=!1){this.config=x.jsonParser(t),e===!0&&this.clearResult(!1)}setRectList(t,e=!1){const i=this.rectList.length;this.rectList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}get selectedRect(){return this.rectList.find(t=>t.id===this.selectedRectID)}get selectedID(){return this.selectedRectID}get selectedText(){var t;return(t=this.selectedRect)==null?void 0:t.textAttribute}get dataList(){return this.rectList}get currentShowList(){let t=[];const[e,i]=x.getRenderResultList(this.rectList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=x.getRenderResultList(this.rectList,x.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=x.getRenderResultList(t,x.getSourceID(this.basicResult),[]);return e}setSelectedID(t){this.setSelectedRectID(t)}setSelectedRectID(t){var e,i;const s=this.selectedRectID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedRectID=t,this.render(),this.emit("selectedChange")}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}updateSelectedRectTextAttribute(t){if(this._textAttributInstance&&t){let e=t;S.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",S.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setRectList(this.rectList.map(i=>i.id===this.selectedRectID?z(N({},i),{textAttribute:e}):i),!0),this.emit("updateTextAttribute"),this.render()}}getHoverRectPointIndex(t){return this.selectedRect?I.returnClosePointIndex(this.getCoordinateUnderZoom(t),Z.getRectPointList(this.selectedRect,this.zoom),At+2):-1}getHoverRectEdgeIndex(t){if(!this.selectedRect)return-1;let e=-1;const{selectedRect:i}=this,s=Z.getRectEdgeList(i,this.zoom),n=this.getCoordinateUnderZoom(t);for(let o=0;o<s.length;o++){const a=s[o],{length:l}=P.getFootOfPerpendicular(n,a.begin,a.end);l<At+10&&(e=o)}return e}getTextIconSvg(t=""){return S.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.getCoordinateUnderZoom(t),i=this.getHoverRectID(t),s=this.currentShowList.find(n=>n.id===this.selectedRectID);if(!(!s||t.button===2||t.button===0&&this.isSpaceKey===!0)){if(this.selectedRectID){if(this.getHoverRectPointIndex(t)>-1){const n=V.Point;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:s},this.dragStatus=O.Start;return}if(this.getHoverRectEdgeIndex(t)>-1){const n=V.Line;this.dragInfo={dragStartCoord:e,dragTarget:n,startTime:+new Date,firstRect:s},this.dragStatus=O.Start;return}}if(i===this.selectedRectID&&!this.drawingRect){const n=V.Plane;this.dragInfo={dragStartCoord:e,dragTarget:n,firstRect:s,startTime:+new Date},this.dragStatus=O.Start}}}onDragMove(t){var e,i,s,n,o,a;if(!this.dragInfo)return;this.dragStatus=O.Move;const l=Z.getRectUnderZoom(this.dragInfo.firstRect,this.zoom),{x:h,y:c,width:u,height:d}=l,g={x:t.x-this.dragInfo.dragStartCoord.x,y:t.y-this.dragInfo.dragStartCoord.y};let v=this.rectList.filter(f=>f.id===this.selectedRectID)[0];switch(this.dragInfo.dragTarget){case V.Plane:v=z(N({},v),{x:h+g.x,y:c+g.y,width:u,height:d});break;case V.Point:{let f=h,b=c,p=u,y=d;switch(this.hoverRectPointIndex){case 0:{f=u-g.x<0?h+u:h+g.x,b=d-g.y<0?c+d:c+g.y,p=Math.abs(g.x-u),y=Math.abs(g.y-d);break}case 1:{f=u+g.x>0?h:h+u+g.x,b=d-g.y<0?c+d:c+g.y,p=Math.abs(u+g.x),y=Math.abs(d-g.y);break}case 2:{f=u+g.x>0?h:h+u+g.x,b=d+g.y>0?c:c+d+g.y,p=Math.abs(u+g.x),y=d+g.y>0?d+g.y:Math.abs(d+g.y);break}case 3:{f=u-g.x<0?h+u:h+g.x,b=d+g.y>0?c:c+d+g.y,p=Math.abs(g.x-u),y=d+g.y>0?d+g.y:Math.abs(d+g.y);break}default:return}v=z(N({},v),{x:f,y:b,width:p,height:y})}break;case V.Line:{let f=h,b=c,p=u,y=d;switch(this.hoverRectEdgeIndex){case 0:{b=d-g.y<0?c+d:c+g.y,y=Math.abs(g.y-d);break}case 1:{f=u+g.x>0?h:h+u+g.x,p=Math.abs(u+g.x);break}case 2:{b=d+g.y>0?c:c+d+g.y,y=d+g.y>0?d+g.y:Math.abs(d+g.y);break}case 3:{f=u-g.x<0?h+u:h+g.x,p=Math.abs(g.x-u);break}default:return}v=z(N({},v),{x:f,y:b,width:p,height:y});break}default:return}if(this.config.drawOutsideTarget===!1){if(this.basicResult){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&Z.isRectNotInPolygon(v,Ce(this.basicResult.pointList,this.zoom)))return;const f=this.basicResult.x*this.zoom,b=this.basicResult.y*this.zoom,p=this.basicResult.width*this.zoom,y=this.basicResult.height*this.zoom;if(this.dragInfo.dragTarget!==V.Plane&&(v.x<f-.01||v.y<b-.01||v.width>f+p-v.x+.01||v.height>b+y-v.y+.01))return;if(v.x<f&&(v.x=f),v.y<b&&(v.y=b),v.width>f+p-v.x)switch(this.dragInfo.dragTarget){case V.Plane:v.x=f+p-u;break;case V.Point:case V.Line:g.x>0&&g.y>0&&(v.width=f+p-v.x);break;default:return}if(v.height>b+y-v.y)switch(this.dragInfo.dragTarget){case V.Plane:v.y=b+y-d;break}}else if(v.x<0&&(v.x=0),v.y<0&&(v.y=0),this.imgInfo)switch(this.dragInfo.dragTarget){case V.Plane:v.x+v.width>((s=this.imgInfo)==null?void 0:s.width)&&(v.x=this.imgInfo.width-u),v.y+v.height>((n=this.imgInfo)==null?void 0:n.height)&&(v.y=this.imgInfo.height-d);break;default:if(v.x+v.width>((o=this.imgInfo)==null?void 0:o.width)+.01||v.y+v.height>((a=this.imgInfo)==null?void 0:a.height)+.01)return}}this.setRectList(this.rectList.map(f=>f.id===v.id?Z.getRectUnderZoom(v,1/this.zoom):f)),this.render()}onMouseMove(t){var e,i;if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const s=this.getCoordinateUnderZoom(t),n=I.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.selectedRectID&&this.dragInfo){this.onDragMove(n);return}if(this.selectedRectID){const l=this.getHoverRectPointIndex(t);if(l!==this.hoverRectPointIndex){this.hoverRectPointIndex=l,this.hoverRectEdgeIndex=-1,this.render();return}if(this.hoverRectPointIndex===-1){const h=this.getHoverRectEdgeIndex(t);if(h!==this.hoverRectEdgeIndex){this.hoverRectEdgeIndex=h,this.render();return}}}const o=this.getHoverRectID(t),a=this.hoverRectID;if(this.hoverRectID=o,o!==a&&this.render(),this.drawingRect&&this.firstClickCoord){let{x:l,y:h}=this.firstClickCoord,{width:c,height:u}=this.drawingRect;if(c=Math.abs(l-n.x),u=Math.abs(h-n.y),n.x<l&&(l=n.x),n.y<h&&(h=n.y),this.config.drawOutsideTarget===!1){if(((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&Z.isRectNotInPolygon(z(N({},this.drawingRect),{x:l,y:h,width:c,height:u}),Ce(this.basicResult.pointList,this.zoom)))return;n.x<0&&(c=Math.abs(this.firstClickCoord.x),l=0),n.y<0&&(u=Math.abs(this.firstClickCoord.y),h=0),this.imgInfo&&(l+c>this.imgInfo.width&&(c=Math.abs(this.imgInfo.width-l)),h+u>this.imgInfo.height&&(u=Math.abs(this.imgInfo.height-h)))}this.drawingRect=z(N({},this.drawingRect),{x:l,y:h,width:c,height:u}),this.render()}}setAttributeLockList(t){this.setSelectedRectID(void 0),super.setAttributeLockList(t)}setBasicResult(t){super.setBasicResult(t),this.clearActiveStatus()}setRectValidAndRender(t){!t||(this.setRectList(this.rectList.map(e=>e.id===t?z(N({},e),{valid:!e.valid}):e),!0),this.render(),this.emit("updateResult"))}createNewDrawingRect(t,e){if(!this.imgInfo)return;const i=this.getCoordinateUnderZoom(t),s=I.changeDrawOutsideTarget(i,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(this.setSelectedRectID(""),this.hoverRectID="",this.drawOutSideTarget&&(s.x<0&&(s.x=0),s.y<0&&(s.y=0)),this.drawingRect=z(N({},s),{width:0,height:0,attribute:this.defaultAttribute,valid:!t.ctrlKey,id:J(8,62),sourceID:e,textAttribute:""}),this.hasMarkerConfig){const n=x.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(n)this.drawingRect&&(this.drawingRect=z(N({},this.drawingRect),{label:n.label})),this.markerIndex=n.index,this.emit("markIndexChange");else{this.emit("messageInfo",B.getMessagesByLocale(C.MarkerFinish,this.lang)),this.drawingRect=void 0;return}}if(this.config.textConfigurable){let n="";n=S.getTextAttribute(this.rectList.filter(o=>x.isSameSourceID(o.sourceID,e)),this.config.textCheckType),this.drawingRect&&(this.drawingRect=z(N({},this.drawingRect),{textAttribute:n}))}if(Object.assign(this.drawingRect,{order:x.getMaxOrder(this.rectList.filter(n=>x.isSameSourceID(n.sourceID,e)))+1}),this.firstClickCoord=N({},s),this.firstCurrentPos=N({},this.currentPos),this.dataInjectionAtCreation){const n=this.dataInjectionAtCreation(this.drawingRect);n&&Object.assign(this.drawingRect,n)}}addDrawingRectToRectList(){if(!this.drawingRect)return;let{width:t,height:e}=this.drawingRect;if(t/=this.zoom,e/=this.zoom,Math.round(t)<this.config.minWidth||Math.round(e)<this.config.minHeight){this.emit("messageInfo",B.getMessagesByLocale(C.RectErrorSizeNotice,this.lang)),this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=O.Wait,this.render();return}const i=this.getDrawingRectWithRectList();this.setRectList(i,!0),this.history.pushHistory(this.rectList),this.setSelectedIdAfterAddingDrawingRect(),this.firstClickCoord=void 0,this.drawingRect=void 0,this.dragInfo=void 0,this.dragStatus=O.Wait}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||(this.config.textConfigurable?this.setSelectedRectID(this.drawingRect.id):this.setSelectedRectID())}getDrawingRectWithRectList(){if(!this.drawingRect)return this.rectList;let{x:t,y:e,width:i,height:s}=this.drawingRect;return t/=this.zoom,e/=this.zoom,i/=this.zoom,s/=this.zoom,[...this.rectList,z(N({},this.drawingRect),{x:t,y:e,width:i,height:s})]}rightMouseUp(t){const e=this.getHoverRectID(t),i=this.rectList.find(n=>n.id===e),{selectedRectID:s}=this;if(this.setSelectedRectID(void 0),i&&this.setDefaultAttribute(i.attribute),this.drawingRect)this.drawingRect=void 0,this.firstClickCoord=void 0;else if(s!==e&&this.dblClickListener.clearRightDblClick(),this.setSelectedRectID(e),this.hoverRectID="",(i==null?void 0:i.label)&&this.hasMarkerConfig){const n=x.getCurrentMarkerIndex(i.label,this.config.markerList);n>=0&&(this.setMarkerIndex(n),this.emit("markIndexChange"))}this.render()}shiftRightMouseUp(t){const e=this.getHoverRectID(t);this.emit("shiftRightMouseUp",e)}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;if(this.dragInfo&&this.dragStatus===O.Move){this.dragInfo=void 0,this.dragStatus=O.Wait,this.history.pushHistory(this.rectList),this.emit("updateResult");return}if(t.button===2&&t.shiftKey===!0){this.shiftRightMouseUp(t);return}if(t.button===2){this.rightMouseUp(t);return}const e=x.getSourceID(this.basicResult);if(this.drawingRect){this.addDrawingRectToRectList();return}if(t.ctrlKey===!0&&t.button===0&&this.hoverRectID){this.setRectValidAndRender(this.hoverRectID);return}this.createNewDrawingRect(t,e),this.render()}onRightDblClick(t){super.onRightDblClick(t);const e=this.getHoverRectID(t);this.selectedRectID&&this.selectedRectID===e&&this.deleteRect(e)}onKeyDown(t){if(!x.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case A.Ctrl:this.drawingRect&&(this.drawingRect=z(N({},this.drawingRect),{valid:!t.ctrlKey}),this.render());break;case A.F:this.selectedRectID&&this.setRectValidAndRender(this.selectedRectID);break;case A.Z:this.setIsHidden(!this.isHidden),this.render();break;case A.Delete:this.deleteRect(this.selectedRectID);break;case A.Tab:{if(t.preventDefault(),this.drawingRect)return;let i=G.ascend;t.shiftKey&&(i=G.descend);const[s,n]=x.getRenderResultList(this.rectList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);let o=[...s];n&&(o=[...o,n]);const a=st.getViewPort(this.canvas,this.currentPos,this.zoom);o=o.filter(h=>st.inViewPort({x:h.x,y:h.y},a));const l=x.getNextSelectedRectID(o,i,this.selectedRectID);l&&(this.setSelectedRectID(l.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(l.attribute));break}default:{if(this.config.attributeConfigurable){const i=S.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}return!0}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case A.Ctrl:this.drawingRect&&(this.drawingRect=z(N({},this.drawingRect),{valid:!0}),this.render());break}}onWheel(t){const e=this.zoom;let i,s;this.drawingRect&&this.firstClickCoord&&(i=Z.getRectUnderZoom(this.drawingRect,1/e),s=I.changePointByZoom(this.firstClickCoord,1/e)),super.onWheel(t,!1),i&&s&&(this.drawingRect=Z.getRectUnderZoom(i,this.zoom),this.firstClickCoord=I.changePointByZoom(s,this.zoom)),this.render()}getCurrentSelectedData(){const{selectedRect:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:t.width*this.zoom*.6,textAttribute:t.textAttribute,color:i}}getRenderStyle(t){const e=this.getColor(t.attribute);let i,s;return t.valid===!1?(i=e==null?void 0:e.invalid.stroke,s=e==null?void 0:e.invalid.fill):(i=e==null?void 0:e.valid.stroke,s=e==null?void 0:e.valid.fill),{strokeColor:i,fillColor:s,textColor:i,toolColor:e}}renderTextAttribute(){var t;const{selectedRect:e}=this;if(!this.ctx||this.config.textConfigurable!==!0||!e)return;const{x:i,y:s,width:n,height:o,attribute:a,valid:l}=e,h=n*this.zoom*.6,c=I.getOffsetCoordinate({x:i,y:s+o},this.currentPos,this.zoom),u=this.getColor(a),d=l?u==null?void 0:u.valid.stroke:u==null?void 0:u.invalid.stroke,g=4;this._textAttributInstance||(this._textAttributInstance=new $t({width:h,container:this.container,icon:this.getTextIconSvg(a),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedRectTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${e.textAttribute}`,{left:c.x,top:c.y+g,color:d,width:h})}renderSelectedRect(t){const{selectedRect:e}=this;if(!this.ctx||!t||!e)return;const{ctx:i}=this;let s=10;const n=Z.getRectPointList(e),o=n.length,a=this.getColor(t.attribute);n.forEach((l,h)=>{var c,u;if(i.save(),i.moveTo(l.x,l.y),i.beginPath(),this.hoverRectPointIndex===h?s=At+6:s=At,t.valid===!1?(i.strokeStyle=a==null?void 0:a.invalid.stroke,i.fillStyle=a==null?void 0:a.invalid.stroke):(i.strokeStyle=a==null?void 0:a.valid.stroke,i.fillStyle=a==null?void 0:a.valid.stroke),i.arc(l.x*this.zoom+this.currentPos.x,l.y*this.zoom+this.currentPos.y,s,0,2*Math.PI),i.fill(),this.hoverRectEdgeIndex===h){i.beginPath(),i.lineWidth=10;const d=this.getColor(t.attribute),g=t.valid===!1?(c=d==null?void 0:d.invalid)==null?void 0:c.stroke:(u=d==null?void 0:d.valid)==null?void 0:u.stroke;i.strokeStyle=g,i.moveTo(n[h].x*this.zoom+this.currentPos.x,n[h].y*this.zoom+this.currentPos.y),i.lineTo(n[(h+1)%o].x*this.zoom+this.currentPos.x,n[(h+1)%o].y*this.zoom+this.currentPos.y),i.stroke()}i.restore()}),this.renderTextAttribute()}renderDrawingRect(t,e=this.zoom,i=!1){var s,n,o,a;if(this.ctx&&t){const{ctx:l,style:h}=this,{hiddenText:c=!1}=h;l.save();const{strokeColor:u,fillColor:d,textColor:g}=this.getRenderStyle(t);l.font="lighter 14px Arial";let v="";((s=this.config)==null?void 0:s.isShowOrder)&&t.order&&(t==null?void 0:t.order)>0&&(v=`${t.order}`),t.label&&this.hasMarkerConfig&&(v=`${x.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${de.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(v=`${v} ${S.getAttributeShowText(t.attribute,(n=this.config)==null?void 0:n.attributeList)}`);const f=I.changeRectByZoom(t,i?e:this.zoom,this.currentPos);c||m.drawText(this.canvas,{x:f.x,y:f.y-6},v,z(N({color:u,font:"normal normal 900 14px SourceHanSansCN-Regular"},ft),{textMaxWidth:300}));const b=(a=(o=this.style)==null?void 0:o.width)!=null?a:2;(t.id===this.hoverRectID||t.id===this.selectedRectID)&&m.drawRectWithFill(this.canvas,f,{color:d}),m.drawRect(this.canvas,f,{color:u,thickness:b,hiddenText:!0}),l.restore();let p=`${Math.round(t.width)} * ${Math.round(t.height)}`;i===!0&&(p=`${Math.round(t.width/this.zoom)} * ${Math.round(f.height/this.zoom)}`);const y=p.length*7;if(c||m.drawText(this.canvas,{x:f.x+f.width-y,y:f.y+f.height+15},p,N({color:g,font:"normal normal 600 14px Arial"},ft)),!c&&t.textAttribute&&t.id!==this.selectedRectID){const w=0,D=Math.max(20,f.width-y);m.drawText(this.canvas,{x:f.x,y:f.y+f.height+20+w},t.textAttribute,N({color:g,font:"italic normal 900 14px Arial",textMaxWidth:D},ft))}}}renderStaticRect(){var t;if(!(((t=this.rectList)==null?void 0:t.length)>0&&JSON.stringify(this.rectList)))return;const{renderEnhance:e={}}=this,[i,s]=x.getRenderResultList(this.rectList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedRectID);this.isHidden||i==null||i.forEach(n=>{this.renderDrawingRect(n),e.staticRender&&e.staticRender(this.canvas,I.changeRectByZoom(n,this.zoom,this.currentPos),this.getRenderStyle(n))}),s&&(this.renderDrawingRect(s),this.renderSelectedRect(s),e.selectedRender&&e.selectedRender(this.canvas,I.changeRectByZoom(s,this.zoom,this.currentPos),this.getRenderStyle(s)))}renderCreatingRect(){if(!this.drawingRect)return;const{renderEnhance:t={}}=this;this.renderDrawingRect(this.drawingRect,1,!0),t.creatingRender&&t.creatingRender(this.canvas,I.changeRectByZoom(this.drawingRect,1,this.currentPos),this.getRenderStyle(this.drawingRect))}renderRect(){this.renderStaticRect(),this.renderCreatingRect()}render(){!this.ctx||(super.render(),this.renderRect(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}setDefaultAttribute(t){const e=this.defaultAttribute;if(this.defaultAttribute=t!=null?t:"",e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedRect:i}=this;if(i&&(this.setRectList(this.rectList.map(s=>s.id===this.selectedID?z(N({},s),{attribute:this.defaultAttribute}):s),!0),this.history.pushHistory(this.rectList),this.render()),this.drawingRect&&(this.drawingRect=z(N({},this.drawingRect),{attribute:this.defaultAttribute}),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(this.defaultAttribute)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setValid(t){super.setValid(t),this.emit("updateResult")}clearActiveStatus(){this.drawingRect=void 0,this.firstClickCoord=void 0,this.dragInfo=void 0,this.dragStatus=O.Wait,this.setSelectedRectID(void 0)}clearResult(t=!0){const e=this.rectList.filter(i=>i.disableDelete===!0);e.length>0&&t&&this.emit("messageInfo",B.getMessagesByLocale(C.ClearPartialData,this.lang)),this.setRectList(e,!0),this.setSelectedRectID(void 0)}deleteRect(t){var e;if(!t)return;const i=this.rectList.find(s=>s.id===t);if((i==null?void 0:i.disableDelete)===!0){this.emit("messageInfo",B.getMessagesByLocale(C.DisableDelete,this.lang));return}this.setRectList(this.rectList.filter(s=>s.id!==t),!0),this.history.pushHistory(this.rectList),this.setSelectedRectID(void 0),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.render()}exportData(){const{rectList:t}=this;return[t,this.basicImgInfo]}undo(){const t=this.history.undo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}redo(){const t=this.history.redo();t&&(t.length!==this.rectList.length&&this.setSelectedRectID(""),this.setRectList(t,!0),this.render())}}var fn=Object.defineProperty,vn=Object.defineProperties,pn=Object.getOwnPropertyDescriptors,ki=Object.getOwnPropertySymbols,bn=Object.prototype.hasOwnProperty,yn=Object.prototype.propertyIsEnumerable,Oi=(r,t,e)=>t in r?fn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,xn=(r,t)=>{for(var e in t||(t={}))bn.call(t,e)&&Oi(r,e,t[e]);if(ki)for(var e of ki(t))yn.call(t,e)&&Oi(r,e,t[e]);return r},mn=(r,t)=>vn(r,pn(t));const In={textConfigurable:!1,attributeConfigurable:!0,attributeList:[]};class wn extends pe{constructor(t){super(mn(xn({},t),{config:JSON.stringify(In)}))}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||this.setSelectedRectID(this.drawingRect.id)}}class Ln{constructor(t){this._domMap=new Map,this._container=t.container,this._height=t.height}wheelChange(t){t.stopPropagation()}clearTag(t){const e=this._container,i=window.self.document.getElementById(t);i&&e&&e.contains(i)&&(i.removeEventListener("wheel",this.wheelChange),e==null||e.removeChild(i))}render(t){const e=Array.from(this._domMap.keys()),i=t.map(s=>s.id);t.forEach(s=>{const{text:n,textMaxWidth:o,color:a="white",background:l="rgba(0, 0, 0, 0.6)",style:h}=s;if(this._domMap.has(s.id)){const c=this._domMap.get(s.id);c&&(c.innerHTML=n)}else{const c=m.drawTagByDom(this._container,n,s.id);c&&(c.setAttribute("style",`
77
+ `),(o=(n=this.canvas)==null?void 0:n.parentNode)==null||o.appendChild(a)}render(){this.renderTag(),super.render(),this.emit("render")}exportData(){let{tagResult:t}=this;return this.isImgError&&(t=[]),[t,this.basicImgInfo]}}class ot{static getStrokeAndFill(t,e=!0,i={}){const{isSelected:s=!1,isHover:n=!1}=i;return s?{stroke:e?t.validSelected.stroke:t.invalidSelected.stroke,fill:e?t.validSelected.fill:t.invalidSelected.fill}:n?{stroke:e?t.validHover.stroke:t.invalidHover.stroke,fill:e?t.validHover.fill:t.invalidHover.fill}:{stroke:e?t.valid.stroke:t.invalid.stroke,fill:e?t.valid.fill:t.invalid.fill}}static getStyle2String(t){if(!!t)return Object.entries(t).reduce((e,i)=>`${e} ${i[0]}: ${i[1]};`,"")}}var Co=Object.defineProperty,Do=Object.defineProperties,_o=Object.getOwnPropertyDescriptors,as=Object.getOwnPropertySymbols,Ro=Object.prototype.hasOwnProperty,Ao=Object.prototype.propertyIsEnumerable,ls=Math.pow,hs=(r,t,e)=>t in r?Co(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,le=(r,t)=>{for(var e in t||(t={}))Ro.call(t,e)&&hs(r,e,t[e]);if(as)for(var e of as(t))Ao.call(t,e)&&hs(r,e,t[e]);return r},Ze=(r,t)=>Do(r,_o(t));const cs=200;class ds extends gt{constructor(t){super(t);this.setMarkerIndex=e=>{this.markerIndex=e},this.setMarkerIndexAndSelect=e=>{if(!this.config.markerList)return;this.markerIndex=e;const i=this.config.markerList[e].value,s=this.currentPageResult.find(n=>n.label===i);s&&(this.setSelectedID(s.id),this.config.attributeConfigurable===!0&&this.setDefaultAttribute(s.attribute)),this.emit("markIndexChange")},this.textChange=e=>{this.config.textConfigurable!==!0||!this.selectedID||(this.setPointList(M.textChange(e,this.selectedID,this.pointList)),this.emit("selectedChange"),this.render())},this.isMinDistance=e=>{const i=I.changePointByZoom(e,this.zoom);return this.pointList.some(s=>{const n=I.changePointByZoom(s,this.zoom);return _.getLineLength(n,i)<.2})},this.config=x.jsonParser(t.config),this.pointList=[],this.markerIndex=0,this.setStyle(t.style),this.createPoint=this.createPoint.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.setSelectedID=this.setSelectedID.bind(this)}get dataList(){return this.pointList}get drawOutsideTarget(){var t;return(t=this.config.drawOutsideTarget)!=null?t:this.config.drawPointOut}setNextMarker(t=this.pointList){if(this.hasMarkerConfig){const e=x.getNextMarker(this.getCurrentPageResult(t),this.config.markerList);e&&this.setMarkerIndexAndSelect(e.index)}}setResult(t){this.clearActiveStatus(),this.setPointList(t),this.setNextMarker(t),this.render()}setPointList(t,e=!1){const i=this.pointList.length;this.pointList=t,i!==t.length&&this.emit("updatePageNumber"),e&&this.emit("updateResult")}setConfig(t,e=!1){this.config=x.jsonParser(t),e===!0&&this.clearResult()}clearResult(){this.setPointList([]),this.setSelectedID(void 0),this.history.pushHistory([]),this.hoverID="",this.render()}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.pointList.forEach(s=>{s.id===i&&(s.attribute=t)}),this.history.pushHistory(this.pointList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}get selectedText(){var t;return(t=this.pointList.find(e=>e.id===this.selectedID))==null?void 0:t.textAttribute}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}getTextIconSvg(t=""){return M.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}clearActiveStatus(){this.hoverID=void 0,this.dragStatus=E.Wait,this.setSelectedID(void 0)}setBasicResult(t){super.setBasicResult(t),this.setNextMarker(),this.clearActiveStatus()}onMouseDown(t){if(!(super.onMouseDown(t)||this.forbidMouseOperation)){if(t.button===0&&!this.hoverID){this.createPoint(t),this.render();return}return this.hoverID===this.selectedID&&t.button===0&&(this.dragStatus=E.Start),this.render(),!0}}onMouseMove(t){super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo||(this.hoverID=this.getHoverId(),(this.dragStatus===E.Start||this.dragStatus===E.Move)&&this.onDragMove(t),this.hoverID&&this.render())}onMouseUp(t){if(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)return!0;t.button===2&&this.rightMouseUp(),this.dragStatus===E.Move&&this.history.pushHistory(this.pointList),this.dragStatus=E.Wait,this.render()}onDragMove(t){var e,i;if(!this.imgInfo)return;this.dragStatus=E.Move;const s=this.getCoordinateUnderZoom(t),n=I.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.drawOutsideTarget,this.basicResult,this.zoom),o=this.drawOutsideTarget?I.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos):I.changePointByZoom(n,1/this.zoom);this.drawOutsideTarget===!1&&this.dependToolName===D.Polygon&&((i=(e=this.basicResult)==null?void 0:e.pointList)==null?void 0:i.length)>0&&!S.isInPolygon(o,this.basicResult.pointList)||(this.pointList.forEach(a=>{a.id===this.selectedID&&(a.x=o.x,a.y=o.y)}),this.render())}onKeyDown(t){if(!x.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case O.Delete:this.deletePoint();break;case O.Tab:{this.onTabKeyDown(t);break}case O.Z:this.setIsHidden(!this.isHidden),this.render();break;default:{if(this.config.attributeConfigurable){const i=M.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}createPoint(t){var e,i,s,n;if(!this.imgInfo)return;const{upperLimit:o}=this.config;if(o&&this.currentPageResult.length>=o){this.emit("messageInfo",`${Z.getMessagesByLocale(R.LowerLimitPoint,this.lang)}`);return}const a=x.getSourceID(this.basicResult),l=this.getCoordinateUnderZoom(t);let h=I.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.config.edgeAdsorption&&this.referenceData&&[D.Polygon,D.Line].includes((e=this.referenceData)==null?void 0:e.toolName)){const g=((i=this.referenceData)==null?void 0:i.toolName)===D.Polygon,{dropFoot:p,hasClosed:f}=S.getClosestPoint(h,this.referenceData.result,(n=(s=this.referenceData.config)==null?void 0:s.lineType)!=null?n:k.Line,Nt/this.zoom,{isClose:g});p&&(h=p),f&&this.emit("messageSuccess",`${Z.getMessagesByLocale(R.SuccessfulEdgeAdsorption,this.lang)}`)}if(this.drawOutsideTarget===!1){if(this.dependToolName&&this.basicCanvas){let d=!1;switch(this.dependToolName){case D.Rect:{d=!Y.isInRect(h,this.basicResult);break}case D.Polygon:{d=!S.isInPolygon(h,this.basicResult.pointList);break}}if(d)return}if(l.x<0||l.y<0||l.x>this.imgInfo.width||l.y>this.imgInfo.height)return}if(this.isMinDistance(h))return;let c=Ze(le({},h),{attribute:this.defaultAttribute,valid:!t.ctrlKey,id:it(8,62),sourceID:a,textAttribute:"",order:x.getMaxOrder(this.pointList.filter(d=>x.isSameSourceID(d.sourceID,a)))+1});if(this.config.textConfigurable){let d="";d=M.getTextAttribute(this.pointList.filter(g=>x.isSameSourceID(g.sourceID,a)),this.config.textCheckType),c=Ze(le({},c),{textAttribute:d})}if(this.hasMarkerConfig){const d=x.getNextMarker(this.currentPageResult,this.config.markerList,this.markerIndex);if(d)c=Ze(le({},c),{label:d.label}),this.markerIndex=d.index,this.emit("markIndexChange");else{this.emit("messageInfo",Z.getMessagesByLocale(R.MarkerFinish,this.lang));return}}this.hoverID=c.id;const u=[...this.pointList,c];this.setPointList(u),this.history.pushHistory(u),this.setSelectedID(c.id)}isInPoint(t,e,i=this.zoom){return(this.style.width+2)/i>=Math.sqrt(ls(t.x-e.x,2)+ls(t.y-e.y,2))}getHoverId(){var t;const e=I.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos),i=(t=this.pointList)==null?void 0:t.find(s=>this.isInPoint(e,s));return i==null?void 0:i.id}rightMouseUp(){if(this.selectedID===this.hoverID){const e=this.pointList.filter(i=>i.id!==this.selectedID);this.setPointList(e),this.history.pushHistory(e),this.setSelectedID(""),this.hoverID="";return}const t=this.pointList.find(e=>e.id===this.hoverID);if(this.setSelectedID(this.hoverID),this.setDefaultAttribute(t==null?void 0:t.attribute),(t==null?void 0:t.label)&&this.hasMarkerConfig){const e=x.getCurrentMarkerIndex(t.label,this.config.markerList);e>=0&&(this.setMarkerIndex(e),this.emit("markIndexChange"))}}onTabKeyDown(t){if(t.preventDefault(),this.dragStatus===E.Move||this.dragStatus===E.Start)return;let e=q.ascend;t.shiftKey&&(e=q.descend);const[i,s]=x.getRenderResultList(this.pointList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let n=[...i];s&&(n=[...n,s]);const o=x.getNextSelectedRectID(n,e,this.selectedID);o&&this.setSelectedID(o.id)}get currentPageResult(){const[t]=x.getRenderResultList(this.pointList,x.getSourceID(this.basicResult),[]);return t}getCurrentPageResult(t){const[e]=x.getRenderResultList(t,x.getSourceID(this.basicResult),[]);return e}exportData(){const{pointList:t}=this;return[t,this.basicImgInfo]}deletePoint(){var t;this.selectedID&&(this.setPointList(this.pointList.filter(e=>e.id!==this.selectedID)),this.history.pushHistory(this.pointList),(t=this._textAttributInstance)==null||t.clearTextAttribute(),this.emit("selectedChange"),this.render())}undoAndRedo(t){var e,i;if(this.dragStatus===E.Move||this.dragStatus===E.Start)return;const s=(i=(e=this.history)[t])==null?void 0:i.call(e);(s==null?void 0:s.some(n=>n.id===this.selectedID))||this.setSelectedID(""),s&&(this.setPointList(s,!0),this.render())}undo(){this.undoAndRedo("undo")}redo(){this.undoAndRedo("redo")}getCurrentSelectedData(){var t;if(!this.selectedID)return;const e=(t=this.pointList)==null?void 0:t.find(n=>n.id===this.selectedID),i=this.getColor(e==null?void 0:e.attribute),s=(e==null?void 0:e.valid)?i==null?void 0:i.valid.stroke:i==null?void 0:i.invalid.stroke;return this.dragStatus=E.Wait,{width:cs*this.zoom*.6,textAttribute:(e==null?void 0:e.textAttribute)||"",color:s}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;M.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",M.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPointList(M.textChange(e,this.selectedID,this.pointList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t,e;const i=(t=this.pointList)==null?void 0:t.find(g=>g.id===this.selectedID);if(!this.ctx||this.config.textConfigurable!==!0||!i)return;const{x:s,y:n,attribute:o,valid:a}=i,l=cs*this.zoom*.6,h=I.getOffsetCoordinate({x:s,y:n},this.currentPos,this.zoom),c=this.getColor(o),u=a?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,d=4;this._textAttributInstance||(this._textAttributInstance=new oe({width:l,container:this.container,icon:this.getTextIconSvg(o),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((e=this._textAttributInstance)==null?void 0:e.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${i.textAttribute}`,{left:h.x,top:h.y+d,color:u,width:l})}renderPoint(t){var e,i,s;const{textAttribute:n="",attribute:o}=t,a=t.id===this.selectedID,l=this.getColor(o),h=I.changePointByZoom(t,this.zoom,this.currentPos),{width:c=2,hiddenText:u=!1}=this.style,d=ot.getStrokeAndFill(l,t.valid,{isSelected:a||t.id===this.hoverID});L.drawCircle(this.canvas,h,c,{startAngleDeg:0,endAngleDeg:360,thickness:1,color:d.stroke,fill:d.fill});let g="";(((e=this.config)==null?void 0:e.isShowOrder)||((i=this.config)==null?void 0:i.showOrder))&&t.order&&(t==null?void 0:t.order)>0&&(g=`${t.order}`),t.label&&this.hasMarkerConfig&&(g=`${x.getCurrentMarkerIndex(t.label,this.config.markerList)+1}_${Be.getMarkerShowText(t.label,this.config.markerList)}`),t.attribute&&(g=`${g} ${M.getAttributeShowText(t.attribute,(s=this.config)==null?void 0:s.attributeList)}`),u||L.drawText(this.canvas,{x:h.x+c/2,y:h.y-c-4},g,{textAlign:"center",color:d.stroke}),a?this.renderTextAttribute():u||L.drawText(this.canvas,{x:h.x+c,y:h.y+c+24},n,le({color:d.stroke},rt))}renderPointList(){const[t,e]=x.getRenderResultList(this.pointList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);this.isHidden||t.forEach(i=>{this.renderPoint(i)}),e&&this.renderPoint(e)}renderTop(){var t,e,i;const s=this.getLineColor(this.defaultAttribute);if(this.renderCursorLine(s),this.config.edgeAdsorption&&this.referenceData){let n=I.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);const o=((t=this.referenceData)==null?void 0:t.toolName)===D.Polygon,{dropFoot:a}=S.getClosestPoint(n,this.referenceData.result,(i=(e=this.referenceData.config)==null?void 0:e.lineType)!=null?i:k.Line,Nt/this.zoom,{isClose:o});a&&n!==a&&n!==a&&(n=a,L.drawCircle(this.canvas,I.changePointByZoom(n,this.zoom,this.currentPos),5,{color:"white",fill:"white"}),L.drawCircle(this.canvas,I.changePointByZoom(n,this.zoom,this.currentPos),3,{fill:s,color:s}))}}render(){!this.ctx||(super.render(),this.renderPointList(),this.renderTop())}}var To=Object.defineProperty,So=Object.defineProperties,Oo=Object.getOwnPropertyDescriptors,us=Object.getOwnPropertySymbols,ko=Object.prototype.hasOwnProperty,Mo=Object.prototype.propertyIsEnumerable,gs=(r,t,e)=>t in r?To(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ue=(r,t)=>{for(var e in t||(t={}))ko.call(t,e)&&gs(r,e,t[e]);if(us)for(var e of us(t))Mo.call(t,e)&&gs(r,e,t[e]);return r},Ve=(r,t)=>So(r,Oo(t)),fs;(function(r){r[r.Create=0]="Create",r[r.Active=1]="Active",r[r.None=2]="None"})(fs||(fs={}));const xt=16,he={x:0,y:20},je=3,ce=5,Eo=2;class ps extends gt{constructor(t){super(t);this.drawActivatedLine=(e,i,s)=>{const n=j.cloneDeep(this.activeLine);if(!n||n.length===0)return;const o=this.isActiveLineValid();let a;const l=this.selectedID?this.lineList.find(c=>c.id===this.selectedID):void 0;l?a=l.order:a=this.nextOrder();const h=this.getLineColorByAttribute({attribute:this.defaultAttribute,valid:!!o});n.map(c=>Object.assign(c,this.coordUtils.getRenderCoord(c))),this.updateActiveArea(),this.drawLine(n,e,h,!0,!0),this.drawLineNumber(n[0],a,h,"",this.defaultAttribute,o),e&&this.isCreate&&this.arc(e,je,h),this.cursor&&!this.selectedPoint&&!s&&!this.isShift&&this.arc(this.cursor,ce,h)},this.drawHoverPoint=e=>{if(!this.isMousedown&&e&&this.isLineSelected){const i=this.getPointList(this.activeLine),s=this.activeLine.find(o=>B.calcDistance(this.coordUtils.getRenderCoord(o),e)<=ce);let n;!s&&this.activeLine&&(n=this.findNearestPoint(i,e)),this.hoverPointID=s?s.id:void 0,this.cursor=s||n==null?void 0:n.point}},this.lineList=[],this.activeLine=[],this.coordsInsideActiveArea=!1,this.hoverLineSegmentIndex=-1,this.isShift=!1,this.isReference=!1,this.drawCurveLine=(e,i,s,n=!0,o=!1,a)=>{const l=ie(i,xt);e.save(),e.lineCap="round",e.lineJoin="round",e.strokeStyle=s.color,n&&(e.lineWidth=s.lineWidth),o&&B.setReferenceCtx(e),i.forEach(({specialEdge:h},c)=>{const u=l.splice(0,xt+1);e.save(),e.beginPath(),a===c&&(e.lineWidth=4),u.forEach(({x:d,y:g},p)=>{const f=p>0?"lineTo":"moveTo";h&&B.setSpecialEdgeStyle(e),e[f](d,g)}),e.stroke(),e.restore()}),e.restore()},this.drawLine=(e,i,s,n=!1,o=!1)=>{const a=i?e.concat(i):e,l={color:s,lineWidth:o?1:this.lineStyle.lineWidth};this.isCurve?B.drawCurveLine(this.ctx,a,l,!n,this.isReference,o?this.hoverLineSegmentIndex:-1):this.drawStraightLine(a,l,o),n&&e.forEach(h=>{var c,u;const d=h.id,g=d&&[this.hoverPointID,(c=this.selectedPoint)==null?void 0:c.id].includes(d)?ce:je;this.arc(h,g,s),[this.hoverPointID,(u=this.selectedPoint)==null?void 0:u.id].includes(d)||this.arc(h,Eo,"white")})},this.drawStraightLine=(e,i,s=!1)=>{const{ctx:n}=this;n&&(n.save(),n.lineCap="round",n.lineJoin="round",n.strokeStyle=i.color,n.lineWidth=i.lineWidth,this.isReference&&B.setReferenceCtx(n),e.forEach((o,a)=>{if(n.beginPath(),a>0){const l=e[a-1];n.save(),(l==null?void 0:l.specialEdge)&&B.setSpecialEdgeStyle(n),s&&this.hoverLineSegmentIndex+1===a&&(n.lineWidth=4),n.moveTo(l.x,l.y),n.lineTo(o.x,o.y),n.stroke(),n.restore()}}),n.restore())},this.drawLines=()=>{try{const e=j.cloneDeep(this.attributeFilteredLines);if(this.isHidden)return;e.forEach(i=>{if(i.id!==this.selectedID&&i.pointList){i.pointList.map(l=>Object.assign(l,this.coordUtils.getRenderCoord(l)));const{order:s,label:n}=i,o=s,a=i&&this.getLineColorByAttribute(i);this.drawLine(i.pointList,void 0,a,!1),this.drawLineNumber(i.pointList[0],o,a,n,i.attribute,i.valid),i.id!==this.textEditingID&&this.drawLineTextAttribute(i.pointList[1],a,i==null?void 0:i.textAttribute)}})}catch(e){console.error(e,"\u7EBF\u6761\u5DE5\u5177\u6570\u636E\u89E3\u6790\u9519\u8BEF"),this.lineList=[],this.clearCanvas()}},this.render=e=>{super.render(),this.drawLines(),this.drawActivatedLine(e,void 0,!0),this.renderTextAttribute(),this.renderCursorLine(this.getLineColor(this.defaultAttribute))},this.moveLineInPolygon=(e,i)=>{var s;if(!Array.isArray(this.activeLine))return!1;((s=this.activeLine)==null?void 0:s.every(o=>this.isInBasicPolygon({x:o.x+e,y:o.y+i})))&&(this.lineDragging=!0,this.moveActiveArea(e,i))},this.moveLineInRectRange=(e,i,s,n)=>{if(this.activeArea===void 0)return;const{top:o,left:a,right:l,bottom:h}=this.activeArea,c=[a,l].map(v=>j.isNumber(v)?v+e:0),u=[o,h].map(v=>j.isNumber(v)?v+i:0),d=a>=0&&l&&_.isInRange(c,s),g=o>=0&&h&&_.isInRange(u,n),p=d?e:0,f=g?i:0;this.lineDragging=!0,this.moveActiveArea(p,f)},this.onRightClick=e=>{if(this.cursor=void 0,this.isCreate){if(this.isLinePointsNotEnough())return;this.stopLineCreating(!0);return}this.setActiveArea(this.getCoordinate(e),!0),this.emit("contextmenu")},this.updateSelectedAttributeAfterHistoryChanged=()=>{if(this.selectedID){const e=this.lineList.find(s=>s.id===this.selectedID),i=e==null?void 0:e.attribute;typeof i=="string"&&(this.defaultAttribute=i,this.updateAttribute(i),this.render())}},this.onLeftClick=e=>{const i=this.getCoordinate(e),{lineDragging:s}=this;if(this.lineDragging=!1,this.isSpaceKey)return;if(this.isNone&&e.ctrlKey){const o=this.findHoverLine(i);o&&this.setInvalidLine(o.id);return}if(this.isLinePointsExceed())return;const n=this.getNextPoint(e,i);if(this.isCreate||this.isNone){this.setCreatStatusAndAddPoint(n);return}if(this.isActive){if(s)return;if(this.isMouseCoordOutsideActiveArea()){this.setNoneStatus(!1),this.setCreatStatusAndAddPoint(n);return}if(e.shiftKey){this.updateLineSegmentSpecial(i);return}if(this.coordsInsideActiveArea&&e.ctrlKey){this.setInvalidLine(this.selectedID);return}this.addLinePointToActiveLine()}},this.onDblclick=()=>{},this.onKeyUp=e=>{if(super.onKeyUp(e),this.isShift=!1,this.hoverLineSegmentIndex=-1,e.keyCode===O.Esc){this.stopLineCreating(!1);return}if(this.isActive){if(e.keyCode===O.Delete){this.deleteLine();return}if(e.keyCode===O.F){this.setInvalidLine(this.selectedID);return}if(e.keyCode===O.Space){this.continueToEdit();return}}this.keyboardEventWhileLineCreating(e)},this.onRightDblClick=e=>{super.onRightDblClick(e);const i=this.getCoordinate(e);if(this.isActive){const s=this.findHoveredPoint(i);if(s){this.deleteSelectedLinePoint(s.id);return}this.deleteSelectedLine(i)}},this.setReference=e=>{this.isReference=e},this.pointsWithinRange=e=>!(this.lowerLimitPointNum&&e<this.lowerLimitPointNum||this.upperLimitPointNum&&e>this.upperLimitPointNum),this.setLineList=e=>{const i=e.length!==this.lineListLen;this.lineList=e,i&&this.emit("updatePageNumber")},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.updateSelectedTextAttribute(e),this.emit("selectedChange"))},this.status=2,this.isMousedown=!1,this.lineDragging=!1,this.isLineValid=!0,this.setConfig(t.config),this.prevAxis={x:0,y:0},this.textEditingID="",this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this),this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.actionsHistory=new Fe,this.dependToolConfig={lineType:k.Line}}get isLineSelected(){return this.selectedID&&this.activeLine}get selectedLinePoints(){return this.activeLine?this.getPointList(this.activeLine):[]}get isCreate(){return this.status===0}get isActive(){return this.status===1}get isNone(){return this.status===2}get isCurve(){return this.config.lineType===k.Curve}get isMultipleColor(){return this.config.lineColor===te.MultiColor}get imageSize(){return this.rotate%180==0?this.basicImgInfo:{width:this.basicImgInfo.height,height:this.basicImgInfo.width}}get lineListLen(){return this.lineList.length}get edgeAdsorptionEnabled(){return this.edgeAdsorption&&!this.isCurve&&this.lineListLen>0}get attributeConfigurable(){return this.config.attributeConfigurable}get isTextConfigurable(){return this.config.textConfigurable}get isDependPolygon(){return this.dependToolName===D.Polygon}get isDependRect(){return this.dependToolName===D.Rect}get isCurrentAttributeLocked(){return this.attributeLockList.includes(this.defaultAttribute)}get attributeFilteredLines(){return this.attributeLockList.length>0?this.lineList.filter(t=>this.attributeLockList.includes((t==null?void 0:t.attribute)||"")):this.lineList}get enableOutOfTarget(){return this.config.enableOutOfTarget}get showOrder(){return this.config.showOrder}get edgeAdsorption(){return this.config.edgeAdsorption}get attributeList(){return this.config.attributeList}get lowerLimitPointNum(){return this.config.lowerLimitPointNum}get upperLimitPointNum(){return this.config.upperLimitPointNum}get textCheckType(){return this.config.textCheckType}get customFormat(){return this.config.customFormat}get dataList(){return this.lineList}get hasActiveLine(){return this.activeLine&&this.activeLine.length>0}get viewPortLines(){const t=bt.getViewPort(this.canvas,this.currentPos,this.zoom);return this.isHidden?[]:this.attributeFilteredLines.filter(e=>{var i;return(i=e==null?void 0:e.pointList)==null?void 0:i.some(s=>bt.inViewPort(s,t))})}get lineStyle(){return{lineWidth:this.style.width,color:this.getLineColor(this.defaultAttribute),opacity:this.style.opacity}}get selectedText(){var t,e;return(e=(t=this.lineList.find(i=>i.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:""}get currentPageResult(){return this.lineList}updateStatus(t,e=!1){if(t!==this.status){if(e){let i="";this.textCheckType===Q.Order&&this.isTextConfigurable&&(i=M.getTextAttribute(this.lineList,this.textCheckType)),this.emit("updateText",i)}this.status=t,this.lineStatusChanged()}}isInBasicPolygon(t){var e,i;return Ut(t,((e=this.basicResult)==null?void 0:e.pointList)||[],(i=this.dependToolConfig)==null?void 0:i.lineType)}getPolygonPointList(){if(!this.basicResult)return[];const{pointList:t}=this.basicResult,{lineType:e}=this.dependToolConfig;return e===k.Curve?Ae(t.reduce((i,s)=>[...i,s.x,s.y],[]),.5,!0,20):t}getNextCoordByRenderCoord(t){return this.getNextCoordByAbsCoord(this.coordUtils.getAbsCoord(t))}getNextCoordByAbsCoord(t){var e;const i=(e=this.activeLine)==null?void 0:e.slice(-1)[0];return i?this.coordUtils.getNextCoordByDependTool(t,i):t}pointInLine(t,e,i){return t.filter(s=>s).length<2?!1:t.some((s,n)=>{if(n===0)return!1;const o=this.coordUtils.getRenderCoord(t[n-1]),a=this.coordUtils.getRenderCoord(s);return B.isInLine(e,o,a,i)})}arc(t,e=je,i){var s,n,o,a,l,h;if(this.ctx){const{x:c,y:u}=t;(s=this.ctx)==null||s.save(),(n=this.ctx)==null||n.beginPath(),this.ctx.fillStyle=i||this.lineStyle.color,(o=this.ctx)==null||o.arc(c,u,e,0,360),(a=this.ctx)==null||a.closePath(),(l=this.ctx)==null||l.fill(),(h=this.ctx)==null||h.restore()}}renderActiveArea(){if(this.isActive&&this.activeArea&&this.ctx){const{top:t,left:e,right:i,bottom:s}=this.activeArea,{x:n,y:o}=this.coordUtils.getRenderCoord({x:e,y:t});this.ctx.save(),this.ctx.beginPath(),this.ctx.strokeStyle="#B3B8FF",this.ctx.rect(n,o,(i-e)*this.zoom,(s-t)*this.zoom),this.ctx.stroke(),this.ctx.restore()}}addLinePoint(t){var e,i,s,n;this.arc(t),(e=this.activeLine)==null||e.push(Ve(Ue({},t),{id:it()})),((i=this.activeLine)==null?void 0:i.length)===1?(s=this.actionsHistory)==null||s.initRecord(this.activeLine):(n=this.actionsHistory)==null||n.pushHistory(this.activeLine),this.render()}setCreatStatusAndAddPoint(t,e=!1){this.updateStatus(0,e),this.addLinePoint(t)}isActiveLineValid(){var t;return this.selectedID?(t=this.lineList.find(e=>e.id===this.selectedID))==null?void 0:t.valid:this.isLineValid}nextOrder(){return this.lineListLen===0?1:this.lineList.slice(-1)[0].order+1}getLineColorByAttribute(t,e=!1){return ot.getStrokeAndFill(this.getColor(t.attribute),t.valid,{isSelected:e}).stroke}updateActiveArea(){this.activeArea=this.getActiveArea(),this.renderActiveArea()}getActiveArea(){return this.hasActiveLine?_.calcViewportBoundaries(this.activeLine,this.isCurve,xt,this.zoom):void 0}drawLineNumber(t,e=1,i,s="",n,o=!0){var a,l,h;if((this.showOrder||this.attributeConfigurable)&&this.ctx){let c=this.showOrder?e.toString():`${s}`;if(this.attributeConfigurable){const u=n?(h=(l=(a=this.attributeList)==null?void 0:a.find(d=>d.value===n))==null?void 0:l.key)!=null?h:n:"";c=[c,`${!o&&u?"\u65E0\u6548":""}${u}`].filter(d=>d).join("_")}this.drawText(t,c,i)}}drawLineTextAttribute(t,e,i){if(t&&i)return this.drawText(t,i,e,200)}drawText(t,e,i,s){var n,o;this.ctx&&((n=this.ctx)==null||n.save(),this.ctx.font="italic bold 14px SourceHanSansCN-Regular",this.ctx.fillStyle=i,this.ctx.strokeStyle=i,this.ctx.shadowColor="rgba(0, 0, 0, 0.6)",this.ctx.shadowOffsetY=2,this.ctx.shadowBlur=4,s?L.wrapText(this.canvas,e,t.x-he.x,t.y-he.y,s):this.ctx.fillText(e,t.x-he.x,t.y-he.y),(o=this.ctx)==null||o.restore())}moveActiveArea(t,e){this.activeArea&&(this.activeArea=Object.assign(this.activeArea,{top:this.activeArea.top+e,bottom:this.activeArea.bottom+e,right:this.activeArea.right+t,left:this.activeArea.left+t})),this.activeLine&&(this.activeLine.map(i=>Object.assign(i,{x:i.x+t,y:i.y+e})),this.updateLines())}findHoveredPoint(t){if(!!this.activeLine)return this.activeLine.find(e=>{const i=this.coordUtils.getRenderCoord(e);return B.calcDistance(i,t)<=ce})}findHoverLine(t){return j.cloneDeep(this.lineList).reverse().find(({pointList:i})=>{const s=i?this.getPointList(i):[],n=this.getLineWidthScope();return s.some((o,a)=>{if(a===0)return!1;const l=this.coordUtils.getRenderCoord(o),h=this.coordUtils.getRenderCoord(s[a-1]);return B.isInLine(t,l,h,n)})})}getAdsorptionPoint(t){let e,i,s;return j.cloneDeep(this.lineList).reverse().forEach(({pointList:n,id:o})=>{if(o===this.selectedID||!n||(n==null?void 0:n.length)<2)return;const a=this.findNearestPoint(n,t);if(a){if(a.minDistance===0){e=a.point;return}(i===void 0||a.minDistance<i)&&(e=a.point,i=a.minDistance)}}),s||e}findNearestPoint(t,e,i=7){let s;const n=i;for(let o=1;o<=t.length-1;o++){const a=this.coordUtils.getRenderCoord(t[o]),l=this.coordUtils.getRenderCoord(t[o-1]),{length:h,footPoint:c}=_.getFootOfPerpendicular(e,a,l),u=B.calcTwoPointDistance(a,e),d=B.calcTwoPointDistance(l,e);if(u<=i*2){s=a,i=0;break}if(d<=i*2){s=l,i=0;break}h<i&&(s=c,i=h)}return s?{point:s,minDistance:n}:void 0}getPointList(t){return this.isCurve?ie(t,xt):t}moveSelectedLine(t){const e=(t.x-this.prevAxis.x)/this.zoom,i=(t.y-this.prevAxis.y)/this.zoom;if(this.enableOutOfTarget){this.lineDragging=!0,this.moveActiveArea(e,i);return}if(this.isDependPolygon){this.moveLineInPolygon(e,i);return}let s=[0,this.imageSize.width],n=[0,this.imageSize.height];if(this.isDependRect){const{x:o,y:a,width:l,height:h}=this.basicResult;s=[o,o+l],n=[a,a+h]}this.moveLineInRectRange(e,i,s,n)}moveSelectPoint(t){if(!this.selectedPoint)return;const e=t.x-this.prevAxis.x,i=t.y-this.prevAxis.y,s=(this.selectedPoint?this.selectedPoint.x:0)+e/this.zoom,n=(this.selectedPoint?this.selectedPoint.y:0)+i/this.zoom,o={x:s,y:n};Object.assign(this.selectedPoint,this.getNextCoordByAbsCoord(o)),this.updateLines(),this.render()}getCoordByConfig(t,e){var i;const s=!!t.shiftKey,n=t.altKey;if(((i=this.activeLine)==null?void 0:i.length)>0&&s){const o=this.activeLine.slice(-1)[0];return B.getVHPoint(o,e,this.coordUtils.getAbsCoord(e),this.coordUtils.getRenderCoord(o))}return this.edgeAdsorptionEnabled&&!n?this.getAdsorptionPoint(e):e}getNextPoint(t,e){const i=this.getCoordByConfig(t,e)||e;return this.enableOutOfTarget?i:this.getNextCoordByRenderCoord(i)}lineHover(){this.render()}mouseMoveHandler(t){const e=this.getCoordinate(t),i=t.which===1;if(this.isCreate){this.hasActiveLine&&this.renderNextPoint(t,e);return}if(this.isNone&&(this.lineHover(),this.edgeAdsorptionEnabled&&!t.altKey)){const s=this.getAdsorptionPoint(e);s&&this.arc(s)}if(this.isActive){if(this.isMousedown&&i){if(this.selectedPoint){this.moveSelectPoint(e);return}if(this.coordsInsideActiveArea){this.moveSelectedLine(e),this.drawActivatedLine(void 0,void 0,!0);return}}this.drawHoverPoint(e),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);this.mouseMoveHandler(t),this.prevAxis=e}setActiveArea(t,e=!1){const i=this.findHoverLine(t);if(i){const s=this.lineList.findIndex(a=>a.id===(i==null?void 0:i.id)),n=_.calcViewportBoundaries((i==null?void 0:i.pointList)||[],this.isCurve,xt,this.zoom),o=this.lineList[s];this.updateStatus(1),this.setActiveLine(o.pointList),this.setSelectedLineID(o.id),this.activeArea=n,this.updateLineAttributes(o)}else e&&this.setNoneStatus();this.render()}setActiveLineByID(t){const e=this.lineList.find(i=>i.id===t);if(e){const i=_.calcViewportBoundaries((e==null?void 0:e.pointList)||[],this.isCurve,xt,this.zoom);this.updateStatus(1),this.setActiveLine(e.pointList),this.setSelectedLineID(e.id),this.activeArea=i,this.updateLineAttributes(e)}this.render()}setActiveLine(t){this.activeLine=t?j.cloneDeep(t):void 0}historyChanged(t){const e=`${t}Enabled`;if(this.isCreate){if(this.actionsHistory&&this.actionsHistory[e]){const i=this.actionsHistory&&this.actionsHistory[t]();this.setActiveLine(i),this.render()}return}if(this.history&&this.history[e]){const i=this.history[t](),s=i==null?void 0:i.find(n=>n.id===this.selectedID);this.lineList=i,this.selectedID&&s?this.setActiveLine(s==null?void 0:s.pointList):this.setNoneStatus(),this.render()}this.emit("dataUpdated",this.lineList)}undo(){this.historyChanged("undo"),this.updateSelectedAttributeAfterHistoryChanged()}redo(){this.historyChanged("redo"),this.updateSelectedAttributeAfterHistoryChanged()}isCoordInsideTarget(t){if(this.isDependPolygon)return this.isInBasicPolygon(t);if(this.isDependRect){const{x:e,y:i,width:s,height:n}=this.basicResult,o=[e,e+s],a=[i,i+n];return _.isInRange(t.x,o)&&_.isInRange(t.y,a)}return _.isInRange(t.x,[0,this.imageSize.width])&&_.isInRange(t.y,[0,this.imageSize.height])}getPointInsertIndex(t,e){if(t&&this.activeLine){const i=this.getPointList(this.activeLine);return this.activeLine.length===2?1:this.activeLine.findIndex((s,n)=>{if(n>0){const o=this.activeLine?this.activeLine[n-1]:void 0,a=this.isCurve?i.slice((n-1)*(xt+1),n*(xt+1)):[o,s];return this.pointInLine(a,t,e||this.getLineWidthScope())}return!1})}return-1}getLineWidthScope(){return this.lineStyle.lineWidth}isMouseCoordOutsideActiveArea(){return!this.coordsInsideActiveArea&&!this.selectedPoint}isLinePointsExceed(){return this.isCreate&&this.activeLine&&this.upperLimitPointNum&&~~this.upperLimitPointNum<=this.activeLine.length}isLinePointsNotEnough(){var t;return this.activeLine&&((t=this.activeLine)==null?void 0:t.length)<this.lowerLimitPointNum}updateLineSegmentSpecial(t){const e=this.getPointInsertIndex(t,2)-1;if(e>-1){const i=this.activeLine[e];i.specialEdge=!i.specialEdge,this.hoverLineSegmentIndex=-1,this.render()}}addLinePointToActiveLine(){var t;const e=this.getPointInsertIndex(this.cursor),i=this.pointsWithinRange(this.activeLine.length+1);this.cursor&&e>-1&&i&&(this.activeLine.splice(e,0,Ve(Ue({},this.coordUtils.getAbsCoord(this.cursor)),{id:it()})),this.updateLines(),(t=this.history)==null||t.pushHistory(this.lineList),this.render(),this.cursor=void 0)}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.getCoordinate(t);if(this.isMousedown=!0,this.prevAxis=e,t.which===3){this.cursor=void 0;return}this.selectedPoint=this.findHoveredPoint(e),this.coordsInsideActiveArea=this.isActive&&this.activeArea?B.inArea(this.activeArea,this.coordUtils.getAbsCoord(e)):!1,this.lineDragging=!1}lineHasChanged(){const t=this.lineList.find(e=>e.id===this.selectedID);return t?JSON.stringify(t.pointList)!==JSON.stringify(this.activeLine):!1}updateLines(){const t=this.lineList.find(e=>e.id===this.selectedID);t&&(t.pointList=j.cloneDeep(this.activeLine),this.emit("dataUpdated",this.lineList))}onMouseUp(t){const e=()=>{this.isMousedown=!1,this.hoverPointID=void 0,this.cursor=void 0,this.selectedPoint=void 0};if(this.hoverPointID=void 0,super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo){e();return}t.which===1&&this.onLeftClick(t),t.which===3&&this.onRightClick(t),e()}isTextValid(t){return M.textAttributeValidate(this.textCheckType,this.customFormat,t)}createLineData(){const t=it(),e={pointList:j.cloneDeep(this.activeLine),id:t,valid:this.isLineValid,order:this.nextOrder()};return e.attribute=this.defaultAttribute,e}stopLineCreating(t=!0){var e,i,s,n;const o=this.selectedID?!0:!!this.isTextConfigurable;let a;if(t){if(this.selectedID){const l=this.lineList.find(h=>h.id===this.selectedID);a=this.selectedID,l&&(l.pointList=j.cloneWith(this.activeLine),j.isEqual(l.pointList,(e=this.history)==null?void 0:e.pushHistory(this.lineList))||(i=this.history)==null||i.pushHistory(this.lineList))}else if(this.isCreate&&this.activeLine&&this.activeLine.length>1){const l=this.createLineData();a=l.id,this.setLineList([...this.lineList,l]),(s=this.history)==null||s.pushHistory(this.lineList)}}o?this.setActiveStatus(a):this.setNoneStatus(),(n=this.actionsHistory)==null||n.empty(),this.emit("dataUpdated",this.lineList),this.render()}setActiveStatus(t){const e=t?this.lineList.find(i=>i.id===t):void 0;if(e){const i=e==null?void 0:e.pointList;this.updateStatus(1),this.setActiveLine(i),this.setSelectedLineID(t)}else this.setNoneStatus()}setNoneStatus(t=!0){t&&this.updateStatus(2),this.activeLine=[],this.setSelectedLineID(void 0),this.activeArea=void 0,this.isLineValid=!0,this.cursor=void 0}setKeyDownStatus(t,e){this.isShift=e!=null?e:t.keyCode===O.Shift}continueToEdit(){var t;this.updateStatus(0),this.cursor=void 0,(t=this.actionsHistory)==null||t.pushHistory(this.activeLine),this.render()}setInvalidLineOnCreating(t){if(this.selectedID&&t.keyCode!==O.Ctrl||!this.isCreate)return;const e=!t.ctrlKey;this.selectedID?this.setInvalidLine(this.selectedID,e,!1):this.isLineValid=e}onKeyDown(t){if(super.onKeyDown(t),this.setKeyDownStatus(t),t.keyCode===O.Z&&!t.ctrlKey&&this.toggleIsHide(),t.keyCode===O.Shift&&this.render(),t.keyCode===O.Tab){t.preventDefault(),this.selectToNextLine(t);return}if(this.isCreate&&this.keyboardEventWhileLineCreating(t),this.config.attributeConfigurable){const e=M.getAttributeByKeycode(t.keyCode,this.config.attributeList);e!==void 0&&this.setDefaultAttribute(e)}}selectToNextLine(t){const e=x.getNextSelectedRectIDByEvent(this.viewPortLines.map(i=>{var s,n,o,a;return Ve(Ue({},i),{x:(n=(s=i.pointList[0])==null?void 0:s.x)!=null?n:0,y:(a=(o=i.pointList[0])==null?void 0:o.y)!=null?a:0})}),t,this.selectedID);e&&this.setActiveLineByID(e.id)}keyboardEventWhileLineCreating(t){!this.isCreate||(t.keyCode===O.Ctrl&&this.setInvalidLineOnCreating(t),[O.Shift,O.Alt].includes(t.keyCode)&&this.renderNextPoint(t,this.prevAxis))}renderNextPoint(t,e){const i=this.coordUtils.getRenderCoord(this.getNextPoint(t,e));this.render(i)}deleteSelectedLine(t){const e=_.calcViewportBoundaries(this.activeLine,this.isCurve,xt,this.zoom);B.inArea(e,this.coordUtils.getAbsCoord(t))&&this.deleteLine()}deleteSelectedLinePoint(t){var e;this.pointsWithinRange(this.activeLine.length-1)&&t&&(this.setActiveLine(this.activeLine.filter(s=>s.id!==t)),this.updateLines(),(e=this.history)==null||e.pushHistory(this.lineList)),this.cursor=void 0,this.render()}deleteLine(){var t;this.lineList=this.lineList.filter(e=>e.id!==this.selectedID),(t=this.history)==null||t.pushHistory(this.lineList),this.setNoneStatus(),this.emit("dataUpdated",this.lineList),this.render()}setInvalidLine(t,e,i=!0){var s;const n=this.lineList.find(o=>o.id===t);n&&(n.valid=e!==void 0?e:!n.valid,(s=this.history)==null||s.pushHistory(this.lineList),i&&this.render())}empty(){var t,e;this.lineList=[],this.setNoneStatus(),this.selectedPoint=void 0,(t=this.actionsHistory)==null||t.empty(),(e=this.history)==null||e.init(),this.emit("dataUpdated",this.lineList),this.render()}setAttribute(t){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)))}setTextAttribute(t){var e;this.isTextConfigurable&&(this.setLineAttribute("textAttribute",t),(e=this.history)==null||e.applyAttribute(this.selectedID,"textAttribute",t))}setLineAttribute(t,e,i){const s=i||this.selectedID;if(s){const n=this.lineList.find(o=>o.id===s);n&&(n[t]=e)}this.render()}updateAttribute(t){this.emit("updateAttribute",t)}updateLineAttributes(t){var e;if(this.attributeConfigurable&&t){const i=(t==null?void 0:t.attribute)||"";this.defaultAttribute=i,this.updateAttribute(i)}if(this.isTextConfigurable&&t){const i=(t==null?void 0:t.textAttribute)||"";this.updateTextAttribute(i)}(e=this.history)==null||e.updateHistory(this.lineList)}lineStatusChanged(){this.emit("lineStatusChanged",{status:this.status,selectedLineID:this.selectedID})}updateTextAttribute(t){if(this.selectedID){const e=this.lineList.find(i=>i.id===this.selectedID);e&&(e.textAttribute=t)}this.emit("updateText",t)}saveData(){this.stopLineCreating(),this.setNoneStatus(),this.render()}setTextEditingID(t){this.textEditingID=t,this.render()}setSelectedLineID(t){var e,i;if(this.selectedID===t)return;const s=this.selectedID;t!==s&&s&&((e=this._textAttributeInstance)==null||e.changeSelected()),t||(i=this._textAttributeInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.emit("selectedChange")}attributeLockListChange(t){this.attributeLockList=t,this.render()}setResult(t){this.setNoneStatus(),this.setLineList(t),this.render()}setConfig(t){super.setConfig(t)}toggleIsHide(){this.setIsHidden(!this.isHidden),this.render()}clearCanvas(){super.clearCanvas()}clearResult(){this.setResult([]),this.setSelectedLineID(void 0),this.render()}exportData(){return[this.lineList,this.basicImgInfo]}setDefaultAttribute(t=""){var e;this.attributeConfigurable&&(this.defaultAttribute=t,this.setLineAttribute("attribute",t),this.selectedID&&((e=this.history)==null||e.pushHistory(this.lineList)),this.emit("changeAttributeSidebar"))}getCurrentSelectedData(){var t,e;const i=this.isActiveLineValid(),s=this.defaultAttribute,n=this.getColor(s),o=i?n==null?void 0:n.valid.stroke:n==null?void 0:n.invalid.stroke,a=(e=(t=this.lineList.find(l=>l.id===this.selectedID))==null?void 0:t.textAttribute)!=null?e:"";return{color:o,textAttribute:a}}renderTextAttribute(){var t,e,i,s;if(!this.ctx||!this.activeLine||((t=this.activeLine)==null?void 0:t.length)<2||this.isCreate)return;const n=this.isActiveLineValid(),o=this.defaultAttribute,{x:a,y:l}=this.activeLine[1],h=this.coordUtils.getRenderCoord({x:a,y:l}),c=this.getColor(o),u=n?c==null?void 0:c.valid.stroke:c==null?void 0:c.invalid.stroke,d=(i=(e=this.lineList.find(g=>g.id===this.selectedID))==null?void 0:e.textAttribute)!=null?i:"";this._textAttributeInstance||(this._textAttributeInstance=new oe({container:this.container,icon:this.getTextIconSvg(o),color:u,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributeInstance&&!((s=this._textAttributeInstance)==null?void 0:s.isExit)&&this._textAttributeInstance.appendToContainer(),this._textAttributeInstance.update(`${d}`,{left:h.x,top:h.y,color:u}),this._textAttributeInstance.updateIcon(this.getTextIconSvg(o))}getTextIconSvg(t=""){return M.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}updateSelectedTextAttribute(t){if(this._textAttributeInstance&&t&&this.selectedID){let e=t;!M.textAttributeValidate(this.config.textCheckType,"",e)&&(this.emit("messageError",M.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setTextAttribute(e),this.emit("updateTextAttribute"),this.render()}}}class vs extends gt{constructor(t){super(t);this.getSingleResult=e=>{const i={};return this.config.configList.length>0&&this.config.configList.forEach(s=>{var n;i[s.key]=(n=s.default)!=null?n:""}),{value:i,id:it(),sourceID:e!=null?e:x.getSourceID()}},this.getInitResultList=(e,i)=>e>0?i.map(s=>this.getSingleResult(s.id)):[this.getSingleResult()],this.textList=[],this.setShowDefaultCursor(!0),this.setConfig(t.config),this.initTextDisplayContainer()}get dataList(){return this.textList}get textValueContainerID(){return"textValueContainer"}get textValueContainer(){return document.getElementById(this.textValueContainerID)}get currentPageResult(){return this.textList}setResult(t){var e;this.textList=t,this.toggleTextContainerVisible(!0);const i=(e=this.textList[0])==null?void 0:e.value;i&&Object.keys(i).forEach(s=>{this.renderText(s,i[s])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!i)}updateTextValue(t,e){this.textList[0].value[t]=e,this.renderText(t,e),this.emit("valueUpdated")}renderText(t,e){const i=document.getElementById(`textKey${t}`);i&&(i.innerText=e)}getTextDomID(t){return`textKey${t}`}initTextDisplayContainer(){const t=document.createElement("div"),e={position:"absolute",right:"0",top:"0","z-index":"20","max-width":"20%","font-family":"SourceHanSansCN-Regular",background:"rgb(102, 230, 255)",color:"white","word-break":"break-all","line-height":"24px","white-space":"pre-wrap","max-height":"80%","overflow-y":"auto",opacity:"0.6"};t.setAttribute("style",Object.keys(e).reduce((i,s)=>(i+=`${s}: ${e[s]};`,i),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(i=>{const s=document.createElement("div"),n=document.createElement("div"),o=document.createElement("div");s.setAttribute("style","padding: 8px 16px"),n.innerText=`${i.key}:`,o.innerText="",o.setAttribute("id",this.getTextDomID(i.key)),s.appendChild(n),s.appendChild(o),t.appendChild(s)}),this.container.appendChild(t)}exportData(){return[this.textList,this.basicImgInfo]}destroyCanvas(){super.destroyCanvas(),this.textValueContainer&&this.container.removeChild(this.textValueContainer)}onKeyDown(t){super.onKeyDown(t),t.keyCode===O.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const e=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=e}}}var Bo=Object.defineProperty,No=Object.defineProperties,Ho=Object.getOwnPropertyDescriptors,ms=Object.getOwnPropertySymbols,Fo=Object.prototype.hasOwnProperty,zo=Object.prototype.propertyIsEnumerable,ys=(r,t,e)=>t in r?Bo(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,J=(r,t)=>{for(var e in t||(t={}))Fo.call(t,e)&&ys(r,e,t[e]);if(ms)for(var e of ms(t))zo.call(t,e)&&ys(r,e,t[e]);return r},ft=(r,t)=>No(r,Ho(t));const bs=164;class We extends gt{constructor(t){super(t);this.isAllowDouble=e=>{const{selectedID:i}=this,s=this.getHoverID(e);return!!(i&&i===s)},this.textChange=e=>{this.config.textConfigurable===!1||!this.selectedID||(this.setPolygonList(M.textChange(e,this.selectedID,this.polygonList)),this.emit("selectedChange"),this.render())},this.config=x.jsonParser(t.config),this.drawingPointList=[],this.polygonList=[],this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.drawingHistory=new Fe,this.isCtrl=!1,this.isAlt=!1,this.isCombined=!1,this.pattern=et.Normal,this.getCurrentSelectedData=this.getCurrentSelectedData.bind(this),this.updateSelectedTextAttribute=this.updateSelectedTextAttribute.bind(this)}eventBinding(){super.eventBinding(),this.container.removeEventListener("mouseup",this.onMouseUp),this.container.addEventListener("mouseup",this.dragMouseUp),this.dblClickListener.addEvent(this.onMouseUp,this.onLeftDblClick,this.onRightDblClick,this.isAllowDouble)}eventUnbinding(){super.eventUnbinding(),this.container.removeEventListener("mouseup",this.dragMouseUp)}destroy(){super.destroy(),this._textAttributInstance&&this._textAttributInstance.clearTextAttribute()}get selectedPolygon(){return S.getPolygonByID(this.polygonList,this.selectedID)}get hoverPolygon(){return this.polygonList.find(t=>t.id===this.hoverID&&t.id!==this.selectedID)}get polygonListUnderZoom(){return this.polygonList.map(t=>ft(J({},t),{pointList:I.changePointListByZoom(t.pointList,this.zoom)}))}get selectedText(){var t;return(t=this.selectedPolygon)==null?void 0:t.textAttribute}get dataList(){return this.polygonList}setPattern(t,e=!1){var i;((i=this.drawingPointList)==null?void 0:i.length)>0&&e===!0||(this.pattern=t)}get currentShowList(){let t=[];const[e,i]=x.getRenderResultList(this.polygonList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);return t=e,this.isHidden&&(t=[]),i&&t.push(i),t}get currentPageResult(){const[t]=x.getRenderResultList(this.polygonList,x.getSourceID(this.basicResult),[]);return t}setResultAndSelectedID(t,e){this.setPolygonList(t),e&&(this.selectedID=e),this.render()}setResult(t){this.clearActiveStatus(),this.setPolygonList(t),this.render()}setPolygonDataByID(t,e){return this.polygonList.map(i=>i.id===e?J(J({},i),t):i)}rotatePolygon(t=1,e=jt.Clockwise,i=this.selectedID){if(!i)return;const s=S.getPolygonByID(this.polygonList,i);if(!s)return;const n=S.updatePolygonByRotate(e,t,s==null?void 0:s.pointList);this.setPolygonList(this.setPolygonDataByID({pointList:n},i)),this.render()}addPointInDrawing(t){if(!this.imgInfo||this.forbidAddNewPolygonFuc&&this.forbidAddNewPolygonFuc(t))return;const{upperLimitPointNum:e,edgeAdsorption:i}=this.config;if(e&&this.drawingPointList.length>=e){this.emit("messageInfo",`${Z.getMessagesByLocale(R.UpperLimitErrorNotice,this.lang)}${e}`);return}this.deleteSelectedID();const s=this.getCoordinateUnderZoom(t),n=I.changeDrawOutsideTarget(s,{x:0,y:0},this.imgInfo,this.config.drawOutsideTarget,this.basicResult,this.zoom);if(I.returnClosePointIndex(n,I.changePointListByZoom(this.drawingPointList,this.zoom))===0){this.addDrawingPointToPolygonList();return}const{dropFoot:a}=S.getClosestPoint(n,this.polygonListUnderZoom,this.config.lineType,Nt),l=I.changePointByZoom(a&&t.altKey===!1&&i?a:n,1/this.zoom);if(this.pattern===et.Rect&&this.drawingPointList.length===2){const h=_.getRectangleByRightAngle(l,this.drawingPointList);if(this.drawingPointList=h,this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(this.drawingPointList)){this.emit("messageInfo",`${Z.getMessagesByLocale(R.ForbiddenCreationOutsideBoundary,this.lang)}`),this.drawingPointList=[];return}this.addDrawingPointToPolygonList(!0);return}this.drawingPointList.push(l),this.drawingPointList.length===1?this.drawingHistory.initRecord(this.drawingPointList):this.drawingHistory.pushHistory(this.drawingPointList)}clearResult(){this.setPolygonList([]),this.deleteSelectedID(),this.render()}clearPolygonDrag(){this.drawingPointList=[],this.dragInfo=void 0,this.dragInfo=void 0,this.dragStatus=E.Wait,this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,this.hoverID=""}clearActiveStatus(){this.clearPolygonDrag(),this.deleteSelectedID()}clearDrawingStatus(){this.drawingPointList=[]}setPolygonList(t){const e=this.polygonList.length;this.polygonList=t,e!==t.length&&this.emit("updatePageNumber")}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render(),this.emit("selectedChange")}setDefaultAttribute(t=""){const e=this.defaultAttribute;if(this.defaultAttribute=t,e!==t){this.changeStyle(t),this.emit("changeAttributeSidebar");const{selectedID:i}=this;if(i&&(this.selectedPolygon&&(this.selectedPolygon.attribute=t),this.history.pushHistory(this.polygonList),this.render()),this._textAttributInstance){if(this.attributeLockList.length>0&&!this.attributeLockList.includes(t)){this._textAttributInstance.clearTextAttribute();return}this._textAttributInstance.updateIcon(this.getTextIconSvg(t))}}}setStyle(t){var e;super.setStyle(t),this._textAttributInstance&&this.config.attributeConfigurable===!1&&((e=this._textAttributInstance)==null||e.updateIcon(this.getTextIconSvg()))}setPolygonValidAndRender(t){if(!t)return;const e=this.polygonList.map(i=>i.id===t?ft(J({},i),{valid:!i.valid}):i);this.setPolygonList(e),this.history.pushHistory(this.polygonList),this.render(),this.emit("updateResult")}addDrawingPointToPolygonList(t){let{lowerLimitPointNum:e=3}=this.config;if(e<3&&(e=3),this.drawingPointList.length<e){this.drawingPointList=[],this.editPolygonID="";return}const i=x.getSourceID(this.basicResult),s=[...this.polygonList];if(this.editPolygonID){const n=s.find(o=>o.id===this.editPolygonID);if(!n)return;n.pointList=this.drawingPointList,this.editPolygonID=""}else{const n=it(8,62);let o={id:n,sourceID:i,valid:!this.isCtrl,textAttribute:"",pointList:this.drawingPointList,attribute:this.defaultAttribute,order:x.getMaxOrder(s.filter(a=>x.isSameSourceID(a.sourceID,i)))+1};if(this.config.textConfigurable){let a="";a=M.getTextAttribute(this.polygonList.filter(l=>x.isSameSourceID(l.sourceID,i)),this.config.textCheckType),o=ft(J({},o),{textAttribute:a})}this.pattern===et.Rect&&t===!0&&(o=ft(J({},o),{isRect:!0})),s.push(o),this.emit("polygonCreated",o,this.zoom,this.currentPos),this.setSelectedIdAfterAddingDrawing(n)}this.setPolygonList(s),this.isCtrl=!1,this.drawingPointList=[],this.history.pushHistory(s)}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&(this.config.textConfigurable?this.setSelectedID(t):this.deleteSelectedID())}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),s=this.currentShowList.map(n=>ft(J({},n),{pointList:I.changePointListByZoom(n.pointList,this.zoom)}));return S.getHoverPolygonID(i,s,10,(e=this.config)==null?void 0:e.lineType)}getHoverEdgeIndex(t){var e;if(!this.selectedID)return-1;const i=this.selectedPolygon;if(!i)return-1;const s=this.getCoordinateUnderZoom(t),n=I.changePointListByZoom(i.pointList,this.zoom);return S.getHoverEdgeIndex(s,n,(e=this.config)==null?void 0:e.lineType)}getHoverPointIndex(t){if(!this.selectedID)return-1;const e=this.selectedPolygon;if(!e)return-1;const i=this.getCoordinateUnderZoom(t),s=I.changePointListByZoom(e.pointList,this.zoom);return I.returnClosePointIndex(i,s)}deletePolygon(t){var e;if(!t)return;const i=this.polygonList.find(s=>s.id===t);this.emit("deletedObject",{deletedObject:i,id:t}),this.setPolygonList(this.polygonList.filter(s=>s.id!==t)),this.history.pushHistory(this.polygonList),(e=this._textAttributInstance)==null||e.clearTextAttribute(),this.emit("selectedChange"),this.render()}deletePolygonPoint(t){if(!this.selectedID)return;const{selectedPolygon:e}=this;if(!e)return;let{lowerLimitPointNum:i}=this.config;if(i<3&&(i=3),e.pointList.length<=i){this.emit("messageInfo",`${Z.getMessagesByLocale(R.LowerLimitErrorNotice,this.lang)}${i}`);return}e==null||e.pointList.splice(t,1),this.history.pushHistory(this.polygonList),this.render()}spaceKeydown(){var t,e,i;if(this.selectedID){if(((t=this.selectedPolygon)==null?void 0:t.isRect)===!0){this.emit("messageInfo",`${Z.getMessagesByLocale(R.UnableToReannotation,this.lang)}`);return}this.editPolygonID=this.selectedID,this.drawingPointList=(i=(e=this.selectedPolygon)==null?void 0:e.pointList)!=null?i:[],this.drawingHistory.empty(),this.drawingHistory.initRecord(this.drawingPointList),this.hoverID="",this.deleteSelectedID(),this.render()}}onTabKeyDown(t){t.preventDefault();let e=q.ascend;t.shiftKey&&(e=q.descend),this.switchToNextPolygon(e)}switchToNextPolygon(t){if(this.drawingPointList.length>0)return;const[e,i]=x.getRenderResultList(this.polygonList,x.getSourceID(this.basicResult),this.attributeLockList,this.selectedID);let s=[...e];i&&(s=[...s,i]);const n=bt.getViewPort(this.canvas,this.currentPos,this.zoom),o=s.map(l=>{var h,c,u,d;return ft(J({},l),{x:(c=(h=l.pointList[0])==null?void 0:h.x)!=null?c:0,y:(d=(u=l.pointList[0])==null?void 0:u.y)!=null?d:0})}).filter(l=>bt.inViewPort({x:l.x,y:l.y},n)),a=x.getNextSelectedRectID(o,t,this.selectedID);if(a){this.setSelectedID(a.id);const{selectedPolygon:l}=this;l&&this.setDefaultAttribute(l.attribute)}this.render()}onKeyDown(t){if(!x.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t;switch(e){case O.Space:this.spaceKeydown();break;case O.Esc:this.drawingPointList=[],this.editPolygonID="";break;case O.F:this.selectedID&&this.setPolygonValidAndRender(this.selectedID);break;case O.Z:if(t.altKey){this.onCombinedExecute();return}this.setIsHidden(!this.isHidden),this.render();break;case O.Delete:this.deletePolygon(this.selectedID),this.render();break;case O.Ctrl:this.isCtrl=!0;break;case O.Alt:this.isAlt===!1&&(t.preventDefault(),this.isAlt=!0,this.render());break;case O.Tab:{this.onTabKeyDown(t);break}case O.X:t.altKey&&this.segment();break;default:{if(this.config.attributeConfigurable){const i=M.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}break}}}onKeyUp(t){switch(super.onKeyUp(t),t.keyCode){case O.Ctrl:this.isCtrl=!1;break;case O.Alt:{const e=this.isAlt;this.isAlt=!1,e===!0&&this.render();break}}}rightMouseUp(t){if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}this.setSelectedID(this.hoverID);const{selectedPolygon:e}=this;e&&this.setDefaultAttribute(e.attribute)}onLeftDblClick(t){if(this.hoverEdgeIndex>-1){const e=this.getCoordinateUnderZoom(t),{selectedPolygon:i}=this;if(!i)return;const{dropFoot:s}=S.getClosestPoint(e,this.polygonListUnderZoom,this.config.lineType,Nt);if(!s)return;const{upperLimitPointNum:n}=this.config;if(n&&i.pointList.length>=n){this.emit("messageInfo",`${Z.getMessagesByLocale(R.UpperLimitErrorNotice,this.lang)}${n}`),this.clearPolygonDrag();return}i==null||i.pointList.splice(this.hoverEdgeIndex+1,0,I.changePointByZoom(s,1/this.zoom)),this.setPolygonDataByID(i,this.selectedID),this.history.pushHistory(this.polygonList),this.hoverPointIndex=-1,this.hoverEdgeIndex=-1,this.render()}this.dragInfo=void 0}onRightDblClick(t){this.dragInfo=void 0,this.clearImgDrag();const e=this.getHoverID(t),i=this.getHoverPointIndex(t);if(this.hoverPointIndex>-1&&this.hoverPointIndex===i){this.deletePolygonPoint(i),this.dragInfo=void 0,this.hoverPointIndex=-1,this.render();return}this.hoverID===this.selectedID&&this.deletePolygon(e),this.render()}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||t.ctrlKey===!0)return;const e=this.selectedPolygon;if(!e||t.button!==0||this.getHoverID(t)!==this.selectedID)return;const s=e.pointList,n=this.getCoordinateUnderZoom(t);let o=[0],a=ct.Plane;this.dragStatus=E.Start;const l=this.getHoverPointIndex(t),h=this.getHoverEdgeIndex(t);return l>-1?(a=ct.Point,o=[l]):h>-1&&this.hoverEdgeIndex>-1&&(a=ct.Line,o=[h,(h+1)%s.length]),this.dragInfo={dragStartCoord:n,dragTarget:a,initPointList:s,changePointIndex:o,originPolygon:this.selectedPolygon},!0}segment(){var t;if(!this.selectedID||((t=this.config)==null?void 0:t.lineType)!==k.Line)return;const e=S.getPolygonPointList(this.selectedID,this.currentShowList),i=this.currentShowList.filter(o=>o.id!==this.selectedID);if(i.length===0||e.length===0)return;const s=S.getWrapPolygonIndex(e,i);let n=[...this.polygonList];if(s===-1){const o=S.segmentPolygonByPolygon(e,i);if(!o)return;const a=o.shift();if(!a)return;let l="",h=!0;const c=x.getSourceID(this.basicResult);let u="";n=this.polygonList.map(d=>{var g,p;return d.id===this.selectedID?(l=d.attribute,h=(g=d==null?void 0:d.valid)!=null?g:!0,u=(p=d==null?void 0:d.textAttribute)!=null?p:"",ft(J({},d),{pointList:a})):d}),o.length>0&&o.forEach((d,g)=>{n.push({sourceID:c,id:it(8,62),pointList:d,valid:h,order:x.getMaxOrder(this.currentShowList)+1+g,attribute:l,textAttribute:u})})}else n[s].pointList=S.clipPolygonFromWrapPolygon(e,n[s].pointList),n=n.filter(o=>o.id!==this.selectedID);this.setPolygonList(n),this.history.pushHistory(n),this.render()}onCombinedExecute(){if(!this.selectedID){this.emit("messageInfo",yt.t("PolygonsToBeCombinedNeedToBeSelected"));return}this.isCombined=!this.isCombined}combine(t){var e;const i=this.getHoverID(t);if(!i||!this.selectedID||this.selectedID===i)return;if(((e=this.config)==null?void 0:e.lineType)!==k.Line){this.emit("messageInfo",yt.t("CurveModeDoesNotSupportCutting"));return}const s=this.polygonList.find(h=>h.id===this.selectedID),n=this.currentShowList.find(h=>h.id===i);if(!n||!s)return;const o=S.combinePolygonWithPolygon(s,n);if(!o)return;const{newPolygon:a,unionList:l}=o;if(l.length===1&&a){const h=this.polygonList.filter(c=>!l.includes(c.id)).map(c=>c.id===this.selectedID?a:c);this.setPolygonList(h),this.history.pushHistory(h),this.render(),this.emit("messageInfo",yt.t("CombineSuccess"))}else this.emit("messageInfo",yt.t("CombiningFailedNotify"));this.isCombined=!1}isPolygonOutSide(t){if(this.dependToolName&&this.basicCanvas&&this.basicResult){let a=!1;switch(this.dependToolName){case D.Rect:{a=t.filter(l=>!Y.isInRect(l,this.basicResult)).length>0;break}case D.Polygon:{a=S.isPointListOutSidePolygon(t,this.basicResult.pointList,this.config.lineType);break}}return a}if(!this.imgInfo)return!1;const{left:e,top:i,right:s,bottom:n}=_.calcViewportBoundaries(I.changePointListByZoom(t,this.zoom)),o=1e-5;return e<0||i<0||s>this.imgInfo.width+o||n>this.imgInfo.height+o}onDragMove(t){if(!this.dragInfo||!this.selectedID)return;const{selectedPolygon:e}=this;let i=e==null?void 0:e.pointList;if(!i)return;const{initPointList:s,dragStartCoord:n,dragTarget:o,changePointIndex:a}=this.dragInfo,l=this.getCoordinateUnderZoom(t);let h={x:(l.x-n.x)/this.zoom,y:(l.y-n.y)/this.zoom};if(this.pattern===et.Rect&&(e==null?void 0:e.isRect)===!0&&a&&[ct.Line].includes(o)){const u=_.getArrayIndex(a[0]-2,4),d=_.getArrayIndex(a[0]-1,4),g=[s[u],s[d]];h=_.getRectPerpendicularOffset(n,l,g),h={x:h.x/this.zoom,y:h.y/this.zoom}}switch(this.dragStatus=E.Move,o){case ct.Plane:i=i.map((u,d)=>ft(J({},u),{x:s[d].x+h.x,y:s[d].y+h.y}));break;case ct.Point:case ct.Line:i=i.map((u,d)=>a&&a.includes(d)?ft(J({},u),{x:s[d].x+h.x,y:s[d].y+h.y}):u);break}if(this.pattern===et.Rect&&(e==null?void 0:e.isRect)===!0&&o===ct.Point&&a&&(i=_.getPointListFromPointOffset(s,a[0],h)),this.config.drawOutsideTarget===!1&&this.imgInfo&&this.isPolygonOutSide(i))return;const c=this.polygonList.map(u=>{if(u.id===this.selectedID){const d=ft(J({},u),{pointList:i});return u.isRect===!0&&this.pattern===et.Normal&&Object.assign(d,{isRect:!1}),d}return u});this.setPolygonList(c),this.render()}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;if(this.selectedID&&this.dragInfo){this.onDragMove(t);return}let e=-1,i=-1;const{selectedID:s}=this;if(s&&(this.hoverEdgeIndex=-1,this.hoverPointIndex=-1,e=this.getHoverPointIndex(t),e>-1?this.hoverPointIndex=e:(i=this.getHoverEdgeIndex(t),this.hoverEdgeIndex=i)),this.drawingPointList.length>0)return;const n=this.getHoverID(t);this.hoverID!==n&&(this.hoverID=n,this.render())}leftMouseUp(t){const e=this.getHoverID(t);if(this.drawingPointList.length===0&&t.ctrlKey===!0&&e){this.setPolygonValidAndRender(e);return}this.addPointInDrawing(t)}onMouseUp(t){if(this.isCombined){switch(t.button){case 0:this.combine(t);break;case 2:this.isCombined=!1;break;default:return}return}if(!(super.onMouseUp(t)||this.forbidMouseOperation||!this.imgInfo)){if(this.dragInfo&&this.dragStatus===E.Move){const{originPolygon:e}=this.dragInfo;this.dragInfo=void 0,this.dragStatus=E.Wait,this.history.pushHistory(this.polygonList),this.emit("updateResult"),this.emit("updatePolygonByDrag",{newPolygon:this.selectedPolygon,originPolygon:e});return}switch(t.button){case 0:{this.leftMouseUp(t);break}case 2:{this.rightMouseUp(t);break}}this.render()}}dragMouseUp(){this.dragStatus===E.Start&&(this.dragInfo=void 0,this.dragStatus=E.Wait)}exportData(){const{polygonList:t}=this;return[t,this.basicImgInfo]}getTextIconSvg(t=""){return M.getTextIconSvg(t,this.config.attributeList,this.config.attributeConfigurable,this.baseIcon)}getCurrentSelectedData(){const{selectedPolygon:t}=this;if(!t)return;const e=this.getColor(t.attribute),i=t.valid?e==null?void 0:e.valid.stroke:e==null?void 0:e.invalid.stroke;return{width:bs,textAttribute:t.textAttribute,color:i}}updateSelectedTextAttribute(t){if(this._textAttributInstance&&t&&this.selectedID){let e=t;M.textAttributeValidate(this.config.textCheckType,"",e)===!1&&(this.emit("messageError",M.getErrorNotice(this.config.textCheckType,this.lang)),e=""),this.setPolygonList(M.textChange(e,this.selectedID,this.polygonList)),this.emit("updateTextAttribute"),this.render()}}renderTextAttribute(){var t;const{selectedPolygon:e}=this;if(!this.ctx||this.config.textConfigurable===!1||!e)return;const{pointList:i,attribute:s,valid:n,textAttribute:o}=e,{x:a,y:l}=i[i.length-1],h=bs,c=I.getOffsetCoordinate({x:a,y:l},this.currentPos,this.zoom),u=this.getColor(s),d=n?u==null?void 0:u.valid.stroke:u==null?void 0:u.invalid.stroke;this._textAttributInstance||(this._textAttributInstance=new oe({width:h,container:this.container,icon:this.getTextIconSvg(s),color:d,getCurrentSelectedData:this.getCurrentSelectedData,updateSelectedTextAttribute:this.updateSelectedTextAttribute})),this._textAttributInstance&&!((t=this._textAttributInstance)==null?void 0:t.isExit)&&this._textAttributInstance.appendToContainer(),this._textAttributInstance.update(`${o}`,{left:c.x,top:c.y,color:d,width:h})}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,s,n,o,a;if([this.selectedID,this.editPolygonID].includes(e.id))return;const{textAttribute:l,attribute:h}=e,c=this.getColor(h),u=ot.getStrokeAndFill(c,e.valid),d=I.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);L.drawPolygonWithFillAndLine(this.canvas,d,{fillColor:u.fill,strokeColor:u.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(n=this.config)==null?void 0:n.lineType});let g=`${(o=M.getAttributeShowText(h,this.config.attributeList))!=null?o:""}`;((a=this.config)==null?void 0:a.isShowOrder)&&(e==null?void 0:e.order)>0&&(g=`${e.order} ${g}`),L.drawText(this.canvas,d[0],g,J({color:u.stroke},rt));const p=d[d.length-1];L.drawText(this.canvas,{x:p.x+Tt.x,y:p.y+Tt.y},l,J({color:u.stroke},rt))}))}renderSelectedPolygon(){var t,e,i;if(this.selectedID){const s=this.selectedPolygon;if(s){const n=this.getColor(s.attribute),o=ot.getStrokeAndFill(n,s.valid,{isSelected:!0});L.drawSelectedPolygonWithFillAndLine(this.canvas,I.changePointListByZoom(s.pointList,this.zoom,this.currentPos),{fillColor:o.fill,strokeColor:o.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(t=this.config)==null?void 0:t.lineType});let a=`${(e=M.getAttributeShowText(s.attribute,this.config.attributeList))!=null?e:""}`;((i=this.config)==null?void 0:i.isShowOrder)&&(s==null?void 0:s.order)>0&&(a=`${s.order} ${a}`),L.drawText(this.canvas,I.changePointByZoom(s.pointList[0],this.zoom,this.currentPos),a,J({color:o.stroke},rt)),this.renderTextAttribute()}}}renderHoverPolygon(){var t;if(this.hoverID&&this.hoverID!==this.editPolygonID){const{hoverPolygon:e}=this;if(e){let i="";const s=this.getColor(e.attribute);e.valid?i=s.validHover.fill:i=ot.getStrokeAndFill(s,!1,{isHover:!0}).fill,L.drawPolygonWithFill(this.canvas,I.changePointListByZoom(e.pointList,this.zoom,this.currentPos),{color:i,lineType:(t=this.config)==null?void 0:t.lineType})}}}renderPolygon(){var t,e,i,s;this.renderStaticPolygon(),this.renderHoverPolygon(),this.renderSelectedPolygon();const n=this.getColor(this.defaultAttribute),o=ot.getStrokeAndFill(n,!this.isCtrl);if(((t=this.drawingPointList)==null?void 0:t.length)>0){let a=[...this.drawingPointList],l=I.getOriginCoordinateWithOffsetCoordinate(this.coord,this.zoom,this.currentPos);if(this.pattern===et.Rect&&a.length===2)a=_.getRectangleByRightAngle(l,a);else{if(((e=this.config)==null?void 0:e.edgeAdsorption)&&this.isAlt===!1){const{dropFoot:h}=S.getClosestPoint(l,this.polygonList,(i=this.config)==null?void 0:i.lineType,Nt/this.zoom);h&&(l=h)}a.push(l)}L.drawSelectedPolygonWithFillAndLine(this.canvas,I.changePointListByZoom(a,this.zoom,this.currentPos),{fillColor:o.fill,strokeColor:o.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!1,lineType:this.config.lineType})}if(this.hoverPointIndex>-1&&this.selectedID){const a=this.selectedPolygon;if(!a)return;const l=ot.getStrokeAndFill(n,a.valid,{isSelected:!0}),h=a==null?void 0:a.pointList[this.hoverPointIndex];if(h){const{x:c,y:u}=I.changePointByZoom(h,this.zoom,this.currentPos);L.drawCircleWithFill(this.canvas,{x:c,y:u},5,{color:l.fill})}}if(this.hoverEdgeIndex>-1&&this.selectedID){const a=this.selectedPolygon;if(!a)return;const l=ot.getStrokeAndFill(n,a.valid,{isSelected:!0});L.drawLineWithPointList(this.canvas,I.changePointListByZoom(a.pointList,this.zoom,this.currentPos),{color:l.stroke,thickness:10,hoverEdgeIndex:this.hoverEdgeIndex,lineType:(s=this.config)==null?void 0:s.lineType})}}render(){!this.ctx||(super.render(),this.renderPolygon(),this.renderCursorLine(this.getLineColor(this.defaultAttribute)))}renderCursorLine(t){if(super.renderCursorLine(t),this.isCombined){const{x:e,y:i}=this.coord,s=10,n=186,o=32;L.drawRectWithFill(this.canvas,{x:e+s,y:i-s*4-1,width:n,height:o},{color:"black"}),L.drawText(this.canvas,{x:e,y:i},yt.t("ClickAnotherPolygon"),{textAlign:"center",color:"white",offsetX:n/2+s,offsetY:-(o/2+s/2)}),L.drawRect(this.canvas,{x:e-s,y:i-s,width:s*2,height:s*2},{lineDash:[6],color:"white"})}}undo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.undo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.undo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}redo(){if(this.drawingPointList.length>0){const e=this.drawingHistory.redo();if(!e)return;this.drawingPointList=e,this.render();return}const t=this.history.redo();t&&(t.length!==this.polygonList.length&&this.deleteSelectedID(),this.setPolygonList(t),this.render())}deleteSelectedID(){this.setSelectedID("")}}var $o=Object.defineProperty,Zo=Object.defineProperties,Uo=Object.getOwnPropertyDescriptors,xs=Object.getOwnPropertySymbols,Vo=Object.prototype.hasOwnProperty,jo=Object.prototype.propertyIsEnumerable,ws=(r,t,e)=>t in r?$o(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Wo=(r,t)=>{for(var e in t||(t={}))Vo.call(t,e)&&ws(r,e,t[e]);if(xs)for(var e of xs(t))jo.call(t,e)&&ws(r,e,t[e]);return r},Xo=(r,t)=>Zo(r,Uo(t));const Yo={textConfigurable:!1,attributeConfigurable:!0,attributeList:[]};class Ko extends ae{constructor(t){super(Xo(Wo({},t),{config:JSON.stringify(Yo)}))}setSelectedIdAfterAddingDrawingRect(){!this.drawingRect||this.setSelectedRectID(this.drawingRect.id)}}class Go{constructor(t){this._domMap=new Map,this._container=t.container,this._height=t.height}wheelChange(t){t.stopPropagation()}clearTag(t){const e=this._container,i=window.self.document.getElementById(t);i&&e&&e.contains(i)&&(i.removeEventListener("wheel",this.wheelChange),e==null||e.removeChild(i))}render(t){const e=Array.from(this._domMap.keys()),i=t.map(s=>s.id);t.forEach(s=>{const{text:n,textMaxWidth:o,color:a="white",background:l="rgba(0, 0, 0, 0.6)",style:h}=s;if(this._domMap.has(s.id)){const c=this._domMap.get(s.id);c&&(c.innerHTML=n)}else{const c=L.drawTagByDom(this._container,n,s.id);c&&(c.setAttribute("style",`
78
78
  position: absolute;
79
79
  top: 0;
80
80
  right: 0;
@@ -92,5 +92,16 @@
92
92
  max-height: ${this._height*.8}px;
93
93
  overflow-y: scroll;
94
94
  clear: both;
95
- ${et.getStyle2String(h)}
96
- `),c.addEventListener("wheel",this.wheelChange),this._domMap.set(s.id,c))}}),e.forEach(s=>{i.indexOf(s)===-1&&(this.clearTag(s),this._domMap.delete(s))})}}var Pn=Object.defineProperty,Cn=Object.defineProperties,Dn=Object.getOwnPropertyDescriptors,Mi=Object.getOwnPropertySymbols,_n=Object.prototype.hasOwnProperty,Rn=Object.prototype.propertyIsEnumerable,Ei=(r,t,e)=>t in r?Pn(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,$=(r,t)=>{for(var e in t||(t={}))_n.call(t,e)&&Ei(r,e,t[e]);if(Mi)for(var e of Mi(t))Rn.call(t,e)&&Ei(r,e,t[e]);return r},Lt=(r,t)=>Cn(r,Dn(t));const An=3,Tn=3,be="#6371FF";class Sn extends rt{constructor(t){super(Lt($({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.getHoverRectID=i=>{var s,n;const o=this.getCoordinateUnderZoom(i),a=I.changePointByZoom(o,1/this.zoom);if(((s=this.annotations)==null?void 0:s.length)<=0||!((n=this.annotations)==null?void 0:n.length))return;let l="",h=Number.MAX_SAFE_INTEGER;for(let c=0;c<this.annotations.length;c++){const u=this.annotations[c];switch(u.type){case"rect":{const d=u.annotation;if(Z.isInRect(o,d,An,this.zoom)){const g=d.width*d.height;g<h&&(l=d.id,h=g)}break}case"polygon":{const d=u.annotation;if(_.isInPolygon(a,d.pointList)){const g=_.getPolygonArea(d.pointList);g<h&&(l=d.id,h=g)}break}}}return l};var e;this.style=(e=t.style)!=null?e:{stroke:be,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new Ln({container:this.container,height:this.canvas.height})}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let i=[];e&&(i=[e]),this.emit("onChange","selected",i),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,i=this.getHoverRectID(t);if(e!==i){this.mouseHoverID=i;let s=[];i&&(s=[i]),this.emit("onChange","hover",s),this.render()}}updateData(t){this.annotations=t,this.render()}getSpecificStyle(t){const e=F.pick(t,["stroke","thickness","fill","radius"]),i=$($({},this.style),e);return i.stroke&&Object.assign(i,{color:i.stroke}),i}getRenderText(t,e=!1){let i="",s="";return!t||e===!0?{headerText:i,bottomText:s}:((t==null?void 0:t.order)&&(i=`${t.order}`),(t==null?void 0:t.label)&&(i?i=`${i}_${t.label}`:i=`${t.label}`),(t==null?void 0:t.attribute)&&(i?i=`${i} ${t.attribute}`:i=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(s=t==null?void 0:t.textAttribute),{headerText:i,bottomText:s})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}render(){try{if(super.render(),this.loading===!0)return;this.renderDomInstance.render(this.annotations.filter(t=>t.type==="text"&&t.annotation.position==="rt").map(t=>t.annotation)),this.annotations.forEach(t=>{var e,i,s,n,o,a,l,h,c,u,d,g,v;switch(t.type){case"rect":{const f=t.annotation,{hiddenText:b=!1,isReference:p}=f,{zoom:y}=this,w=I.changeRectByZoom(f,this.zoom,this.currentPos),{x:D,y:R,width:E,height:H}=w,k=this.getSpecificStyle(f);if(f.id===this.mouseHoverID||k.fill){const ot=xe((i=(e=k==null?void 0:k.fill)!=null?e:k==null?void 0:k.stroke)!=null?i:be),Pt=`rgba(${ot[0]}, ${ot[1]}, ${ot[2]},${ot[3]*.8})`;m.drawRectWithFill(this.canvas,w,{color:Pt})}m.drawRect(this.canvas,w,$(Lt($({},k),{hiddenText:!0}),this.getReferenceOptions(p)));const{headerText:W,bottomText:dt}=this.getRenderText(f,f==null?void 0:f.hiddenText);W&&m.drawText(this.canvas,{x:D,y:R-6},W,Lt($({color:k.stroke,font:"normal normal 900 14px SourceHanSansCN-Regular"},ft),{textMaxWidth:300}));const ut=`${Math.round(E/y)} * ${Math.round(H/y)}`,Tt=ut.length*7;if(b||m.drawText(this.canvas,{x:D+E-Tt,y:R+H+15},ut,$({color:k.stroke,font:"normal normal 600 14px Arial"},ft)),dt){const ot=20,Pt=Math.max(20,E-Tt);m.drawText(this.canvas,{x:D,y:R+H+ot},f.textAttribute,$({color:k.stroke,font:"italic normal 900 14px Arial",textMaxWidth:Pt},ft))}break}case"polygon":{const f=t.annotation;if(!(((s=f==null?void 0:f.pointList)==null?void 0:s.length)>=3))return;const{lineType:b=T.Line}=f,p=I.changePointListByZoom((n=f==null?void 0:f.pointList)!=null?n:[],this.zoom,this.currentPos),y=this.getSpecificStyle(f);if(f.id===this.mouseHoverID||y.fill){const k=xe((a=(o=y==null?void 0:y.fill)!=null?o:y==null?void 0:y.stroke)!=null?a:be),W=`rgba(${k[0]}, ${k[1]}, ${k[2]},${k[3]*.8})`;m.drawPolygonWithFill(this.canvas,p,{color:W,lineType:b})}const w=Lt($(Lt($({},y),{isClose:!0}),this.getReferenceOptions(f==null?void 0:f.isReference)),{lineType:b,strokeColor:y.stroke});let D=[];if(f.showKeyPoint?D=m.drawPolygonWithKeyPoint(this.canvas,p,w):D=m.drawPolygon(this.canvas,p,w),(f==null?void 0:f.showDirection)===!0&&((l=f==null?void 0:f.pointList)==null?void 0:l.length)>2){let k=p[0],W=P.getLineCenterPoint([p[0],p[1]]);if(b===T.Curve){const dt=Math.floor(Y/2);k=D[dt],W=D[dt+1]}m.drawArrowByCanvas(this.canvas,k,W,{color:y.stroke,thickness:y.thickness}),m.drawCircle(this.canvas,p[0],y.thickness+6,{color:y.stroke,thickness:y.thickness})}const{headerText:E,bottomText:H}=this.getRenderText(f,f==null?void 0:f.hiddenText);if(E&&m.drawText(this.canvas,p[0],E,$({color:y.stroke},K)),H){const k=p[p.length-1];m.drawText(this.canvas,{x:k.x+vt.x,y:k.y+vt.y},H,$({color:y.stroke},K))}break}case"line":{const f=t.annotation;if(!(((h=f==null?void 0:f.pointList)==null?void 0:h.length)>=2))return;const{lineType:b=T.Line}=f,p=I.changePointListByZoom((c=f==null?void 0:f.pointList)!=null?c:[],this.zoom,this.currentPos),y=this.getSpecificStyle(f),w=m.drawPolygon(this.canvas,p,Lt($($({},y),this.getReferenceOptions(f==null?void 0:f.isReference)),{lineType:b}));if((f==null?void 0:f.showDirection)===!0&&((u=f==null?void 0:f.pointList)==null?void 0:u.length)>2){let H=p[0],k=P.getLineCenterPoint([p[0],p[1]]);if(b===T.Curve){const W=Math.floor(Y/2);H=w[W],k=w[W+1]}m.drawArrowByCanvas(this.canvas,H,k,{color:y.stroke,thickness:y.thickness}),m.drawCircle(this.canvas,p[0],y.thickness+6,{color:y.stroke,thickness:y.thickness})}const{headerText:R,bottomText:E}=this.getRenderText(f,f==null?void 0:f.hiddenText);if(R&&m.drawText(this.canvas,p[0],R,$({color:y.stroke},K)),E){const H=p[p.length-1];m.drawText(this.canvas,{x:H.x+vt.x,y:H.y+vt.y},E,$({color:y.stroke},K))}break}case"point":{const f=t.annotation,b=I.changePointByZoom(f,this.zoom,this.currentPos),p=this.getSpecificStyle(f),y=(d=p.radius)!=null?d:Tn;m.drawCircle(this.canvas,b,y,p);const{headerText:w,bottomText:D}=this.getRenderText(f,f==null?void 0:f.hiddenText);w&&m.drawText(this.canvas,{x:b.x+y/2,y:b.y-y-4},w,{textAlign:"center",color:p.stroke}),D&&m.drawText(this.canvas,{x:b.x+y,y:b.y+y+24},D,$({color:p.stroke},K));break}case"text":{const f=t.annotation,{text:b,x:p,y,textMaxWidth:w,color:D="white",background:R="rgba(0, 0, 0, 0.6)",lineHeight:E=25,font:H=Mt,position:k}=f,W=10,dt=10,ut=I.changePointByZoom({x:p,y},this.zoom,this.currentPos),{width:Tt,height:ot,fontHeight:Pt=0}=P.getTextArea(this.canvas,f.text,w,H,E);if(k==="rt")break;m.drawRectWithFill(this.canvas,{x:ut.x,y:ut.y,width:Tt+dt*2,height:ot+W*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:R}),m.drawText(this.canvas,{x:ut.x+dt,y:ut.y+Pt+W},b,{color:D,lineHeight:E,font:H,textMaxWidth:w});break}default:}(v=(g=t.annotation)==null?void 0:g.renderEnhance)==null||v.call(g,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:t,toolInstance:this})})}catch(t){console.error("ViewOperation Render Error",t)}}}const kn={0:"\u76EE\u6807\u68C0\u6D4B",1:"\u56FE\u50CF\u5206\u7C7B"},On={0:"\u6807\u6CE8\u6587\u4EF6\u4F20\u8F93\u4E2D",1:"\u6807\u6CE8\u6587\u4EF6\u4F20\u8F93\u91CD\u8BD5",2:"\u6807\u6CE8\u6587\u4EF6\u4F20\u8F93\u5931\u8D25",3:"\u6807\u6CE8\u4E2D",4:"\u4EFB\u52A1\u7EC8\u6B62",5:"\u4EFB\u52A1\u5B8C\u6210",6:"\u6570\u636E\u5DF2\u53D1\u5E03"};var ye;(function(r){r[r.Upload=0]="Upload",r[r.UploadRetry=1]="UploadRetry",r[r.UploadFail=2]="UploadFail",r[r.Annotation=3]="Annotation",r[r.Terminated=4]="Terminated",r[r.Finish=5]="Finish",r[r.Publish=6]="Publish"})(ye||(ye={}));var Mn=Object.freeze({__proto__:null,ANNOTATION_TYPE:kn,ANNOTATION_STATUS:On,get EAnnotationStatus(){return ye}});class En{static load(t){return new Promise((e,i)=>{const s=new Image;t.startsWith("file")?s.src=encodeURI(t):s.src=t,s.onload=()=>{e(s)},s.onerror=()=>{i(s)}})}}var Hn=(r,t,e)=>new Promise((i,s)=>{var n=l=>{try{a(e.next(l))}catch(h){s(h)}},o=l=>{try{a(e.throw(l))}catch(h){s(h)}},a=l=>l.done?i(l.value):Promise.resolve(l.value).then(n,o);a((e=e.apply(r,t)).next())});const Nn=r=>new Promise((t,e)=>{const i=document.createElement("img");i.crossOrigin="Anonymous",i.onerror=s=>{console.error(s),e(i)},i.src=r,i.onload=()=>{t(i)}});class Bn{constructor(t){this.setImgSrc=s=>Hn(this,null,function*(){const n=yield Nn(s);!n||this.setImgNode(n)});var e,i;this.container=t.container,this.size=t.size,this.toolName=t.toolName,this.imgNode=t.imgNode,this.config=(e=t.config)!=null?e:JSON.stringify(We(t.toolName)),this.style=(i=t.style)!=null?i:Ve,this.i18nLanguage="cn",this._initToolOperation()}setToolName(t,e){this.toolName=t;const i=e||JSON.stringify(We(t));this.config=i,this._initToolOperation()}setImgNode(t,e){!this.toolInstance||(this.imgNode=t,this.toolInstance.setImgNode(t,e))}setSize(t){this.size=t}setStyle(t){this.style=t}_initToolOperation(){this.toolInstance&&this.toolInstance.destroy();const t=x.getCurrentOperation(this.toolName);if(!t)return;const e={container:this.container,size:this.size,config:this.config,drawOutSideTarget:!1,style:this.style};this.imgNode&&Object.assign(e,{imgNode:this.imgNode}),this.toolInstance=new t(e),this.setLang(this.i18nLanguage),this.toolInstance.init()}setBasicInfo(t,e){this.dependToolName=t,this.basicResult=e,this.toolInstance.setDependName(t),this.toolInstance.setBasicResult(e),this.toolInstance.renderBasicCanvas()}clearBasicResult(){this.setBasicInfo()}forbidOperation(){this.toolInstance.setForbidOperation(!0)}launchOperation(){this.toolInstance.setForbidOperation(!1)}setLang(t){switch(this.i18nLanguage=t,t){case"cn":this.toolInstance.setLang(at.Zh);break;case"en":this.toolInstance.setLang(at.US);break}}setDataInjectionAtCreation(t){this.toolInstance.setDataInjectionAtCreation(t)}setRenderEnhance(t){this.toolInstance.setRenderEnhance(t)}}const Fn=x;export{Bn as AnnotationEngine,I as AxisUtils,rt as BasicToolOperation,x as CommonToolUtils,Qe as DblClickEventListener,m as DrawUtils,En as ImgUtils,pi as LineToolOperation,de as MarkerUtils,P as MathUtils,wn as MeasureOperation,Ii as PointOperation,di as PolygonOperation,pe as RectOperation,Z as RectUtils,ui as TagOperation,Rt as TagUtils,wi as TextToolOperation,Sn as ViewOperation,ns as cAnnotation,Mn as cAnnotationTask,pr as cKeyCode,$s as cStyle,ji as cTool,Fn as toolUtils,J as uuid};
95
+ ${ot.getStyle2String(h)}
96
+ `),c.addEventListener("wheel",this.wheelChange),this._domMap.set(s.id,c))}}),e.forEach(s=>{i.indexOf(s)===-1&&(this.clearTag(s),this._domMap.delete(s))})}}var Jo=Object.defineProperty,qo=Object.defineProperties,Qo=Object.getOwnPropertyDescriptors,Ps=Object.getOwnPropertySymbols,ta=Object.prototype.hasOwnProperty,ea=Object.prototype.propertyIsEnumerable,Is=(r,t,e)=>t in r?Jo(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,W=(r,t)=>{for(var e in t||(t={}))ta.call(t,e)&&Is(r,e,t[e]);if(Ps)for(var e of Ps(t))ea.call(t,e)&&Is(r,e,t[e]);return r},Zt=(r,t)=>qo(r,Qo(t));const ia=3,sa=3,Xe="#6371FF";class na extends gt{constructor(t){super(Zt(W({},t),{showDefaultCursor:!0}));this.style={},this.annotations=[],this.getHoverRectID=i=>{var s,n;const o=this.getCoordinateUnderZoom(i),a=I.changePointByZoom(o,1/this.zoom);if(((s=this.annotations)==null?void 0:s.length)<=0||!((n=this.annotations)==null?void 0:n.length))return;let l="",h=Number.MAX_SAFE_INTEGER;for(let c=0;c<this.annotations.length;c++){const u=this.annotations[c];switch(u.type){case"rect":{const d=u.annotation;if(Y.isInRect(o,d,ia,this.zoom)){const g=d.width*d.height;g<h&&(l=d.id,h=g)}break}case"polygon":{const d=u.annotation;if(S.isInPolygon(a,d.pointList)){const g=S.getPolygonArea(d.pointList);g<h&&(l=d.id,h=g)}break}}}return l};var e;this.style=(e=t.style)!=null?e:{stroke:Xe,thickness:3},this.annotations=t.annotations,this.loading=!1,this.renderDomInstance=new Go({container:this.container,height:this.canvas.height})}setLoading(t){this.loading=t,this.render()}onMouseLeave(){super.onMouseLeave(),this.mouseHoverID=void 0,this.emit("onChange","hover",[])}onMouseDown(t){if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const e=this.mouseHoverID;if(t.button===0){let i=[];e&&(i=[e]),this.emit("onChange","selected",i),this.render()}}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,i=this.getHoverRectID(t);if(e!==i){this.mouseHoverID=i;let s=[];i&&(s=[i]),this.emit("onChange","hover",s),this.render()}}updateData(t){this.annotations=t,this.render()}getSpecificStyle(t){const e=j.pick(t,["stroke","thickness","fill","radius"]),i=W(W({},this.style),e);return i.stroke&&Object.assign(i,{color:i.stroke}),i}getRenderText(t,e=!1){let i="",s="";return!t||e===!0?{headerText:i,bottomText:s}:((t==null?void 0:t.order)&&(i=`${t.order}`),(t==null?void 0:t.label)&&(i?i=`${i}_${t.label}`:i=`${t.label}`),(t==null?void 0:t.attribute)&&(i?i=`${i} ${t.attribute}`:i=`${t.attribute}`),(t==null?void 0:t.textAttribute)&&(s=t==null?void 0:t.textAttribute),{headerText:i,bottomText:s})}getReferenceOptions(t){return t?{lineCap:"butt",lineDash:[20,20]}:{}}render(){try{if(super.render(),this.loading===!0)return;this.renderDomInstance.render(this.annotations.filter(t=>t.type==="text"&&t.annotation.position==="rt").map(t=>t.annotation)),this.annotations.forEach(t=>{var e,i,s,n,o,a,l,h,c,u,d,g,p;switch(t.type){case"rect":{const f=t.annotation,{hiddenText:v=!1,isReference:y,hiddenRectSize:b=!1}=f,{zoom:w}=this,A=I.changeRectByZoom(f,this.zoom,this.currentPos),{x:P,y:N,width:z,height:H}=A,F=this.getSpecificStyle(f);if(f.id===this.mouseHoverID||F.fill){const st=gi((i=(e=F==null?void 0:F.fill)!=null?e:F==null?void 0:F.stroke)!=null?i:Xe),St=`rgba(${st[0]}, ${st[1]}, ${st[2]},${st[3]*.8})`;L.drawRectWithFill(this.canvas,A,{color:St})}L.drawRect(this.canvas,A,W(Zt(W({},F),{hiddenText:!0}),this.getReferenceOptions(y)));const{headerText:at,bottomText:pt}=this.getRenderText(f,f==null?void 0:f.hiddenText);at&&L.drawText(this.canvas,{x:P,y:N-6},at,Zt(W({color:F.stroke,font:"normal normal 900 14px SourceHanSansCN-Regular"},At),{textMaxWidth:300}));const Dt=`${Math.round(z/w)} * ${Math.round(H/w)}`,lt=Dt.length*7;if(!v&&!b&&L.drawText(this.canvas,{x:P+z-lt,y:N+H+15},Dt,W({color:F.stroke,font:"normal normal 600 14px Arial"},At)),pt){const st=20,St=Math.max(20,z-lt);L.drawText(this.canvas,{x:P,y:N+H+st},f.textAttribute,W({color:F.stroke,font:"italic normal 900 14px Arial",textMaxWidth:St},At))}break}case"polygon":{const f=t.annotation;if(!(((s=f==null?void 0:f.pointList)==null?void 0:s.length)>=3))return;const{lineType:v=k.Line}=f,y=I.changePointListByZoom((n=f==null?void 0:f.pointList)!=null?n:[],this.zoom,this.currentPos),b=this.getSpecificStyle(f);if(f.id===this.mouseHoverID||b.fill){const H=gi((a=(o=b==null?void 0:b.fill)!=null?o:b==null?void 0:b.stroke)!=null?a:Xe),F=`rgba(${H[0]}, ${H[1]}, ${H[2]},${H[3]*.8})`;L.drawPolygonWithFill(this.canvas,y,{color:F,lineType:v})}const w=Zt(W(Zt(W({},b),{isClose:!0}),this.getReferenceOptions(f==null?void 0:f.isReference)),{lineType:v,strokeColor:b.stroke});let A=[];if(f.showKeyPoint?A=L.drawPolygonWithKeyPoint(this.canvas,y,w):A=L.drawPolygon(this.canvas,y,w),(f==null?void 0:f.showDirection)===!0&&((l=f==null?void 0:f.pointList)==null?void 0:l.length)>2){let H=y[0],F=_.getLineCenterPoint([y[0],y[1]]);if(v===k.Curve){const at=Math.floor(tt/2);H=A[at],F=A[at+1]}L.drawArrowByCanvas(this.canvas,H,F,{color:b.stroke,thickness:b.thickness}),L.drawCircle(this.canvas,y[0],b.thickness+6,{color:b.stroke,thickness:b.thickness})}const{headerText:N,bottomText:z}=this.getRenderText(f,f==null?void 0:f.hiddenText);if(N&&L.drawText(this.canvas,y[0],N,W({color:b.stroke},rt)),z){const H=y[y.length-1];L.drawText(this.canvas,{x:H.x+Tt.x,y:H.y+Tt.y},z,W({color:b.stroke},rt))}break}case"line":{const f=t.annotation;if(!(((h=f==null?void 0:f.pointList)==null?void 0:h.length)>=2))return;const{lineType:v=k.Line}=f,y=I.changePointListByZoom((c=f==null?void 0:f.pointList)!=null?c:[],this.zoom,this.currentPos),b=this.getSpecificStyle(f),w=L.drawPolygon(this.canvas,y,Zt(W(W({},b),this.getReferenceOptions(f==null?void 0:f.isReference)),{lineType:v}));if((f==null?void 0:f.showDirection)===!0&&((u=f==null?void 0:f.pointList)==null?void 0:u.length)>2){let z=y[0],H=_.getLineCenterPoint([y[0],y[1]]);if(v===k.Curve){const F=Math.floor(tt/2);z=w[F],H=w[F+1]}L.drawArrowByCanvas(this.canvas,z,H,{color:b.stroke,thickness:b.thickness}),L.drawCircle(this.canvas,y[0],b.thickness+6,{color:b.stroke,thickness:b.thickness})}const{headerText:P,bottomText:N}=this.getRenderText(f,f==null?void 0:f.hiddenText);if(P&&L.drawText(this.canvas,y[0],P,W({color:b.stroke},rt)),N){const z=y[y.length-1];L.drawText(this.canvas,{x:z.x+Tt.x,y:z.y+Tt.y},N,W({color:b.stroke},rt))}break}case"point":{const f=t.annotation,v=I.changePointByZoom(f,this.zoom,this.currentPos),y=this.getSpecificStyle(f),b=(d=y.radius)!=null?d:sa;L.drawCircle(this.canvas,v,b,y);const{headerText:w,bottomText:A}=this.getRenderText(f,f==null?void 0:f.hiddenText);w&&L.drawText(this.canvas,{x:v.x+b/2,y:v.y-b-4},w,{textAlign:"center",color:y.stroke}),A&&L.drawText(this.canvas,{x:v.x+b,y:v.y+b+24},A,W({color:y.stroke},rt));break}case"text":{const f=t.annotation,{text:v,x:y,y:b,textMaxWidth:w,color:A="white",background:P="rgba(0, 0, 0, 0.6)",lineHeight:N=25,font:z=ee,position:H}=f,F=10,at=10,pt=I.changePointByZoom({x:y,y:b},this.zoom,this.currentPos),{width:Dt,height:lt,fontHeight:st=0}=_.getTextArea(this.canvas,f.text,w,z,N);if(H==="rt")break;L.drawRectWithFill(this.canvas,{x:pt.x,y:pt.y,width:Dt+at*2,height:lt+F*2,id:"",sourceID:"",valid:!0,textAttribute:"",attribute:""},{color:P}),L.drawText(this.canvas,{x:pt.x+at,y:pt.y+st+F},v,{color:A,lineHeight:N,font:z,textMaxWidth:w});break}default:}(p=(g=t.annotation)==null?void 0:g.renderEnhance)==null||p.call(g,{ctx:this.ctx,canvas:this.canvas,currentPos:this.currentPos,zoom:this.zoom,data:t,toolInstance:this})})}catch(t){console.error("ViewOperation Render Error",t)}}}var ra=Object.defineProperty,oa=Object.defineProperties,aa=Object.getOwnPropertyDescriptors,Ls=Object.getOwnPropertySymbols,la=Object.prototype.hasOwnProperty,ha=Object.prototype.propertyIsEnumerable,Cs=(r,t,e)=>t in r?ra(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ds=(r,t)=>{for(var e in t||(t={}))la.call(t,e)&&Cs(r,e,t[e]);if(Ls)for(var e of Ls(t))ha.call(t,e)&&Cs(r,e,t[e]);return r},_s=(r,t)=>oa(r,aa(t));class Rs extends We{constructor(t){super(t);this.selectedIDs=[],this.rightMouseUp=s=>{if(this.drawingPointList.length>0){this.addDrawingPointToPolygonList();return}s.ctrlKey&&this.hoverID?this.emit("addSelectedIDs",this.hoverID):this.emit("setSelectedIDs",this.hoverID)},this.onKeyDown=()=>{},this.onKeyUp=()=>{},this.renderSingleSelectedPolygon=s=>{var n;if(this.selectedPolygons){const o=this.getColor(s.attribute),a=ot.getStrokeAndFill(o,s.valid,{isSelected:!0}),l=I.changePointListByZoom(s.pointList,this.zoom,this.currentPos);L.drawSelectedPolygonWithFillAndLine(this.canvas,l,{fillColor:"transparent",strokeColor:a.stroke,pointColor:"white",thickness:2,lineCap:"round",isClose:!0,lineType:(n=this.config)==null?void 0:n.lineType}),s.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(l)}};var e,i;this.showDirectionLine=(e=t.showDirectionLine)!=null?e:!0,this.forbidAddNew=(i=t.forbidAddNew)!=null?i:!1}get getSelectedIDs(){return this.selectedIDs}setSelectedIDs(t){this.selectedIDs=t,this.setSelectedID(this.selectedIDs.length===1?this.selectedIDs[0]:""),this.render()}deleteSelectedID(){super.deleteSelectedID(),this.selectedIDs=[],this.emit("deleteSelectedIDs")}get selectedPolygons(){return S.getPolygonByIDs(this.polygonList,this.selectedIDs)}getLineColor(){return"rgba(0, 255, 255, 0.5)"}renderStaticPolygon(){var t;this.isHidden===!1&&((t=this.polygonList)==null||t.forEach(e=>{var i,s,n;if([...this.selectedIDs,this.editPolygonID].includes(e.id))return;const{attribute:o}=e,a=this.getColor(o),l=ot.getStrokeAndFill(a,e.valid),h=I.changePointListByZoom(e.pointList||[],this.zoom,this.currentPos);L.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:"transparent",strokeColor:l.stroke,pointColor:"white",thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineCap:"round",isClose:!0,lineType:(n=this.config)==null?void 0:n.lineType}),e.isRect===!0&&this.showDirectionLine===!0&&this.renderRectPolygonDirection(h)}))}renderSelectedPolygon(){var t;(t=this.selectedPolygons)==null||t.forEach(e=>{this.renderSingleSelectedPolygon(e)})}renderRectPolygonDirection(t){t.length<2||L.drawLine(this.canvas,t[0],t[1],{color:"red",thickness:3})}get currentPolygonListByPattern(){return this.polygonList.filter(t=>this.pattern===et.Rect?t.isRect===!0:this.pattern===et.Normal?t.isRect!==!0:!0)}getHoverID(t){var e;const i=this.getCoordinateUnderZoom(t),n=this.currentPolygonListByPattern.map(o=>_s(Ds({},o),{pointList:I.changePointListByZoom(o.pointList,this.zoom)}));return S.getHoverPolygonID(i,n,10,(e=this.config)==null?void 0:e.lineType)}switchToNextPolygon(t=q.ascend){if(this.drawingPointList.length>0)return;const e=this.currentPolygonListByPattern.map(s=>{var n,o,a,l;return _s(Ds({},s),{x:(o=(n=s.pointList[0])==null?void 0:n.x)!=null?o:0,y:(l=(a=s.pointList[0])==null?void 0:a.y)!=null?l:0})}),i=x.getNextSelectedRectID(e,t,this.selectedID);return i&&this.setSelectedIDs([i.id]),this.render(),[i.id]}setSelectedIdAfterAddingDrawing(t){this.drawingPointList.length!==0&&this.setSelectedID(t)}setSelectedID(t){var e,i;const s=this.selectedID;t!==s&&s&&((e=this._textAttributInstance)==null||e.changeSelected()),t||(i=this._textAttributInstance)==null||i.clearTextAttribute(),this.selectedID=t,this.render()}addPointInDrawing(t){this.forbidAddNew||super.addPointInDrawing(t)}}const ca={0:"\u76EE\u6807\u68C0\u6D4B",1:"\u56FE\u50CF\u5206\u7C7B"},da={0:"\u6807\u6CE8\u6587\u4EF6\u4F20\u8F93\u4E2D",1:"\u6807\u6CE8\u6587\u4EF6\u4F20\u8F93\u91CD\u8BD5",2:"\u6807\u6CE8\u6587\u4EF6\u4F20\u8F93\u5931\u8D25",3:"\u6807\u6CE8\u4E2D",4:"\u4EFB\u52A1\u7EC8\u6B62",5:"\u4EFB\u52A1\u5B8C\u6210",6:"\u6570\u636E\u5DF2\u53D1\u5E03"};var Ye;(function(r){r[r.Upload=0]="Upload",r[r.UploadRetry=1]="UploadRetry",r[r.UploadFail=2]="UploadFail",r[r.Annotation=3]="Annotation",r[r.Terminated=4]="Terminated",r[r.Finish=5]="Finish",r[r.Publish=6]="Publish"})(Ye||(Ye={}));var ua=Object.freeze({__proto__:null,ANNOTATION_TYPE:ca,ANNOTATION_STATUS:da,get EAnnotationStatus(){return Ye}}),ga=Object.defineProperty,As=Object.getOwnPropertySymbols,fa=Object.prototype.hasOwnProperty,pa=Object.prototype.propertyIsEnumerable,Ts=(r,t,e)=>t in r?ga(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ss=(r,t)=>{for(var e in t||(t={}))fa.call(t,e)&&Ts(r,e,t[e]);if(As)for(var e of As(t))pa.call(t,e)&&Ts(r,e,t[e]);return r};const Os={x:8,y:26},va=2;class ma extends gt{constructor(t){super(t);this.getHoverRectID=e=>{var i,s;const n=this.getCoordinateUnderZoom(e),o=(s=(i=this.resultList.find(a=>a.toolName===D.Rect))==null?void 0:i.result)!=null?s:[];if(o.length>0){const a=o.filter(l=>Y.isInRect(n,l,va,this.zoom));if(a.length===0)return"";if(a.length===1)return a[0].id;if(a.length>1)return a.map(h=>({size:h.width*h.height,id:h.id})).sort((h,c)=>h.size-c.size)[0].id}return""},this.resultList=[],this.hoverID=[],this.fillID=[],this.render=this.render.bind(this),this.drawPolygon=this.drawPolygon.bind(this),this.drawRect=this.drawRect.bind(this),this.drawTag=this.drawTag.bind(this),this.setShowDefaultCursor(!0),this.forbidOperation=!0}onMouseDown(t){var e,i;if(super.onMouseDown(t)||this.forbidMouseOperation||!this.imgInfo)return!0;const s=this.mouseHoverID,n=(i=(e=this.resultList.find(o=>o.toolName===D.Rect))==null?void 0:e.result)!=null?i:[];if(t.button===0){let o=[s],a=!0;s&&n.find(l=>l.id===s&&(l==null?void 0:l.isSelected))&&(a=!1),s||(o=n.map(l=>l.id),a=!1),this.emit("setSelectedID",o,a),this.render()}}updateRotate(){}onMouseMove(t){if(super.onMouseMove(t)||this.forbidMouseOperation||!this.imgInfo)return;const e=this.mouseHoverID,i=this.getHoverRectID(t);if(e!==i){this.mouseHoverID=i;let s=[i];i||(s=[]),this.emit("setHoverID",s),this.render()}}setResult(t){this.resultList=cn(t),this.render()}drawPolygon(t,e){t==null||t.forEach(i=>{var s,n,o,a,l;const h=this.getColor(i.attribute,e),c=ot.getStrokeAndFill(h,i.valid);let u=(n=(s=this.style)==null?void 0:s.width)!=null?n:2;this.hoverID.includes(i.id)?(u=4,L.drawPolygonWithFillAndLine(this.canvas,I.changePointListByZoom(i.pointList,this.zoom,this.currentPos),{fillColor:c.fill,strokeColor:c.stroke,pointColor:"white",thickness:u,lineCap:"round",isClose:!0,lineType:e==null?void 0:e.lineType})):L.drawPolygon(this.canvas,I.changePointListByZoom(i.pointList,this.zoom,this.currentPos),{color:c.fill,lineType:(o=this.config)==null?void 0:o.lineType,thickness:u,isClose:!0});let d=`${(l=M.getAttributeShowText(i.attribute,(a=e==null?void 0:e.attributeList)!=null?a:[]))!=null?l:""}`;(e==null?void 0:e.isShowOrder)&&(i==null?void 0:i.order)>0&&(d=`${i.order} ${d}`),L.drawText(this.canvas,I.changePointByZoom(i.pointList[0],this.zoom,this.currentPos),d,Ss({color:c.stroke},rt));const g=I.changePointListByZoom(i.pointList||[],this.zoom,this.currentPos),p=g[g.length-1];L.drawText(this.canvas,{x:p.x+Os.x,y:p.y+Os.y},i==null?void 0:i.textAttribute,Ss({color:c.stroke},rt))})}drawRect(t,e){t==null||t.forEach(i=>{let s=1;this.hoverID.includes(i.id)&&(s=3);const n=this.getColor(i.attribute,e),o=I.changeRectByZoom(i,this.zoom,this.currentPos);L.drawRect(this.canvas,o,{color:(i==null?void 0:i.valid)?n.valid.stroke:n.invalid.stroke,thickness:s}),this.fillID.includes(i.id)&&L.drawRectWithFill(this.canvas,o,{color:(i==null?void 0:i.valid)?n.valid.fill:n.invalid.fill})})}drawTag(t,e){const i=t.reduce((s,n)=>[...s,...(e==null?void 0:e.inputList)?Yt.getTagNameList(n.result,e.inputList):Yt.getTagnameListWithoutConfig(n.result)],[]);L.drawTag(this.canvas,i)}setHoverID(t){this.hoverID=t,this.render()}setFillID(t){this.fillID=t,this.render()}render(){var t;super.render(),(t=this.resultList)==null||t.forEach(e=>{switch(e==null?void 0:e.toolName){case D.Rect:this.drawRect(e.result,x.jsonParser(e.config));break;case D.Polygon:this.drawPolygon(e.result,x.jsonParser(e.config));break;case D.Tag:this.drawTag(e.result,x.jsonParser(e.config));break}})}exportData(){return[[],{}]}}var ya=(r,t,e)=>new Promise((i,s)=>{var n=l=>{try{a(e.next(l))}catch(h){s(h)}},o=l=>{try{a(e.throw(l))}catch(h){s(h)}},a=l=>l.done?i(l.value):Promise.resolve(l.value).then(n,o);a((e=e.apply(r,t)).next())});class ba extends ae{constructor(t){super(t);this.onKeydown=e=>{switch(e.keyCode){case O.Esc:e.preventDefault(),e.stopPropagation(),this.clearPredictionInfo();break;case O.Z:e.ctrlKey&&(e.preventDefault(),e.stopPropagation(),this.rectList=[],this.render());break}},this.segmentPrediction=e=>ya(this,null,function*(){const i=this.getCoordinateUnderZoom(e);if(this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}yield this.runPrediction({point:i,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),this.clearPredictionInfo()}),this.isRunSegment=!1,this.runPrediction=t.runPrediction}setRunPrediction(t){this.runPrediction=t}eventBinding(){document.addEventListener("keydown",t=>this.onKeydown(t)),super.eventBinding()}clearPredictionInfo(){this.rectList=[],this.isShowCursor=!1,this.coord={x:-1,y:-1},this.drawingRect=void 0,this.isRunSegment=!1,this.clearCanvas(),this.render()}onMouseUp(t){if(!this.isRunSegment){if(t.button===0&&this.rectList.length===1&&!this.isRunSegment){t.stopPropagation(),this.segmentPrediction(t),this.clearActiveStatus();return}super.onMouseUp(t)}}onMouseDown(t){this.isRunSegment||super.onMouseDown(t)}renderCursorLine(){var t;if(!this.ctx)return;const{ctx:e}=this,i=10,s=1,{x:n,y:o}=this.coord;e.save(),e.strokeStyle="white",e.setLineDash([6]),e.lineWidth=s,e.strokeRect(n-i,o-i,i*2,i*2),e.restore();let a=`\u2460 ${yt.t("FramingOfObjectToBeDivided")}`;const l=yt.language==="en";let h=l?326:186;if(((t=this.rectList)==null?void 0:t.length)===1){a=`\u2461 ${yt.t("ClickOnTarget")}`,h=l?232:142;const c=2;e.save(),e.strokeStyle="white";const u=s+i;e.beginPath(),e.moveTo(n+u+c*2,o+u+c),e.arc(n+u+c,o+u+c,c,0,Math.PI*2,!0),e.stroke(),e.restore()}this.isRunSegment&&(h=l?316:136,a=yt.t("SplittingAlgorithmPrediction")),e.save(),e.fillStyle=this.style.strokeColor,e.fillRect(n+i,o-i*4-1,h,32),e.restore(),e.save(),e.font="14px Source Han Sans CN",e.fillStyle="white",e.fillText(a,n+i+14,o-i*2),e.restore(),super.renderCursorLine()}renderDrawingRect(t,e,i=!1){if(this.ctx&&t){const s=I.changeRectByZoom(t,i?e:this.zoom,this.currentPos),{x:n,y:o,width:a,height:l}=s;this.ctx.save(),this.ctx.lineCap="butt",this.ctx.lineWidth=this.style.strokeWidth,this.ctx.strokeStyle="white",this.ctx.strokeRect(n,o,a,l),this.ctx.strokeStyle=this.style.strokeColor,this.ctx.setLineDash([6]),this.ctx.strokeRect(n,o,a,l),this.ctx.restore()}}renderTextAttribute(){}renderSelectedRect(){}}const ks=r=>{switch(r){case D.Rect:case D.RectTrack:return ae;case D.SegmentByRect:return ba;case D.Tag:return os;case D.Polygon:return We;case Qt.Check:return ma;case D.Line:return ps;case D.Point:return ds;case D.Text:return vs;default:throw new Error("not match tool")}};class Ke extends x{}Ke.getCurrentOperation=ks;class xa{static load(t){return new Promise((e,i)=>{const s=new Image;t.startsWith("file")?s.src=encodeURI(t):s.src=t,s.onload=()=>{e(s)},s.onerror=()=>{i(s)}})}}const wa=r=>{const t=document.createElement("canvas");t.width=r.width,t.height=r.height;const e=t.getContext("2d");return e?(e.fillStyle="transparent",e.fillRect(0,0,r.width,r.height),t.toDataURL()):""},Ms=(r,t,e)=>{const i=r[t];return r[t]=r[e],r[e]=i,r},Es=class{static isSingleTool(r){return!this.isHybridTool(r)}static isHybridTool(r){return Array.isArray(r)}};let Kt=Es;Kt.getTopToolName=r=>Es.isHybridTool(r)?r[r.length-1]:r;class Pa{constructor(t){this.toolOperationList=[],this.toolOperationDom=[];var e,i;this.init(),this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(e=t.config)!=null?e:JSON.stringify(Ne(Kt.getTopToolName(t.toolName))),this.style=(i=t.style)!=null?i:He}setImgNode(t,e){this.toolOperationList.forEach(i=>{i.setImgNode(t,e)})}setSize(t){this.toolOperationList.forEach(e=>{e.setSize(t)})}syncPosition(t,e,i,s){this.toolOperationList.forEach(n=>{s!==n&&(n.setCurrentPos(t),n.setZoom(e),n.setImgInfo(i),n.renderBasicCanvas(),n.render())})}get defaultSize(){var t,e;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((e=this.imgNode)==null?void 0:e.height)||this.size.height}}createDom(){const{width:t,height:e}=this.defaultSize,i=window.document.createElement("div");i.style.position="absolute",i.style.left="0",i.style.top="0",i.style.width=`${t}px`,i.style.height=`${e}px`;const s=this.toolOperationList.length+1;return i.style.zIndex=`${s}`,i}getEmptyImage(t,e){const i=wa({width:t,height:e}),s=new Image;return s.src=i,s}createOperation(t,e,i){var s;const{width:n,height:o}=this.defaultSize,a=this.createDom(),l=this.getEmptyImage(n,o),h={container:a,size:this.size,config:(s=this==null?void 0:this.config)!=null?s:"{}",drawOutSideTarget:!1,style:this.style,imgNode:e||l,hiddenImg:!!t};i&&Object.assign(h,i);let c;if(!t)c=new gt(h),a.style.zIndex="0",c.init();else{const u=ks(t);if(!u)return;c=new u(h)}return c==null||c.init(),c.canvas.id=t!=null?t:"basicCanvas",c.on("dragMove",({currentPos:u,zoom:d,imgInfo:g})=>{this.syncPosition(u,d,g,c)}),c.on("renderZoom",(u,d,g)=>{u&&d&&this.syncPosition(d,u,g,c)}),t?(this.container.appendChild(a),this.toolOperationList.push(c),this.toolOperationDom.push(a),c):(this.container.insertBefore(a,this.container.childNodes[0]),this.toolOperationList.unshift(c),this.toolOperationDom.unshift(a),c)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,e=t-1,i=t-2,s=this.toolOperationDom[e],n=this.toolOperationDom[i];if(!(!n||!s))return s.style.zIndex=`${e-1}`,n.style.zIndex=`${e}`,this.toolOperationList[e].clearActiveStatus(),this.toolOperationList[e].clearCursorLine(),this.toolOperationList[e].render(),this.toolOperationList=Ms(this.toolOperationList,e,i),this.toolOperationDom=Ms(this.toolOperationDom,e,i),this.toolOperationList[e]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[]}}var Ia=(r,t,e)=>new Promise((i,s)=>{var n=l=>{try{a(e.next(l))}catch(h){s(h)}},o=l=>{try{a(e.throw(l))}catch(h){s(h)}},a=l=>l.done?i(l.value):Promise.resolve(l.value).then(n,o);a((e=e.apply(r,t)).next())});const La=r=>new Promise((t,e)=>{const i=document.createElement("img");i.crossOrigin="Anonymous",i.onerror=s=>{console.error(s),e(i)},i.src=r,i.onload=()=>{t(i)}});class Ca{constructor(t){this.setImgSrc=s=>Ia(this,null,function*(){const n=yield La(s);!n||this.setImgNode(n)});var e,i;this.container=t.container,this.size=t.size,this.toolName=t.toolName,this.imgNode=t.imgNode,this.config=(e=t.config)!=null?e:JSON.stringify(Ne(Kt.getTopToolName(t.toolName))),this.style=(i=t.style)!=null?i:He,this.toolScheduler=new Pa(t),this.i18nLanguage="cn",this._initToolOperation()}setToolName(t,e){this.toolName=t;const i=e||JSON.stringify(Ne(Kt.getTopToolName(t)));this.config=i,this._initToolOperation()}setImgNode(t,e){this.toolScheduler.setImgNode(t,e),this.imgNode=t}setSize(t){this.size=t,this.toolScheduler.setSize(t)}setStyle(t){this.style=t}_initToolOperation(){this.toolScheduler.destroyAllLayer();let t=[];const e={hiddenImg:!0};Kt.isSingleTool(this.toolName)?(t=[this.toolName],Object.assign(e,{hiddenImg:!1})):t=this.toolName,t.length>1&&this.toolScheduler.createOperation(void 0,this.imgNode),t.forEach((i,s)=>{const n=this.toolScheduler.createOperation(i,void 0,e);s===t.length-1&&(this.toolInstance=n)}),this.setLang(this.i18nLanguage)}setBasicInfo(t,e){this.dependToolName=t,this.basicResult=e,this.toolInstance.setDependName(t),this.toolInstance.setBasicResult(e),this.toolInstance.renderBasicCanvas()}clearBasicResult(){this.setBasicInfo()}forbidOperation(){this.toolInstance.setForbidOperation(!0)}launchOperation(){this.toolInstance.setForbidOperation(!1)}setLang(t){switch(this.i18nLanguage=t,t){case"cn":this.toolInstance.setLang(Pt.Zh);break;case"en":this.toolInstance.setLang(Pt.US);break}}setDataInjectionAtCreation(t){this.toolInstance.setDataInjectionAtCreation(t)}setRenderEnhance(t){this.toolInstance.setRenderEnhance(t)}switchLastTwoCanvas(){const t=this.toolScheduler.switchLastTwoCanvas();if(t)return this.toolInstance=t,t}get firstToolInstance(){return this.toolScheduler.getFirstToolOperation()}setCustomRenderStyle(t){this.toolInstance.setCustomRenderStyle(t)}}class Bs extends dn{constructor(t){super(t);this.littleEndian=!0}load(t,e,i,s){const n=this,o=new un(n.manager);o.setPath(n.path),o.setResponseType("arraybuffer"),o.setRequestHeader(n.requestHeader),o.setWithCredentials(n.withCredentials),o.load(t,function(a){try{e(n.parse(a))}catch(l){s?s(l):console.error(l),n.manager.itemError(t)}},i,s)}parse(t){function e(u,d){const g=u.length,p=new Uint8Array(d);let f=0,v=0,y,b,w;do if(y=u[f++],y<1<<5){if(y++,v+y>d)throw new Error("Output buffer is not large enough");if(f+y>g)throw new Error("Invalid compressed data");do p[v++]=u[f++];while(--y)}else{if(b=y>>5,w=v-((y&31)<<8)-1,f>=g)throw new Error("Invalid compressed data");if(b===7&&(b+=u[f++],f>=g))throw new Error("Invalid compressed data");if(w-=u[f++],v+b+2>d)throw new Error("Output buffer is not large enough");if(w<0)throw new Error("Invalid compressed data");if(w>=v)throw new Error("Invalid compressed data");do p[v++]=p[w++];while(--b+2)}while(f<g);return p}function i(u){const d={},g=u.search(/[\n\r]data\s(\S*)\s/i),p=/[\n\r]data\s(\S*)\s/i.exec(u.slice(g-1));if(d.data=p[1],d.headerLen=p[0].length+g,d.str=u.slice(0,d.headerLen),d.str=d.str.replace(/#.*/gi,""),d.version=/version (.*)/i.exec(d.str),d.fields=/fields (.*)/i.exec(d.str),d.size=/size (.*)/i.exec(d.str),d.type=/type (.*)/i.exec(d.str),d.count=/count (.*)/i.exec(d.str),d.width=/width (.*)/i.exec(d.str),d.height=/height (.*)/i.exec(d.str),d.viewpoint=/viewpoint (.*)/i.exec(d.str),d.points=/points (.*)/i.exec(d.str),d.version!==null&&(d.version=parseFloat(d.version[1])),d.fields=d.fields!==null?d.fields[1].split(" "):[],d.type!==null&&(d.type=d.type[1].split(" ")),d.width!==null&&(d.width=parseInt(d.width[1])),d.height!==null&&(d.height=parseInt(d.height[1])),d.viewpoint!==null&&(d.viewpoint=d.viewpoint[1]),d.points!==null&&(d.points=parseInt(d.points[1],10)),d.points===null&&(d.points=d.width*d.height),d.size!==null&&(d.size=d.size[1].split(" ").map(function(v){return parseInt(v,10)})),d.count!==null)d.count=d.count[1].split(" ").map(function(v){return parseInt(v,10)});else{d.count=[];for(let v=0,y=d.fields.length;v<y;v++)d.count.push(1)}d.offset={};let f=0;for(let v=0,y=d.fields.length;v<y;v++)d.data==="ascii"?d.offset[d.fields[v]]=v:(d.offset[d.fields[v]]=f,f+=d.size[v]*d.count[v]);return d.rowSize=f,d}const s=gn.decodeText(new Uint8Array(t)),n=i(s),o=[],a=[],l=[];if(n.data==="ascii"){const{offset:u}=n,g=s.slice(n.headerLen).split(`
97
+ `);for(let p=0,f=g.length;p<f;p++){if(g[p]==="")continue;const v=g[p].split(" ");if(u.x!==void 0&&(o.push(parseFloat(v[u.x])),o.push(parseFloat(v[u.y])),o.push(parseFloat(v[u.z]))),this.genColorByCoord){const b=this.genColorByCoord(parseFloat(v[u.x]),parseFloat(v[u.y]),parseFloat(v[u.z])).map(w=>w/255);l.push(...b)}u.normal_x!==void 0&&(a.push(parseFloat(v[u.normal_x])),a.push(parseFloat(v[u.normal_y])),a.push(parseFloat(v[u.normal_z])))}}if(n.data==="binary_compressed"){const u=new Uint32Array(t.slice(n.headerLen,n.headerLen+8)),d=u[0],g=u[1],p=e(new Uint8Array(t,n.headerLen+8,d),g),f=new DataView(p.buffer),{offset:v}=n;for(let y=0;y<n.points;y++)if(v.x!==void 0&&(o.push(f.getFloat32(n.points*v.x+n.size[0]*y,this.littleEndian)),o.push(f.getFloat32(n.points*v.y+n.size[1]*y,this.littleEndian)),o.push(f.getFloat32(n.points*v.z+n.size[2]*y,this.littleEndian))),v.normal_x!==void 0&&(a.push(f.getFloat32(n.points*v.normal_x+n.size[4]*y,this.littleEndian)),a.push(f.getFloat32(n.points*v.normal_y+n.size[5]*y,this.littleEndian)),a.push(f.getFloat32(n.points*v.normal_z+n.size[6]*y,this.littleEndian))),this.genColorByCoord){const w=this.genColorByCoord(f.getFloat32(n.points*v.x+n.size[0]*y,this.littleEndian),f.getFloat32(n.points*v.y+n.size[0]*y,this.littleEndian),f.getFloat32(n.points*v.z+n.size[0]*y,this.littleEndian)).map(A=>A/255);l.push(...w)}}if(n.data==="binary"){const u=new DataView(t,n.headerLen),{offset:d}=n;for(let g=0,p=0;g<n.points;g++,p+=n.rowSize)if(d.x!==void 0&&(o.push(u.getFloat32(p+d.x,this.littleEndian)),o.push(u.getFloat32(p+d.y,this.littleEndian)),o.push(u.getFloat32(p+d.z,this.littleEndian))),d.normal_x!==void 0&&(a.push(u.getFloat32(p+d.normal_x,this.littleEndian)),a.push(u.getFloat32(p+d.normal_y,this.littleEndian)),a.push(u.getFloat32(p+d.normal_z,this.littleEndian))),this.genColorByCoord){const v=this.genColorByCoord(u.getFloat32(p+d.x,this.littleEndian),u.getFloat32(p+d.y,this.littleEndian),u.getFloat32(p+d.z,this.littleEndian)).map(y=>y/255);l.push(...v)}}const h=new fn;o.length>0&&h.setAttribute("position",new ye(o,3)),a.length>0&&h.setAttribute("normal",new ye(a,3)),l.length>0&&h.setAttribute("color",new ye(l,3)),h.computeBoundingSphere();const c=new pn({size:.01});return l.length>0?c.vertexColors=!0:c.color.setHex(16777215),new vn(h,c)}genColorByCoord(t,e,i){return i<=0?[128,128,128]:i<5?[255,0,0]:i<10?[0,255,0]:[0,0,255]}}var Da=Object.defineProperty,_a=(r,t,e)=>t in r?Da(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ra=(r,t,e)=>(_a(r,typeof t!="symbol"?t+"":t,e),e);const Ns={type:"change"},Ge={type:"start"},Hs={type:"end"};class Aa extends mn{constructor(t,e){super();Ra(this,"listenToKeyEvents",m=>{m.addEventListener("keydown",onKeyDown),this._domElementKeyEvents=m}),e===void 0&&console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.'),e===document&&console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.'),this.object=t,this.domElement=e,this.domElement.style.touchAction="none",this.enabled=!0,this.target=new wt,this.minDistance=0,this.maxDistance=Infinity,this.minZoom=0,this.maxZoom=Infinity,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-Infinity,this.maxAzimuthAngle=Infinity,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:kt.ROTATE,MIDDLE:kt.DOLLY,RIGHT:kt.PAN},this.touches={ONE:Mt.ROTATE,TWO:Mt.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this.getPolarAngle=function(){return a.phi},this.getAzimuthalAngle=function(){return a.theta},this.getDistance=function(){return this.object.position.distanceTo(this.target)},this.saveState=function(){i.target0.copy(i.target),i.position0.copy(i.object.position),i.zoom0=i.object.zoom},this.reset=function(){i.target.copy(i.target0),i.object.position.copy(i.position0),i.object.zoom=i.zoom0,i.object.updateProjectionMatrix(),i.dispatchEvent(Ns),i.update(),n=s.NONE},this.update=function(){const m=new wt,T=new fi().setFromUnitVectors(t.up,new wt(0,1,0)),U=T.clone().invert(),V=new wt,ht=new fi,Ot=2*Math.PI;return function(){const{position:ui}=i.object;m.copy(ui).sub(i.target),m.applyQuaternion(T),a.setFromVector3(m),i.autoRotate&&n===s.NONE&&F(z()),i.enableDamping?(a.theta+=l.theta*i.dampingFactor,a.phi+=l.phi*i.dampingFactor):(a.theta+=l.theta,a.phi+=l.phi);let vt=i.minAzimuthAngle,mt=i.maxAzimuthAngle;return isFinite(vt)&&isFinite(mt)&&(vt<-Math.PI?vt+=Ot:vt>Math.PI&&(vt-=Ot),mt<-Math.PI?mt+=Ot:mt>Math.PI&&(mt-=Ot),vt<=mt?a.theta=Math.max(vt,Math.min(mt,a.theta)):a.theta=a.theta>(vt+mt)/2?Math.max(vt,a.theta):Math.min(mt,a.theta)),a.phi=Math.max(i.minPolarAngle,Math.min(i.maxPolarAngle,a.phi)),a.makeSafe(),a.radius*=h,a.radius=Math.max(i.minDistance,Math.min(i.maxDistance,a.radius)),i.enableDamping===!0?i.target.addScaledVector(c,i.dampingFactor):i.target.add(c),m.setFromSpherical(a),m.applyQuaternion(U),ui.copy(i.target).add(m),i.object.lookAt(i.target),i.enableDamping===!0?(l.theta*=1-i.dampingFactor,l.phi*=1-i.dampingFactor,c.multiplyScalar(1-i.dampingFactor)):(l.set(0,0,0),c.set(0,0,0)),h=1,u||V.distanceToSquared(i.object.position)>o||8*(1-ht.dot(i.object.quaternion))>o?(i.dispatchEvent(Ns),V.copy(i.object.position),ht.copy(i.object.quaternion),u=!1,!0):!1}}(),this.dispose=function(){i.domElement.removeEventListener("contextmenu",hi),i.domElement.removeEventListener("pointerdown",oi),i.domElement.removeEventListener("pointercancel",ai),i.domElement.removeEventListener("wheel",li),i.domElement.removeEventListener("pointermove",ge),i.domElement.removeEventListener("pointerup",fe),i._domElementKeyEvents!==null&&i._domElementKeyEvents.removeEventListener("keydown",sn)};const i=this,s={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6};let n=s.NONE;const o=1e-6,a=new pi,l=new pi;let h=1;const c=new wt;let u=!1;const d=new dt,g=new dt,p=new dt,f=new dt,v=new dt,y=new dt,b=new dt,w=new dt,A=new dt,P=[],N={};function z(){return 2*Math.PI/60/60*i.autoRotateSpeed}function H(){return Math.pow(.95,i.zoomSpeed)}function F(m){l.theta-=m}function at(m){l.phi-=m}const pt=function(){const m=new wt;return function(U,V){m.setFromMatrixColumn(V,0),m.multiplyScalar(-U),c.add(m)}}(),Dt=function(){const m=new wt;return function(U,V){i.screenSpacePanning===!0?m.setFromMatrixColumn(V,1):(m.setFromMatrixColumn(V,0),m.crossVectors(i.object.up,m)),m.multiplyScalar(U),c.add(m)}}(),lt=function(){const m=new wt;return function(U,V){const ht=i.domElement;if(i.object.isPerspectiveCamera){const{position:Ot}=i.object;m.copy(Ot).sub(i.target);let Gt=m.length();Gt*=Math.tan(i.object.fov/2*Math.PI/180),pt(2*U*Gt/ht.clientHeight,i.object.matrix),Dt(2*V*Gt/ht.clientHeight,i.object.matrix)}else i.object.isOrthographicCamera?(pt(U*(i.object.right-i.object.left)/i.object.zoom/ht.clientWidth,i.object.matrix),Dt(V*(i.object.top-i.object.bottom)/i.object.zoom/ht.clientHeight,i.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),i.enablePan=!1)}}();function st(m){i.object.isPerspectiveCamera?h/=m:i.object.isOrthographicCamera?(i.object.zoom=Math.max(i.minZoom,Math.min(i.maxZoom,i.object.zoom*m)),i.object.updateProjectionMatrix(),u=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),i.enableZoom=!1)}function St(m){i.object.isPerspectiveCamera?h*=m:i.object.isOrthographicCamera?(i.object.zoom=Math.max(i.minZoom,Math.min(i.maxZoom,i.object.zoom/m)),i.object.updateProjectionMatrix(),u=!0):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),i.enableZoom=!1)}function qe(m){d.set(m.clientX,m.clientY)}function Vs(m){b.set(m.clientX,m.clientY)}function Qe(m){f.set(m.clientX,m.clientY)}function js(m){g.set(m.clientX,m.clientY),p.subVectors(g,d).multiplyScalar(i.rotateSpeed);const T=i.domElement;F(2*Math.PI*p.x/T.clientHeight),at(2*Math.PI*p.y/T.clientHeight),d.copy(g),i.update()}function Ws(m){w.set(m.clientX,m.clientY),A.subVectors(w,b),A.y>0?st(H()):A.y<0&&St(H()),b.copy(w),i.update()}function Xs(m){v.set(m.clientX,m.clientY),y.subVectors(v,f).multiplyScalar(i.panSpeed),lt(y.x,y.y),f.copy(v),i.update()}function Ys(m){m.deltaY<0?St(H()):m.deltaY>0&&st(H()),i.update()}function Ks(m){let T=!1;switch(m.code){case i.keys.UP:lt(0,i.keyPanSpeed),T=!0;break;case i.keys.BOTTOM:lt(0,-i.keyPanSpeed),T=!0;break;case i.keys.LEFT:lt(i.keyPanSpeed,0),T=!0;break;case i.keys.RIGHT:lt(-i.keyPanSpeed,0),T=!0;break}T&&(m.preventDefault(),i.update())}function ti(){if(P.length===1)d.set(P[0].pageX,P[0].pageY);else{const m=.5*(P[0].pageX+P[1].pageX),T=.5*(P[0].pageY+P[1].pageY);d.set(m,T)}}function ei(){if(P.length===1)f.set(P[0].pageX,P[0].pageY);else{const m=.5*(P[0].pageX+P[1].pageX),T=.5*(P[0].pageY+P[1].pageY);f.set(m,T)}}function ii(){const m=P[0].pageX-P[1].pageX,T=P[0].pageY-P[1].pageY,U=Math.sqrt(m*m+T*T);b.set(0,U)}function Gs(){i.enableZoom&&ii(),i.enablePan&&ei()}function Js(){i.enableZoom&&ii(),i.enableRotate&&ti()}function si(m){if(P.length==1)g.set(m.pageX,m.pageY);else{const U=pe(m),V=.5*(m.pageX+U.x),ht=.5*(m.pageY+U.y);g.set(V,ht)}p.subVectors(g,d).multiplyScalar(i.rotateSpeed);const T=i.domElement;F(2*Math.PI*p.x/T.clientHeight),at(2*Math.PI*p.y/T.clientHeight),d.copy(g)}function ni(m){if(P.length===1)v.set(m.pageX,m.pageY);else{const T=pe(m),U=.5*(m.pageX+T.x),V=.5*(m.pageY+T.y);v.set(U,V)}y.subVectors(v,f).multiplyScalar(i.panSpeed),lt(y.x,y.y),f.copy(v)}function ri(m){const T=pe(m),U=m.pageX-T.x,V=m.pageY-T.y,ht=Math.sqrt(U*U+V*V);w.set(0,ht),A.set(0,Math.pow(w.y/b.y,i.zoomSpeed)),st(A.y),b.copy(w)}function qs(m){i.enableZoom&&ri(m),i.enablePan&&ni(m)}function Qs(m){i.enableZoom&&ri(m),i.enableRotate&&si(m)}function oi(m){i.enabled!==!1&&(P.length===0&&(i.domElement.setPointerCapture(m.pointerId),i.domElement.addEventListener("pointermove",ge),i.domElement.addEventListener("pointerup",fe)),on(m),m.pointerType==="touch"?nn(m):tn(m))}function ge(m){i.enabled!==!1&&(m.pointerType==="touch"?rn(m):en(m))}function fe(m){ci(m),P.length===0&&(i.domElement.releasePointerCapture(m.pointerId),i.domElement.removeEventListener("pointermove",ge),i.domElement.removeEventListener("pointerup",fe)),i.dispatchEvent(Hs),n=s.NONE}function ai(m){ci(m)}function tn(m){let T;switch(m.button){case 0:T=i.mouseButtons.LEFT;break;case 1:T=i.mouseButtons.MIDDLE;break;case 2:T=i.mouseButtons.RIGHT;break;default:T=-1}switch(T){case kt.DOLLY:if(i.enableZoom===!1)return;Vs(m),n=s.DOLLY;break;case kt.ROTATE:if(m.ctrlKey||m.metaKey||m.shiftKey){if(i.enablePan===!1)return;Qe(m),n=s.PAN}else{if(i.enableRotate===!1)return;qe(m),n=s.ROTATE}break;case kt.PAN:if(m.ctrlKey||m.metaKey||m.shiftKey){if(i.enableRotate===!1)return;qe(m),n=s.ROTATE}else{if(i.enablePan===!1)return;Qe(m),n=s.PAN}break;default:n=s.NONE}n!==s.NONE&&i.dispatchEvent(Ge)}function en(m){if(i.enabled!==!1)switch(n){case s.ROTATE:if(i.enableRotate===!1)return;js(m);break;case s.DOLLY:if(i.enableZoom===!1)return;Ws(m);break;case s.PAN:if(i.enablePan===!1)return;Xs(m);break}}function li(m){i.enabled===!1||i.enableZoom===!1||n!==s.NONE||(m.preventDefault(),i.dispatchEvent(Ge),Ys(m),i.dispatchEvent(Hs))}function sn(m){i.enabled===!1||i.enablePan===!1||Ks(m)}function nn(m){switch(di(m),P.length){case 1:switch(i.touches.ONE){case Mt.ROTATE:if(i.enableRotate===!1)return;ti(),n=s.TOUCH_ROTATE;break;case Mt.PAN:if(i.enablePan===!1)return;ei(),n=s.TOUCH_PAN;break;default:n=s.NONE}break;case 2:switch(i.touches.TWO){case Mt.DOLLY_PAN:if(i.enableZoom===!1&&i.enablePan===!1)return;Gs(),n=s.TOUCH_DOLLY_PAN;break;case Mt.DOLLY_ROTATE:if(i.enableZoom===!1&&i.enableRotate===!1)return;Js(),n=s.TOUCH_DOLLY_ROTATE;break;default:n=s.NONE}break;default:n=s.NONE}n!==s.NONE&&i.dispatchEvent(Ge)}function rn(m){switch(di(m),n){case s.TOUCH_ROTATE:if(i.enableRotate===!1)return;si(m),i.update();break;case s.TOUCH_PAN:if(i.enablePan===!1)return;ni(m),i.update();break;case s.TOUCH_DOLLY_PAN:if(i.enableZoom===!1&&i.enablePan===!1)return;qs(m),i.update();break;case s.TOUCH_DOLLY_ROTATE:if(i.enableZoom===!1&&i.enableRotate===!1)return;Qs(m),i.update();break;default:n=s.NONE}}function hi(m){i.enabled!==!1&&m.preventDefault()}function on(m){P.push(m)}function ci(m){delete N[m.pointerId];for(let T=0;T<P.length;T++)if(P[T].pointerId==m.pointerId){P.splice(T,1);return}}function di(m){let T=N[m.pointerId];T===void 0&&(T=new dt,N[m.pointerId]=T),T.set(m.pageX,m.pageY)}function pe(m){const T=m.pointerId===P[0].pointerId?P[1]:P[0];return N[T.pointerId]}i.domElement.addEventListener("contextmenu",hi),i.domElement.addEventListener("pointerdown",oi),i.domElement.addEventListener("pointercancel",ai),i.domElement.addEventListener("wheel",li,{passive:!1}),this.update()}}class Je{constructor(){this.MAX_SIZE=50,this.cacheList=[],this.loadPCDFile=t=>new Promise((e,i)=>{var s;if(this.pointsMap.get(t)){const n=(s=this.pointsMap.get(t))==null?void 0:s.clone();e(n);return}if(this.cacheList.length>this.MAX_SIZE){const n=this.cacheList.shift();n&&this.pointsMap.delete(n.src)}this.cacheList.push({src:t}),this.pcdLoader.load(t,n=>{this.pointsMap.set(t,n.clone()),e(n)},()=>{},n=>{i(n)})}),this.pcdLoader=new Bs,this.pointsMap=new Map}static getInstance(){return this.instance==null&&(this.instance=new Je),this.instance}}var Ta=Object.defineProperty,Sa=Object.defineProperties,Oa=Object.getOwnPropertyDescriptors,Fs=Object.getOwnPropertySymbols,ka=Object.prototype.hasOwnProperty,Ma=Object.prototype.propertyIsEnumerable,zs=(r,t,e)=>t in r?Ta(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,de=(r,t)=>{for(var e in t||(t={}))ka.call(t,e)&&zs(r,e,t[e]);if(Fs)for(var e of Fs(t))Ma.call(t,e)&&zs(r,e,t[e]);return r},ue=(r,t)=>Sa(r,Oa(t)),$s=(r,t,e)=>new Promise((i,s)=>{var n=l=>{try{a(e.next(l))}catch(h){s(h)}},o=l=>{try{a(e.throw(l))}catch(h){s(h)}},a=l=>l.done?i(l.value):Promise.resolve(l.value).then(n,o);a((e=e.apply(r,t)).next())});const Ea=30;class Zs{constructor({container:t,noAppend:e,isOrthographicCamera:i,orthographicParams:s,backgroundColor:n="black"}){this.zAxisLimit=10,this.initCameraPosition=new C.Vector3(-1,0,10),this.isOrthographicCamera=!1,this.pointsUuid="",this.pointCloudObjectName="pointCloud",this.rangeObjectName="range",this.showDirection=!0,this.AddBoxToSense=(o,a=16777215)=>{var l;const h=(l=o.id)!=null?l:it();this.removeObjectByName(h);const{center:c,width:u,height:d,depth:g,rotation:p}=o,f=new C.Group,v=new C.BoxGeometry(u,d,g),y=new C.MeshBasicMaterial({color:"blue"}),b=new C.Mesh(v,y),w=new C.BoxHelper(b,a),A=this.generateBoxArrow(o),P=this.generateBoxTrackID(o);f.add(w),f.add(A),f.add(P),f.position.set(c.x,c.y,c.z),f.rotation.set(0,0,p),f.name=h,this.scene.add(f)},this.overridePointShader=o=>{o.vertexShader=`
98
+ attribute float sizes;
99
+ attribute float visibility;
100
+ varying float vVisible;
101
+ ${o.vertexShader}`.replace("gl_PointSize = size;",`gl_PointSize = size;
102
+ vVisible = visibility;
103
+ `),o.fragmentShader=`
104
+ varying float vVisible;
105
+ ${o.fragmentShader}`.replace("#include <clipping_planes_fragment>",`
106
+ if (vVisible < 0.5) discard;
107
+ #include <clipping_planes_fragment>`)},this.loadPCDFile=(o,a)=>$s(this,null,function*(){this.clearPointCloud();const l=yield this.cacheInstance.loadPCDFile(o);l.name=this.pointCloudObjectName,this.renderPointCloud(l),a&&a()}),this.loadPCDFileByBox=(o,a,l)=>$s(this,null,function*(){this.clearPointCloud();const h=u=>{u.material.size=1;const{width:d=0,height:g=0,depth:p=0}=l!=null?l:{},f=this.filterPointsByBox(ue(de({},a),{width:a.width+d,height:a.height+g,depth:a.depth+p}),u.geometry.attributes.position.array,u.geometry.attributes.color.array),v=new C.Points(f,u.material);v.name=this.pointCloudObjectName,this.scene.add(v),this.render()},c=yield this.cacheInstance.loadPCDFile(o);h(c)}),this.generateBoxArrow=({width:o,depth:a})=>{const l=new C.Vector3(1,0,0),h=new C.Vector3(-o/2,0,-a/2),c=o,u=16776960,d=new C.ArrowHelper(l,h,c,u);return d.visible=this.showDirection,d},this.generateBoxTrackID=o=>{const a=new C.Texture(this.getTextCanvas(o.trackID.toString()));a.needsUpdate=!0;const l=new C.SpriteMaterial({map:a,depthWrite:!1}),h=new C.Sprite(l);return h.scale.set(5,5,5),h.position.set(-o.width/2,0,o.depth/2+.5),h},this.applyZAxisPoints=o=>{this.zAxisLimit=o,this.filterZAxisPoints(),this.render()},this.updatePointSize=o=>{const a=this.scene.getObjectByName(this.pointCloudObjectName);if(!a)return;const l=a.material.size;o?a.material.size=Math.min(l*1.2,10):a.material.size=Math.max(l/1.2,1),this.render()},this.container=t,this.renderer=new C.WebGLRenderer({antialias:!0}),this.backgroundColor=n,i&&s?(this.isOrthographicCamera=!0,this.camera=new C.OrthographicCamera(s.left,s.right,s.top,s.bottom,s.near,s.far)):this.camera=new C.PerspectiveCamera(30,this.containerWidth/this.containerHeight,1,1e3),this.initCamera(),this.scene=new C.Scene,this.controls=new Aa(this.camera,this.renderer.domElement),this.pcdLoader=new Bs,this.axesHelper=new C.AxesHelper(1e3),this.scene.add(this.camera),e||t.appendChild(this.renderer.domElement),this.init(),this.cacheInstance=Je.getInstance()}get containerWidth(){return this.container.clientWidth}get containerHeight(){return this.container.clientHeight}setInitCameraPosition(t){this.initCameraPosition=t}initCamera(){const{camera:t}=this;if(this.isOrthographicCamera){const{x:e,y:i,z:s}=this.initCameraPosition;t.position.set(e,i,s)}else t.position.set(-1,0,500);t.up.set(0,0,1)}initControls(){const{controls:t}=this,e=[0,0,0];t.target=new C.Vector3(...e),t.addEventListener("change",()=>{this.render()}),t.maxPolarAngle=Math.PI/2,t.update()}initRenderer(){const{renderer:t}=this;t.setPixelRatio(window.devicePixelRatio),t.setSize(this.containerWidth,this.containerHeight)}init(){const{scene:t}=this;t.background=new C.Color(this.backgroundColor),this.initControls(),this.initRenderer()}removeObjectByName(t){const e=this.scene.getObjectByName(t);e&&e.removeFromParent()}transferKitti2Matrix(t,e,i){const s=me.transferMatrix34FromKitti2Three(t),n=me.transferMatrix33FromKitti2Three(e),o=me.transferMatrix34FromKitti2Three(i),a=this.createThreeMatrix4(s),l=this.createThreeMatrix4(n),h=this.createThreeMatrix4(o);return{composeMatrix4:h.clone().premultiply(l).premultiply(a),PM:a,RM:l,TM:h}}pointCloudLidar2image(t,e){const i=qt.getAllViewData(t),{P:s,R:n,T:o}=e,{composeMatrix4:a}=this.transferKitti2Matrix(s,n,o);return i.map(h=>({type:h.type,pointList:h.pointList.map(c=>this.rotatePoint(c,t.center,t.rotation)).map(c=>this.lidar2image(c,a)).filter(c=>c!==void 0)}))}lidar2image(t,e){const s=new C.Vector4(t.x,t.y,t.z).applyMatrix4(e);if(s.z<0)return;const n=1/s.z,o=new C.Matrix4().set(n,0,0,0,0,n,0,0,0,0,n,0,0,0,0,1);return s.applyMatrix4(o)}generateBox(t,e=16777215){this.AddBoxToSense(t,e),this.render()}generateBoxes(t){t.forEach(e=>{this.generateBox(e)}),this.render()}getOrthographicCamera(t){const{center:e,width:i,height:s}=t,n=10,o=e.x-i/2-n,a=e.x-i/2+n,l=e.y+s/2+n,h=e.y-s/2-n,c=100,u=-100,d=500/c;return{left:o,right:a,top:l,bottom:h,near:c,far:u,zoom:d}}updateCameraByBox(t,e){const{center:i,width:s,height:n,depth:o,rotation:a}=t,l=this.getCameraVector(i,a,{width:s,height:n,depth:o},e);return this.updateCamera(l,i),l}updateOrthoCamera(t,e){const i=this.updateCameraByBox(t,e);return this.camera.zoom=1,this.camera.updateProjectionMatrix(),{cameraPositionVector:i}}updateTopCamera(){this.camera.zoom=1,this.initCamera(),this.initControls(),this.camera.updateProjectionMatrix(),this.render()}updateCamera(t,e){this.camera.position.set(t.x,t.y,t.z),this.controls.target=new C.Vector3(e.x,e.y,e.z),this.controls.update()}resetCamera(){this.updateCamera({x:-1,y:0,z:500},{x:0,y:0,z:0})}createThreeMatrix4(t){return new C.Matrix4().set(...t)}rotatePoint(t,e,i){var s;const n=new C.Vector3(t.x,t.y,(s=t==null?void 0:t.z)!=null?s:1),o=new C.Matrix4().makeRotationZ(i),a=new C.Matrix4().makeTranslation(e.x,e.y,e.z),l=new C.Matrix4().makeTranslation(-e.x,-e.y,-e.z);return n.clone().applyMatrix4(l).applyMatrix4(o).applyMatrix4(a)}getCuboidFromPointCloudBox(t){const{center:e,width:i,height:s,depth:n,rotation:o}=t,a=[{x:e.x+i/2,y:e.y+s/2},{x:e.x+i/2,y:e.y-s/2},{x:e.x-i/2,y:e.y-s/2},{x:e.x-i/2,y:e.y+s/2}].map(c=>{const u=this.rotatePoint(c,e,o);return{x:u.x,y:u.y}}),l=e.z+n/2,h=e.z-n/2;return{polygonPointList:a,zMax:l,zMin:h}}filterPointsByBox(t,e,i){const s=[],n=[],{zMin:o,zMax:a,polygonPointList:l}=this.getCuboidFromPointCloudBox(t);for(let c=0;c<e.length;c+=3){const u=e[c],d=e[c+1],g=e[c+2];Ut({x:u,y:d},l)&&g>=o&&g<=a&&(s.push(u),s.push(d),s.push(g),n.push(i[c]),n.push(i[c+1]),n.push(i[c+2]))}const h=new C.BufferGeometry;return h.setAttribute("position",new C.Float32BufferAttribute(s,3)),h.setAttribute("color",new C.Float32BufferAttribute(n,3)),h.computeBoundingSphere(),h}filterPointsColor(t,e,i){const{zMin:s,zMax:n,polygonPointList:o}=this.getCuboidFromPointCloudBox(t);for(let a=0;a<e.length;a+=3){const l=e[a],h=e[a+1],c=e[a+2];if(Ut({x:l,y:h},o)&&c>=s&&c<=n)i[a]=0,i[a+1]=1,i[a+2]=1;else{const[d,g,p]=qt.getStandardColorByCoord(l,h,c);i[a]=d,i[a+1]=g,i[a+2]=p}}}getCameraVector(t,e,i,s=nt.Front,n=Ea){let o=_t.frontViewMatrix4(n);switch(s){case nt.Front:break;case nt.Back:o=_t.backViewMatrix4(n);break;case nt.Left:o=_t.leftViewMatrix4(n);break;case nt.Right:o=_t.rightViewMatrix4(n);break;case nt.Top:o=_t.topViewMatrix4(n);break;case nt.LFT:o=_t.leftFrontTopViewMatrix4(n,i);break;case nt.RBT:o=_t.rightBackTopViewMatrix4(n,i);break}const a=this.createThreeMatrix4(o),l=new C.Matrix4().makeTranslation(-t.x,-t.y,-t.z),h=new C.Matrix4().makeTranslation(t.x,t.y,t.z),c=new C.Matrix4().makeRotationZ(e);return new C.Vector3(t.x,t.y,t.z).clone().applyMatrix4(a).applyMatrix4(l).applyMatrix4(c).applyMatrix4(h)}createRange(t){this.removeObjectByName(this.rangeObjectName);const i=new C.EllipseCurve(0,0,t,t,0,2*Math.PI,!1,0).getPoints(50),s=new C.BufferGeometry().setFromPoints(i),n=new C.LineBasicMaterial({color:16711680}),o=new C.Line(s,n);return o.name=this.rangeObjectName,o}renderPointCloud(t){t.material.size=1,t.name=this.pointCloudObjectName;const e=new C.PointsMaterial({vertexColors:!0});e.onBeforeCompile=this.overridePointShader;const i=this.createRange(t.geometry.boundingSphere.radius*2);this.pointsUuid=t.uuid,t.material=e,this.filterZAxisPoints(t),this.scene.add(t),this.scene.add(i),this.render()}clearPointCloud(){this.removeObjectByName(this.pointCloudObjectName)}clearPointCloudAndRender(){this.clearPointCloud(),this.render()}hightLightOriginPointCloud(t){const e=this.scene.getObjectByName(this.pointCloudObjectName);!e||(this.filterPointsColor(t,e.geometry.attributes.position.array,e.geometry.attributes.color.array),e.geometry.attributes.color.needsUpdate=!0,this.render())}setShowDirection(t){this.showDirection=t,this.scene.children.forEach(e=>{e.type==="Group"&&e.children.forEach(i=>{i.type==="ArrowHelper"&&(i.visible=t)})}),this.render()}getTextCanvas(t){const e=document.createElement("canvas"),i=e.getContext("2d");return i&&(i.font=`${50}px " bold`,i.fillStyle="white",i.textAlign="center",i.textBaseline="middle",i.fillText(t,e.width/2,e.height/2)),e}getSensesPointZAxisInPolygon(t){const e=this.scene.children.find(n=>n.uuid===this.pointsUuid);let i=0,s=0;if(e&&(e==null?void 0:e.geometry)){const n=e==null?void 0:e.geometry.attributes.position;for(let o=0;o<n.count;o++){const a=o*3,l=n.getX(a),h=n.getY(a),c=n.getZ(a);Ut({x:l,y:h},t)&&c&&(s=Math.max(c,s),i=Math.min(c,i))}}return{maxZ:s,minZ:i}}getBasicCoordinate2Canvas(t){const e=this.containerWidth/2,i=this.containerHeight/2;return{x:t.x*e+e,y:t.y*i+i,z:t.z}}get basicCoordinate2CanvasMatrix4(){const t=this.containerWidth/2,e=this.containerHeight/2;return new C.Matrix4().set(t,0,0,t,0,e,0,e,0,0,1,0,0,0,0,1)}getCanvas2BasicCoordinate(t){const e=this.containerWidth/2,i=this.containerHeight/2;return new C.Vector3(t.x/e-e/2,-(t.y/i-i/2),1)}getPolygonSidePoints(t){const{center:{x:e,y:i,z:s},height:n,width:o,depth:a}=t,l={x:e+o/2,y:i+n/2,z:s-a/2},h={x:e+o/2,y:i+n/2,z:s+a/2},c={x:e-o/2,y:i+n/2,z:s+a/2},u={x:e-o/2,y:i+n/2,z:s-a/2};return[l,h,c,u]}getPolygonBackPoints(t){const{center:{x:e,y:i,z:s},height:n,width:o,depth:a}=t,l={x:e-o/2,y:i+n/2,z:s+a/2},h={x:e-o/2,y:i+n/2,z:s-a/2},c={x:e-o/2,y:i-n/2,z:s-a/2},u={x:e-o/2,y:i-n/2,z:s+a/2};return[l,h,c,u]}getPolygonTopPoints(t){const{center:{x:e,y:i,z:s},height:n,width:o,depth:a}=t,l={x:e+o/2,y:i+n/2,z:s+a/2},h={x:e+o/2,y:i-n/2,z:s+a/2},c={x:e-o/2,y:i-n/2,z:s+a/2},u={x:e-o/2,y:i+n/2,z:s+a/2};return[l,h,c,u]}getModelTransformationMatrix(t){const{center:{x:e,y:i,z:s},rotation:n}=t,o=new C.Matrix4().makeTranslation(-e,-i,-s),a=new C.Matrix4().makeTranslation(e,i,s),l=new C.Matrix4().makeRotationZ(n);return new C.Matrix4().multiply(a).multiply(l).multiply(o)}getBoxSidePolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,nt.Left)}getBoxBackPolygon2DCoordinate(t){return this.getBoxPolygon2DCoordinate(t,nt.Back)}boxParams2ViewPolygon(t,e){switch(e){case nt.Left:return this.getPolygonSidePoints(t);case nt.Back:return this.getPolygonBackPoints(t);default:return this.getPolygonTopPoints(t)}}getBoxPolygon2DCoordinate(t,e){const i=this.boxParams2ViewPolygon(t,e),{width:s,height:n}=t,o=new C.Matrix4().premultiply(this.camera.matrixWorldInverse).premultiply(this.camera.projectionMatrix),a=new C.Matrix4().premultiply(this.getModelTransformationMatrix(t)).premultiply(o).premultiply(this.basicCoordinate2CanvasMatrix4);this.sideMatrix=a;const l=i.map(u=>new C.Vector3(u.x,u.y,u.z)).map(u=>u.applyMatrix4(this.sideMatrix)),h=this.containerWidth/s,c=this.containerHeight/n;return{polygon2d:l,zoom:Math.min(h,c)/2}}getBoxTopPolygon2DCoordinate(t){const{width:e,height:i}=t,n=this.getPolygonTopPoints(t).map(l=>new C.Vector3(l.x,l.y,l.z)).map(l=>l.applyMatrix4(this.getModelTransformationMatrix(t))).map(l=>({x:l.y,y:l.x})).map(l=>({x:-(l.x-this.containerWidth/2),y:-(l.y-this.containerHeight/2)})),o=this.containerWidth/e,a=this.containerHeight/i;return{polygon2d:n,zoom:Math.min(o,a)/2}}getNewBoxBySideUpdate(t,e,i,s){const n=new C.Matrix4().makeRotationZ(s.rotation),o=new C.Vector3(-t.x,0,0).applyMatrix4(n);let a=s;return a.center={x:a.center.x+o.x,y:a.center.y+o.y,z:a.center.z-t.z},a=ue(de({},a),{width:a.width+e,height:a.height,depth:a.depth+i}),{newBoxParams:a}}getNewBoxByBackUpdate(t,e,i,s){const n=new C.Matrix4().makeRotationZ(s.rotation),o=new C.Vector3(0,-t.x,0).applyMatrix4(n);let a=s;return a.center={x:a.center.x+o.x,y:a.center.y+o.y,z:a.center.z-t.z},a=ue(de({},a),{width:a.width,height:a.height+e,depth:a.depth+i}),{newBoxParams:a}}getNewBoxBySideUpdateByPoints(t,e,i,s){var n;const o=(n=this.sideMatrix)==null?void 0:n.invert();if(!this.sideMatrix||!o){console.error("No sideMatrix");return}this.camera.zoom=1,this.camera.updateProjectionMatrix();const a=t.map(v=>new C.Vector3(v.x,v.y,v.z)).map(v=>v.applyMatrix4(o)),[l,h,c,u]=a,d=Math.max(Math.abs(l.x-c.x),Math.abs(l.x-h.x)),p=h.add(u).applyMatrix3(new C.Matrix3().set(1/2,0,0,0,1/2,0,0,0,1/2)).clone().applyMatrix3(new C.Matrix3().set(-1,0,0,0,-1,0,0,0,-1)).add(new C.Vector3(s.center.x,s.center.y,s.center.z));return{newBoxParams:ue(de({},s),{center:{x:s.center.x-p.x,y:s.center.y-p.y,z:s.center.z-i},width:d,height:s.height,depth:s.depth+e,rotation:s.rotation})}}filterZAxisPoints(t){const e=t||this.scene.children.find(i=>i.uuid===this.pointsUuid);if(e){const{attributes:i}=e.geometry,{position:s}=i,n=[],{count:o}=s;for(let a=0;a<o;a++){const l=s.getZ(a);n.push(l>this.zAxisLimit?0:1)}e.geometry.setAttribute("visibility",new C.Float32BufferAttribute(n,1)),e.geometry.attributes.visibility.needsUpdate=!0}}render(){this.renderer.render(this.scene,this.camera)}}class Us{constructor(t){this.container=t.container}createCanvas(t,e){if(typeof t!="string")return this.container.appendChild(t),t.style.position="absolute",t.style.left="0",t.style.top="0",t;const i=document.createElement("canvas");return i.id=t,e&&e.size&&(i.width=e.size.width,i.height=e.size.height),this.container.appendChild(i),i}destroyCanvas(t){const e=document.getElementById(t);return e&&this.container.removeChild(e),e}}const Ba=r=>{const t=document.createElement("canvas");t.width=r.width,t.height=r.height;const e=t.getContext("2d");return e?(e.fillStyle="black",e.fillRect(0,0,r.width,r.height),t.toDataURL()):""};class Na{constructor({size:t,container:e,pcdPath:i,polygonOperationProps:s}){this.updatePolygonList=(d,g)=>{let p=d.map(f=>{const{polygon2d:v}=this.pointCloudInstance.getBoxTopPolygon2DCoordinate(f);return{id:f.id,sourceID:"",pointList:v,isRect:!0}});g&&(p=p.concat(g)),this.pointCloud2dOperation.setResult(p)};const n={left:-t.width/2,right:t.width/2,top:t.height/2,bottom:-t.height/2,near:100,far:-100},o=Ba(t),a=new Image;a.src=o;const l=new Us({container:e}),h=new Zs({container:e,noAppend:!0,isOrthographicCamera:!0,orthographicParams:n});i&&h.loadPCDFile(i),l.createCanvas(h.renderer.domElement);const c={container:e,size:t,config:'{ "textConfigurable": false }',imgNode:a,isAppend:!1};s&&Object.assign(c,s);const u=new Rs(c);u.eventBinding(),u.setPattern(et.Rect),l.createCanvas(u.canvas,{size:t}),this.pointCloud2dOperation=u,this.pointCloudInstance=h,this.canvasScheduler=l}addPolygonListOnTopView(t){const e=qt.getBoxParamsFromResultList(t),i=qt.getPolygonListFromResultList(t);this.updatePolygonList(e,i)}updateData(t,e){!this.pointCloud2dOperation||!this.pointCloudInstance||(this.pointCloudInstance.loadPCDFile(t),this.addPolygonListOnTopView(e))}initAllPosition(){this.pointCloudInstance.updateTopCamera(),this.pointCloud2dOperation.initPosition()}clearAllData(){this.pointCloudInstance.clearPointCloudAndRender(),this.pointCloud2dOperation.clearResult()}}const Ha=Ke,Fa=Ke;export{Ca as AnnotationEngine,I as AxisUtils,gt as BasicToolOperation,Us as CanvasScheduler,Ha as CommonToolUtils,Gi as DblClickEventListener,L as DrawUtils,xa as ImgUtils,ps as LineToolOperation,Be as MarkerUtils,_ as MathUtils,Ko as MeasureOperation,Zs as PointCloud,Rs as PointCloud2dOperation,Na as PointCloudAnnotation,ds as PointOperation,We as PolygonOperation,ae as RectOperation,Y as RectUtils,os as TagOperation,Yt as TagUtils,vs as TextToolOperation,Wt as UnitUtils,na as ViewOperation,Nn as cAnnotation,ua as cAnnotationTask,cr as cKeyCode,Fr as cStyle,Ln as cTool,Fa as toolUtils,it as uuid};