@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 +1,290 @@
1
- import{ImgConversionUtils as n}from"@labelbee/lb-utils";import r from"../../utils/tool/AxisUtils.js";import a from"../../utils/tool/DrawUtils.js";import{EToolName as h,EScribblePattern as o}from"../../constant/tool.js";import c from"../../utils/tool/CommonToolUtils.js";import l from"../../utils/tool/AttributeUtils.js";import{BasicToolOperation as u}from"./basicToolOperation.js";const d=20,C="white";class v extends u{constructor(t){super(t);this.toolName=h.ScribbleTool,this.action=o.Scribble,this.getOriginCoordinate=i=>r.changePointByZoom(this.getCoordinateUnderZoomByRotate(i),1/this.zoom),this.onMouseDown=i=>{super.onMouseDown(i)||this.forbidMouseOperation||!this.imgInfo||(this.initCacheCanvas(this.imgNode),this.mouseEvents("onMouseDown").call(this,i))},this.onMouseMove=i=>{super.onMouseMove(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseMove").call(this,i)},this.onMouseUp=i=>{super.onMouseUp(i)||this.forbidMouseOperation||!this.imgInfo||this.mouseEvents("onMouseUp").call(this,i)},this.mouseEvents=i=>({[o.Scribble]:{onMouseMove:this.onScribbleMove,onMouseUp:this.onScribbleEnd,onMouseDown:this.onScribbleStart},[o.Erase]:{onMouseMove:this.onEraseMove,onMouseUp:this.onEraseEnd,onMouseDown:this.onEraseStart}})[this.action][i],this.setPattern=i=>{switch(this.action=i,i){case o.Erase:{this.setCustomCursor(this.cursorErase);break}default:{this.setCustomCursor("none");break}}};var e;if(this.penSize=d,((e=this.config.attributeList)==null?void 0:e.length)>0){const i=this.config.attributeList[0];this.setDefaultAttribute(i.value)}}get cursorErase(){const t='<?xml version="1.0" encoding="UTF-8"?><svg width="24" heighst="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#icon-65e7e1747c11bad3)"><path d="M44.7818 24.1702L31.918 7.09935L14.1348 20.5L27.5 37L30.8556 34.6643L44.7818 24.1702Z" fill="#141414" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M27.4998 37L23.6613 40.0748L13.0978 40.074L10.4973 36.6231L4.06543 28.0876L14.4998 20.2248" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M13.2056 40.072L44.5653 40.072" stroke="#000000" stroke-width="4" stroke-linecap="round"/></g><defs><clipPath id="icon-65e7e1747c11bad3"><rect width="48" height="48" fill="#df4c4c"/></clipPath></defs></svg>';return`url(${`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(t)))}`}) 0 0, auto`}get defaultCursor(){return this.action===o.Erase?this.cursorErase:this.isShowDefaultCursor?"default":"none"}get color(){var t,e;return(e=(t=this==null?void 0:this.defaultAttributeInfo)==null?void 0:t.color)!=null?e:C}get penSizeWithZoom(){return this.penSize/this.zoom}get cacheCanvasToDataUrl(){var t;return(t=this.cacheCanvas)==null?void 0:t.toDataURL("image/png",0)}setPenSize(t){this.penSize=t}initCacheCanvas(t){if(this.cacheCanvas||!t)return;const{canvas:e,ctx:i}=n.createCanvas(t);this.cacheCanvas=e,this.cacheContext=i}updateCacheCanvasSize(t){this.cacheCanvas&&(this.cacheCanvas.width=t.width,this.cacheCanvas.height=t.height)}updateUrl2CacheContext(t){n.createImgDom(t).then(e=>{this.cacheContext||this.initCacheCanvas(e),this.cacheContext&&(this.cacheContext.save(),this.clearCacheCanvas(),this.cacheContext.drawImage(e,0,0,e.width,e.height),this.cacheContext.restore(),this.render())})}setImgNode(t,e){super.setImgNode(t,e),this.cacheCanvas?this.updateCacheCanvasSize(t):this.initCacheCanvas(t)}setResult(t){var e,i;let{url:s}=(e=t==null?void 0:t[0])!=null?e:{};if(this.clearCacheCanvas(),s||(s=(i=this.cacheCanvasToDataUrl)!=null?i:""),this.history.initRecord([s],!0),!s){this.render();return}this.updateUrl2CacheContext(s)}onKeyDown(t){if(!c.hotkeyFilter(t)||super.onKeyDown(t)===!1)return;const{keyCode:e}=t,i=l.getAttributeByKeycode(e,this.config.attributeList);i!==void 0&&this.setDefaultAttribute(i)}eventBinding(){super.eventBinding()}setDefaultAttribute(t){const e=this.config.attributeList.find(i=>i.value===t);e&&(this.defaultAttribute=e.value,this.defaultAttributeInfo=e,this.emit("changeAttributeSidebar"),this.render())}clearStatusAfterLeave(){this.onScribbleEnd(),this.startPoint=void 0}onMouseLeave(){super.onMouseLeave(),this.clearStatusAfterLeave()}onScribbleStart(t){if(!this.cacheContext)return;this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.strokeStyle=this.color,this.cacheContext.lineWidth=this.penSizeWithZoom,this.cacheContext.lineCap="round",this.cacheContext.lineJoin="round";const e=this.getOriginCoordinate(t);this.cacheContext.moveTo(e.x,e.y),this.startPoint=e}onScribbleMove(t){if(t.buttons===1&&this.cacheContext&&this.startPoint){const e=this.getOriginCoordinate(t);this.cacheContext.lineTo(e.x,e.y),this.cacheContext.stroke()}}onScribbleEnd(){var t,e;this.startPoint&&((t=this.cacheContext)==null||t.closePath(),(e=this.cacheContext)==null||e.restore(),this.startPoint=void 0,this.history.pushHistory(this.cacheCanvasToDataUrl))}eraseArc(t){var e;if(this.cacheContext){const i=this.getOriginCoordinate(t);this.cacheContext.save(),this.cacheContext.beginPath(),this.cacheContext.arc(i.x,i.y,this.penSizeWithZoom/2,0,Math.PI*2,!1),this.cacheContext.clip(),this.cacheContext.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),(e=this.cacheContext)==null||e.restore()}}onEraseStart(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseMove(t){!this.cacheContext||t.buttons!==1||this.eraseArc(t)}onEraseEnd(){}exportData(){const t=this.cacheCanvasToDataUrl;return[[],this.basicImgInfo,{imgBase64:t}]}clearCacheCanvas(){var t;(t=this.cacheContext)==null||t.clearRect(0,0,this.cacheContext.canvas.width,this.cacheContext.canvas.height),this.render()}clearResult(){this.clearCacheCanvas(),this.history.pushHistory(this.cacheCanvasToDataUrl)}renderPoint(t){a.drawCircleWithFill(this.canvas,this.coord,t,{color:this.color})}renderBorderPoint(t){a.drawCircle(this.canvas,this.coord,t,{color:"black"})}render(){if(super.render(),!this.ctx||!this.cacheCanvas||(this.ctx.save(),this.ctx.globalAlpha=.5,a.drawImg(this.canvas,this.cacheCanvas,{zoom:this.zoom,currentPos:this.currentPos,rotate:this.rotate}),this.ctx.restore(),this.forbidOperation||this.forbidCursorLine))return;const t=this.penSize/2;this.action===o.Erase?this.renderBorderPoint(t):this.renderPoint(t)}undo(){const t=this.history.undo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}redo(){const t=this.history.redo();t&&this.cacheCanvas&&this.updateUrl2CacheContext(t)}}export{v as default};
1
+ import { ImgConversionUtils } from '@labelbee/lb-utils';
2
+ import AxisUtils from '../../utils/tool/AxisUtils.js';
3
+ import DrawUtils from '../../utils/tool/DrawUtils.js';
4
+ import { EToolName, EScribblePattern } from '../../constant/tool.js';
5
+ import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
6
+ import AttributeUtils from '../../utils/tool/AttributeUtils.js';
7
+ import { BasicToolOperation } from './basicToolOperation.js';
8
+
9
+ const DEFAULT_PEN_SIZE = 20;
10
+ const DEFAULT_COLOR = "white";
11
+ class ScribbleTool extends BasicToolOperation {
12
+ constructor(props) {
13
+ super(props);
14
+ this.toolName = EToolName.ScribbleTool;
15
+ this.action = EScribblePattern.Scribble;
16
+ this.getOriginCoordinate = (e) => {
17
+ return AxisUtils.changePointByZoom(this.getCoordinateUnderZoomByRotate(e), 1 / this.zoom);
18
+ };
19
+ this.onMouseDown = (e) => {
20
+ if (super.onMouseDown(e) || this.forbidMouseOperation || !this.imgInfo) {
21
+ return void 0;
22
+ }
23
+ this.initCacheCanvas(this.imgNode);
24
+ this.mouseEvents("onMouseDown").call(this, e);
25
+ };
26
+ this.onMouseMove = (e) => {
27
+ if (super.onMouseMove(e) || this.forbidMouseOperation || !this.imgInfo) {
28
+ return void 0;
29
+ }
30
+ this.mouseEvents("onMouseMove").call(this, e);
31
+ };
32
+ this.onMouseUp = (e) => {
33
+ if (super.onMouseUp(e) || this.forbidMouseOperation || !this.imgInfo) {
34
+ return void 0;
35
+ }
36
+ this.mouseEvents("onMouseUp").call(this, e);
37
+ };
38
+ this.mouseEvents = (eventType) => {
39
+ const events = {
40
+ [EScribblePattern.Scribble]: {
41
+ onMouseMove: this.onScribbleMove,
42
+ onMouseUp: this.onScribbleEnd,
43
+ onMouseDown: this.onScribbleStart
44
+ },
45
+ [EScribblePattern.Erase]: {
46
+ onMouseMove: this.onEraseMove,
47
+ onMouseUp: this.onEraseEnd,
48
+ onMouseDown: this.onEraseStart
49
+ }
50
+ };
51
+ return events[this.action][eventType];
52
+ };
53
+ this.setPattern = (pattern) => {
54
+ this.action = pattern;
55
+ switch (pattern) {
56
+ case EScribblePattern.Erase: {
57
+ this.setCustomCursor(this.cursorErase);
58
+ break;
59
+ }
60
+ default: {
61
+ this.setCustomCursor("none");
62
+ break;
63
+ }
64
+ }
65
+ };
66
+ var _a;
67
+ this.penSize = DEFAULT_PEN_SIZE;
68
+ if (((_a = this.config.attributeList) == null ? void 0 : _a.length) > 0) {
69
+ const firstAttributeInfo = this.config.attributeList[0];
70
+ this.setDefaultAttribute(firstAttributeInfo.value);
71
+ }
72
+ }
73
+ get cursorErase() {
74
+ const svgIcon = `<?xml version="1.0" encoding="UTF-8"?><svg width="24" heighst="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#icon-65e7e1747c11bad3)"><path d="M44.7818 24.1702L31.918 7.09935L14.1348 20.5L27.5 37L30.8556 34.6643L44.7818 24.1702Z" fill="#141414" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M27.4998 37L23.6613 40.0748L13.0978 40.074L10.4973 36.6231L4.06543 28.0876L14.4998 20.2248" stroke="#000000" stroke-width="4" stroke-linejoin="miter"/><path d="M13.2056 40.072L44.5653 40.072" stroke="#000000" stroke-width="4" stroke-linecap="round"/></g><defs><clipPath id="icon-65e7e1747c11bad3"><rect width="48" height="48" fill="#df4c4c"/></clipPath></defs></svg>`;
75
+ const iconUrl = `data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(svgIcon)))}`;
76
+ return `url(${iconUrl}) 0 0, auto`;
77
+ }
78
+ get defaultCursor() {
79
+ if (this.action === EScribblePattern.Erase) {
80
+ return this.cursorErase;
81
+ }
82
+ return this.isShowDefaultCursor ? "default" : "none";
83
+ }
84
+ get color() {
85
+ var _a, _b;
86
+ return (_b = (_a = this == null ? void 0 : this.defaultAttributeInfo) == null ? void 0 : _a.color) != null ? _b : DEFAULT_COLOR;
87
+ }
88
+ get penSizeWithZoom() {
89
+ return this.penSize / this.zoom;
90
+ }
91
+ get cacheCanvasToDataUrl() {
92
+ var _a;
93
+ return (_a = this.cacheCanvas) == null ? void 0 : _a.toDataURL("image/png", 0);
94
+ }
95
+ setPenSize(size) {
96
+ this.penSize = size;
97
+ }
98
+ initCacheCanvas(imgNode) {
99
+ if (this.cacheCanvas || !imgNode) {
100
+ return;
101
+ }
102
+ const {canvas, ctx} = ImgConversionUtils.createCanvas(imgNode);
103
+ this.cacheCanvas = canvas;
104
+ this.cacheContext = ctx;
105
+ }
106
+ updateCacheCanvasSize(imgNode) {
107
+ if (this.cacheCanvas) {
108
+ this.cacheCanvas.width = imgNode.width;
109
+ this.cacheCanvas.height = imgNode.height;
110
+ }
111
+ }
112
+ updateUrl2CacheContext(url) {
113
+ ImgConversionUtils.createImgDom(url).then((img) => {
114
+ if (!this.cacheContext) {
115
+ this.initCacheCanvas(img);
116
+ }
117
+ if (this.cacheContext) {
118
+ this.cacheContext.save();
119
+ this.clearCacheCanvas();
120
+ this.cacheContext.drawImage(img, 0, 0, img.width, img.height);
121
+ this.cacheContext.restore();
122
+ this.render();
123
+ }
124
+ });
125
+ }
126
+ setImgNode(imgNode, basicImgInfo) {
127
+ super.setImgNode(imgNode, basicImgInfo);
128
+ if (this.cacheCanvas) {
129
+ this.updateCacheCanvasSize(imgNode);
130
+ } else {
131
+ this.initCacheCanvas(imgNode);
132
+ }
133
+ }
134
+ setResult(data) {
135
+ var _a, _b;
136
+ let {url} = (_a = data == null ? void 0 : data[0]) != null ? _a : {};
137
+ this.clearCacheCanvas();
138
+ if (!url) {
139
+ url = (_b = this.cacheCanvasToDataUrl) != null ? _b : "";
140
+ }
141
+ this.history.initRecord([url], true);
142
+ if (!url) {
143
+ this.render();
144
+ return;
145
+ }
146
+ this.updateUrl2CacheContext(url);
147
+ }
148
+ onKeyDown(e) {
149
+ if (!CommonToolUtils.hotkeyFilter(e) || super.onKeyDown(e) === false) {
150
+ return;
151
+ }
152
+ const {keyCode} = e;
153
+ const keyCode2Attribute = AttributeUtils.getAttributeByKeycode(keyCode, this.config.attributeList);
154
+ if (keyCode2Attribute !== void 0) {
155
+ this.setDefaultAttribute(keyCode2Attribute);
156
+ }
157
+ }
158
+ eventBinding() {
159
+ super.eventBinding();
160
+ }
161
+ setDefaultAttribute(attributeValue) {
162
+ const attributeInfo = this.config.attributeList.find((v) => v.value === attributeValue);
163
+ if (attributeInfo) {
164
+ this.defaultAttribute = attributeInfo.value;
165
+ this.defaultAttributeInfo = attributeInfo;
166
+ this.emit("changeAttributeSidebar");
167
+ this.render();
168
+ }
169
+ }
170
+ clearStatusAfterLeave() {
171
+ this.onScribbleEnd();
172
+ this.startPoint = void 0;
173
+ }
174
+ onMouseLeave() {
175
+ super.onMouseLeave();
176
+ this.clearStatusAfterLeave();
177
+ }
178
+ onScribbleStart(e) {
179
+ if (!this.cacheContext) {
180
+ return;
181
+ }
182
+ this.cacheContext.save();
183
+ this.cacheContext.beginPath();
184
+ this.cacheContext.strokeStyle = this.color;
185
+ this.cacheContext.lineWidth = this.penSizeWithZoom;
186
+ this.cacheContext.lineCap = "round";
187
+ this.cacheContext.lineJoin = "round";
188
+ const originCoordinate = this.getOriginCoordinate(e);
189
+ this.cacheContext.moveTo(originCoordinate.x, originCoordinate.y);
190
+ this.startPoint = originCoordinate;
191
+ }
192
+ onScribbleMove(e) {
193
+ if (e.buttons === 1 && this.cacheContext && this.startPoint) {
194
+ const originCoordinate = this.getOriginCoordinate(e);
195
+ this.cacheContext.lineTo(originCoordinate.x, originCoordinate.y);
196
+ this.cacheContext.stroke();
197
+ }
198
+ }
199
+ onScribbleEnd() {
200
+ var _a, _b;
201
+ if (this.startPoint) {
202
+ (_a = this.cacheContext) == null ? void 0 : _a.closePath();
203
+ (_b = this.cacheContext) == null ? void 0 : _b.restore();
204
+ this.startPoint = void 0;
205
+ this.history.pushHistory(this.cacheCanvasToDataUrl);
206
+ }
207
+ }
208
+ eraseArc(e) {
209
+ var _a;
210
+ if (this.cacheContext) {
211
+ const originCoordinate = this.getOriginCoordinate(e);
212
+ this.cacheContext.save();
213
+ this.cacheContext.beginPath();
214
+ this.cacheContext.arc(originCoordinate.x, originCoordinate.y, this.penSizeWithZoom / 2, 0, Math.PI * 2, false);
215
+ this.cacheContext.clip();
216
+ this.cacheContext.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
217
+ (_a = this.cacheContext) == null ? void 0 : _a.restore();
218
+ }
219
+ }
220
+ onEraseStart(e) {
221
+ if (!this.cacheContext || e.buttons !== 1) {
222
+ return;
223
+ }
224
+ this.eraseArc(e);
225
+ }
226
+ onEraseMove(e) {
227
+ if (!this.cacheContext || e.buttons !== 1) {
228
+ return;
229
+ }
230
+ this.eraseArc(e);
231
+ }
232
+ onEraseEnd() {
233
+ }
234
+ exportData() {
235
+ const imgBase64 = this.cacheCanvasToDataUrl;
236
+ return [[], this.basicImgInfo, {imgBase64}];
237
+ }
238
+ clearCacheCanvas() {
239
+ var _a;
240
+ (_a = this.cacheContext) == null ? void 0 : _a.clearRect(0, 0, this.cacheContext.canvas.width, this.cacheContext.canvas.height);
241
+ this.render();
242
+ }
243
+ clearResult() {
244
+ this.clearCacheCanvas();
245
+ this.history.pushHistory(this.cacheCanvasToDataUrl);
246
+ }
247
+ renderPoint(radius) {
248
+ DrawUtils.drawCircleWithFill(this.canvas, this.coord, radius, {color: this.color});
249
+ }
250
+ renderBorderPoint(radius) {
251
+ DrawUtils.drawCircle(this.canvas, this.coord, radius, {color: "black"});
252
+ }
253
+ render() {
254
+ super.render();
255
+ if (!this.ctx || !this.cacheCanvas) {
256
+ return;
257
+ }
258
+ this.ctx.save();
259
+ this.ctx.globalAlpha = 0.5;
260
+ DrawUtils.drawImg(this.canvas, this.cacheCanvas, {
261
+ zoom: this.zoom,
262
+ currentPos: this.currentPos,
263
+ rotate: this.rotate
264
+ });
265
+ this.ctx.restore();
266
+ if (this.forbidOperation || this.forbidCursorLine) {
267
+ return;
268
+ }
269
+ const radius = this.penSize / 2;
270
+ if (this.action === EScribblePattern.Erase) {
271
+ this.renderBorderPoint(radius);
272
+ } else {
273
+ this.renderPoint(radius);
274
+ }
275
+ }
276
+ undo() {
277
+ const url = this.history.undo();
278
+ if (url && this.cacheCanvas) {
279
+ this.updateUrl2CacheContext(url);
280
+ }
281
+ }
282
+ redo() {
283
+ const url = this.history.redo();
284
+ if (url && this.cacheCanvas) {
285
+ this.updateUrl2CacheContext(url);
286
+ }
287
+ }
288
+ }
289
+
290
+ export { ScribbleTool as default };
@@ -1 +1,129 @@
1
- import a from"../../utils/uuid.js";import r from"../../constant/keyCode.js";import l from"../../utils/tool/CommonToolUtils.js";import{BasicToolOperation as u}from"./basicToolOperation.js";class d extends u{constructor(t){super(t);this.getSingleResult=i=>{const e={};return this.config.configList.length>0&&this.config.configList.forEach(n=>{var o;e[n.key]=(o=n.default)!=null?o:""}),{value:e,id:a(),sourceID:i!=null?i:l.getSourceID()}},this.getInitResultList=(i,e)=>i>0?e.map(n=>this.getSingleResult(n.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 i;this.textList=t,this.toggleTextContainerVisible(!0);const e=(i=this.textList[0])==null?void 0:i.value;e&&Object.keys(e).forEach(n=>{this.renderText(n,e[n])}),this.emit("valueUpdated"),this.toggleTextContainerVisible(!!e)}updateTextValue(t,i){this.textList[0].value[t]=i,this.renderText(t,i),this.emit("valueUpdated")}renderText(t,i){const e=document.getElementById(`textKey${t}`);e&&(e.innerText=i)}getTextDomID(t){return`textKey${t}`}initTextDisplayContainer(){const t=document.createElement("div"),i={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(i).reduce((e,n)=>(e+=`${n}: ${i[n]};`,e),"")),t.setAttribute("id",this.textValueContainerID),this.config.configList.forEach(e=>{const n=document.createElement("div"),o=document.createElement("div"),s=document.createElement("div");n.setAttribute("style","padding: 8px 16px"),o.innerText=`${e.key}:`,s.innerText="",s.setAttribute("id",this.getTextDomID(e.key)),n.appendChild(o),n.appendChild(s),t.appendChild(n)}),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===r.Z&&this.toggleTextContainerVisible()}toggleTextContainerVisible(t){if(this.textValueContainer){const i=(t!==void 0?!t:this.textValueContainer.style.display==="block")?"none":"block";this.textValueContainer.style.display=i}}}export{d as default};
1
+ import uuid from '../../utils/uuid.js';
2
+ import EKeyCode from '../../constant/keyCode.js';
3
+ import CommonToolUtils from '../../utils/tool/CommonToolUtils.js';
4
+ import { BasicToolOperation } from './basicToolOperation.js';
5
+
6
+ class TextToolOperation extends BasicToolOperation {
7
+ constructor(props) {
8
+ super(props);
9
+ this.getSingleResult = (sourceID) => {
10
+ const initValue = {};
11
+ if (this.config.configList.length > 0) {
12
+ this.config.configList.forEach((i) => {
13
+ var _a;
14
+ initValue[i.key] = (_a = i.default) != null ? _a : "";
15
+ });
16
+ }
17
+ return {value: initValue, id: uuid(), sourceID: sourceID != null ? sourceID : CommonToolUtils.getSourceID()};
18
+ };
19
+ this.getInitResultList = (dataSourceStep, basicResultList) => {
20
+ if (dataSourceStep > 0) {
21
+ return basicResultList.map((i) => this.getSingleResult(i.id));
22
+ }
23
+ return [this.getSingleResult()];
24
+ };
25
+ this.textList = [];
26
+ this.setShowDefaultCursor(true);
27
+ this.setConfig(props.config);
28
+ this.initTextDisplayContainer();
29
+ }
30
+ get dataList() {
31
+ return this.textList;
32
+ }
33
+ get textValueContainerID() {
34
+ return "textValueContainer";
35
+ }
36
+ get textValueContainer() {
37
+ return document.getElementById(this.textValueContainerID);
38
+ }
39
+ get currentPageResult() {
40
+ return this.textList;
41
+ }
42
+ setResult(textResultList) {
43
+ var _a;
44
+ this.textList = textResultList;
45
+ this.toggleTextContainerVisible(true);
46
+ const values = (_a = this.textList[0]) == null ? void 0 : _a.value;
47
+ if (values) {
48
+ Object.keys(values).forEach((k) => {
49
+ this.renderText(k, values[k]);
50
+ });
51
+ }
52
+ this.emit("valueUpdated");
53
+ this.toggleTextContainerVisible(!!values);
54
+ }
55
+ updateTextValue(k, v) {
56
+ this.textList[0].value[k] = v;
57
+ this.renderText(k, v);
58
+ this.emit("valueUpdated");
59
+ }
60
+ renderText(key, value) {
61
+ const textDom = document.getElementById(`textKey${key}`);
62
+ if (textDom) {
63
+ textDom.innerText = value;
64
+ }
65
+ }
66
+ getTextDomID(key) {
67
+ return `textKey${key}`;
68
+ }
69
+ initTextDisplayContainer() {
70
+ const dom = document.createElement("div");
71
+ const domStyle = {
72
+ position: "absolute",
73
+ right: "0",
74
+ top: "0",
75
+ "z-index": "20",
76
+ "max-width": "20%",
77
+ "font-family": "SourceHanSansCN-Regular",
78
+ background: "rgb(102, 230, 255)",
79
+ color: "white",
80
+ "word-break": "break-all",
81
+ "line-height": "24px",
82
+ "white-space": "pre-wrap",
83
+ "max-height": "80%",
84
+ "overflow-y": "auto",
85
+ opacity: "0.6"
86
+ };
87
+ dom.setAttribute("style", Object.keys(domStyle).reduce((pre, key) => {
88
+ pre += `${key}: ${domStyle[key]};`;
89
+ return pre;
90
+ }, ""));
91
+ dom.setAttribute("id", this.textValueContainerID);
92
+ this.config.configList.forEach((i) => {
93
+ const div = document.createElement("div");
94
+ const label = document.createElement("div");
95
+ const value = document.createElement("div");
96
+ div.setAttribute("style", "padding: 8px 16px");
97
+ label.innerText = `${i.key}:`;
98
+ value.innerText = "";
99
+ value.setAttribute("id", this.getTextDomID(i.key));
100
+ div.appendChild(label);
101
+ div.appendChild(value);
102
+ dom.appendChild(div);
103
+ });
104
+ this.container.appendChild(dom);
105
+ }
106
+ exportData() {
107
+ return [this.textList, this.basicImgInfo];
108
+ }
109
+ destroyCanvas() {
110
+ super.destroyCanvas();
111
+ if (this.textValueContainer) {
112
+ this.container.removeChild(this.textValueContainer);
113
+ }
114
+ }
115
+ onKeyDown(e) {
116
+ super.onKeyDown(e);
117
+ if (e.keyCode === EKeyCode.Z) {
118
+ this.toggleTextContainerVisible();
119
+ }
120
+ }
121
+ toggleTextContainerVisible(isVisible) {
122
+ if (this.textValueContainer) {
123
+ const display = (isVisible !== void 0 ? !isVisible : this.textValueContainer.style.display === "block") ? "none" : "block";
124
+ this.textValueContainer.style.display = display;
125
+ }
126
+ }
127
+ }
128
+
129
+ export { TextToolOperation as default };