@labelbee/lb-annotation 1.21.0-dev.1 → 1.21.0-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- "use strict";var lbUtils=require("@labelbee/lb-utils"),keyCode=require("../../constant/keyCode.js"),RectUtils=require("../../utils/tool/RectUtils.js"),uuid=require("../../utils/uuid.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),SAMToolbarClass=require("./SAMToolbarClass.js"),segmentByRect=require("./segmentByRect.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(s,t,e)=>t in s?__defProp(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,__spreadValues=(s,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(s,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(s,e,t[e]);return s},__spreadProps=(s,t)=>__defProps(s,__getOwnPropDescs(t)),__async=(s,t,e)=>new Promise((i,r)=>{var a=o=>{try{n(e.next(o))}catch(d){r(d)}},l=o=>{try{n(e.throw(o))}catch(d){r(d)}},n=o=>o.done?i(o.value):Promise.resolve(o.value).then(a,l);n((e=e.apply(s,t)).next())});class SegmentBySAM extends segmentByRect{constructor(t){super(t);this.segmentPrediction=e=>__async(this,null,function*(){var i,r,a,l;if(this.isRunSegment)return;const n=this.getCoordinateInOrigin(e);if(!RectUtils.isInRect(n,this.rectList[0],0,1)){(i=this.onOutSide)==null||i.call(this);return}if(this.clickType==="add"&&this.addPoints.push([n.x,n.y]),this.clickType==="remove"&&this.removePoints.push([n.x,n.y]),this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}(r=this.toolbarInstance)==null||r.setDisabled(!0);try{const d=yield this.runPrediction({addPoints:this.addPoints,removePoints:this.removePoints,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),c=d==null?void 0:d.filter(h=>{var u;return((u=h==null?void 0:h.pointList)==null?void 0:u.length)>2}).map(h=>__spreadProps(__spreadValues({},h),{id:uuid(),attribute:this.defaultAttribute}));this.predictionResult=c,(a=this.SAMHistory)==null||a.pushHistory(this.predictionResult)}finally{(l=this.toolbarInstance)==null||l.setDisabled(!1),this.isRunSegment=!1}}),this.clickType="add",this.addPoints=[],this.removePoints=[],this.predictionResult=[],this.onOutSide=t.onOutSide,this.onFinish=t.onFinish,this.SAMHistory=new ActionsHistory,this.clearPredictionInfo=this.clearPredictionInfo.bind(this),this.onLanguageChanged=this.onLanguageChanged.bind(this)}onKeydown(t){switch(super.onKeydown(t),t.keyCode){case keyCode.Minus:this.toggleClickType("remove");break;case keyCode.Equal:this.toggleClickType("add");break}}onMouseUp(t){var e;if(t.button===0&&((e=this.rectList)==null?void 0:e.length)){this.segmentPrediction(t);return}super.onMouseUp(t)}eventBinding(){super.eventBinding(),lbUtils.i18n.on("languageChanged",this.onLanguageChanged)}eventUnbinding(){super.eventUnbinding(),lbUtils.i18n.off("languageChanged",this.onLanguageChanged)}setOnOutSide(t){this.onOutSide=t}onMouseDown(t){var e;t.button===0&&((e=this.rectList)==null?void 0:e.length)||super.onMouseDown(t)}onLanguageChanged(){var t;(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,this.renderToolbar()}drawPredictionResult(){var t;const e=this.getColor(this.defaultAttribute);(t=this.predictionResult)==null||t.forEach(i=>{this.drawPolygon(i,e)})}drawPolygon(t,e){var i,r;const a=AxisUtils.default.changePointListByZoom(t.pointList,this.zoom,this.currentPos),l=StyleUtils.getStrokeAndFill(e,!0,{isHover:!0});DrawUtils.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:l.fill,strokeColor:l.stroke,thickness:(r=(i=this.style)==null?void 0:i.width)!=null?r:2,lineType:lbUtils.ELineTypes.Line})}clearPredictionInfo(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,super.clearPredictionInfo(),this.render()}renderToolbar(){const t=this.rectList[0];if(!t)return;this.toolbarInstance||(this.toolbarInstance=new SAMToolbarClass.default({container:this.container,toggleClickType:i=>this.toggleClickType(i),finish:()=>{var i,r;(r=this.onFinish)==null||r.call(this,(i=this.predictionResult)!=null?i:[]),this.clearPredictionInfo()},reset:()=>this.reset(),i18n:lbUtils.i18n}));const e=SAMToolbarClass.getSAMToolbarOffset({rect:t,zoom:this.zoom,currentPos:this.currentPos});this.toolbarInstance.update(e)}toggleClickType(t){var e;this.clickType=t,(e=this.toolbarInstance)==null||e.onToggle(t),this.render()}reset(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.SAMHistory)==null||t.empty(),this.render()}cursorText(){var t;let e=`\u2460 ${lbUtils.i18n.t("PleaseFrameTheObjectToBeDividedFirst")}`;return((t=this.rectList)==null?void 0:t.length)===1&&(this.clickType==="add"&&(e=this.addPoints.length===0?`\u2461 ${lbUtils.i18n.t("ClickOnTheTargetObjectToSplitIt")}`:`\u2461 ${lbUtils.i18n.t("ClickTheTargetObjectAgainToIncreaseTheSegmentation")}`),this.clickType==="remove"&&(e=this.removePoints.length===0?`\u2461 ${lbUtils.i18n.t("ClickOnTheTargetObjectToDeleteTheSegmentation")}`:`\u2461 ${lbUtils.i18n.t("ClickAgainOnTheTargetObjectToDeleteTheSegmentation")}`)),this.isRunSegment&&(e=lbUtils.i18n.t("SplittingAlgorithmPrediction")),e}undo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.undo();this.predictionResult=e,this.render()}redo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.redo();this.predictionResult=e,this.render()}render(){var t,e;if(super.render(),(t=this.rectList)==null?void 0:t.length){this.renderToolbar(),this.drawPredictionResult();return}(e=this.toolbarInstance)==null||e.clearToolbarDOM(),this.toolbarInstance=void 0}}module.exports=SegmentBySAM;
1
+ "use strict";var lbUtils=require("@labelbee/lb-utils"),keyCode=require("../../constant/keyCode.js"),RectUtils=require("../../utils/tool/RectUtils.js"),uuid=require("../../utils/uuid.js"),DrawUtils=require("../../utils/tool/DrawUtils.js"),AxisUtils=require("../../utils/tool/AxisUtils.js"),StyleUtils=require("../../utils/tool/StyleUtils.js"),ActionsHistory=require("../../utils/ActionsHistory.js"),SAMToolbarClass=require("./SAMToolbarClass.js"),segmentByRect=require("./segmentByRect.js"),__defProp=Object.defineProperty,__defProps=Object.defineProperties,__getOwnPropDescs=Object.getOwnPropertyDescriptors,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(s,t,e)=>t in s?__defProp(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,__spreadValues=(s,t)=>{for(var e in t||(t={}))__hasOwnProp.call(t,e)&&__defNormalProp(s,e,t[e]);if(__getOwnPropSymbols)for(var e of __getOwnPropSymbols(t))__propIsEnum.call(t,e)&&__defNormalProp(s,e,t[e]);return s},__spreadProps=(s,t)=>__defProps(s,__getOwnPropDescs(t)),__async=(s,t,e)=>new Promise((i,n)=>{var l=r=>{try{a(e.next(r))}catch(h){n(h)}},o=r=>{try{a(e.throw(r))}catch(h){n(h)}},a=r=>r.done?i(r.value):Promise.resolve(r.value).then(l,o);a((e=e.apply(s,t)).next())});class SegmentBySAM extends segmentByRect{constructor(t){super(t);this.segmentPrediction=e=>__async(this,null,function*(){var i,n,l,o,a,r,h,c;if(this.isRunSegment)return;const d=this.getCoordinateInOrigin(e),p={x:0,y:0,width:(n=(i=this.basicImgInfo)==null?void 0:i.width)!=null?n:0,height:(o=(l=this.basicImgInfo)==null?void 0:l.height)!=null?o:0};if(!RectUtils.isInRect(d,p,0,1)){(a=this.onOutSide)==null||a.call(this);return}if(this.clickType==="add"&&this.addPoints.push([d.x,d.y]),this.clickType==="remove"&&this.removePoints.push([d.x,d.y]),this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}(r=this.toolbarInstance)==null||r.setDisabled(!0);try{const g=yield this.runPrediction({addPoints:this.addPoints,removePoints:this.removePoints,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),f=g==null?void 0:g.filter(u=>{var v;return((v=u==null?void 0:u.pointList)==null?void 0:v.length)>2}).map(u=>__spreadProps(__spreadValues({},u),{id:uuid(),attribute:this.defaultAttribute}));this.predictionResult=f,(h=this.SAMHistory)==null||h.pushHistory(this.predictionResult)}finally{(c=this.toolbarInstance)==null||c.setDisabled(!1),this.isRunSegment=!1}}),this.clickType="add",this.addPoints=[],this.removePoints=[],this.predictionResult=[],this.onOutSide=t.onOutSide,this.onFinish=t.onFinish,this.SAMHistory=new ActionsHistory,this.clearPredictionInfo=this.clearPredictionInfo.bind(this),this.onLanguageChanged=this.onLanguageChanged.bind(this)}onKeydown(t){switch(super.onKeydown(t),t.keyCode){case keyCode.Minus:this.toggleClickType("remove");break;case keyCode.Equal:this.toggleClickType("add");break}}onMouseUp(t){var e;if(t.button===0&&((e=this.rectList)==null?void 0:e.length)){this.segmentPrediction(t);return}super.onMouseUp(t)}eventBinding(){super.eventBinding(),lbUtils.i18n.on("languageChanged",this.onLanguageChanged)}eventUnbinding(){super.eventUnbinding(),lbUtils.i18n.off("languageChanged",this.onLanguageChanged)}setOnOutSide(t){this.onOutSide=t}onMouseDown(t){var e;t.button===0&&((e=this.rectList)==null?void 0:e.length)||super.onMouseDown(t)}onLanguageChanged(){var t;(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,this.renderToolbar()}drawPredictionResult(){var t;const e=this.getColor(this.defaultAttribute);(t=this.predictionResult)==null||t.forEach(i=>{this.drawPolygon(i,e)})}drawPolygon(t,e){var i,n;const l=AxisUtils.default.changePointListByZoom(t.pointList,this.zoom,this.currentPos),o=StyleUtils.getStrokeAndFill(e,!0,{isHover:!0});DrawUtils.drawPolygonWithFillAndLine(this.canvas,l,{fillColor:o.fill,strokeColor:o.stroke,thickness:(n=(i=this.style)==null?void 0:i.width)!=null?n:2,lineType:lbUtils.ELineTypes.Line})}clearPredictionInfo(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,super.clearPredictionInfo(),this.render()}renderToolbar(){const t=this.rectList[0];if(!t)return;this.toolbarInstance||(this.toolbarInstance=new SAMToolbarClass.default({container:this.container,toggleClickType:i=>this.toggleClickType(i),finish:()=>{var i,n;(n=this.onFinish)==null||n.call(this,(i=this.predictionResult)!=null?i:[]),this.clearPredictionInfo()},reset:()=>this.reset(),i18n:lbUtils.i18n}));const e=SAMToolbarClass.getSAMToolbarOffset({rect:t,zoom:this.zoom,currentPos:this.currentPos});this.toolbarInstance.update(e)}toggleClickType(t){var e;this.clickType=t,(e=this.toolbarInstance)==null||e.onToggle(t),this.render()}reset(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.SAMHistory)==null||t.empty(),this.render()}cursorText(){var t;let e=`\u2460 ${lbUtils.i18n.t("PleaseFrameTheObjectToBeDividedFirst")}`;return((t=this.rectList)==null?void 0:t.length)===1&&(this.clickType==="add"&&(e=this.addPoints.length===0?`\u2461 ${lbUtils.i18n.t("ClickOnTheTargetObjectToSplitIt")}`:`\u2461 ${lbUtils.i18n.t("ClickTheTargetObjectAgainToIncreaseTheSegmentation")}`),this.clickType==="remove"&&(e=this.removePoints.length===0?`\u2461 ${lbUtils.i18n.t("ClickOnTheTargetObjectToDeleteTheSegmentation")}`:`\u2461 ${lbUtils.i18n.t("ClickAgainOnTheTargetObjectToDeleteTheSegmentation")}`)),this.isRunSegment&&(e=lbUtils.i18n.t("SplittingAlgorithmPrediction")),e}undo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.undo();this.predictionResult=e,this.render()}redo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.redo();this.predictionResult=e,this.render()}render(){var t,e;if(super.render(),(t=this.rectList)==null?void 0:t.length){this.renderToolbar(),this.drawPredictionResult();return}(e=this.toolbarInstance)==null||e.clearToolbarDOM(),this.toolbarInstance=void 0}}module.exports=SegmentBySAM;
@@ -39,7 +39,7 @@ export default class RectUtils {
39
39
  * @param scope
40
40
  * @param zoom
41
41
  */
42
- static isInRect(coordinate: ICoordinate, rect: IRect, scope?: number, zoom?: number): boolean;
42
+ static isInRect(coordinate: ICoordinate, rect: Pick<IRect, 'x' | 'y' | 'width' | 'height'>, scope?: number, zoom?: number): boolean;
43
43
  /**
44
44
  * rect 与 zoom 的乘积
45
45
  * @param rect
@@ -1 +1 @@
1
- import{i18n as n,ELineTypes as m}from"@labelbee/lb-utils";import g from"../../constant/keyCode.js";import y from"../../utils/tool/RectUtils.js";import b from"../../utils/uuid.js";import P from"../../utils/tool/DrawUtils.js";import T from"../../utils/tool/AxisUtils.js";import _ from"../../utils/tool/StyleUtils.js";import O from"../../utils/ActionsHistory.js";import S,{getSAMToolbarOffset as w}from"./SAMToolbarClass.js";import C from"./segmentByRect.js";var I=Object.defineProperty,k=Object.defineProperties,L=Object.getOwnPropertyDescriptors,v=Object.getOwnPropertySymbols,A=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,p=(o,t,e)=>t in o?I(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,j=(o,t)=>{for(var e in t||(t={}))A.call(t,e)&&p(o,e,t[e]);if(v)for(var e of v(t))R.call(t,e)&&p(o,e,t[e]);return o},M=(o,t)=>k(o,L(t)),D=(o,t,e)=>new Promise((i,s)=>{var h=l=>{try{r(e.next(l))}catch(d){s(d)}},a=l=>{try{r(e.throw(l))}catch(d){s(d)}},r=l=>l.done?i(l.value):Promise.resolve(l.value).then(h,a);r((e=e.apply(o,t)).next())});class U extends C{constructor(t){super(t);this.segmentPrediction=e=>D(this,null,function*(){var i,s,h,a;if(this.isRunSegment)return;const r=this.getCoordinateInOrigin(e);if(!y.isInRect(r,this.rectList[0],0,1)){(i=this.onOutSide)==null||i.call(this);return}if(this.clickType==="add"&&this.addPoints.push([r.x,r.y]),this.clickType==="remove"&&this.removePoints.push([r.x,r.y]),this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}(s=this.toolbarInstance)==null||s.setDisabled(!0);try{const d=yield this.runPrediction({addPoints:this.addPoints,removePoints:this.removePoints,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),f=d==null?void 0:d.filter(c=>{var u;return((u=c==null?void 0:c.pointList)==null?void 0:u.length)>2}).map(c=>M(j({},c),{id:b(),attribute:this.defaultAttribute}));this.predictionResult=f,(h=this.SAMHistory)==null||h.pushHistory(this.predictionResult)}finally{(a=this.toolbarInstance)==null||a.setDisabled(!1),this.isRunSegment=!1}}),this.clickType="add",this.addPoints=[],this.removePoints=[],this.predictionResult=[],this.onOutSide=t.onOutSide,this.onFinish=t.onFinish,this.SAMHistory=new O,this.clearPredictionInfo=this.clearPredictionInfo.bind(this),this.onLanguageChanged=this.onLanguageChanged.bind(this)}onKeydown(t){switch(super.onKeydown(t),t.keyCode){case g.Minus:this.toggleClickType("remove");break;case g.Equal:this.toggleClickType("add");break}}onMouseUp(t){var e;if(t.button===0&&((e=this.rectList)==null?void 0:e.length)){this.segmentPrediction(t);return}super.onMouseUp(t)}eventBinding(){super.eventBinding(),n.on("languageChanged",this.onLanguageChanged)}eventUnbinding(){super.eventUnbinding(),n.off("languageChanged",this.onLanguageChanged)}setOnOutSide(t){this.onOutSide=t}onMouseDown(t){var e;t.button===0&&((e=this.rectList)==null?void 0:e.length)||super.onMouseDown(t)}onLanguageChanged(){var t;(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,this.renderToolbar()}drawPredictionResult(){var t;const e=this.getColor(this.defaultAttribute);(t=this.predictionResult)==null||t.forEach(i=>{this.drawPolygon(i,e)})}drawPolygon(t,e){var i,s;const h=T.changePointListByZoom(t.pointList,this.zoom,this.currentPos),a=_.getStrokeAndFill(e,!0,{isHover:!0});P.drawPolygonWithFillAndLine(this.canvas,h,{fillColor:a.fill,strokeColor:a.stroke,thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineType:m.Line})}clearPredictionInfo(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,super.clearPredictionInfo(),this.render()}renderToolbar(){const t=this.rectList[0];if(!t)return;this.toolbarInstance||(this.toolbarInstance=new S({container:this.container,toggleClickType:i=>this.toggleClickType(i),finish:()=>{var i,s;(s=this.onFinish)==null||s.call(this,(i=this.predictionResult)!=null?i:[]),this.clearPredictionInfo()},reset:()=>this.reset(),i18n:n}));const e=w({rect:t,zoom:this.zoom,currentPos:this.currentPos});this.toolbarInstance.update(e)}toggleClickType(t){var e;this.clickType=t,(e=this.toolbarInstance)==null||e.onToggle(t),this.render()}reset(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.SAMHistory)==null||t.empty(),this.render()}cursorText(){var t;let e=`\u2460 ${n.t("PleaseFrameTheObjectToBeDividedFirst")}`;return((t=this.rectList)==null?void 0:t.length)===1&&(this.clickType==="add"&&(e=this.addPoints.length===0?`\u2461 ${n.t("ClickOnTheTargetObjectToSplitIt")}`:`\u2461 ${n.t("ClickTheTargetObjectAgainToIncreaseTheSegmentation")}`),this.clickType==="remove"&&(e=this.removePoints.length===0?`\u2461 ${n.t("ClickOnTheTargetObjectToDeleteTheSegmentation")}`:`\u2461 ${n.t("ClickAgainOnTheTargetObjectToDeleteTheSegmentation")}`)),this.isRunSegment&&(e=n.t("SplittingAlgorithmPrediction")),e}undo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.undo();this.predictionResult=e,this.render()}redo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.redo();this.predictionResult=e,this.render()}render(){var t,e;if(super.render(),(t=this.rectList)==null?void 0:t.length){this.renderToolbar(),this.drawPredictionResult();return}(e=this.toolbarInstance)==null||e.clearToolbarDOM(),this.toolbarInstance=void 0}}export{U as default};
1
+ import{i18n as r,ELineTypes as _}from"@labelbee/lb-utils";import f from"../../constant/keyCode.js";import T from"../../utils/tool/RectUtils.js";import O from"../../utils/uuid.js";import S from"../../utils/tool/DrawUtils.js";import w from"../../utils/tool/AxisUtils.js";import I from"../../utils/tool/StyleUtils.js";import C from"../../utils/ActionsHistory.js";import k,{getSAMToolbarOffset as R}from"./SAMToolbarClass.js";import A from"./segmentByRect.js";var L=Object.defineProperty,j=Object.defineProperties,M=Object.getOwnPropertyDescriptors,m=Object.getOwnPropertySymbols,D=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,y=(o,t,e)=>t in o?L(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e,x=(o,t)=>{for(var e in t||(t={}))D.call(t,e)&&y(o,e,t[e]);if(m)for(var e of m(t))U.call(t,e)&&y(o,e,t[e]);return o},H=(o,t)=>j(o,M(t)),B=(o,t,e)=>new Promise((i,s)=>{var a=n=>{try{h(e.next(n))}catch(d){s(d)}},l=n=>{try{h(e.throw(n))}catch(d){s(d)}},h=n=>n.done?i(n.value):Promise.resolve(n.value).then(a,l);h((e=e.apply(o,t)).next())});class E extends A{constructor(t){super(t);this.segmentPrediction=e=>B(this,null,function*(){var i,s,a,l,h,n,d,g;if(this.isRunSegment)return;const c=this.getCoordinateInOrigin(e),b={x:0,y:0,width:(s=(i=this.basicImgInfo)==null?void 0:i.width)!=null?s:0,height:(l=(a=this.basicImgInfo)==null?void 0:a.height)!=null?l:0};if(!T.isInRect(c,b,0,1)){(h=this.onOutSide)==null||h.call(this);return}if(this.clickType==="add"&&this.addPoints.push([c.x,c.y]),this.clickType==="remove"&&this.removePoints.push([c.x,c.y]),this.isRunSegment=!0,this.render(),!this.runPrediction){this.emit("messageError","You needs to set runPrediction function"),this.clearPredictionInfo();return}(n=this.toolbarInstance)==null||n.setDisabled(!0);try{const v=yield this.runPrediction({addPoints:this.addPoints,removePoints:this.removePoints,rect:{x:this.rectList[0].x,y:this.rectList[0].y,w:this.rectList[0].width,h:this.rectList[0].height}}),P=v==null?void 0:v.filter(u=>{var p;return((p=u==null?void 0:u.pointList)==null?void 0:p.length)>2}).map(u=>H(x({},u),{id:O(),attribute:this.defaultAttribute}));this.predictionResult=P,(d=this.SAMHistory)==null||d.pushHistory(this.predictionResult)}finally{(g=this.toolbarInstance)==null||g.setDisabled(!1),this.isRunSegment=!1}}),this.clickType="add",this.addPoints=[],this.removePoints=[],this.predictionResult=[],this.onOutSide=t.onOutSide,this.onFinish=t.onFinish,this.SAMHistory=new C,this.clearPredictionInfo=this.clearPredictionInfo.bind(this),this.onLanguageChanged=this.onLanguageChanged.bind(this)}onKeydown(t){switch(super.onKeydown(t),t.keyCode){case f.Minus:this.toggleClickType("remove");break;case f.Equal:this.toggleClickType("add");break}}onMouseUp(t){var e;if(t.button===0&&((e=this.rectList)==null?void 0:e.length)){this.segmentPrediction(t);return}super.onMouseUp(t)}eventBinding(){super.eventBinding(),r.on("languageChanged",this.onLanguageChanged)}eventUnbinding(){super.eventUnbinding(),r.off("languageChanged",this.onLanguageChanged)}setOnOutSide(t){this.onOutSide=t}onMouseDown(t){var e;t.button===0&&((e=this.rectList)==null?void 0:e.length)||super.onMouseDown(t)}onLanguageChanged(){var t;(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,this.renderToolbar()}drawPredictionResult(){var t;const e=this.getColor(this.defaultAttribute);(t=this.predictionResult)==null||t.forEach(i=>{this.drawPolygon(i,e)})}drawPolygon(t,e){var i,s;const a=w.changePointListByZoom(t.pointList,this.zoom,this.currentPos),l=I.getStrokeAndFill(e,!0,{isHover:!0});S.drawPolygonWithFillAndLine(this.canvas,a,{fillColor:l.fill,strokeColor:l.stroke,thickness:(s=(i=this.style)==null?void 0:i.width)!=null?s:2,lineType:_.Line})}clearPredictionInfo(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.toolbarInstance)==null||t.clearToolbarDOM(),this.toolbarInstance=void 0,super.clearPredictionInfo(),this.render()}renderToolbar(){const t=this.rectList[0];if(!t)return;this.toolbarInstance||(this.toolbarInstance=new k({container:this.container,toggleClickType:i=>this.toggleClickType(i),finish:()=>{var i,s;(s=this.onFinish)==null||s.call(this,(i=this.predictionResult)!=null?i:[]),this.clearPredictionInfo()},reset:()=>this.reset(),i18n:r}));const e=R({rect:t,zoom:this.zoom,currentPos:this.currentPos});this.toolbarInstance.update(e)}toggleClickType(t){var e;this.clickType=t,(e=this.toolbarInstance)==null||e.onToggle(t),this.render()}reset(){var t;this.addPoints=[],this.removePoints=[],this.predictionResult=[],(t=this.SAMHistory)==null||t.empty(),this.render()}cursorText(){var t;let e=`\u2460 ${r.t("PleaseFrameTheObjectToBeDividedFirst")}`;return((t=this.rectList)==null?void 0:t.length)===1&&(this.clickType==="add"&&(e=this.addPoints.length===0?`\u2461 ${r.t("ClickOnTheTargetObjectToSplitIt")}`:`\u2461 ${r.t("ClickTheTargetObjectAgainToIncreaseTheSegmentation")}`),this.clickType==="remove"&&(e=this.removePoints.length===0?`\u2461 ${r.t("ClickOnTheTargetObjectToDeleteTheSegmentation")}`:`\u2461 ${r.t("ClickAgainOnTheTargetObjectToDeleteTheSegmentation")}`)),this.isRunSegment&&(e=r.t("SplittingAlgorithmPrediction")),e}undo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.undo();this.predictionResult=e,this.render()}redo(){var t;const e=(t=this.SAMHistory)==null?void 0:t.redo();this.predictionResult=e,this.render()}render(){var t,e;if(super.render(),(t=this.rectList)==null?void 0:t.length){this.renderToolbar(),this.drawPredictionResult();return}(e=this.toolbarInstance)==null||e.clearToolbarDOM(),this.toolbarInstance=void 0}}export{E as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labelbee/lb-annotation",
3
- "version": "1.21.0-dev.1",
3
+ "version": "1.21.0-dev.2",
4
4
  "description": "Annotation tool collection",
5
5
  "keywords": [
6
6
  "annotation",