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