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

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 (188) hide show
  1. package/dist/_virtual/MathUtilsWorker.js +1 -8
  2. package/dist/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +2 -35
  3. package/dist/_virtual/filterBoxWorker.js +1 -8
  4. package/dist/_virtual/highlightWorker.js +1 -8
  5. package/dist/assets/attributeIcon/icon_canvasEdit0.svg.js +1 -5
  6. package/dist/assets/attributeIcon/icon_canvasEdit1.svg.js +1 -5
  7. package/dist/assets/attributeIcon/icon_canvasEdit2.svg.js +1 -5
  8. package/dist/assets/attributeIcon/icon_canvasEdit3.svg.js +1 -5
  9. package/dist/assets/attributeIcon/icon_canvasEdit4.svg.js +1 -5
  10. package/dist/assets/attributeIcon/icon_canvasEdit5.svg.js +1 -5
  11. package/dist/assets/attributeIcon/icon_canvasEdit6.svg.js +1 -5
  12. package/dist/assets/attributeIcon/icon_canvasEdit7.svg.js +1 -5
  13. package/dist/assets/attributeIcon/icon_canvasEdit8.svg.js +1 -5
  14. package/dist/assets/attributeIcon/icon_canvasEdit_miss.svg.js +1 -5
  15. package/dist/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -5
  16. package/dist/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -5
  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 +12 -5
  20. package/dist/assets/attributeIcon/icon_editFEN.svg.js +1 -5
  21. package/dist/assets/attributeIcon/icon_editHUANG.svg.js +1 -5
  22. package/dist/assets/attributeIcon/icon_editLAN.svg.js +1 -5
  23. package/dist/assets/attributeIcon/icon_editLV.svg.js +1 -5
  24. package/dist/assets/attributeIcon/icon_editQING.svg.js +1 -5
  25. package/dist/constant/annotation.js +1 -127
  26. package/dist/constant/annotationTask.js +1 -30
  27. package/dist/constant/defaultConfig.js +1 -266
  28. package/dist/constant/keyCode.js +1 -38
  29. package/dist/constant/style.js +1 -98
  30. package/dist/constant/tool.js +1 -236
  31. package/dist/core/index.js +1 -150
  32. package/dist/core/pointCloud/OrbitControls.js +1 -665
  33. package/dist/core/pointCloud/PCDLoader.js +2 -260
  34. package/dist/core/pointCloud/annotation.js +1 -215
  35. package/dist/core/pointCloud/cache.js +1 -53
  36. package/dist/core/pointCloud/index.js +5 -991
  37. package/dist/core/pointCloud/matrix.js +1 -138
  38. package/dist/core/scheduler.js +1 -233
  39. package/dist/core/toolOperation/LineToolOperation.js +1 -1434
  40. package/dist/core/toolOperation/ScribbleTool.js +1 -292
  41. package/dist/core/toolOperation/TextToolOperation.js +1 -131
  42. package/dist/core/toolOperation/ViewOperation.js +1 -556
  43. package/dist/core/toolOperation/basicToolOperation.js +1 -881
  44. package/dist/core/toolOperation/checkOperation.js +1 -208
  45. package/dist/core/toolOperation/cuboidOperation.js +1 -754
  46. package/dist/core/toolOperation/cuboidToggleButtonClass.js +7 -152
  47. package/dist/core/toolOperation/eventListener.js +1 -37
  48. package/dist/core/toolOperation/measureOperation.js +1 -41
  49. package/dist/core/toolOperation/pointCloud2dOperation.js +1 -365
  50. package/dist/core/toolOperation/pointOperation.js +1 -696
  51. package/dist/core/toolOperation/polygonOperation.js +1 -1251
  52. package/dist/core/toolOperation/rectOperation.js +1 -1233
  53. package/dist/core/toolOperation/segmentByRect.js +1 -174
  54. package/dist/core/toolOperation/tagOperation.js +3 -201
  55. package/dist/core/toolOperation/textAttributeClass.js +16 -182
  56. package/dist/index.js +1 -185
  57. package/dist/locales/constants.js +1 -24
  58. package/dist/locales/en_US/message.js +1 -25
  59. package/dist/locales/index.js +1 -19
  60. package/dist/locales/zh_CN/message.js +1 -25
  61. package/dist/newCore/CanvasScheduler.js +1 -35
  62. package/dist/utils/ActionsHistory.js +1 -84
  63. package/dist/utils/ImgUtils.js +1 -23
  64. package/dist/utils/MathUtils.js +2 -385
  65. package/dist/utils/VectorUtils.js +1 -25
  66. package/dist/utils/tool/AttributeUtils.js +1 -218
  67. package/dist/utils/tool/AxisUtils.js +1 -340
  68. package/dist/utils/tool/CanvasUtils.js +1 -62
  69. package/dist/utils/tool/CommonToolUtils.js +1 -174
  70. package/dist/utils/tool/CuboidUtils.js +1 -704
  71. package/dist/utils/tool/DblClickEventListener.js +1 -102
  72. package/dist/utils/tool/DrawUtils.js +3 -492
  73. package/dist/utils/tool/EnhanceCommonToolUtils.js +1 -53
  74. package/dist/utils/tool/ImgPosUtils.js +1 -58
  75. package/dist/utils/tool/LineToolUtils.js +1 -261
  76. package/dist/utils/tool/MarkerUtils.js +1 -56
  77. package/dist/utils/tool/PolygonUtils.js +1 -460
  78. package/dist/utils/tool/RectUtils.js +1 -155
  79. package/dist/utils/tool/RenderDomClass.js +7 -57
  80. package/dist/utils/tool/RenderDomUtils.js +4 -21
  81. package/dist/utils/tool/StyleUtils.js +1 -31
  82. package/dist/utils/tool/TagUtils.js +1 -129
  83. package/dist/utils/tool/UnitUtils.js +1 -12
  84. package/dist/utils/tool/ZoomUtils.js +1 -72
  85. package/dist/utils/tool/polygonTool.js +1 -133
  86. package/dist/utils/uuid.js +1 -26
  87. package/es/_virtual/MathUtilsWorker.js +1 -6
  88. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__browser__createBase64WorkerFactory.js +2 -31
  89. package/es/_virtual/filterBoxWorker.js +1 -6
  90. package/es/_virtual/highlightWorker.js +1 -6
  91. package/es/assets/attributeIcon/icon_canvasEdit0.svg.js +1 -3
  92. package/es/assets/attributeIcon/icon_canvasEdit1.svg.js +1 -3
  93. package/es/assets/attributeIcon/icon_canvasEdit2.svg.js +1 -3
  94. package/es/assets/attributeIcon/icon_canvasEdit3.svg.js +1 -3
  95. package/es/assets/attributeIcon/icon_canvasEdit4.svg.js +1 -3
  96. package/es/assets/attributeIcon/icon_canvasEdit5.svg.js +1 -3
  97. package/es/assets/attributeIcon/icon_canvasEdit6.svg.js +1 -3
  98. package/es/assets/attributeIcon/icon_canvasEdit7.svg.js +1 -3
  99. package/es/assets/attributeIcon/icon_canvasEdit8.svg.js +1 -3
  100. package/es/assets/attributeIcon/icon_canvasEdit_miss.svg.js +1 -3
  101. package/es/assets/attributeIcon/icon_cuboidFAB.svg.js +5 -3
  102. package/es/assets/attributeIcon/icon_cuboidLeft.svg.js +7 -3
  103. package/es/assets/attributeIcon/icon_cuboidMore.svg.js +5 -3
  104. package/es/assets/attributeIcon/icon_cuboidRight.svg.js +5 -3
  105. package/es/assets/attributeIcon/icon_cuboidTop.svg.js +12 -3
  106. package/es/assets/attributeIcon/icon_editFEN.svg.js +1 -3
  107. package/es/assets/attributeIcon/icon_editHUANG.svg.js +1 -3
  108. package/es/assets/attributeIcon/icon_editLAN.svg.js +1 -3
  109. package/es/assets/attributeIcon/icon_editLV.svg.js +1 -3
  110. package/es/assets/attributeIcon/icon_editQING.svg.js +1 -3
  111. package/es/constant/annotation.js +1 -113
  112. package/es/constant/annotationTask.js +1 -25
  113. package/es/constant/defaultConfig.js +1 -260
  114. package/es/constant/keyCode.js +1 -36
  115. package/es/constant/style.js +1 -74
  116. package/es/constant/tool.js +1 -220
  117. package/es/core/index.js +1 -148
  118. package/es/core/pointCloud/OrbitControls.js +1 -661
  119. package/es/core/pointCloud/PCDLoader.js +2 -256
  120. package/es/core/pointCloud/annotation.js +1 -211
  121. package/es/core/pointCloud/cache.js +1 -49
  122. package/es/core/pointCloud/index.js +5 -962
  123. package/es/core/pointCloud/matrix.js +1 -109
  124. package/es/core/scheduler.js +1 -228
  125. package/es/core/toolOperation/LineToolOperation.js +1 -1421
  126. package/es/core/toolOperation/ScribbleTool.js +1 -290
  127. package/es/core/toolOperation/TextToolOperation.js +1 -129
  128. package/es/core/toolOperation/ViewOperation.js +1 -549
  129. package/es/core/toolOperation/basicToolOperation.js +1 -877
  130. package/es/core/toolOperation/checkOperation.js +1 -206
  131. package/es/core/toolOperation/cuboidOperation.js +1 -752
  132. package/es/core/toolOperation/cuboidToggleButtonClass.js +7 -150
  133. package/es/core/toolOperation/eventListener.js +1 -35
  134. package/es/core/toolOperation/measureOperation.js +1 -39
  135. package/es/core/toolOperation/pointCloud2dOperation.js +1 -359
  136. package/es/core/toolOperation/pointOperation.js +1 -690
  137. package/es/core/toolOperation/polygonOperation.js +1 -1245
  138. package/es/core/toolOperation/rectOperation.js +1 -1228
  139. package/es/core/toolOperation/segmentByRect.js +1 -172
  140. package/es/core/toolOperation/tagOperation.js +3 -199
  141. package/es/core/toolOperation/textAttributeClass.js +16 -180
  142. package/es/index.js +1 -46
  143. package/es/locales/constants.js +1 -22
  144. package/es/locales/en_US/message.js +1 -23
  145. package/es/locales/index.js +1 -17
  146. package/es/locales/zh_CN/message.js +1 -23
  147. package/es/newCore/CanvasScheduler.js +1 -31
  148. package/es/utils/ActionsHistory.js +1 -78
  149. package/es/utils/ImgUtils.js +1 -21
  150. package/es/utils/MathUtils.js +2 -380
  151. package/es/utils/VectorUtils.js +1 -23
  152. package/es/utils/tool/AttributeUtils.js +1 -212
  153. package/es/utils/tool/AxisUtils.js +1 -335
  154. package/es/utils/tool/CanvasUtils.js +1 -60
  155. package/es/utils/tool/CommonToolUtils.js +1 -172
  156. package/es/utils/tool/CuboidUtils.js +1 -680
  157. package/es/utils/tool/DblClickEventListener.js +1 -100
  158. package/es/utils/tool/DrawUtils.js +3 -490
  159. package/es/utils/tool/EnhanceCommonToolUtils.js +1 -48
  160. package/es/utils/tool/ImgPosUtils.js +1 -56
  161. package/es/utils/tool/LineToolUtils.js +1 -255
  162. package/es/utils/tool/MarkerUtils.js +1 -54
  163. package/es/utils/tool/PolygonUtils.js +1 -458
  164. package/es/utils/tool/RectUtils.js +1 -153
  165. package/es/utils/tool/RenderDomClass.js +7 -55
  166. package/es/utils/tool/RenderDomUtils.js +4 -19
  167. package/es/utils/tool/StyleUtils.js +1 -29
  168. package/es/utils/tool/TagUtils.js +1 -127
  169. package/es/utils/tool/UnitUtils.js +1 -10
  170. package/es/utils/tool/ZoomUtils.js +1 -70
  171. package/es/utils/tool/polygonTool.js +1 -126
  172. package/es/utils/uuid.js +1 -24
  173. package/package.json +3 -4
  174. package/LICENSE +0 -203
  175. package/dist/core/pointCloud/segmentation.js +0 -144
  176. package/dist/core/pointCloud/selector/Sse3dLassoSelector.js +0 -26
  177. package/dist/core/pointCloud/selector/Sse3dSelector.js +0 -16
  178. package/dist/types/core/pointCloud/segmentation.d.ts +0 -0
  179. package/dist/types/core/pointCloud/selector/Sse3dLassoSelector.d.ts +0 -0
  180. package/dist/types/core/pointCloud/selector/Sse3dSelector.d.ts +0 -0
  181. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__createBase64WorkerFactory.js +0 -12
  182. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__auto__isNodeJS.js +0 -7
  183. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__WorkerClass.js +0 -11
  184. package/es/_virtual/_rollup-plugin-web-worker-loader__helper__node__createBase64WorkerFactory.js +0 -18
  185. package/es/core/pointCloud/segmentation.js +0 -120
  186. package/es/core/pointCloud/selector/Sse3dLassoSelector.js +0 -24
  187. package/es/core/pointCloud/selector/Sse3dSelector.js +0 -14
  188. package/es/core/toolOperation/scribbleTool2.js +0 -249
@@ -1,109 +1 @@
1
- import * as THREE from 'three';
2
- import { MatrixUtils, PointCloudUtils } from '@labelbee/lb-utils';
3
- import uuid from '../../utils/uuid.js';
4
-
5
- var __defProp = Object.defineProperty;
6
- var __defProps = Object.defineProperties;
7
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- function createThreeMatrix4(matrix4) {
25
- return new THREE.Matrix4().set(...matrix4);
26
- }
27
- function transferKitti2Matrix(P, R, T) {
28
- const PMA = MatrixUtils.transferMatrix34FromKitti2Three(P);
29
- const RMA = MatrixUtils.transferMatrix33FromKitti2Three(R);
30
- const TMA = MatrixUtils.transferMatrix34FromKitti2Three(T);
31
- const PM = createThreeMatrix4(PMA);
32
- const RM = createThreeMatrix4(RMA);
33
- const TM = createThreeMatrix4(TMA);
34
- return {
35
- composeMatrix4: TM.clone().premultiply(RM).premultiply(PM),
36
- PM,
37
- RM,
38
- TM
39
- };
40
- }
41
- function rotatePoint(points, centerPoint, rotationZ) {
42
- var _a;
43
- const pointVector = new THREE.Vector3(points.x, points.y, (_a = points == null ? void 0 : points.z) != null ? _a : 1);
44
- const Rz = new THREE.Matrix4().makeRotationZ(rotationZ);
45
- const TFrom = new THREE.Matrix4().makeTranslation(centerPoint.x, centerPoint.y, centerPoint.z);
46
- const TBack = new THREE.Matrix4().makeTranslation(-centerPoint.x, -centerPoint.y, -centerPoint.z);
47
- return pointVector.clone().applyMatrix4(TBack).applyMatrix4(Rz).applyMatrix4(TFrom);
48
- }
49
- function lidar2image(point, composeMatrix4) {
50
- const vector = new THREE.Vector4(point.x, point.y, point.z);
51
- const newV = vector.applyMatrix4(composeMatrix4);
52
- if (newV.z < 0) {
53
- return void 0;
54
- }
55
- const z = 1 / newV.z;
56
- const fixMatrix4 = new THREE.Matrix4().set(z, 0, 0, 0, 0, z, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
57
- return newV.applyMatrix4(fixMatrix4);
58
- }
59
- function getCuboidFromPointCloudBox(boxParams) {
60
- const {center, width, height, depth, rotation} = boxParams;
61
- const polygonPointList = [
62
- {
63
- x: center.x + width / 2,
64
- y: center.y - height / 2
65
- },
66
- {
67
- x: center.x + width / 2,
68
- y: center.y + height / 2
69
- },
70
- {
71
- x: center.x - width / 2,
72
- y: center.y + height / 2
73
- },
74
- {
75
- x: center.x - width / 2,
76
- y: center.y - height / 2
77
- }
78
- ].map((v) => {
79
- const vector = rotatePoint(v, center, rotation);
80
- return {
81
- x: vector.x,
82
- y: vector.y
83
- };
84
- });
85
- const zMax = center.z + depth / 2;
86
- const zMin = center.z - depth / 2;
87
- return __spreadProps(__spreadValues({}, boxParams), {
88
- polygonPointList,
89
- zMax,
90
- zMin
91
- });
92
- }
93
- function pointCloudLidar2image(boxParams, cameraMatrix) {
94
- const allViewData = PointCloudUtils.getAllViewData(boxParams);
95
- const {P, R, T} = cameraMatrix;
96
- const {composeMatrix4} = transferKitti2Matrix(P, R, T);
97
- const transferViewData = allViewData.map((viewData) => ({
98
- type: viewData.type,
99
- pointList: viewData.pointList.map((point) => rotatePoint(point, boxParams.center, boxParams.rotation)).map((point) => lidar2image(point, composeMatrix4)).map((point) => {
100
- if (!point) {
101
- return void 0;
102
- }
103
- return {id: uuid(), x: point == null ? void 0 : point.x, y: point == null ? void 0 : point.y};
104
- }).filter((v) => v !== void 0)
105
- })).filter((v) => v.pointList.length !== 0);
106
- return transferViewData;
107
- }
108
-
109
- export { createThreeMatrix4, getCuboidFromPointCloudBox, lidar2image, pointCloudLidar2image, rotatePoint, transferKitti2Matrix };
1
+ import*as p from"three";import{MatrixUtils as x,PointCloudUtils as w}from"@labelbee/lb-utils";import _ from"../../utils/uuid.js";var g=Object.defineProperty,h=Object.defineProperties,z=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,O=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable,M=(r,t,e)=>t in r?g(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,P=(r,t)=>{for(var e in t||(t={}))O.call(t,e)&&M(r,e,t[e]);if(m)for(var e of m(t))T.call(t,e)&&M(r,e,t[e]);return r},V=(r,t)=>h(r,z(t));function u(r){return new p.Matrix4().set(...r)}function d(r,t,e){const o=x.transferMatrix34FromKitti2Three(r),n=x.transferMatrix33FromKitti2Three(t),a=x.transferMatrix34FromKitti2Three(e),l=u(o),c=u(n),s=u(a);return{composeMatrix4:s.clone().premultiply(c).premultiply(l),PM:l,RM:c,TM:s}}function y(r,t,e){var o;const n=new p.Vector3(r.x,r.y,(o=r==null?void 0:r.z)!=null?o:1),a=new p.Matrix4().makeRotationZ(e),l=new p.Matrix4().makeTranslation(t.x,t.y,t.z),c=new p.Matrix4().makeTranslation(-t.x,-t.y,-t.z);return n.clone().applyMatrix4(c).applyMatrix4(a).applyMatrix4(l)}function v(r,t){const o=new p.Vector4(r.x,r.y,r.z).applyMatrix4(t);if(o.z<0)return;const n=1/o.z,a=new p.Matrix4().set(n,0,0,0,0,n,0,0,0,0,n,0,0,0,0,1);return o.applyMatrix4(a)}function R(r){const{center:t,width:e,height:o,depth:n,rotation:a}=r,l=[{x:t.x+e/2,y:t.y-o/2},{x:t.x+e/2,y:t.y+o/2},{x:t.x-e/2,y:t.y+o/2},{x:t.x-e/2,y:t.y-o/2}].map(i=>{const f=y(i,t,a);return{x:f.x,y:f.y}}),c=t.z+n/2,s=t.z-n/2;return V(P({},r),{polygonPointList:l,zMax:c,zMin:s})}function b(r,t){const e=w.getAllViewData(r),{P:o,R:n,T:a}=t,{composeMatrix4:l}=d(o,n,a);return e.map(s=>({type:s.type,pointList:s.pointList.map(i=>y(i,r.center,r.rotation)).map(i=>v(i,l)).map(i=>{if(!!i)return{id:_(),x:i==null?void 0:i.x,y:i==null?void 0:i.y}}).filter(i=>i!==void 0)})).filter(s=>s.pointList.length!==0)}export{u as createThreeMatrix4,R as getCuboidFromPointCloudBox,v as lidar2image,b as pointCloudLidar2image,y as rotatePoint,d as transferKitti2Matrix};
@@ -1,228 +1 @@
1
- import { getConfig, styleDefaultConfig } from '../constant/defaultConfig.js';
2
- import { getCurrentOperation } from '../utils/tool/EnhanceCommonToolUtils.js';
3
- import { BasicToolOperation } from './toolOperation/basicToolOperation.js';
4
-
5
- const createEmptyImage = (size) => {
6
- const canvas = document.createElement("canvas");
7
- canvas.width = size.width;
8
- canvas.height = size.height;
9
- const ctx = canvas.getContext("2d");
10
- if (ctx) {
11
- ctx.fillStyle = "transparent";
12
- ctx.fillRect(0, 0, size.width, size.height);
13
- return canvas.toDataURL();
14
- }
15
- return "";
16
- };
17
- const arraySwap = (array, index1, index2) => {
18
- const a = array[index1];
19
- array[index1] = array[index2];
20
- array[index2] = a;
21
- return array;
22
- };
23
- const _HybridToolUtils = class {
24
- static isSingleTool(toolName) {
25
- return !this.isHybridTool(toolName);
26
- }
27
- static isHybridTool(toolName) {
28
- return Array.isArray(toolName);
29
- }
30
- };
31
- let HybridToolUtils = _HybridToolUtils;
32
- HybridToolUtils.getTopToolName = (toolName) => {
33
- return _HybridToolUtils.isHybridTool(toolName) ? toolName[toolName.length - 1] : toolName;
34
- };
35
- class ToolScheduler {
36
- constructor(props) {
37
- this.toolOperationList = [];
38
- this.toolOperationDom = [];
39
- this.toolOperationNameList = [];
40
- var _a, _b;
41
- this.init();
42
- this.container = props.container;
43
- this.size = props.size;
44
- this.imgNode = props.imgNode;
45
- this.config = (_a = props.config) != null ? _a : JSON.stringify(getConfig(HybridToolUtils.getTopToolName(props.toolName)));
46
- this.style = (_b = props.style) != null ? _b : styleDefaultConfig;
47
- }
48
- setImgNode(imgNode, basicImgInfo) {
49
- this.toolOperationList.forEach((toolInstance) => {
50
- toolInstance.setImgNode(imgNode, basicImgInfo);
51
- });
52
- }
53
- setImgAttribute(imgAttribute) {
54
- this.toolOperationList.forEach((toolInstance) => {
55
- toolInstance.setImgAttribute(imgAttribute);
56
- });
57
- }
58
- setSize(size) {
59
- this.toolOperationList.forEach((toolInstance) => {
60
- toolInstance.setSize(size);
61
- });
62
- }
63
- syncPosition(currentPos, zoom, imgInfo, currentToolInstance) {
64
- this.toolOperationList.forEach((toolInstance) => {
65
- if (currentToolInstance === toolInstance) {
66
- return;
67
- }
68
- toolInstance.setCurrentPos(currentPos);
69
- toolInstance.setZoom(zoom);
70
- toolInstance.setImgInfo(imgInfo);
71
- toolInstance.renderBasicCanvas();
72
- toolInstance.render();
73
- });
74
- }
75
- get defaultSize() {
76
- var _a, _b;
77
- return {
78
- width: ((_a = this.imgNode) == null ? void 0 : _a.width) || this.size.width,
79
- height: ((_b = this.imgNode) == null ? void 0 : _b.height) || this.size.height
80
- };
81
- }
82
- createDom() {
83
- const {width, height} = this.defaultSize;
84
- const dom = window.document.createElement("div");
85
- dom.style.position = "absolute";
86
- dom.style.left = "0";
87
- dom.style.top = "0";
88
- dom.style.width = `${width}px`;
89
- dom.style.height = `${height}px`;
90
- const zIndex = this.toolOperationList.length + 1;
91
- dom.style.zIndex = `${zIndex}`;
92
- return dom;
93
- }
94
- getEmptyImage(width, height) {
95
- const imgSrc = createEmptyImage({width, height});
96
- const emptyImgNode = new Image();
97
- emptyImgNode.src = imgSrc;
98
- return emptyImgNode;
99
- }
100
- createOperation(tool, imgNode, config) {
101
- var _a;
102
- const {width, height} = this.defaultSize;
103
- const dom = this.createDom();
104
- const emptyImgNode = this.getEmptyImage(width, height);
105
- const defaultData = {
106
- container: dom,
107
- size: this.size,
108
- config: (_a = this == null ? void 0 : this.config) != null ? _a : "{}",
109
- drawOutSideTarget: false,
110
- style: this.style,
111
- imgNode: imgNode || emptyImgNode,
112
- hiddenImg: !!tool
113
- };
114
- if (config) {
115
- Object.assign(defaultData, config);
116
- }
117
- let toolInstance;
118
- if (!tool) {
119
- toolInstance = new BasicToolOperation(defaultData);
120
- dom.style.zIndex = "0";
121
- toolInstance.init();
122
- } else {
123
- const ToolOperation = getCurrentOperation(tool);
124
- if (!ToolOperation) {
125
- return;
126
- }
127
- toolInstance = new ToolOperation(defaultData);
128
- }
129
- toolInstance == null ? void 0 : toolInstance.init();
130
- toolInstance.canvas.id = tool != null ? tool : "basicCanvas";
131
- toolInstance.on("dragMove", ({currentPos, zoom, imgInfo}) => {
132
- this.syncPosition(currentPos, zoom, imgInfo, toolInstance);
133
- });
134
- toolInstance.on("renderZoom", (zoom, currentPos, imgInfo) => {
135
- if (zoom && currentPos) {
136
- this.syncPosition(currentPos, zoom, imgInfo, toolInstance);
137
- }
138
- });
139
- if (!tool) {
140
- this.container.insertBefore(dom, this.container.childNodes[0]);
141
- this.toolOperationList.unshift(toolInstance);
142
- this.toolOperationDom.unshift(dom);
143
- return toolInstance;
144
- }
145
- this.container.appendChild(dom);
146
- this.toolOperationList.push(toolInstance);
147
- this.toolOperationNameList.push(tool);
148
- this.toolOperationDom.push(dom);
149
- return toolInstance;
150
- }
151
- switchLastTwoCanvas() {
152
- if (this.toolOperationDom.length < 3) {
153
- console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");
154
- return;
155
- }
156
- const len = this.toolOperationDom.length;
157
- const lastOneIndex = len - 1;
158
- const last2SecondIndex = len - 2;
159
- const lastOneDom = this.toolOperationDom[lastOneIndex];
160
- const last2SecondDom = this.toolOperationDom[last2SecondIndex];
161
- if (!last2SecondDom || !lastOneDom) {
162
- return;
163
- }
164
- lastOneDom.style.zIndex = `${lastOneIndex - 1}`;
165
- last2SecondDom.style.zIndex = `${lastOneIndex}`;
166
- this.toolOperationList[lastOneIndex].clearActiveStatus();
167
- this.toolOperationList[lastOneIndex].clearCursorLine();
168
- this.toolOperationList[lastOneIndex].render();
169
- this.toolOperationList = arraySwap(this.toolOperationList, lastOneIndex, last2SecondIndex);
170
- this.toolOperationDom = arraySwap(this.toolOperationDom, lastOneIndex, last2SecondIndex);
171
- return this.toolOperationList[lastOneIndex];
172
- }
173
- getFirstToolOperation() {
174
- if (this.toolOperationList.length > 1) {
175
- return this.toolOperationList[1];
176
- }
177
- return this.toolOperationList[0];
178
- }
179
- switchToCanvas(toolName) {
180
- var _a, _b, _c, _d;
181
- const chosenIndex = this.toolOperationNameList.indexOf(toolName);
182
- if (chosenIndex < 0 || this.toolOperationList.length < 1 || chosenIndex > this.toolOperationDom.length - 1) {
183
- return;
184
- }
185
- const lastOneIndex = this.toolOperationDom.length - 1;
186
- const chosenDom = this.toolOperationDom[chosenIndex];
187
- const lastOneDom = this.toolOperationDom[lastOneIndex];
188
- if (!chosenDom || !lastOneDom) {
189
- return;
190
- }
191
- const temp = lastOneDom.style.zIndex;
192
- lastOneDom.style.zIndex = `${chosenDom.style.zIndex}`;
193
- chosenDom.style.zIndex = `${temp}`;
194
- (_b = (_a = this.toolOperationList[lastOneIndex]).clearActiveStatus) == null ? void 0 : _b.call(_a);
195
- (_d = (_c = this.toolOperationList[lastOneIndex]).clearCursorLine) == null ? void 0 : _d.call(_c);
196
- this.toolOperationList[lastOneIndex].render();
197
- this.toolOperationList = arraySwap(this.toolOperationList, lastOneIndex, chosenIndex);
198
- this.toolOperationDom = arraySwap(this.toolOperationDom, lastOneIndex, chosenIndex);
199
- this.toolOperationNameList = arraySwap(this.toolOperationNameList, lastOneIndex, chosenIndex);
200
- return this.toolOperationList[lastOneIndex];
201
- }
202
- updateDataByToolName(toolName, result) {
203
- const operationIndex = this.toolOperationNameList.indexOf(toolName);
204
- if (operationIndex >= 0) {
205
- const operationInstance = this.toolOperationList[operationIndex];
206
- operationInstance.setResult(result);
207
- }
208
- }
209
- clearStatusAndResult() {
210
- this.toolOperationList.forEach((toolInstance) => {
211
- var _a;
212
- (_a = toolInstance.clearActiveStatus) == null ? void 0 : _a.call(toolInstance);
213
- toolInstance.clearResult();
214
- });
215
- }
216
- destroyAllLayer() {
217
- this.toolOperationList.forEach((toolInstance) => {
218
- toolInstance.destroyCanvas();
219
- this.init();
220
- });
221
- }
222
- init() {
223
- this.toolOperationList = [];
224
- this.toolOperationDom = [];
225
- }
226
- }
227
-
228
- export { HybridToolUtils, ToolScheduler };
1
+ import{getConfig as f,styleDefaultConfig as L}from"../constant/defaultConfig.js";import{getCurrentOperation as y}from"../utils/tool/EnhanceCommonToolUtils.js";import{BasicToolOperation as v}from"./toolOperation/basicToolOperation.js";const D=e=>{const t=document.createElement("canvas");t.width=e.width,t.height=e.height;const i=t.getContext("2d");return i?(i.fillStyle="transparent",i.fillRect(0,0,e.width,e.height),t.toDataURL()):""},p=(e,t,i)=>{const o=e[t];return e[t]=e[i],e[i]=o,e},g=class{static isSingleTool(e){return!this.isHybridTool(e)}static isHybridTool(e){return Array.isArray(e)}};let u=g;u.getTopToolName=e=>g.isHybridTool(e)?e[e.length-1]:e;class I{constructor(t){this.toolOperationList=[],this.toolOperationDom=[],this.toolOperationNameList=[];var i,o;this.init(),this.container=t.container,this.size=t.size,this.imgNode=t.imgNode,this.config=(i=t.config)!=null?i:JSON.stringify(f(u.getTopToolName(t.toolName))),this.style=(o=t.style)!=null?o:L}setImgNode(t,i){this.toolOperationList.forEach(o=>{o.setImgNode(t,i)})}setImgAttribute(t){this.toolOperationList.forEach(i=>{i.setImgAttribute(t)})}setSize(t){this.toolOperationList.forEach(i=>{i.setSize(t)})}syncPosition(t,i,o,s){this.toolOperationList.forEach(a=>{s!==a&&(a.setCurrentPos(t),a.setZoom(i),a.setImgInfo(o),a.renderBasicCanvas(),a.render())})}get defaultSize(){var t,i;return{width:((t=this.imgNode)==null?void 0:t.width)||this.size.width,height:((i=this.imgNode)==null?void 0:i.height)||this.size.height}}createDom(){const{width:t,height:i}=this.defaultSize,o=window.document.createElement("div");o.style.position="absolute",o.style.left="0",o.style.top="0",o.style.width=`${t}px`,o.style.height=`${i}px`;const s=this.toolOperationList.length+1;return o.style.zIndex=`${s}`,o}getEmptyImage(t,i){const o=D({width:t,height:i}),s=new Image;return s.src=o,s}createOperation(t,i,o){var s;const{width:a,height:l}=this.defaultSize,r=this.createDom(),d=this.getEmptyImage(a,l),h={container:r,size:this.size,config:(s=this==null?void 0:this.config)!=null?s:"{}",drawOutSideTarget:!1,style:this.style,imgNode:i||d,hiddenImg:!!t};o&&Object.assign(h,o);let n;if(!t)n=new v(h),r.style.zIndex="0",n.init();else{const c=y(t);if(!c)return;n=new c(h)}return n==null||n.init(),n.canvas.id=t!=null?t:"basicCanvas",n.on("dragMove",({currentPos:c,zoom:m,imgInfo:O})=>{this.syncPosition(c,m,O,n)}),n.on("renderZoom",(c,m,O)=>{c&&m&&this.syncPosition(m,c,O,n)}),t?(this.container.appendChild(r),this.toolOperationList.push(n),this.toolOperationNameList.push(t),this.toolOperationDom.push(r),n):(this.container.insertBefore(r,this.container.childNodes[0]),this.toolOperationList.unshift(n),this.toolOperationDom.unshift(r),n)}switchLastTwoCanvas(){if(this.toolOperationDom.length<3){console.error("switchLastTwoCanvas is just used the layer which has 3 canvas");return}const t=this.toolOperationDom.length,i=t-1,o=t-2,s=this.toolOperationDom[i],a=this.toolOperationDom[o];if(!(!a||!s))return s.style.zIndex=`${i-1}`,a.style.zIndex=`${i}`,this.toolOperationList[i].clearActiveStatus(),this.toolOperationList[i].clearCursorLine(),this.toolOperationList[i].render(),this.toolOperationList=p(this.toolOperationList,i,o),this.toolOperationDom=p(this.toolOperationDom,i,o),this.toolOperationList[i]}getFirstToolOperation(){return this.toolOperationList.length>1?this.toolOperationList[1]:this.toolOperationList[0]}switchToCanvas(t){var i,o,s,a;const l=this.toolOperationNameList.indexOf(t);if(l<0||this.toolOperationList.length<1||l>this.toolOperationDom.length-1)return;const r=this.toolOperationDom.length-1,d=this.toolOperationDom[l],h=this.toolOperationDom[r];if(!d||!h)return;const n=h.style.zIndex;return h.style.zIndex=`${d.style.zIndex}`,d.style.zIndex=`${n}`,(o=(i=this.toolOperationList[r]).clearActiveStatus)==null||o.call(i),(a=(s=this.toolOperationList[r]).clearCursorLine)==null||a.call(s),this.toolOperationList[r].render(),this.toolOperationList=p(this.toolOperationList,r,l),this.toolOperationDom=p(this.toolOperationDom,r,l),this.toolOperationNameList=p(this.toolOperationNameList,r,l),this.toolOperationList[r]}updateDataByToolName(t,i){const o=this.toolOperationNameList.indexOf(t);o>=0&&this.toolOperationList[o].setResult(i)}clearStatusAndResult(){this.toolOperationList.forEach(t=>{var i;(i=t.clearActiveStatus)==null||i.call(t),t.clearResult()})}destroyAllLayer(){this.toolOperationList.forEach(t=>{t.destroyCanvas(),this.init()})}init(){this.toolOperationList=[],this.toolOperationDom=[]}}export{u as HybridToolUtils,I as ToolScheduler};