@labelbee/lb-annotation 1.14.0-alpha.2 → 1.14.0-alpha.3

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 (187) hide show
  1. package/dist/_virtual/MathUtilsWorker.js +8 -1
  2. package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +35 -2
  3. package/dist/_virtual/filterBoxWorker.js +8 -1
  4. package/dist/_virtual/highlightWorker.js +8 -1
  5. package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +5 -1
  6. package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +5 -1
  7. package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +5 -1
  8. package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +5 -1
  9. package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +5 -1
  10. package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +5 -1
  11. package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +5 -1
  12. package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +5 -1
  13. package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +5 -1
  14. package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +5 -1
  15. package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
  16. package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +5 -7
  17. package/dist/assets/attributeIcon/icon_cuboidMore.svg.js +5 -5
  18. package/dist/assets/attributeIcon/icon_cuboidRight.svg.js +5 -5
  19. package/dist/assets/attributeIcon/icon_cuboidTop.svg.js +5 -12
  20. package/dist/assets/attributeIcon/icon_editFEN.svg.js +5 -1
  21. package/dist/assets/attributeIcon/icon_editHUANG.svg.js +5 -1
  22. package/dist/assets/attributeIcon/icon_editLAN.svg.js +5 -1
  23. package/dist/assets/attributeIcon/icon_editLV.svg.js +5 -1
  24. package/dist/assets/attributeIcon/icon_editQING.svg.js +5 -1
  25. package/dist/constant/annotation.js +127 -1
  26. package/dist/constant/annotationTask.js +30 -1
  27. package/dist/constant/defaultConfig.js +266 -1
  28. package/dist/constant/keyCode.js +38 -1
  29. package/dist/constant/style.js +98 -1
  30. package/dist/constant/tool.js +236 -1
  31. package/dist/core/index.js +150 -1
  32. package/dist/core/pointCloud/OrbitControls.js +665 -1
  33. package/dist/core/pointCloud/PCDLoader.js +260 -2
  34. package/dist/core/pointCloud/annotation.js +215 -1
  35. package/dist/core/pointCloud/cache.js +53 -1
  36. package/dist/core/pointCloud/index.js +991 -5
  37. package/dist/core/pointCloud/matrix.js +138 -1
  38. package/dist/core/pointCloud/segmentation.js +144 -0
  39. package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +26 -0
  40. package/dist/core/pointCloud/selector/Sse3dSelector.js +16 -0
  41. package/dist/core/scheduler.js +233 -1
  42. package/dist/core/toolOperation/LineToolOperation.js +1434 -1
  43. package/dist/core/toolOperation/ScribbleTool.js +292 -1
  44. package/dist/core/toolOperation/TextToolOperation.js +131 -1
  45. package/dist/core/toolOperation/ViewOperation.js +556 -1
  46. package/dist/core/toolOperation/basicToolOperation.js +881 -1
  47. package/dist/core/toolOperation/checkOperation.js +208 -1
  48. package/dist/core/toolOperation/cuboidOperation.js +754 -1
  49. package/dist/core/toolOperation/cuboidToggleButtonClass.js +152 -7
  50. package/dist/core/toolOperation/eventListener.js +37 -1
  51. package/dist/core/toolOperation/measureOperation.js +41 -1
  52. package/dist/core/toolOperation/pointCloud2dOperation.js +365 -1
  53. package/dist/core/toolOperation/pointOperation.js +696 -1
  54. package/dist/core/toolOperation/polygonOperation.js +1251 -1
  55. package/dist/core/toolOperation/rectOperation.js +1233 -1
  56. package/dist/core/toolOperation/segmentByRect.js +174 -1
  57. package/dist/core/toolOperation/tagOperation.js +201 -3
  58. package/dist/core/toolOperation/textAttributeClass.js +182 -16
  59. package/dist/index.js +185 -1
  60. package/dist/locales/constants.js +24 -1
  61. package/dist/locales/en_US/message.js +25 -1
  62. package/dist/locales/index.js +19 -1
  63. package/dist/locales/zh_CN/message.js +25 -1
  64. package/dist/newCore/CanvasScheduler.js +35 -1
  65. package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
  66. package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
  67. package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
  68. package/dist/utils/ActionsHistory.js +84 -1
  69. package/dist/utils/ImgUtils.js +23 -1
  70. package/dist/utils/MathUtils.js +385 -2
  71. package/dist/utils/VectorUtils.js +25 -1
  72. package/dist/utils/tool/AttributeUtils.js +218 -1
  73. package/dist/utils/tool/AxisUtils.js +340 -1
  74. package/dist/utils/tool/CanvasUtils.js +62 -1
  75. package/dist/utils/tool/CommonToolUtils.js +174 -1
  76. package/dist/utils/tool/CuboidUtils.js +704 -1
  77. package/dist/utils/tool/DblClickEventListener.js +102 -1
  78. package/dist/utils/tool/DrawUtils.js +492 -3
  79. package/dist/utils/tool/EnhanceCommonToolUtils.js +53 -1
  80. package/dist/utils/tool/ImgPosUtils.js +58 -1
  81. package/dist/utils/tool/LineToolUtils.js +261 -1
  82. package/dist/utils/tool/MarkerUtils.js +56 -1
  83. package/dist/utils/tool/PolygonUtils.js +460 -1
  84. package/dist/utils/tool/RectUtils.js +155 -1
  85. package/dist/utils/tool/RenderDomClass.js +57 -7
  86. package/dist/utils/tool/RenderDomUtils.js +21 -4
  87. package/dist/utils/tool/StyleUtils.js +31 -1
  88. package/dist/utils/tool/TagUtils.js +129 -1
  89. package/dist/utils/tool/UnitUtils.js +12 -1
  90. package/dist/utils/tool/ZoomUtils.js +72 -1
  91. package/dist/utils/tool/polygonTool.js +133 -1
  92. package/dist/utils/uuid.js +26 -1
  93. package/es/_virtual/MathUtilsWorker.js +6 -1
  94. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +12 -0
  95. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +7 -0
  96. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +31 -2
  97. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +11 -0
  98. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +18 -0
  99. package/es/_virtual/filterBoxWorker.js +6 -1
  100. package/es/_virtual/highlightWorker.js +6 -1
  101. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +3 -1
  102. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +3 -1
  103. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +3 -1
  104. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +3 -1
  105. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +3 -1
  106. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +3 -1
  107. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +3 -1
  108. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +3 -1
  109. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +3 -1
  110. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +3 -1
  111. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +3 -5
  112. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +3 -7
  113. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +3 -5
  114. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +3 -5
  115. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +3 -12
  116. package/es/assets/attributeIcon/icon_editFEN.svg.js +3 -1
  117. package/es/assets/attributeIcon/icon_editHUANG.svg.js +3 -1
  118. package/es/assets/attributeIcon/icon_editLAN.svg.js +3 -1
  119. package/es/assets/attributeIcon/icon_editLV.svg.js +3 -1
  120. package/es/assets/attributeIcon/icon_editQING.svg.js +3 -1
  121. package/es/constant/annotation.js +113 -1
  122. package/es/constant/annotationTask.js +25 -1
  123. package/es/constant/defaultConfig.js +260 -1
  124. package/es/constant/keyCode.js +36 -1
  125. package/es/constant/style.js +74 -1
  126. package/es/constant/tool.js +220 -1
  127. package/es/core/index.js +148 -1
  128. package/es/core/pointCloud/OrbitControls.js +661 -1
  129. package/es/core/pointCloud/PCDLoader.js +256 -2
  130. package/es/core/pointCloud/annotation.js +211 -1
  131. package/es/core/pointCloud/cache.js +49 -1
  132. package/es/core/pointCloud/index.js +962 -5
  133. package/es/core/pointCloud/matrix.js +109 -1
  134. package/es/core/pointCloud/segmentation.js +120 -0
  135. package/es/core/pointCloud/selector/Sse3dLassoSelector.js +24 -0
  136. package/es/core/pointCloud/selector/Sse3dSelector.js +14 -0
  137. package/es/core/scheduler.js +228 -1
  138. package/es/core/toolOperation/LineToolOperation.js +1421 -1
  139. package/es/core/toolOperation/ScribbleTool.js +290 -1
  140. package/es/core/toolOperation/TextToolOperation.js +129 -1
  141. package/es/core/toolOperation/ViewOperation.js +549 -1
  142. package/es/core/toolOperation/basicToolOperation.js +877 -1
  143. package/es/core/toolOperation/checkOperation.js +206 -1
  144. package/es/core/toolOperation/cuboidOperation.js +752 -1
  145. package/es/core/toolOperation/cuboidToggleButtonClass.js +150 -7
  146. package/es/core/toolOperation/eventListener.js +35 -1
  147. package/es/core/toolOperation/measureOperation.js +39 -1
  148. package/es/core/toolOperation/pointCloud2dOperation.js +359 -1
  149. package/es/core/toolOperation/pointOperation.js +690 -1
  150. package/es/core/toolOperation/polygonOperation.js +1245 -1
  151. package/es/core/toolOperation/rectOperation.js +1228 -1
  152. package/es/core/toolOperation/scribbleTool2.js +249 -0
  153. package/es/core/toolOperation/segmentByRect.js +172 -1
  154. package/es/core/toolOperation/tagOperation.js +199 -3
  155. package/es/core/toolOperation/textAttributeClass.js +180 -16
  156. package/es/index.js +46 -1
  157. package/es/locales/constants.js +22 -1
  158. package/es/locales/en_US/message.js +23 -1
  159. package/es/locales/index.js +17 -1
  160. package/es/locales/zh_CN/message.js +23 -1
  161. package/es/newCore/CanvasScheduler.js +31 -1
  162. package/es/utils/ActionsHistory.js +78 -1
  163. package/es/utils/ImgUtils.js +21 -1
  164. package/es/utils/MathUtils.js +380 -2
  165. package/es/utils/VectorUtils.js +23 -1
  166. package/es/utils/tool/AttributeUtils.js +212 -1
  167. package/es/utils/tool/AxisUtils.js +335 -1
  168. package/es/utils/tool/CanvasUtils.js +60 -1
  169. package/es/utils/tool/CommonToolUtils.js +172 -1
  170. package/es/utils/tool/CuboidUtils.js +680 -1
  171. package/es/utils/tool/DblClickEventListener.js +100 -1
  172. package/es/utils/tool/DrawUtils.js +490 -3
  173. package/es/utils/tool/EnhanceCommonToolUtils.js +48 -1
  174. package/es/utils/tool/ImgPosUtils.js +56 -1
  175. package/es/utils/tool/LineToolUtils.js +255 -1
  176. package/es/utils/tool/MarkerUtils.js +54 -1
  177. package/es/utils/tool/PolygonUtils.js +458 -1
  178. package/es/utils/tool/RectUtils.js +153 -1
  179. package/es/utils/tool/RenderDomClass.js +55 -7
  180. package/es/utils/tool/RenderDomUtils.js +19 -4
  181. package/es/utils/tool/StyleUtils.js +29 -1
  182. package/es/utils/tool/TagUtils.js +127 -1
  183. package/es/utils/tool/UnitUtils.js +10 -1
  184. package/es/utils/tool/ZoomUtils.js +70 -1
  185. package/es/utils/tool/polygonTool.js +126 -1
  186. package/es/utils/uuid.js +24 -1
  187. package/package.json +7 -5
@@ -1,2 +1,380 @@
1
- import F from"../_virtual/MathUtilsWorker.js";import{SEGMENT_NUMBER as R,DEFAULT_TEXT_MAX_WIDTH as E,DEFAULT_FONT as I,ELineTypes as T}from"../constant/tool.js";import{createSmoothCurvePointsFromPointList as B}from"./tool/polygonTool.js";import w from"./tool/PolygonUtils.js";import h from"./VectorUtils.js";var C=Object.defineProperty,v=Object.defineProperties,S=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertySymbols,U=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable,_=(e,t,o)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,A=(e,t)=>{for(var o in t||(t={}))U.call(t,o)&&_(e,o,t[o]);if(O)for(var o of O(t))j.call(t,o)&&_(e,o,t[o]);return e},L=(e,t)=>v(e,S(t));class M{static tanAPlusB(t,o){return(t+o)/(1-t*o)}static sinAPlusB(t,o,s,r){return r*t+o*s}static cosAPlusB(t,o,s,r){return o*r-t*s}}const m=class{static getRotate(e){return e+90>=360?e+90-360:e+90}static getLineLength(e,t){return Math.sqrt(Math.pow(t.y-e.y,2)+Math.pow(t.x-e.x,2))}static getTextArea(e,t,o=E,s=I,r){if(typeof t!="string")return{width:0,height:0};const i=e.getContext("2d");i.font=s;let n=0;typeof r=="undefined"&&(r=e&&parseInt(window.getComputedStyle(e).lineHeight,10)||parseInt(window.getComputedStyle(document.body).lineHeight,10));const a=e&&parseInt(window.getComputedStyle(e).fontSize,10)||parseInt(window.getComputedStyle(document.body).fontSize,10)||0,c=t.split(`
2
- `);let l=0;for(let f=0;f<c.length;f++){const p=c[f].split("");let g="";for(let y=0;y<p.length;y++){const u=g+p[y],d=i.measureText(u).width;d>o&&y>0?(g=p[y],n+=r,l=o):(g=u,d>l&&(l=d))}f!==c.length-1&&(n+=r)}return{width:l,height:n+a,lineHeight:r,fontHeight:a}}static getLineCenterPoint(e){const[t,o]=e,s=h.getVector(t,o);return{x:t.x+s.x/2,y:t.y+s.y/2}}static getPerpendicularLine(e){if(e.length!==2)return;const[t,o]=e,s={x:o.x+o.y-t.y,y:o.y-(o.x-t.x)};return[o,s]}static getPerpendicularFootOfLine(e,t){if(e.length!==2)return e;const o=this.getPerpendicularLine(e);if(!o)return e;const[s,r]=o;return this.getFootOfPerpendicular(t,s,r).footPoint}static getQuadrangleFromTriangle(e){if(e.length!==3)return e;const[t,o,s]=e,r={x:s.x+t.x-o.x,y:s.y+t.y-o.y};return[t,o,s,r]}static getRectPerpendicularOffset(e,t,o){const[s,r]=o,i=this.getFootOfPerpendicular(e,s,r).footPoint,n=this.getFootOfPerpendicular(t,s,r).footPoint,a={x:i.x-n.x,y:i.y-n.y},c=h.add(t,a);return h.getVector(e,c)}static getArrayIndex(e,t){return e<0?t+e:e>=t?e-t:e}static getPointListFromPointOffset(e,t,o){const s=this.getArrayIndex(t-1,e.length),r=this.getArrayIndex(t+1,e.length),i=this.getArrayIndex(t-2,e.length),n=[...e];n[t]=h.add(n[t],o);const a=this.getFootOfPerpendicular(n[t],n[i],n[s]).footPoint,c=this.getFootOfPerpendicular(n[t],n[r],n[i]).footPoint;return n[s]=a,n[r]=c,n}static getRectCenterPoint(e){const[t,,o]=e;return{x:(t.x+o.x)/2,y:(t.y+o.y)/2}}static rotateRectPointList(e=5,t){const o=this.getRectCenterPoint(t),{PI:s}=Math,r=Math.sin(e*s/180),i=Math.cos(e*s/180);return t.map(n=>{const a=h.getVector(o,n),c=h.len(a),l=a.y/c,f=a.x/c;return{x:c*M.cosAPlusB(l,f,r,i)+o.x,y:c*M.sinAPlusB(l,f,r,i)+o.y}})}static getRectangleByRightAngle(e,t){if(t.length!==2)return t;const o=m.getPerpendicularFootOfLine(t,e);return m.getQuadrangleFromTriangle([...t,o])}static getRadiusFromQuadrangle(e){const[,t,o]=e,s=o.y-t.y,r=t.x-o.x,i=this.getLineLength(t,o),n=s/i,a=Math.acos(n);return r>0?Math.PI*2-a:a}static getCollectionPointByAnnotationDataPromise(e){const t=e.filter(r=>r.type==="point").map(r=>r.annotation),o=e.filter(r=>!!["polygon","line"].includes(r.type)).map(r=>r.type==="polygon"?L(A({},r.annotation),{pointList:w.concatBeginAndEnd(r.annotation.pointList)}):r.annotation),s=new F;return{promise:new Promise(function(i){s.postMessage({points:t,backgroundList:o}),s.onmessage=n=>{i(n.data),s.terminate()}}),close:()=>{s.terminate()}}}static getCollectionPointByAnnotationData(e){const t=[],o=new Set,s=e.filter(n=>n.type==="point").map(n=>n.annotation),r=e.filter(n=>!!["polygon","line"].includes(n.type)).map(n=>n.type==="polygon"?L(A({},n.annotation),{pointList:w.concatBeginAndEnd(n.annotation.pointList)}):n.annotation),i=(n,a)=>{const{dropFoot:c}=w.getClosestPoint(n,a,T.Line,1,{isClose:!1});if(c!==n){const l=`${c.x} + ${c.y}`;o.has(l)||t.push(n),o.add(l)}};return s.forEach(n=>{i(n,r)}),r.forEach(n=>{let a="";a=n.id,r.forEach((c,l)=>{if(c.id===a)return;const f=[...r];f.splice(l,1),c.pointList.forEach(p=>{i(p,f)})})}),{connectionPoints:t}}};let x=m;x.isInRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t),r=n=>n<=s&&n>=o;return(Array.isArray(e)?e:[e]).every(n=>r(n))},x.withinRange=(e,t)=>{const o=Math.min(...t),s=Math.max(...t);return e>s?s:e<o?o:e},x.calcViewportBoundaries=(e,t=!1,o=R,s=1)=>{if(!e)return{top:0,bottom:0,left:0,right:0};const r=20/s,i=[],n=[];let a=e;t&&(a=B(e,o)),a.forEach(({x:u,y:P})=>{i.push(u),n.push(P)});let c=Math.min(...i),l=Math.max(...i),f=Math.min(...n),p=Math.max(...n);const g=l-c,y=p-f;if(g<r){const u=(r-g)/2;c-=u,l+=u}if(y<r){const u=(r-y)/2;f-=u,p+=u}return{top:f,bottom:p,left:c,right:l}},x.getFootOfPerpendicular=(e,t,o,s=!1,r=!1)=>{let i={x:0,y:0};const n=t.x-o.x,a=t.y-o.y;if(Math.abs(n)<1e-8&&Math.abs(a)<1e-8)return i=t,i;let c=(e.x-t.x)*(t.x-o.x)+(e.y-t.y)*(t.y-o.y);c/=n*n+a*a,i.x=t.x+c*n,i.y=t.y+c*a;const l=m.getLineLength(e,i),f=2,p=Math.min(t.x,o.x),g=Math.max(t.x,o.x),y=Math.min(t.y,o.y),u=Math.max(t.y,o.y),P=!(m.isInRange(e.x,[p,g])||m.isInRange(e.y,[y,u])),d=e.x>g+f||e.x<p-f||e.y>u+f||e.y<y-f;return!r&&(s?P:d)?{footPoint:i,length:Infinity}:{footPoint:i,length:l}};var D=x;export{M as Trigonometric,D as default};
1
+ import WorkerFactory from '../_virtual/MathUtilsWorker.js';
2
+ import { SEGMENT_NUMBER, DEFAULT_TEXT_MAX_WIDTH, DEFAULT_FONT, ELineTypes } from '../constant/tool.js';
3
+ import { createSmoothCurvePointsFromPointList } from './tool/polygonTool.js';
4
+ import PolygonUtils from './tool/PolygonUtils.js';
5
+ import Vector from './VectorUtils.js';
6
+
7
+ var __defProp = Object.defineProperty;
8
+ var __defProps = Object.defineProperties;
9
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
10
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
14
+ var __spreadValues = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop))
21
+ __defNormalProp(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
26
+ class Trigonometric {
27
+ static tanAPlusB(tanA, tanB) {
28
+ return (tanA + tanB) / (1 - tanA * tanB);
29
+ }
30
+ static sinAPlusB(sinA, cosA, sinB, cosB) {
31
+ return cosB * sinA + cosA * sinB;
32
+ }
33
+ static cosAPlusB(sinA, cosA, sinB, cosB) {
34
+ return cosA * cosB - sinA * sinB;
35
+ }
36
+ }
37
+ const _MathUtils = class {
38
+ static getRotate(rotate) {
39
+ if (rotate + 90 >= 360) {
40
+ return rotate + 90 - 360;
41
+ }
42
+ return rotate + 90;
43
+ }
44
+ static getLineLength(point1, point2) {
45
+ return Math.sqrt(Math.pow(point2.y - point1.y, 2) + Math.pow(point2.x - point1.x, 2));
46
+ }
47
+ static getTextArea(canvas, text, maxWidth = DEFAULT_TEXT_MAX_WIDTH, font = DEFAULT_FONT, lineHeight) {
48
+ if (typeof text !== "string") {
49
+ return {
50
+ width: 0,
51
+ height: 0
52
+ };
53
+ }
54
+ const context = canvas.getContext("2d");
55
+ context.font = font;
56
+ let height = 0;
57
+ if (typeof lineHeight === "undefined") {
58
+ lineHeight = canvas && parseInt(window.getComputedStyle(canvas).lineHeight, 10) || parseInt(window.getComputedStyle(document.body).lineHeight, 10);
59
+ }
60
+ const fontHeight = canvas && parseInt(window.getComputedStyle(canvas).fontSize, 10) || parseInt(window.getComputedStyle(document.body).fontSize, 10) || 0;
61
+ const arrParagraph = text.split("\n");
62
+ let lineWidth = 0;
63
+ for (let i = 0; i < arrParagraph.length; i++) {
64
+ const arrText = arrParagraph[i].split("");
65
+ let line = "";
66
+ for (let n = 0; n < arrText.length; n++) {
67
+ const testLine = line + arrText[n];
68
+ const metrics = context.measureText(testLine);
69
+ const textWidth = metrics.width;
70
+ if (textWidth > maxWidth && n > 0) {
71
+ line = arrText[n];
72
+ height += lineHeight;
73
+ lineWidth = maxWidth;
74
+ } else {
75
+ line = testLine;
76
+ if (textWidth > lineWidth) {
77
+ lineWidth = textWidth;
78
+ }
79
+ }
80
+ }
81
+ if (i !== arrParagraph.length - 1) {
82
+ height += lineHeight;
83
+ }
84
+ }
85
+ return {
86
+ width: lineWidth,
87
+ height: height + fontHeight,
88
+ lineHeight,
89
+ fontHeight
90
+ };
91
+ }
92
+ static getLineCenterPoint(line) {
93
+ const [p1, p2] = line;
94
+ const vector = Vector.getVector(p1, p2);
95
+ return {
96
+ x: p1.x + vector.x / 2,
97
+ y: p1.y + vector.y / 2
98
+ };
99
+ }
100
+ static getPerpendicularLine(line) {
101
+ if (line.length !== 2) {
102
+ return void 0;
103
+ }
104
+ const [p1, p2] = line;
105
+ const p3 = {
106
+ x: p2.x + p2.y - p1.y,
107
+ y: p2.y - (p2.x - p1.x)
108
+ };
109
+ return [p2, p3];
110
+ }
111
+ static getPerpendicularFootOfLine(line, coordinate) {
112
+ if (line.length !== 2) {
113
+ return line;
114
+ }
115
+ const perpendicularLine = this.getPerpendicularLine(line);
116
+ if (!perpendicularLine) {
117
+ return line;
118
+ }
119
+ const [begin, end] = perpendicularLine;
120
+ return this.getFootOfPerpendicular(coordinate, begin, end).footPoint;
121
+ }
122
+ static getQuadrangleFromTriangle(triangle) {
123
+ if (triangle.length !== 3) {
124
+ return triangle;
125
+ }
126
+ const [p1, p2, p3] = triangle;
127
+ const p4 = {
128
+ x: p3.x + p1.x - p2.x,
129
+ y: p3.y + p1.y - p2.y
130
+ };
131
+ return [p1, p2, p3, p4];
132
+ }
133
+ static getRectPerpendicularOffset(dragStartCoord, currentCoord, basicLine) {
134
+ const [p1, p2] = basicLine;
135
+ const footer1 = this.getFootOfPerpendicular(dragStartCoord, p1, p2).footPoint;
136
+ const footer2 = this.getFootOfPerpendicular(currentCoord, p1, p2).footPoint;
137
+ const offset = {
138
+ x: footer1.x - footer2.x,
139
+ y: footer1.y - footer2.y
140
+ };
141
+ const newPoint = Vector.add(currentCoord, offset);
142
+ const vector3 = Vector.getVector(dragStartCoord, newPoint);
143
+ return vector3;
144
+ }
145
+ static getArrayIndex(index, len) {
146
+ if (index < 0) {
147
+ return len + index;
148
+ }
149
+ if (index >= len) {
150
+ return index - len;
151
+ }
152
+ return index;
153
+ }
154
+ static getPointListFromPointOffset(pointList, changePointIndex, offset) {
155
+ const prePointIndex = this.getArrayIndex(changePointIndex - 1, pointList.length);
156
+ const nextPointIndex = this.getArrayIndex(changePointIndex + 1, pointList.length);
157
+ const originIndex = this.getArrayIndex(changePointIndex - 2, pointList.length);
158
+ const newPointList = [...pointList];
159
+ newPointList[changePointIndex] = Vector.add(newPointList[changePointIndex], offset);
160
+ const newFooter1 = this.getFootOfPerpendicular(newPointList[changePointIndex], newPointList[originIndex], newPointList[prePointIndex]).footPoint;
161
+ const newFooter2 = this.getFootOfPerpendicular(newPointList[changePointIndex], newPointList[nextPointIndex], newPointList[originIndex]).footPoint;
162
+ newPointList[prePointIndex] = newFooter1;
163
+ newPointList[nextPointIndex] = newFooter2;
164
+ return newPointList;
165
+ }
166
+ static getRectCenterPoint(rectPointList) {
167
+ const [p1, , p3] = rectPointList;
168
+ return {
169
+ x: (p1.x + p3.x) / 2,
170
+ y: (p1.y + p3.y) / 2
171
+ };
172
+ }
173
+ static rotateRectPointList(angle = 5, rectPointList) {
174
+ const centerPoint = this.getRectCenterPoint(rectPointList);
175
+ const {PI} = Math;
176
+ const sinB = Math.sin(angle * PI / 180);
177
+ const cosB = Math.cos(angle * PI / 180);
178
+ return rectPointList.map((point) => {
179
+ const vector = Vector.getVector(centerPoint, point);
180
+ const len = Vector.len(vector);
181
+ const sinA = vector.y / len;
182
+ const cosA = vector.x / len;
183
+ return {
184
+ x: len * Trigonometric.cosAPlusB(sinA, cosA, sinB, cosB) + centerPoint.x,
185
+ y: len * Trigonometric.sinAPlusB(sinA, cosA, sinB, cosB) + centerPoint.y
186
+ };
187
+ });
188
+ }
189
+ static getRectangleByRightAngle(coordinate, pointList) {
190
+ if (pointList.length !== 2) {
191
+ return pointList;
192
+ }
193
+ const newPoint = _MathUtils.getPerpendicularFootOfLine(pointList, coordinate);
194
+ return _MathUtils.getQuadrangleFromTriangle([...pointList, newPoint]);
195
+ }
196
+ static getRadiusFromQuadrangle(points) {
197
+ const [, point2, point3] = points;
198
+ const y = point3.y - point2.y;
199
+ const x = point2.x - point3.x;
200
+ const len = this.getLineLength(point2, point3);
201
+ const cosX = y / len;
202
+ const radius = Math.acos(cosX);
203
+ if (x > 0) {
204
+ return Math.PI * 2 - radius;
205
+ }
206
+ return radius;
207
+ }
208
+ static getCollectionPointByAnnotationDataPromise(annotations) {
209
+ const points = annotations.filter((v) => v.type === "point").map((v) => v.annotation);
210
+ const backgroundList = annotations.filter((v) => {
211
+ if (["polygon", "line"].includes(v.type)) {
212
+ return true;
213
+ }
214
+ return false;
215
+ }).map((v) => {
216
+ if (v.type === "polygon") {
217
+ return __spreadProps(__spreadValues({}, v.annotation), {
218
+ pointList: PolygonUtils.concatBeginAndEnd(v.annotation.pointList)
219
+ });
220
+ }
221
+ return v.annotation;
222
+ });
223
+ const mathUtilsWorker = new WorkerFactory();
224
+ return {
225
+ promise: new Promise(function collectionPromise(resolve) {
226
+ mathUtilsWorker.postMessage({points, backgroundList});
227
+ mathUtilsWorker.onmessage = (e) => {
228
+ resolve(e.data);
229
+ mathUtilsWorker.terminate();
230
+ };
231
+ }),
232
+ close: () => {
233
+ mathUtilsWorker.terminate();
234
+ }
235
+ };
236
+ }
237
+ static getCollectionPointByAnnotationData(annotations) {
238
+ const connectionPoints = [];
239
+ const cacheSet = new Set();
240
+ const points = annotations.filter((v) => v.type === "point").map((v) => v.annotation);
241
+ const backgroundList = annotations.filter((v) => {
242
+ if (["polygon", "line"].includes(v.type)) {
243
+ return true;
244
+ }
245
+ return false;
246
+ }).map((v) => {
247
+ if (v.type === "polygon") {
248
+ return __spreadProps(__spreadValues({}, v.annotation), {
249
+ pointList: PolygonUtils.concatBeginAndEnd(v.annotation.pointList)
250
+ });
251
+ }
252
+ return v.annotation;
253
+ });
254
+ const judgeIsConnectPoint = (point, polygonList) => {
255
+ const {dropFoot} = PolygonUtils.getClosestPoint(point, polygonList, ELineTypes.Line, 1, {isClose: false});
256
+ if (dropFoot !== point) {
257
+ const s = `${dropFoot.x} + ${dropFoot.y}`;
258
+ if (!cacheSet.has(s)) {
259
+ connectionPoints.push(point);
260
+ }
261
+ cacheSet.add(s);
262
+ }
263
+ };
264
+ points.forEach((point) => {
265
+ judgeIsConnectPoint(point, backgroundList);
266
+ });
267
+ backgroundList.forEach((v) => {
268
+ let traverseID = "";
269
+ traverseID = v.id;
270
+ backgroundList.forEach((annotation, i) => {
271
+ if (annotation.id === traverseID) {
272
+ return;
273
+ }
274
+ const newPolygonList = [...backgroundList];
275
+ newPolygonList.splice(i, 1);
276
+ annotation.pointList.forEach((point) => {
277
+ judgeIsConnectPoint(point, newPolygonList);
278
+ });
279
+ });
280
+ });
281
+ return {connectionPoints};
282
+ }
283
+ };
284
+ let MathUtils = _MathUtils;
285
+ MathUtils.isInRange = (value, range) => {
286
+ const min = Math.min(...range);
287
+ const max = Math.max(...range);
288
+ const inRange = (v) => v <= max && v >= min;
289
+ const values = Array.isArray(value) ? value : [value];
290
+ return values.every((v) => inRange(v));
291
+ };
292
+ MathUtils.withinRange = (value, range) => {
293
+ const min = Math.min(...range);
294
+ const max = Math.max(...range);
295
+ if (value > max) {
296
+ return max;
297
+ }
298
+ if (value < min) {
299
+ return min;
300
+ }
301
+ return value;
302
+ };
303
+ MathUtils.calcViewportBoundaries = (array, isCurve = false, numberOfSegments = SEGMENT_NUMBER, zoom = 1) => {
304
+ if (!array) {
305
+ return {
306
+ top: 0,
307
+ bottom: 0,
308
+ left: 0,
309
+ right: 0
310
+ };
311
+ }
312
+ const MIN_LENGTH = 20 / zoom;
313
+ const xAxis = [];
314
+ const yAxis = [];
315
+ let points = array;
316
+ if (isCurve) {
317
+ points = createSmoothCurvePointsFromPointList(array, numberOfSegments);
318
+ }
319
+ points.forEach(({x, y}) => {
320
+ xAxis.push(x);
321
+ yAxis.push(y);
322
+ });
323
+ let minX = Math.min(...xAxis);
324
+ let maxX = Math.max(...xAxis);
325
+ let minY = Math.min(...yAxis);
326
+ let maxY = Math.max(...yAxis);
327
+ const diffX = maxX - minX;
328
+ const diffY = maxY - minY;
329
+ if (diffX < MIN_LENGTH) {
330
+ const addLen = (MIN_LENGTH - diffX) / 2;
331
+ minX -= addLen;
332
+ maxX += addLen;
333
+ }
334
+ if (diffY < MIN_LENGTH) {
335
+ const addLen = (MIN_LENGTH - diffY) / 2;
336
+ minY -= addLen;
337
+ maxY += addLen;
338
+ }
339
+ return {
340
+ top: minY,
341
+ bottom: maxY,
342
+ left: minX,
343
+ right: maxX
344
+ };
345
+ };
346
+ MathUtils.getFootOfPerpendicular = (pt, begin, end, useAxisRange = false, allowOverRange = false) => {
347
+ let retVal = {x: 0, y: 0};
348
+ const dx = begin.x - end.x;
349
+ const dy = begin.y - end.y;
350
+ if (Math.abs(dx) < 1e-8 && Math.abs(dy) < 1e-8) {
351
+ retVal = begin;
352
+ return retVal;
353
+ }
354
+ let u = (pt.x - begin.x) * (begin.x - end.x) + (pt.y - begin.y) * (begin.y - end.y);
355
+ u /= dx * dx + dy * dy;
356
+ retVal.x = begin.x + u * dx;
357
+ retVal.y = begin.y + u * dy;
358
+ const length = _MathUtils.getLineLength(pt, retVal);
359
+ const ratio = 2;
360
+ const fromX = Math.min(begin.x, end.x);
361
+ const toX = Math.max(begin.x, end.x);
362
+ const fromY = Math.min(begin.y, end.y);
363
+ const toY = Math.max(begin.y, end.y);
364
+ const allAxisOverRange = !(_MathUtils.isInRange(pt.x, [fromX, toX]) || _MathUtils.isInRange(pt.y, [fromY, toY]));
365
+ const someAxisOverRange = pt.x > toX + ratio || pt.x < fromX - ratio || pt.y > toY + ratio || pt.y < fromY - ratio;
366
+ const isOverRange = useAxisRange ? allAxisOverRange : someAxisOverRange;
367
+ if (!allowOverRange && isOverRange) {
368
+ return {
369
+ footPoint: retVal,
370
+ length: Infinity
371
+ };
372
+ }
373
+ return {
374
+ footPoint: retVal,
375
+ length
376
+ };
377
+ };
378
+ var MathUtils$1 = MathUtils;
379
+
380
+ export { Trigonometric, MathUtils$1 as default };
@@ -1 +1,23 @@
1
- var x=Math.pow;class r{static add(t,a){return{x:t.x+a.x,y:t.y+a.y}}static getVector(t,a){return{x:a.x-t.x,y:a.y-t.y}}static len(t){return Math.sqrt(x(t.x,2)+x(t.y,2))}static dotProduct(t,a){return t.x*a.x+t.y+a.y}}export{r as default};
1
+ var __pow = Math.pow;
2
+ class Vector {
3
+ static add(vector1, vector2) {
4
+ return {
5
+ x: vector1.x + vector2.x,
6
+ y: vector1.y + vector2.y
7
+ };
8
+ }
9
+ static getVector(point1, point2) {
10
+ return {
11
+ x: point2.x - point1.x,
12
+ y: point2.y - point1.y
13
+ };
14
+ }
15
+ static len(vector) {
16
+ return Math.sqrt(__pow(vector.x, 2) + __pow(vector.y, 2));
17
+ }
18
+ static dotProduct(vector1, vector2) {
19
+ return vector1.x * vector2.x + vector1.y + vector2.y;
20
+ }
21
+ }
22
+
23
+ export { Vector as default };
@@ -1 +1,212 @@
1
- import{isNumber as I}from"lodash";import{ToolStyleUtils as O}from"@labelbee/lb-utils";import{ICON_ARRAY as c,NULL_ICON as E,NULL_COLOR as f,COLORS_ARRAY as d}from"../../constant/style.js";import{ETextType as s}from"../../constant/tool.js";import g from"../../locales/index.js";import{EMessage as p}from"../../locales/constants.js";import h from"../MathUtils.js";import y from"../../assets/attributeIcon/icon_canvasEdit_miss.svg.js";var w=Object.defineProperty,N=Object.defineProperties,P=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,R=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,x=(l,t,r)=>t in l?w(l,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):l[t]=r,b=(l,t)=>{for(var r in t||(t={}))R.call(t,r)&&x(l,r,t[r]);if(v)for(var r of v(t))T.call(t,r)&&x(l,r,t[r]);return l},m=(l,t)=>N(l,P(t));const _="^[0-9]+$",A="^[A-Za-z]+$";class M{static getAttributeIcon(t,r,e=!0){var n;const a=r.findIndex(o=>o.value===t);let i=(n=c[a%c.length])!=null?n:E;e||(i=y),i="";const u=new Image;return u.src=i,u}static checkString(t,r){let e="";switch(t){case s.Order:case s.NumberOnly:e=_;break;case s.EnglishOnly:e=A;break;case s.CustomFormat:e=r;break}return e}static checkTextAttibute(t,r){if(t===void 0||t==="")return!0;try{return new RegExp(r).test(t)}catch(e){return!1}}static getAttributeShowText(t,r=[]){var e,n;try{const a=r.findIndex(i=>i.value===t);return(n=(e=r[a])==null?void 0:e.key)!=null?n:t}catch(a){return t}}static getAttributeIndex(t,r){try{const e=r.findIndex(n=>n.value===t);return e>=8?e%8:e}catch(e){return-1}}static getAttributeColor(t,r){try{const e=this.getAttributeIndex(t,r);return e===-1?f:d[e%d.length]}catch(e){return f}}static getTextAttribute(t,r){try{if(r===s.Order){const e=t.map(a=>parseInt(a.textAttribute,10)).filter(a=>I(a)&&a<Number.MAX_SAFE_INTEGER&&a>=0);return e.sort((a,i)=>a-i),`${(e.pop()||0)+1}`}return""}catch(e){return""}}static textChange(t,r,e){return e.map(n=>n.id===r?m(b({},n),{textAttribute:t}):n)}static getErrorNotice(t,r){switch(t){case s.Order:case s.NumberOnly:return g.getMessagesByLocale(p.TextCheckNumberErrorNotice,r);case s.EnglishOnly:return g.getMessagesByLocale(p.TextCheckEnglishErrorNotice,r);case s.CustomFormat:return g.getMessagesByLocale(p.TextCheckCustomErrorNotice,r);default:return""}}static textAttributeValidate(t,r,e){try{return new RegExp(this.checkString(t,r)).test(e)}catch(n){}}static checkTextAttribute(t,r,e,n){let a=!1;return e.forEach(i=>{(i==null?void 0:i.textAttribute)===void 0||(i==null?void 0:i.textAttribute)===""||(n?i.id===n:!0)&&!this.textAttributeValidate(t,r,i.textAttribute)&&(a=!0)}),!!a}static changeTextAttributeInLog(t,r){return t==null?void 0:t.map(e=>e==null?void 0:e.map(n=>{if((r==null?void 0:r.findIndex(a=>(a==null?void 0:a.id)===(n==null?void 0:n.id)))>-1){const a=r==null?void 0:r.find(i=>(i==null?void 0:i.id)===(n==null?void 0:n.id));return m(b({},n),{textAttribute:a==null?void 0:a.textAttribute})}return n}))}static getTextIconSvg(t="",r,e=!1,n){var a;if(e===!0){const i=(r==null?void 0:r.findIndex(o=>(o==null?void 0:o.value)===t))%d.length+1,u=(a=r==null?void 0:r.find(o=>o.value===t))==null?void 0:a.color;if(u){const o=O.rgbaStringToHex(u);return this.generateIconAttribute({fill:o})}return c[i]}return n}static generateIconAttribute({fill:t,width:r=16,height:e=16,xmlns:n="http://www.w3.org/2000/svg",xlink:a="http://www.w3.org/1999/xlink"}){return`<span style={color:${t}}><svg xmlns=${n} xmlns:xlink=${a} width=${r} height=${e} 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='currentColor'/></g></g></svg></span>`}static getAttributeByKeycode(t,r){var e;let n;return h.isInRange(t,[48,57])&&(n=t-48),h.isInRange(t,[96,105])&&(n=t-96),n===0?"":n?(e=r[n-1])==null?void 0:e.value:void 0}}export{A as REGEXP_ENGLISH,_ as REGEXP_NUMBER,M as default};
1
+ import { isNumber } from 'lodash';
2
+ import { ToolStyleUtils } from '@labelbee/lb-utils';
3
+ import { ICON_ARRAY, NULL_ICON, NULL_COLOR, COLORS_ARRAY } from '../../constant/style.js';
4
+ import { ETextType } from '../../constant/tool.js';
5
+ import Locale from '../../locales/index.js';
6
+ import { EMessage } from '../../locales/constants.js';
7
+ import MathUtils from '../MathUtils.js';
8
+ import INVALID_ICON from '../../assets/attributeIcon/icon_canvasEdit_miss.svg.js';
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __defProps = Object.defineProperties;
12
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
13
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
14
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
16
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
17
+ var __spreadValues = (a, b) => {
18
+ for (var prop in b || (b = {}))
19
+ if (__hasOwnProp.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ if (__getOwnPropSymbols)
22
+ for (var prop of __getOwnPropSymbols(b)) {
23
+ if (__propIsEnum.call(b, prop))
24
+ __defNormalProp(a, prop, b[prop]);
25
+ }
26
+ return a;
27
+ };
28
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
29
+ const REGEXP_NUMBER = "^[0-9]+$";
30
+ const REGEXP_ENGLISH = "^[A-Za-z]+$";
31
+ class AttributeUtils {
32
+ static getAttributeIcon(attribute, attributeList, valid = true) {
33
+ var _a;
34
+ const attributeIndex = attributeList.findIndex((i) => i.value === attribute);
35
+ let src = (_a = ICON_ARRAY[attributeIndex % ICON_ARRAY.length]) != null ? _a : NULL_ICON;
36
+ if (!valid) {
37
+ src = INVALID_ICON;
38
+ }
39
+ src = "";
40
+ const img = new Image();
41
+ img.src = src;
42
+ return img;
43
+ }
44
+ static checkString(textCheckType, customFormat) {
45
+ let regExpString = "";
46
+ switch (textCheckType) {
47
+ case ETextType.Order:
48
+ case ETextType.NumberOnly:
49
+ regExpString = REGEXP_NUMBER;
50
+ break;
51
+ case ETextType.EnglishOnly:
52
+ regExpString = REGEXP_ENGLISH;
53
+ break;
54
+ case ETextType.CustomFormat:
55
+ regExpString = customFormat;
56
+ break;
57
+ }
58
+ return regExpString;
59
+ }
60
+ static checkTextAttibute(value, checkStrings) {
61
+ if (value === void 0 || value === "") {
62
+ return true;
63
+ }
64
+ try {
65
+ return new RegExp(checkStrings).test(value);
66
+ } catch (error) {
67
+ return false;
68
+ }
69
+ }
70
+ static getAttributeShowText(attribute, attributeList = []) {
71
+ var _a, _b;
72
+ try {
73
+ const attributeIndex = attributeList.findIndex((i) => i.value === attribute);
74
+ return (_b = (_a = attributeList[attributeIndex]) == null ? void 0 : _a.key) != null ? _b : attribute;
75
+ } catch (error) {
76
+ return attribute;
77
+ }
78
+ }
79
+ static getAttributeIndex(attribute, attributeList) {
80
+ try {
81
+ const attributeIndex = attributeList.findIndex((i) => i.value === attribute);
82
+ if (attributeIndex >= 8) {
83
+ return attributeIndex % 8;
84
+ }
85
+ return attributeIndex;
86
+ } catch (error) {
87
+ return -1;
88
+ }
89
+ }
90
+ static getAttributeColor(attribute, attributeList) {
91
+ try {
92
+ const attributeIndex = this.getAttributeIndex(attribute, attributeList);
93
+ if (attributeIndex === -1) {
94
+ return NULL_COLOR;
95
+ }
96
+ return COLORS_ARRAY[attributeIndex % COLORS_ARRAY.length];
97
+ } catch (error) {
98
+ return NULL_COLOR;
99
+ }
100
+ }
101
+ static getTextAttribute(toolResultList, textCheckType) {
102
+ try {
103
+ if (textCheckType === ETextType.Order) {
104
+ const textAttributeList = toolResultList.map((i) => parseInt(i.textAttribute, 10)).filter((order) => {
105
+ return isNumber(order) && order < Number.MAX_SAFE_INTEGER && order >= 0;
106
+ });
107
+ textAttributeList.sort((a, b) => a - b);
108
+ const maxOrder = textAttributeList.pop();
109
+ return `${(maxOrder || 0) + 1}`;
110
+ }
111
+ return "";
112
+ } catch (error) {
113
+ return "";
114
+ }
115
+ }
116
+ static textChange(value, selectedID, toolList) {
117
+ return toolList.map((item) => {
118
+ if (item.id === selectedID) {
119
+ return __spreadProps(__spreadValues({}, item), {
120
+ textAttribute: value
121
+ });
122
+ }
123
+ return item;
124
+ });
125
+ }
126
+ static getErrorNotice(textCheckType, lang) {
127
+ switch (textCheckType) {
128
+ case ETextType.Order:
129
+ case ETextType.NumberOnly:
130
+ return Locale.getMessagesByLocale(EMessage.TextCheckNumberErrorNotice, lang);
131
+ case ETextType.EnglishOnly:
132
+ return Locale.getMessagesByLocale(EMessage.TextCheckEnglishErrorNotice, lang);
133
+ case ETextType.CustomFormat:
134
+ return Locale.getMessagesByLocale(EMessage.TextCheckCustomErrorNotice, lang);
135
+ default:
136
+ return "";
137
+ }
138
+ }
139
+ static textAttributeValidate(textCheckType, customFormat, text) {
140
+ try {
141
+ const reg = new RegExp(this.checkString(textCheckType, customFormat));
142
+ return reg.test(text);
143
+ } catch (error) {
144
+ }
145
+ }
146
+ static checkTextAttribute(textCheckType, customFormat, resultList, selectedID) {
147
+ let error = false;
148
+ resultList.forEach((item) => {
149
+ if ((item == null ? void 0 : item.textAttribute) === void 0 || (item == null ? void 0 : item.textAttribute) === "") {
150
+ return;
151
+ }
152
+ if ((selectedID ? item.id === selectedID : true) && !this.textAttributeValidate(textCheckType, customFormat, item.textAttribute)) {
153
+ error = true;
154
+ }
155
+ });
156
+ if (error) {
157
+ return true;
158
+ }
159
+ return false;
160
+ }
161
+ static changeTextAttributeInLog(toolLog, toolList) {
162
+ return toolLog == null ? void 0 : toolLog.map((item) => {
163
+ return item == null ? void 0 : item.map((info) => {
164
+ if ((toolList == null ? void 0 : toolList.findIndex((i) => (i == null ? void 0 : i.id) === (info == null ? void 0 : info.id))) > -1) {
165
+ const changeRect = toolList == null ? void 0 : toolList.find((i) => (i == null ? void 0 : i.id) === (info == null ? void 0 : info.id));
166
+ return __spreadProps(__spreadValues({}, info), {
167
+ textAttribute: changeRect == null ? void 0 : changeRect.textAttribute
168
+ });
169
+ }
170
+ return info;
171
+ });
172
+ });
173
+ }
174
+ static getTextIconSvg(attribute = "", attributeList, attributeConfigurable = false, baseIcon) {
175
+ var _a;
176
+ if (attributeConfigurable === true) {
177
+ const attributeIndex = (attributeList == null ? void 0 : attributeList.findIndex((i) => (i == null ? void 0 : i.value) === attribute)) % COLORS_ARRAY.length + 1;
178
+ const color = (_a = attributeList == null ? void 0 : attributeList.find((i) => i.value === attribute)) == null ? void 0 : _a.color;
179
+ if (color) {
180
+ const getHexColor = ToolStyleUtils.rgbaStringToHex(color);
181
+ return this.generateIconAttribute({fill: getHexColor});
182
+ }
183
+ return ICON_ARRAY[attributeIndex];
184
+ }
185
+ return baseIcon;
186
+ }
187
+ static generateIconAttribute({
188
+ fill,
189
+ width = 16,
190
+ height = 16,
191
+ xmlns = "http://www.w3.org/2000/svg",
192
+ xlink = "http://www.w3.org/1999/xlink"
193
+ }) {
194
+ return `<span style={color:${fill}}><svg xmlns=${xmlns} xmlns:xlink=${xlink} width=${width} height=${height} 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='currentColor'/></g></g></svg></span>`;
195
+ }
196
+ static getAttributeByKeycode(keyCode, attributeList) {
197
+ var _a;
198
+ let num;
199
+ if (MathUtils.isInRange(keyCode, [48, 57])) {
200
+ num = keyCode - 48;
201
+ }
202
+ if (MathUtils.isInRange(keyCode, [96, 105])) {
203
+ num = keyCode - 96;
204
+ }
205
+ if (num === 0) {
206
+ return "";
207
+ }
208
+ return num ? (_a = attributeList[num - 1]) == null ? void 0 : _a.value : void 0;
209
+ }
210
+ }
211
+
212
+ export { REGEXP_ENGLISH, REGEXP_NUMBER, AttributeUtils as default };