UNPKG

mskalign-canvas

Version:

一个用于图片标注的javascript库,基于canvas,简单轻量,支持矩形、多边形、点、折线、圆形。

15 lines (13 loc) 80.5 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).MskalignCanvas=e()}(this,(function(){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},t(e,i)};function e(e,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function a(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(a.prototype=i.prototype,new a)}var i=function(){return i=Object.assign||function(t){for(var e,i=1,a=arguments.length;i<a;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},i.apply(this,arguments)};function a(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var a,n,s=i.call(t),o=[];try{for(;(void 0===e||e-- >0)&&!(a=s.next()).done;)o.push(a.value)}catch(t){n={error:t}}finally{try{a&&!a.done&&(i=s.return)&&i.call(s)}finally{if(n)throw n.error}}return o}function n(t,e){for(var i=0,a=e.length,n=t.length;i<a;i++,n++)t[n]=e[i];return t}function s(){for(var t=[],e="0123456789abcdef",i=0;i<36;i++){var a=Math.floor(16*Math.random());t[i]=e.slice(a,a+1)}t[14]="4";var n=3&t[19]|8;return t[19]=e.slice(n,n+1),t[8]=t[13]=t[18]=t[23]="-",t.join("")}function o(t,e,i){for(var a=!1,n=i.length,s=0,o=n-1;s<n;o=s++){var r=i[s][0],h=i[s][1],c=i[o][0],l=i[o][1];h>e!=l>e&&t<(c-r)*(e-h)/(l-h)+r&&(a=!a)}return a}function r(t,e,i,s){var o=t.slice(0,e),r=new Array(i-e+1).fill(s),h=t.slice(i+1);return n(n(n([],a(o)),a(r)),a(h))}var h=function(t,e){this.coor=[],this.components=[],this.isComponent=!1,this.isDisableDelByKey=!1,this.relativeInfo=[],this.relativePoints=[],this.relativeAuxLineIds=[],this.hide=!1,this.hideInSnapshot=!1,this.disable=!1,this.isEdit=!1,this.direction=0,this.pixelSpacing=0,this.apex=null,this.vertebra=null,this.isCtrlShape=!1,this.active=!1,this.activeComponent=!1,this.creating=!1,this.dragging=!1,this.dragAxle="",this.isDash=!1,this.uuid=s(),this.label="",this.labelValue="",this.labelRadius=20,this.angle=null,this.distance=0,this.mark="",this.remark="",this.dragPointAxle="",this.index=e,this.initialVal=t.initialVal?i({},t.initialVal):i({},t),Object.assign(this,t)},c=function(t){function i(e,i){var a=t.call(this,e,i)||this;return a.name="Rect",a.type=1,a}return e(i,t),Object.defineProperty(i.prototype,"ctrlPoints",{get:function(){var t=a(this.coor,2),e=a(t[0],2),i=e[0],n=e[1],s=a(t[1],2),o=s[0],r=s[1];return this.disable||this.hideCtrlDots?[]:[[i,n],[i+(o-i)/2,n],[o,n],[o,n+(r-n)/2],[o,r],[i+(o-i)/2,r],[i,r],[i,n+(r-n)/2]]},enumerable:!1,configurable:!0}),i}(h),l=function(t){function i(e,i){var a=t.call(this,e,i)||this;return a.name="Polygon",a.type=2,a.maxPoints=0,a.maxPoints=e.maxPoints||0,a}return e(i,t),Object.defineProperty(i.prototype,"ctrlPoints",{get:function(){return this.disable||this.hideCtrlDots?[]:this.coor.length>2?this.coor:[]},enumerable:!1,configurable:!0}),i}(h),u=function(t){function i(e,i){var a=t.call(this,e,i)||this;return a.name="Dot",a.type=3,a.outDashDistance=0,a.outDashDistance=e.outDashDistance||0,a}return e(i,t),Object.defineProperty(i.prototype,"ctrlPoints",{get:function(){return this.disable||this.hideCtrlDots?[]:this.coor&&this.coor.length?this.coor:[]},enumerable:!1,configurable:!0}),i}(h),p=function(t){function i(e,i){var a=t.call(this,e,i)||this;return a.name="Line",a.type=4,a.isClose=!1,a.maxPoints=0,a.disableDotLength=0,a.disableStartIndex=0,a.dashIndex=0,a.dashStartIndex=0,a.relevantUUIdList=[],a.attribute="",a.attribute=e.attribute||"",a.maxPoints=e.maxPoints||0,a.dashIndex=e.dashIndex||0,a.dashStartIndex=e.dashStartIndex||0,a.disableStartIndex=e.disableStartIndex||0,a.disableDotLength=e.disableDotLength||0,a.relevantUUIdList=e.relevantUUIdList||[],a}return e(i,t),Object.defineProperty(i.prototype,"ctrlPoints",{get:function(){if(this.disable||!this.coor)return[];var t=this.coor;return this.disableDotLength?r(t,this.disableStartIndex,this.disableDotLength,[]):t.length>1?t:[]},enumerable:!1,configurable:!0}),i}(h),d=function(t){function i(e,i){var a=t.call(this,e,i)||this;return a.name="Circle",a.type=5,a.radius=0,a.radius=e.radius||a.radius,a}return e(i,t),Object.defineProperty(i.prototype,"ctrlPoints",{get:function(){if(this.disable||this.hideCtrlDots)return[];var t=a(this.coor[0],2),e=t[0],i=t[1];return[[e,i-this.radius],[e+this.radius,i],[e,i+this.radius],[e-this.radius,i]]},enumerable:!1,configurable:!0}),i}(h),f=function(t){function i(e,i){var a=t.call(this,e,i)||this;return a.name="Angle",a.type=6,a.flexiblePointIndex=-1,a.isHideLinkLine=!1,a.forceAngel=!1,a.secondLineLength=1e6,a.angle=0,a.forceAngel=e.forceAngel||!1,a.angle=e.angle||0,a.isHideLinkLine=e.isHideLinkLine||!1,a.flexiblePointIndex=e.flexiblePointIndex>=0?e.flexiblePointIndex:-1,a}return e(i,t),Object.defineProperty(i.prototype,"ctrlPoints",{get:function(){return this.disable||this.hideCtrlDots?[]:this.coor.length<=4?this.coor:[]},enumerable:!1,configurable:!0}),i}(h),v=function(t){function i(e,i){var a=t.call(this,e,i)||this;return a.name="Arrow",a.type=7,a.maxPoints=2,a.disableDotLength=0,a.disableStartIndex=0,a.dashIndex=0,a.dashStartIndex=0,a.attribute="",a.attribute=e.attribute||"",a.dashIndex=e.dashIndex||0,a.dashStartIndex=e.dashStartIndex||0,a.disableStartIndex=e.disableStartIndex||0,a.disableDotLength=e.disableDotLength||0,a}return e(i,t),Object.defineProperty(i.prototype,"ctrlPoints",{get:function(){if(this.disable||!this.coor)return[];var t=this.coor;return this.disableDotLength?r(t,this.disableStartIndex,this.disableDotLength,[]):t.length>1?t:[]},enumerable:!1,configurable:!0}),i}(h);function g(t,e,i,a){var n=1*(t[1]-e[1])/(t[0]-e[0]);if(isNaN(n)||n===1/0||n===-1/0||0===n)return function(t,e,i,a){var n=t[1]-e[1],s=t[0]-e[0],o=[0,0];return 0===n?(o[1]=e[1]-a,o[0]=i[0]):0===s&&(o[0]=e[0]-a,o[1]=i[1]),o}(t,e,i,a);var s=t[1]-n*t[0],o=i[0]+n*i[1],r=[0,0];r[0]=1*(o-n*s)/(n*n+1),r[1]=n*r[0]+s;var h=t[0]-e[0],c=e[1]-t[1],l=Math.atan(c/h)*(180/Math.PI);return[r[0]-a*Math.sin(l/180*Math.PI),r[1]-a*Math.cos(l/180*Math.PI)]}function m(t,e){void 0===e&&(e=1);var i=a(t,2),n=i[0],s=i[1],o=a(n,2),r=o[0],h=o[1],c=a(s,2);return[(r+c[0])/2*e,(h+c[1])/2*e]}function y(t,e,i,n){var s=e.offsetX,o=e.offsetY,r=i.w,h=i.h,c=[],l=[],u=!0,p=t.dragAxle,d=t.coor,f="x"===p||""===p,v="y"===p||""===p;if([3,5].includes(t.type)){var g=a(n[0].points[0],2),m=g[0],S=g[1],b=a(d[0],2),I=b[0],x=b[1],M=v?o-S:x;((P=f?s-m:I)<0||P>r||M<0||M>h)&&(u=!1),c=[[P,M]]}else if(100===t.type){l=t.components;for(var C=(null==t?void 0:t.sharePoints)||[],T=function(e){var i=t.components[e];if(i.activeComponent){var c=y(i,{offsetX:s,offsetY:o},{w:r,h:h},[n[e]]);i.coor=c.coor,l[e]=i,u=c.noLimit}else l[e]=i;var p=C.filter((function(t){return i.activeComponent&&t.uuid===i.uuid})),d=[0,1];p&&p.length&&p.forEach((function(t){var e=t.targetShapeIndex,i=t.targetShapePointIndex,r=t.currentShape,h=t.targetShapePointAxle,c=d.includes(h)?h:-1,u=r.dragAxle,p="x"===u||""===u,f="y"===u||""===u;0===c&&(p=!0,f=!1),1===c&&(f=!0,p=!1);var v=l[e].coor[i],g=a(n[e].points[i],2),m=g[0],y=g[1],S=p?s-m:v[0],b=f?o-y:v[1];l[e].coor[i]=[S,b]}))},w=0;w<t.components.length;w++)T(w)}else for(w=0;w<d.length;w++){var D=n[0];if(t&&D&&D.uuid===t.uuid&&D.points&&D.points.length){var E=a(d[w],2),P=(I=E[0],x=E[1],f?s-D.points[w][0]:I);M=v?o-D.points[w][1]:x;(P<0||P>r||M<0||M>h)&&(6!==t.type||t.forceAngel||(u=!1)),c.push([P,M])}}return{noLimit:u,coor:c,components:l}}var S=function(t,e,i,n){var s=n.originX,o=n.originY,r=n.scale,h=n.creating,c=a(t,2),l=c[0],u=c[1],p=a(e,2),d=p[0],f=p[1];if(i<=0)return!1;if(h)return Math.pow(d-l,2)+Math.pow(f-u,2)<=Math.pow(i,2);var v=(l-s)/r-d,g=(u-o)/r-f;return v*v+g*g<=i*i};function b(t,e,i){return i.map((function(i){return function(t,e,i){var n=a(i,2),s=n[0],o=n[1],r=a(t,2),h=r[0],c=r[1],l=e,u=Math.cos(l),p=Math.sin(l);return[u*(s-h)+p*(o-c)+h,u*(o-c)-p*(s-h)+c]}(t,e,i)}))}var I=function(t){return Math.abs(t)>=360?t%360:Math.abs(t)<360?t:0},x=function(t){function i(e,i){var n=t.call(this,e,i)||this;n.name="Ellipse",n.type=8,n.rotation=0,n.radiusX=0,n.radiusY=0,n._ctrlPoints=[],n.rotation=e.rotation||n.rotation,n.radiusX=e.radiusX||n.radiusX,n.radiusY=e.radiusY||n.radiusY;var s=a(n.coor[0],2),o=s[0],r=s[1];return n._ctrlPoints=b([o,r],n.rotation,[[o+n.radiusX,r],[o-n.radiusX,r],[o,r+n.radiusY],[o,r-n.radiusY]]),n}return e(i,t),Object.defineProperty(i.prototype,"ctrlPoints",{get:function(){return this.disable||this.hideCtrlDots?[]:this._ctrlPoints},enumerable:!1,configurable:!0}),i.prototype.updateCtrlPoints=function(){var t=a(this.coor[0],2),e=t[0],i=t[1];this._ctrlPoints=b([e,i],this.rotation,[[e+this.radiusX,i],[e-this.radiusX,i],[e,i+this.radiusY],[e,i-this.radiusY]])},i}(h),M=function(t){function i(e,i){var a=t.call(this,e,i)||this;return a.name="Checkerboard",a.type=9,a.isClose=!1,a.forceAngel=!0,a.maxPoints=2,a.disableDotLength=0,a.disableStartIndex=0,a.dashIndex=0,a.dashStartIndex=0,a.attribute="",a.forceAngel=e.forceAngel||!0,a.attribute=e.attribute||"",a.maxPoints=e.maxPoints||2,a.dashIndex=e.dashIndex||0,a.dashStartIndex=e.dashStartIndex||0,a.disableStartIndex=e.disableStartIndex||0,a.disableDotLength=e.disableDotLength||0,a}return e(i,t),Object.defineProperty(i.prototype,"ctrlPoints",{get:function(){if(this.disable||!this.coor)return[];var t=this.coor;return this.disableDotLength?r(t,this.disableStartIndex,this.disableDotLength,[]):t.length>1?t:[]},enumerable:!1,configurable:!0}),i}(h),C=function(t){function i(e,i){var a=t.call(this,e,i)||this;return a.name="Curve",a.type=10,a.isReverse=!0,a}return e(i,t),Object.defineProperty(i.prototype,"ctrlPoints",{get:function(){return this.disable||this.hideCtrlDots?[]:this.coor.length>2?this.coor:[]},enumerable:!1,configurable:!0}),i}(h),T=function(t){function i(e,i){var a=t.call(this,e,i)||this;return a.name="CompositeGraph",a.type=100,a}return e(i,t),Object.defineProperty(i.prototype,"ctrlPoints",{get:function(){return this.components.length?this.components.map((function(t){return t.disable||t.hideCtrlDots?[]:5===t.type?[t.ctrlPoints[1]]:t.ctrlPoints})).flat():[]},enumerable:!1,configurable:!0}),Object.defineProperty(i.prototype,"sharePoints",{get:function(){var t=this;return(this.relativeInfo.map((function(e){return e.map((function(e){try{var i=e.split("-").map((function(t){return 1*t}));if(i&&i.length>=3){var a=t.components[i[0]];return{uuid:a.uuid,currentShape:a,targetShapeIndex:i[1],targetShapePointIndex:i[2],targetShapePointAxle:i[3]}}return{}}catch(t){return console.error(t),{}}}))}))||[]).flat()},enumerable:!1,configurable:!0}),i}(h),w="2.26.0",D="rgba(255, 0, 0, 1)",E="#d46a66",P="#33CC33",A=function(){function t(){this._eventTree={}}return t.prototype.on=function(t,e){var i=this._eventTree[t];Array.isArray(i)?i.push(e):this._eventTree[t]=[e]},t.prototype.emit=function(t){for(var e=[],i=1;i<arguments.length;i++)e[i-1]=arguments[i];var s=this._eventTree[t];Array.isArray(s)&&s.forEach((function(t){return t.apply(void 0,n([],a(e)))}))},t.prototype.off=function(t,e){var i=this._eventTree[t],a=i.find((function(t){return t===e}));Array.isArray(i)&&a&&i.splice(a,1)},t}();function H(t){return"object"==typeof t&&null!==t}var L={sagittalVerticalAxis:["distance"]};function R(t){return"function"==typeof t}var k=["active","activeComponent","index","hide","isCtrlShape","isComponent","isDash","dragging","disable","angle","distance","label","labelCoor","labelValue","labelRadius","strokeStyle","flexiblePointIndex","isDisableDelByKey","initialVal","relativeInfo","relativePoints","_ctrlPoints","relativeAuxLineIds","relevantUUIdList","forceAngel"],G=["apex","coor","direction","mark"];function _(t,e){var i,n;if(t===e)return{equal:!0};if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return{equal:!1};for(var s=0;s<t.length;s++){if(!(d=_(t[s],e[s])).equal)return d}return{equal:!0}}if(H(t)&&H(e)){var o=Object.entries(t),r=!0;try{for(var h=function(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],a=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&a>=t.length&&(t=void 0),{value:t&&t[a++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(o),c=h.next();!c.done;c=h.next()){var l=a(c.value,2),u=l[0],p=l[1];if(!R(p)&&!R(e[u])&&!(k.includes(u)||Object.keys(L).includes(t.dataType)&&L[t.dataType].includes(u))){var d;if(!(d=_(p,e[u])).equal&&d.changedKeyValues)return localStorage.getItem("debugMode")&&console.log(2222222,"有变化!",u,p,e[u]),d;if(!d.equal&&(r=!1,G.includes(u)))return{equal:!1,changedKeyValues:{uuid:t.uuid,key:u,value1:p,value2:e[u]}}}}}catch(t){i={error:t}}finally{try{c&&!c.done&&(n=h.return)&&n.call(h)}finally{if(i)throw i.error}}return{equal:r}}return{equal:!1}}var O={isNumber:function(t){return"number"==typeof t&&!Number.isNaN(t)&&t!==1/0&&t!==-1/0},isPositiveInt:function(t){return/^\d+$/.test(t)},isNotZeroNumber:function(t){return O.isNumber(t)&&0!=+t},notEmpty:function(t){return!O.isVoid(t)},isFalsy:function(t){return 0!==t&&!t},isVoid:function(t){return null==t||""===t},add:function(t,e){var i,a;try{i=t.toString().split(".")[1].length}catch(t){i=0}try{a=e.toString().split(".")[1].length}catch(t){a=0}var n=Math.abs(i-a),s=Math.pow(10,Math.max(i,a));if(n>0){var o=Math.pow(10,n);i>a?(t=Number(t.toString().replace(".","")),e=Number(e.toString().replace(".",""))*o):(t=Number(t.toString().replace(".",""))*o,e=Number(e.toString().replace(".","")))}else t=Number(t.toString().replace(".","")),e=Number(e.toString().replace(".",""));return(t+e)/s},subtract:function(t,e){var i,a;try{i=t.toString().split(".")[1].length}catch(t){i=0}try{a=e.toString().split(".")[1].length}catch(t){a=0}var n=Math.pow(10,Math.max(i,a));return((t*n-e*n)/n).toFixed(i>=a?i:a)},multiply:function(t,e){var i=0,a=t.toString(),n=e.toString();try{i+=a.split(".")[1].length}catch(t){}try{i+=n.split(".")[1].length}catch(t){}return Number(a.replace(".",""))*Number(n.replace(".",""))/Math.pow(10,i)},getDecimalPointPosition:function(t){try{return(t=t.toString()).split(".")[1].length}catch(t){return 0}},getDecimalPointWithDigits:function(t,e,i,a){void 0===e&&(e=2),void 0===i&&(i=!1),t=t.toString();var n=O.getDecimalPointPosition(t)||e;n>0&&(t=i?Number(t).toFixed(e):t.substring(0,t.length-n));return t},divide:function(t,e){var i=t.toString(),a=e.toString(),n=(i.split(".")[1]||"").length,s=(a.split(".")[1]||"").length;if(n===s)return Number(i.replace(".",""))/Number(a.replace(".",""));var o=s>n,r=Math.abs(n-s),h=0;if(o)for(;r>h;)i+="0",h++;else for(;r>h;)a+="0",h++;return Number(i.replace(".",""))/Number(a.replace(".",""))},translatePercentage:function(t){return(100*t).toFixed(2)+"%"},round:function(t,e,i){void 0===e&&(e=2),void 0===i&&(i=!1);var a=Number(t);if(isNaN(a))return NaN;var n=(a=Math.round(t*Math.pow(10,e))/Math.pow(10,e)).toString();if(i){var s=n.indexOf(".");for(s<0&&(s=n.length,n+=".");n.length<=s+e;)n+="0"}return n}},W=function(t,e){for(var i=t.length,a=new Array(i-1),n=new Array(i-1),s=new Array(i),o=new Array(i),r=new Array(i),h=new Array(i),c=new Array(i-1),l=new Array(i-1),u=0;u<i-1;u++)a[u]=t[u+1]-t[u],0===a[u]&&(t[u+1]-=1e-6,a[u]=t[u+1]-t[u],console.warn("相邻 x 值相同,无法进行三次样条插值, 增加微小扰动以便于拟合"));for(u=1;u<i-1;u++)n[u]=3/a[u]*(e[u+1]-e[u])-3/a[u-1]*(e[u]-e[u-1]);s[0]=1,o[0]=0,r[0]=0;for(u=1;u<i-1;u++)s[u]=2*(t[u+1]-t[u-1])-a[u-1]*o[u-1],o[u]=a[u]/s[u],r[u]=(n[u]-a[u-1]*r[u-1])/s[u];s[i-1]=1,r[i-1]=0,h[i-1]=0;for(var p=i-2;p>=0;p--)h[p]=r[p]-o[p]*h[p+1];for(u=0;u<i-1;u++)l[u]=(h[u+1]-h[u])/(3*a[u]),c[u]=(e[u+1]-e[u])/a[u]-a[u]*(h[u+1]+2*h[u])/3;return{x:t,y:e,b:c,c:h,d:l}},Y=function(t,e){for(var i=t.x,a=t.y,n=t.b,s=t.c,o=t.d,r=[],h=0;h<i.length-1;h++)for(var c=(i[h+1]-i[h])/e,l=0;l<e;l++){var u=i[h]+l*c,p=u-i[h],d=a[h]+n[h]*p+s[h]*p*p+o[h]*p*p*p;r.push([u,d])}return r.push([i[i.length-1],a[a.length-1]]),r},N=["baseGraph","compositeGraph"];return function(t){function n(e,i){var a=t.call(this)||this;a.version=w,a.lock=!1,a.readonly=!1,a.actionType="",a.mouseAction="",a.disableWheel=!1,a.enableKeyMove=!1,a.isMouseInImage=!1,a.transformConfig={horizontalScale:1,rotate:0},a.debugMode=!1,a.disableSort=!1,a.MIN_WIDTH=10,a.MIN_HEIGHT=10,a.MIN_RADIUS=5,a.INTERPOLATION_POINTS=10,a.pixelSpacing=0,a.strokeStyle=P,a.fillStyle="rgba(0, 0, 255,0.1)",a.activeSecondaryStrokeStyle=E,a.activeStrokeStyle=D,a.activeFillStyle="rgba(255, 0, 0, 0.1)",a.ctrlFillStyle="#fff",a.hideLabel=!1,a.isUsePrimitiveMathRound=!1,a.labelFillStyle="transparent",a.labelFont="10px sans-serif",a.labelTextFillStyle=a.strokeStyle,a.labelMaxLen=100,a.WIDTH=0,a.HEIGHT=0,a.dataset=[],a.activeShapeList=[],a.buffer=null,a.luminance=0,a.luminanceStep=5,a.oldLuminanceType=!1,a.hitIndex=-1,a.rememberOrigin=[0,0],a.fixedPointList=[],a.dataType="",a.ctrlHoverRadius=10,a.drawCtrlOuterDash=!0,a.dashLineConfig=[2,4],a.ctrlRadius=1.5,a.lineWidth=1.5,a.lineRoughnessMode="normal",a.modeConfigs={thin:{ctrlRadius:1,lineWidth:1,dashLineConfig:[2,4]},normal:{ctrlRadius:1.5,lineWidth:1.5,dashLineConfig:[2,4]},bold:{ctrlRadius:3,lineWidth:3,dashLineConfig:[3,6]}},a.createType=0,a.createOptions={},a.ctrlIndex=-1,a.ctrlComponentIndex=-1,a.image=new Image,a.IMAGE_WIDTH=0,a.IMAGE_ORIGIN_HEIGHT=0,a.IMAGE_HEIGHT=0,a.originX=0,a.originY=0,a.isRightMouseDown=!1,a.rightMouseDownTimer=null,a.RIGHT_MOUSE_HOLD_THRESHOLD=200,a.isRightMouseHold=!1,a.rightMouseDownTime=0,a.scaleStep=0,a.limitMaxScaleStep=30,a.limitMinScaleStep=-100,a.stepRate=.04,a.maxScaleRate=3,a.minScaleRate=.5,a.scaleRate=1,a.scrollZoom=!0,a.allShapeTypes=[1,2,3,4,5,6,7,8,9,10,100],a.ctrlShapeTypes=[1,2,4,5,6,7,8,9,10,100],a.lineLikeTypes=[2,4,6,7,9,10],a.dblTouch=300,a.dblTouchStore=0,a.alpha=!0,a.curveCtrlHoverIndex=new Map,a.curveCtrlActiveIndex=new Map,a.scaleTouchStore=0,a.isTouch2=!1,a.isMobile=navigator.userAgent.includes("Mobile")||navigator.userAgent.includes("iPhone")||navigator.userAgent.includes("iPad")||navigator.userAgent.includes("iPod")||navigator.userAgent.includes("Android"),a.labelUp=!1,a.labelValueVisible=!1,a.labelCoor=[],a.labelRadius=20,a.auxiliaryLineList=[],a.auxiliaryPointList=[],a.auxiliaryCurveList=[],a.offscreenCanvas=null,a.offscreenCtx=null,a.isMagnifierVisible=a.isMobile,a.magnifierConfig={scale:1.5,offsetX:0,offsetY:0,width:150,height:150},a.oldData={dataset:[]},a.isMiddleMouseDown=!1,a.lastMouseX=0,a.lastMouseY=0,a.ARROW_MOVE_STEP=10,a.handleContextmenu=a.handleContextmenu.bind(a),a.handleMousewheel=a.handleMousewheel.bind(a),a.handleMouseDown=a.handleMouseDown.bind(a),a.handleMouseMove=a.handleMouseMove.bind(a),a.handelMouseUp=a.handelMouseUp.bind(a),a.handelDblclick=a.handelDblclick.bind(a),a.handelKeyup=a.handelKeyup.bind(a);var n="string"==typeof e?document.querySelector(e):e;return n instanceof HTMLCanvasElement?(a.canvas=n,a.offScreen=document.createElement("canvas"),a.debugMode=!!localStorage.getItem("debugMode"),a.initSetting(i),a.initEvents()):console.error("HTMLCanvasElement is required!"),a}return e(n,t),Object.defineProperty(n.prototype,"canMoveImage",{get:function(){return!this.lock&&this.isMouseInImage&&["","move"].includes(this.actionType)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"canZoomImage",{get:function(){return!this.lock&&this.isMouseInImage&&["","zoom"].includes(this.actionType)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"activeShape",{get:function(){return this.dataset.find((function(t){return t.active}))||{}},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"activeComponentShape",{get:function(){return this.activeShape.components.find((function(t){return t.active&&t.activeComponent}))||{}},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"scale",{get:function(){return this.IMAGE_ORIGIN_WIDTH&&this.IMAGE_WIDTH?O.divide(this.IMAGE_WIDTH,this.IMAGE_ORIGIN_WIDTH):1},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"imageMin",{get:function(){return Math.min(this.IMAGE_WIDTH,this.IMAGE_HEIGHT)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"imageOriginMax",{get:function(){return Math.max(this.IMAGE_ORIGIN_WIDTH,this.IMAGE_ORIGIN_HEIGHT)},enumerable:!1,configurable:!0}),n.prototype.mathRound=function(t){return this.isUsePrimitiveMathRound?Math.round(t):t},n.prototype.changeDataByUid=function(t){var e=t.uuid,i=t.key,a=t.value;this.dataset.forEach((function(t){t.uuid===e&&(t.active=!0,t.activeComponent=!1,i&&t[i]!==a&&(t[i]=a))})),this.cancelActive()},n.prototype.changeDataByDataType=function(t){var e=t.dataType,i=t.newData;i&&i.pixelSpacing&&this.setPixelSpacing(i.pixelSpacing,!1),this.dataset=this.dataset.map((function(t){return t.dataType===e&&(t.active=!0,t.activeComponent=!1,i&&Object.keys(i).forEach((function(e){t[e]=i[e]}))),t})),this.cancelActive()},n.prototype.setMode=function(t,e){switch(t){case"lock":this.lock=!!e;break;case"readonly":this.readonly=!!e;break;case"moveOnly":this.readonly=!!e,this.actionType="move";break;case"zoomOnly":this.readonly=!!e,this.actionType="zoom";break;default:this.readonly=!1,this.lock=!1,this.actionType=""}},n.prototype.getMode=function(){return this.lock?"lock":this.readonly&&"move"===this.actionType?"moveOnly":this.readonly&&"zoom"===this.actionType?"zoomOnly":this.readonly?"readonly":""},n.prototype.update=function(){var t=this;this.emit("updating",this.dataset);var e=this.modeConfigs[this.lineRoughnessMode];this.ctrlRadius=e.ctrlRadius,this.lineWidth=e.lineWidth,this.dashLineConfig=e.dashLineConfig,window.cancelAnimationFrame(this.timer),this.timer=window.requestAnimationFrame((function(){t.ctx.save(),t.ctx.clearRect(0,0,t.WIDTH,t.HEIGHT),t.ctx.translate(t.originX,t.originY),t.IMAGE_WIDTH&&t.IMAGE_HEIGHT&&t.ctx.drawImage(t.buffer,0,0,t.IMAGE_WIDTH,t.IMAGE_HEIGHT),t.activeShapeList=[],t.drawAuxiliaryPoints(t.ctx),t.drawAuxiliaryLines(t.ctx),t.drawAuxiliaryCurves(t.ctx);var e=t.dataset;e.forEach((function(e){if(e.getCoor&&"function"==typeof e.getCoor&&(e.coor=e.getCoor(t.dataset,e)||[]),e.getAngle&&"function"==typeof e.getAngle){var i=e.getAngle(t.dataset,e)||{angle:0,direction:0,needDirection:!1},a=i.angle,n=i.direction,s=i.needDirection;e.angle=a,s&&(e.direction=n)}if(e.getDistance&&"function"==typeof e.getDistance&&(e.distance=e.getDistance(t.dataset,e)||0),100!==e.type){if(e.getLabelAndCoor&&"function"==typeof e.getLabelAndCoor){var o=e.getLabelAndCoor(t.dataset,e),r=o.label,h=o.labelCoor,c=o.labelValue;r&&(e.label=r),h&&(e.labelCoor=h),c&&(e.labelValue=c)}}else e.components.length&&e.components.forEach((function(i){if(i.getLabelAndCoor&&"function"==typeof i.getLabelAndCoor){var a=i.getLabelAndCoor(t.dataset,i,e),n=a.label,s=a.labelCoor,o=a.labelValue;n&&(i.label=n),s&&(i.labelCoor=s),o&&(i.labelValue=o)}}))})),t.drawShape(e,t.ctx),t.activeShapeList.length>0&&t.activeShapeList.forEach((function(e){e.type>0&&t.pureDraw(e,t.ctx),-1===e.type&&t.drawAuxiliaryLine(e,t.ctx),-2===e.type&&t.drawDot(e,t.ctx),-3===e.type&&t.drawAuxiliaryCurve(e,t.ctx)})),t.ctrlShapeTypes.includes(t.activeShape.type)&&!t.activeShape.hide&&t.drawCtrlList(t.activeShape),t.ctx.restore();var i=_(t.oldData,{dataset:t.dataset}).equal;if(t.emit("isEdited",!i),t.activeShape&&t.activeShape.type&&"mouseMove"===t.mouseAction){var a="";t.activeShape.creating&&(a="createShape"),t.activeShape.dragging&&(a="moveShape"),a&&t.emit("updatedWithType",{type:a,dataset:t.dataset})}t.emit("updated",t.dataset)}))},n.prototype.setLineRoughness=function(t){this.lineRoughnessMode!==t&&["thin","normal","bold"].includes(t)&&(this.lineRoughnessMode=t,this.update())},n.prototype.setFixedPoint=function(t){this.fixedPointList=t.map((function(t){return{coor:t,uuid:s()}}))},n.prototype.setPixelSpacing=function(t,e){void 0===e&&(e=!0),this.pixelSpacing=t,this.emit("onPixelSpacingChange",t),this.dataset.forEach((function(e){100===e.type?(e.pixelSpacing=t,e.components.forEach((function(e){e.pixelSpacing=t}))):e.pixelSpacing=t})),e&&this.update()},n.prototype.pureUpdateImage=function(t){var e=this;void 0===t&&(t=this.ctx),window.cancelAnimationFrame(this.timer2),this.timer2=window.requestAnimationFrame((function(){t.save(),t.clearRect(0,0,e.WIDTH,e.HEIGHT),t.translate(e.originX,e.originY),e.IMAGE_WIDTH&&e.IMAGE_HEIGHT&&t.drawImage(e.buffer,0,0,e.IMAGE_WIDTH,e.IMAGE_HEIGHT),e.activeShapeList=[],e.drawAuxiliaryPoints(t),e.drawAuxiliaryLines(t),e.drawAuxiliaryCurves(t);var i=e.dataset;i.forEach((function(t){if(t.getCoor&&"function"==typeof t.getCoor&&(t.coor=t.getCoor(e.dataset,t)||[]),t.getAngle&&"function"==typeof t.getAngle){var i=t.getAngle(e.dataset,t)||{angle:0,direction:0,needDirection:!1},a=i.angle,n=i.direction,s=i.needDirection;t.angle=a,s&&(t.direction=n)}if(t.getDistance&&"function"==typeof t.getDistance&&(t.distance=t.getDistance(e.dataset,t)||0),100!==t.type){if(t.getLabelAndCoor&&"function"==typeof t.getLabelAndCoor){var o=t.getLabelAndCoor(e.dataset,t),r=o.label,h=o.labelCoor,c=o.labelValue;r&&(t.label=r),h&&(t.labelCoor=h),c&&(t.labelValue=c)}}else t.components.length&&t.components.forEach((function(i){if(i.getLabelAndCoor&&"function"==typeof i.getLabelAndCoor){var a=i.getLabelAndCoor(e.dataset,i,t),n=a.label,s=a.labelCoor,o=a.labelValue;n&&(i.label=n),s&&(i.labelCoor=s),o&&(i.labelValue=o)}}))})),e.drawShape(i,t),e.activeShapeList.length>0&&e.activeShapeList.forEach((function(i){i.type>0&&e.pureDraw(i,t),-1===i.type&&e.drawAuxiliaryLine(i,t),-2===i.type&&e.drawDot(i,t),-3===i.type&&e.drawAuxiliaryCurve(i,t)})),e.ctrlShapeTypes.includes(e.activeShape.type)&&!e.activeShape.hide&&e.drawCtrlList(e.activeShape),t.restore()}))},n.prototype.createMagnifier=function(){if(this.isMagnifierVisible){this.magnifierCanvas=this.magnifierCanvas||document.createElement("canvas"),this.magnifierCtx=this.magnifierCanvas&&this.magnifierCanvas.getContext("2d",{willReadFrequently:!0});var t=this.magnifierConfig,e=t.width,i=t.height,a=t.offsetX,n=t.offsetY;this.magnifierCanvas.style.position="fixed",this.magnifierCanvas.style.pointerEvents="none",this.magnifierCanvas.style.zIndex="1000",this.magnifierCanvas.style.border="1px solid black",this.magnifierCanvas.style.borderRadius="50%",this.magnifierCanvas.style.width="".concat(e,"px"),this.magnifierCanvas.style.height="".concat(i,"px"),this.magnifierCanvas.style.left="".concat(a,"px"),this.magnifierCanvas.style.top="".concat(n,"px"),document.body.appendChild(this.magnifierCanvas)}},n.prototype.updateMagnifier=function(t,e){if(this.isMagnifierVisible&&this.magnifierCanvas&&this.magnifierCtx){var i=this.magnifierConfig,a=i.width,n=i.height,s=window.devicePixelRatio||1;this.magnifierCanvas.width=a,this.magnifierCanvas.height=n,this.magnifierCtx.clearRect(0,0,a,n);for(var o=this.getImageDataFromCanvas(this.canvas,[t*s-a/2,e*s-n/2,a,n]),r=this.magnifierCanvas.getContext("2d",{willReadFrequently:!0}).createImageData(this.magnifierCanvas.width,this.magnifierCanvas.height),h=0,c=0;c<1*a;c+=1)for(var l=0;l<1*n;l+=1){for(var u=c;u<c+1;u++)for(var p=l;p<l+1;p++){var d=4*(u*a*1+p);r.data[d]=o.data[h],r.data[d+1]=o.data[h+1],r.data[d+2]=o.data[h+2],r.data[d+3]=o.data[h+3]}h+=4}this.magnifierCanvas.getContext("2d",{willReadFrequently:!0}).putImageData(r,0,0),this.magnifierCtx.strokeStyle="rgba(0, 0, 0, 0.5)",this.magnifierCtx.lineWidth=2,this.magnifierCtx.strokeRect(0,0,a,n)}},n.prototype.destroyMagnifier=function(){this.magnifierCanvas&&(this.magnifierCanvas.remove(),this.magnifierCanvas=null,this.magnifierCtx=null)},n.prototype.getImageDataFromCanvas=function(t,e){var i=a(e,4),n=i[0],s=i[1],o=i[2],r=i[3];return t.getContext("2d",{willReadFrequently:!0}).getImageData(n,s,o,r)},n.prototype.cancelActive=function(){this.remember=[],this.dataset.forEach((function(t){t.active=!1,t.dragging=!1,t.activeComponent=!1,100===t.type&&t.components.forEach((function(t){t.active=!1,t.dragging=!1,t.activeComponent=!1}))})),this.emit("select",null),this.update()},n.prototype.viewAllShape=function(){this.dataset.forEach((function(t){t.hide=t.hideInSnapshot||!1,100===t.type&&t.components.forEach((function(e){e.hide=t.hideInSnapshot||!1}))})),this.auxiliaryLineList.forEach((function(t){t.hide=t.hideInSnapshot||!1})),this.auxiliaryPointList.forEach((function(t){t.hide=t.hideInSnapshot||!1}))},n.prototype.getSnapshot=function(t){var e=this;void 0===t&&(t=1),this.fitZoom(),this.viewAllShape(),this.cancelActive(),t*=window.devicePixelRatio||1,this.offscreenCanvas=document.createElement("canvas");var i=a([this.IMAGE_WIDTH*t,this.IMAGE_HEIGHT*t],2),n=i[0],s=i[1];return this.offscreenCanvas.width=n,this.offscreenCanvas.height=s,this.offscreenCtx=this.offscreenCanvas&&this.offscreenCanvas.getContext("2d",{willReadFrequently:!0}),this.offscreenCtx.drawImage(this.image,0,0,n,s),this.offscreenCtx.scale(t,t),this.drawShape(this.dataset,this.offscreenCtx),this.drawAuxiliaryPoints(this.offscreenCtx),this.drawAuxiliaryLines(this.offscreenCtx),this.drawAuxiliaryCurves(this.offscreenCtx),new Promise((function(t){e.on("updated",(function(){e.offscreenCanvas&&t(e.offscreenCanvas.toDataURL("image/png"))}))}))},n.prototype.mergeEvent=function(t){var e=0,a=0,n=0,s=0;if(this.isMobile&&t.touches){var o=t.touches[0],r=o.clientX,h=o.clientY,c=t.target.getBoundingClientRect(),l=c.left,u=c.top;if(e=Math.round(r-l),a=Math.round(h-u),t.touches&&2===t.touches.length){var p=t.touches[1]||{},d=p.clientX,f=void 0===d?0:d,v=p.clientY,g=void 0===v?0:v;n=Math.round(Math.abs((f-r)/2+r)-l),s=Math.round(Math.abs((g-h)/2+h)-u)}else t.touches&&1===t.touches.length&&(n=Math.round(r-l),s=Math.round(h-u))}else e=t.offsetX,a=t.offsetY;return i(i({},t),{mouseX:e,mouseY:a,mouseCX:n,mouseCY:s})},n.prototype.handleContextmenu=function(t){t.preventDefault(),this.evt=t},n.prototype.handleMousewheel=function(t){if(!this.disableWheel&&(t.stopPropagation(),t.preventDefault(),this.evt=t,!this.lock&&this.scrollZoom)){var e=this.mergeEvent(t),i=e.mouseX,a=e.mouseY;this.mouse=[i,a],this.mousePoint=[t.x,t.y],this.setScale(t.deltaY<0,!0)}},n.prototype.handleMouseDown=function(t){var e=this;if(t.stopPropagation(),this.evt=t,!this.lock){if(this.mouseAction="mouseDown",this.isMobile||2!==t.button||(this.isRightMouseDown=!0,this.isRightMouseHold=!1,this.rightMouseDownTime=Date.now(),this.rightMouseDownTimer=setTimeout((function(){e.isRightMouseDown&&(e.isRightMouseHold=!0,e.emit("rightMouseHold",t))}),this.RIGHT_MOUSE_HOLD_THRESHOLD)),!this.isMobile&&1===t.button)return this.isMiddleMouseDown=!0,this.lastMouseX=t.clientX,void(this.lastMouseY=t.clientY);var i=this.mergeEvent(t),n=i.mouseX,s=i.mouseY,o=i.mouseCX,r=i.mouseCY,h=this.mathRound(n/this.scale),c=this.mathRound(s/this.scale);if(this.mouse=this.isMobile&&t.touches&&2===t.touches.length?[o,r]:[n,s],this.mousePoint=[t.x,t.y],this.rememberOrigin=[n-this.originX,s-this.originY],this.isMouseInImage=this.isInImage(t),!this.isMobile&&2===t.buttons)return this.activeShape&&this.activeShape.type&&(this.lineLikeTypes.includes(this.activeShape.type)&&this.activeShape.creating&&(this.activeShape.coor.length&&this.activeShape.coor.pop(),0===this.activeShape.coor.length&&this.dataset.pop()),this.activeShape.creating||this.cancelActive()),void this.update();if(!this.isMobile&&1===t.buttons||this.isMobile&&t.touches&&1===t.touches.length){var l=this.activeShape.ctrlPoints||[];if(this.ctrlIndex=-1,this.ctrlComponentIndex=-1,this.curveCtrlActiveIndex.clear(),this.curveCtrlHoverIndex.clear(),this.dataset.forEach((function(t){if(10===t.type&&t.ctrlPoints){var i=!1;t.ctrlPoints.forEach((function(a,n){!i&&S(e.mouse,a,e.ctrlHoverRadius/e.scale,{creating:t.creating,originX:e.originX,originY:e.originY,scale:e.scale})&&(e.curveCtrlActiveIndex.set(t.uuid,n),i=!0)}))}})),0===this.createType)if(this.activeShape&&this.activeShape.components&&this.activeShape.components.length)for(var u=function(t){var i=p.activeShape.components[t];i.activeComponent=!1,i.ctrlPoints.some((function(a,n){if(S(e.mouse,a,e.ctrlHoverRadius/e.scale,{creating:e.activeShape.creating,originX:e.originX,originY:e.originY,scale:e.scale}))return e.ctrlIndex=n,e.ctrlComponentIndex=t,i.active=!0,i.activeComponent=!0,!0}))},p=this,d=0;d<this.activeShape.components.length;d++)u(d);else this.ctrlIndex=l.findIndex((function(t){return S(e.mouse,t,e.ctrlHoverRadius/e.scale,{creating:e.activeShape.creating,originX:e.originX,originY:e.originY,scale:e.scale})}));if(this.ctrlIndex>-1&&!this.activeShape.creating){if(this.activeShape.readonly)return void this.emit("notify",{type:"readonly",message:"该图形已锁定,无法进行编辑",shape:this.activeShape});if(this.ctrlComponentIndex>-1){var f=a(this.activeComponentShape.ctrlPoints[this.ctrlIndex],2),v=f[0],g=f[1];this.remember=[{uuid:100===this.activeShape.type?this.activeComponentShape.uuid:this.activeShape.uuid,points:[[h-v,c-g]]}]}else{var m=a(l[this.ctrlIndex],2);v=m[0],g=m[1];this.remember=[{uuid:100===this.activeShape.type?this.activeComponentShape.uuid:this.activeShape.uuid,points:[[h-v,c-g]]}]}}else if(this.isInBackground(t)){if(this.activeShape.creating&&!this.readonly){var y=this.mathRound(h-this.originX/this.scale),b=this.mathRound(c-this.originY/this.scale);if(this.activeShape.coor.push([y,b]),this.lineLikeTypes.includes(this.activeShape.type)){var I=!1;if(2===this.activeShape.type&&this.activeShape.coor.length>2){var x=a(this.activeShape.coor[0],2),M=(v=x[0],g=x[1],a(this.activeShape.coor[this.activeShape.coor.length-1],2)),C=M[0],T=M[1],w=S([h-v,c-g],[h-C,c-T],2*this.MIN_RADIUS,{creating:this.activeShape.creating,originX:this.originX,originY:this.originY,scale:this.scale});if(w&&0===this.activeShape.maxPoints&&(I=w,this.activeShape.coor.pop()),this.activeShape.maxPoints>0)this.activeShape.coor.some((function(t,i){return i!==e.activeShape.coor.length-1&&S([h-t[0],c-t[1]],[h-C,c-T],e.MIN_RADIUS/e.scale,{creating:e.activeShape.creating,originX:e.originX,originY:e.originY,scale:e.scale})}))&&(I=!1,this.activeShape.coor.pop()),this.activeShape.coor.length>=this.activeShape.maxPoints&&(I=!0)}if(6===this.activeShape.type&&4===this.activeShape.coor.length&&(I=!0),[4,7].includes(this.activeShape.type)&&this.activeShape.coor.length===this.activeShape.maxPoints&&(I=!0),6===this.activeShape.type&&3===this.activeShape.coor.length&&this.activeShape.forceAngel&&(I=!0),9===this.activeShape.type&&2===this.activeShape.coor.length&&this.activeShape.forceAngel&&(I=!0),I)return this.activeShape.creating=!1,this.emit("add",{shape:this.activeShape,endPoint:this.getActiveShapeLastPointInScreen()}),void this.update()}}else this.createType>0&&!this.readonly?this.createShapes(h,c):this.handleClickOnShapeOrNot(h,c);this.update()}else this.isInBackground(t)||this.handleClickOnShapeOrNot(h,c)}}},n.prototype.handleClickOnShapeOrNot=function(t,e){var i=this.onHitShape(this.mouse,this.dataset),a=i.hitIndex,n=i.hitShape,s=i.hitType,o=i.hitComponentIndex,r=i.hitComponentShape,h=i.hitComponentType,c=i.shape;this.hitIndex=a,this.debugMode&&console.log("点击结果",{hitIndex:a,hitShape:n,hitType:s,hitComponentIndex:o,hitComponentShape:r,hitComponentType:h}),this.lock||this.readonly||(a>-1&&c&&c.readonly?this.emit("notify",{type:"readonly",message:"该图形已锁定,无法进行编辑",shape:c}):a>-1&&N.includes(s)?(n.dragging=!0,this.remember=[],this.dataset.forEach((function(t,e){e===a?(t.active=!0,t.components.length&&t.components.forEach((function(t,e){t.active=!0,o!==e&&!r.isCtrlShape||r.disable?t.activeComponent=!1:t.activeComponent=!0}))):(t.active=!1,t.components.length&&t.components.forEach((function(t){t.active=!1})))})),this.dataset.splice(a,1,n),this.readonly||(this.remember=this.getRememberPoint(n,t,e)),this.emit("select",n)):this.isMobile&&this.cancelActive())},n.prototype.getRememberPoint=function(t,e,i){var n=this;if(100===t.type&&t.components.length>0)return t.components.map((function(t){return n.getRememberPoint(t,e,i)})).flat();if([3,5].includes(t.type)){var s=a(t.coor[0],2),o=s[0],r=s[1];return[{uuid:t.uuid,points:[[e-o,i-r]]}]}var h={uuid:t.uuid,points:[]};return t&&t.coor&&t.coor.forEach((function(t){h.points.push([e-t[0],i-t[1]])})),[h]},n.prototype.watchMouseStatus=function(t){var e=this.onHitShape(t,this.dataset),i=e.hitIndex;e.hitShape;var a=e.hitType,n=e.shape;if(e.hitComponentIndex,e.hitComponentShape,e.hitComponentType,!(this.readonly||n&&n.readonly)){var s="default";if("point"===a?s="pointer":N.includes(a)&&(s="move"),this.canvas.style.cursor=s,this.dataset.forEach((function(t){t.active=!1,t.components.forEach((function(t){t.active=!1})),n&&n.uuid===t.uuid&&(t.active=!0,t.components&&t.components.length&&t.components.forEach((function(t){t.active=!0})))})),10===this.activeShape.type&&"point"===a){var o=this.curveCtrlHoverIndex.get(this.activeShape.uuid);i>-1?o!==i&&(this.curveCtrlHoverIndex.set(this.activeShape.uuid,i),this.update()):void 0!==o&&(this.curveCtrlHoverIndex.clear(),this.update())}else 10===this.activeShape.type&&"point"!==a&&(this.curveCtrlHoverIndex.clear(),this.update())}},n.prototype.handleMouseMove=function(t){var e,i=this;if(t.stopPropagation(),this.evt=t,!this.lock){if(this.mouseAction="mouseMove",this.isMiddleMouseDown){var n=t.clientX,s=t.clientY,o=n-this.lastMouseX,r=s-this.lastMouseY,h=I(this.transformConfig.rotate);if(-1===this.transformConfig.horizontalScale&&0===h)o=-o;else if(-1!==this.transformConfig.horizontalScale&&0!==h){var c=-h*Math.PI/180,l=o*Math.cos(c)-r*Math.sin(c),u=o*Math.sin(c)+r*Math.cos(c);o=l,r=u}else if(-1===this.transformConfig.horizontalScale&&0!==h){c=-h*Math.PI/180,l=o*Math.cos(c)-r*Math.sin(c),u=o*Math.sin(c)+r*Math.cos(c);-0===h?(o=-l,r=-u):Math.abs(h)%180==0?(o=l,r=-u):Math.abs(h)%90==0&&(o=l,r=u)}return this.originX+=o,this.originY+=r,this.lastMouseX=n,this.lastMouseY=s,void this.update()}var p=this.mergeEvent(t),d=p.mouseX,f=p.mouseY,v=p.mouseCX,g=p.mouseCY,m=this.mathRound(d/this.scale),S=this.mathRound(f/this.scale);if(this.mouse=this.isMobile&&t.touches&&2===t.touches.length?[v,g]:[d,f],this.mousePoint=[t.x,t.y],!this.isMobile&&2===t.buttons&&3===t.which||1===t.buttons&&1===t.which&&"zoomOnly"===this.getMode()){t.movementY>1?this.setScale(!1,!1):t.movementY<-1&&this.setScale(!0,!1)}else{if(0===this.createType&&(window.cancelAnimationFrame(this.mouseTimer),this.mouseTimer=window.requestAnimationFrame((function(){i.watchMouseStatus(i.mouse)}))),(!this.isMobile&&1===t.buttons&&1===t.which&&"moveOnly"===this.getMode()||this.isMobile&&t.touches&&1===t.touches.length&&!this.isTouch2)&&-1===this.hitIndex&&-1===this.ctrlIndex&&0===this.createType&&(this.activeShape&&!this.activeShape.dragging||!this.activeShape)&&this.canMoveImage)return this.originX=this.mathRound(d-this.rememberOrigin[0]),this.originY=this.mathRound(f-this.rememberOrigin[1]),void this.update();if((!this.isMobile&&1===t.buttons||this.isMobile&&t.touches&&1===t.touches.length)&&this.activeShape.type){if(this.ctrlIndex>-1&&this.isInBackground(t)){var b=0,x=0;try{if(this.remember&&this.remember.length)b=(e=a(this.remember[0].points[0],2))[0],x=e[1]}catch(t){return void console.error(this.remember,t)}if(!b&&!x)return;if(this.magnifierCanvas){var M=a(this.isMobile?[v,g]:[d,f],2),C=M[0],T=M[1];this.updateMagnifier(C,T)}else this.createMagnifier();if(1===this.activeShape.type||1===this.activeComponentShape.type)this.dragRect([b,x],[m,S]);else if(this.lineLikeTypes.includes(this.activeShape.type)||this.lineLikeTypes.includes(this.activeComponentShape.type)){this.activeShape.dragging=!0;var w=(k=this.lineLikeTypes.includes(this.activeComponentShape.type))?this.activeComponentShape:this.activeShape,D=this.mathRound(m-this.originX/this.scale),E=this.mathRound(S-this.originY/this.scale),P=w.dragPointAxle;"x"===P&&(E=w.coor[this.ctrlIndex][1]),"y"===P&&(D=w.coor[this.ctrlIndex][0]);var A=[D,E];w.coor.splice(this.ctrlIndex,1,A),k?(this.activeComponentShape.coor=w.coor,this.activeComponentShape.dragging=!0):(this.activeShape.coor=w.coor,this.activeShape.dragging=!0)}else if(5===this.activeShape.type&&!this.activeShape.hideCtrlDots||5===this.activeComponentShape.type&&!this.activeComponentShape.hideCtrlDots){this.activeShape.dragging=!0;var H=(k=5===this.activeComponentShape.type)?this.activeComponentShape:this.activeShape;(L=(D=this.mathRound(m-this.originX/this.scale))-H.coor[0][0])>=this.MIN_RADIUS&&(H.radius=L),k?(this.activeComponentShape.coor=H.coor,this.activeComponentShape.radius=H.radius,this.activeComponentShape.dragging=!0):(this.activeShape.coor=H.coor,this.activeShape.radius=H.radius,this.activeShape.dragging=!0)}else if(8===this.activeShape.type||8===this.activeComponentShape.type){this.activeShape.dragging=!0;var L,R=(k=8===this.activeComponentShape.type)?this.activeComponentShape:this.activeShape;D=this.mathRound(m-this.originX/this.scale),E=this.mathRound(S-this.originY/this.scale);if(0===this.ctrlIndex)(L=D-R.coor[0][0])>=this.MIN_RADIUS&&(R.radiusX=L);if(2===this.ctrlIndex)(L=E-R.coor[0][1])>=this.MIN_RADIUS&&(R.radiusY=L);R.updateCtrlPoints(),k?this.activeComponentShape.dragging=!0:this.activeShape.dragging=!0}else if(3===this.activeShape.type||3===this.activeComponentShape.type){this.activeShape.dragging=!0;var k=3===this.activeComponentShape.type,G=[[D=this.mathRound(m-this.originX/this.scale),E=this.mathRound(S-this.originY/this.scale)]];k?this.activeComponentShape.coor=G:this.activeShape.coor=G}}else if(this.activeShape.dragging&&!this.readonly){var _=this.IMAGE_ORIGIN_WIDTH||this.WIDTH,O=this.IMAGE_ORIGIN_HEIGHT||this.HEIGHT,W=y(this.activeShape,{offsetX:m,offsetY:S},{w:_,h:O},this.remember),Y=W.noLimit,N=(G=W.coor,W.components);Y&&(100!==this.activeShape.type&&(this.activeShape.coor=G),100===this.activeShape.type&&(this.activeShape.components=N)),8===this.activeShape.type&&this.activeShape.updateCtrlPoints()}else if(this.activeShape.creating&&this.isInBackground(t)){b=this.mathRound(m-this.originX/this.scale),x=this.mathRound(S-this.originY/this.scale);if(1===this.activeShape.type)this.activeShape.coor.splice(1,1,[b,x]);else if(5===this.activeShape.type){var X=a(this.activeShape.coor[0],2),F=X[0],U=X[1],j=Math.sqrt(Math.pow(F-b,2)+Math.pow(U-x,2));this.activeShape.radius=j}else if(8===this.activeShape.type){var V=a(this.activeShape.coor[0],2);F=V[0],U=V[1],j=Math.sqrt(Math.pow(F-b,2)+Math.pow(U-x,2));this.activeShape.radiusX=j,this.activeShape.radiusY=.5*j,this.activeShape.rotation=0,this.activeShape.updateCtrlPoints()}}this.update()}else if([2,4,6,7,9].includes(this.activeShape.type)&&this.activeShape.creating)this.createOptions&&this.auxiliaryLineList&&this.auxiliaryLineList.length&&this.auxiliaryLineList.forEach((function(t){t.dataType===i.activeShape.dataType&&(t.coor=i.activeShape.coor)})),this.update();else if(this.isMobile&&t.touches&&2===t.touches.length){this.isTouch2=!0;var q=t.touches[0],z=t.touches[1],B=this.scaleTouchStore;this.scaleTouchStore=Math.abs((z.clientX-q.clientX)*(z.clientY-q.clientY)),this.setScale(this.scaleTouchStore>B,!0)}}}},n.prototype.handelMouseUp=function(t){if(t.stopPropagation(),this.evt=t,!this.lock){if(this.destroyMagnifier(),this.mouseAction="mouseUp",!this.isMobile&&2===t.button){clearTimeout(this.rightMouseDownTimer);var e=Date.now()-this.rightMouseDownTime;this.isRightMouseHold||!(e<this.RIGHT_MOUSE_HOLD_THRESHOLD)||this.activeShape&&this.activeShape.creating||this.emit("contextmenu",t),this.isRightMouseDown=!1,this.isRightMouseHold=!1}if(this.isMobile){if(t.touches&&0===t.touches.length&&(this.isTouch2=!1),Date.now()-this.dblTouchStore<this.dblTouch)return void this.handelDblclick(t);this.dblTouchStore=Date.now()}else{if(2===t.buttons&&Date.now()-this.dblTouchStore<this.dblTouch)return void this.handelDblclick(t);this.dblTouchStore=Date.now()}if(this.isMouseInImage=!1,this.remember=[],this.curveCtrlActiveIndex.clear(),this.activeShape.type||this.isMobile||"zoomOnly"!==this.getMode()||this.setScale(!0,!1),this.activeShape.type&&(this.activeShape.dragging=!1,this.activeShape.components.forEach((function(t){t.dragging=!1})),this.activeShape.creating)){if(1===this.activeShape.type){var i=a(this.activeShape.coor,2),n=a(i[0],2),s=n[0],o=n[1],r=a(i[1],2),h=r[0],c=r[1];Math.abs(s-h)<this.MIN_WIDTH||Math.abs(o-c)<this.MIN_HEIGHT?(this.dataset.pop(),this.emit("warn",{type:"create",message:"Width or height cannot be less than 10"})):(this.activeShape.coor=[[Math.min(s,h),Math.min(o,c)],[Math.max(s,h),Math.max(o,c)]],this.activeShape.creating=!1,this.emit("add",{shape:this.activeShape,endPoint:this.getActiveShapeLastPointInScreen()}))}else 5===this.activeShape.type?this.activeShape.radius<this.MIN_RADIUS?(this.dataset.pop(),this.emit("warn",{type:"create",message:"Radius cannot be less than ".concat(this.MIN_RADIUS)})):(this.activeShape.creating=!1,this.emit("add",{shape:this.activeShape,endPoint:this.getActiveShapeLastPointInScreen()})):8===this.activeShape.type&&(this.activeShape.radiusY<this.MIN_RADIUS?(this.dataset.pop(),this.emit("warn","Radius cannot be less than ".concat(this.MIN_WIDTH))):(this.activeShape.creating=!1,this.emit("add",{shape:this.activeShape,endPoint:this.getActiveShapeLastPointInScreen()})));this.update()}this.isMobile||1!==t.button||(console.log("鼠标中键松开"),this.isMiddleMouseDown=!1),this.isMobile||2!==t.button||(clearTimeout(this.rightMouseDownTimer),this.isRightMouseDown=!1,this.isRightMouseHold=!1)}},n.prototype.handelDblclick=function(t){if(t.stopPropagation(),this.evt=t,!this.lock&&(!this.isMobile||t.touches)){this.mouseAction="dblclick";var e=this.activeShape||{},i=e.type,a=e.coor;if(i&&[2,4,9].includes(i)&&this.activeShape.creating){var n=2===i&&a.length>2,s=4===i&&a.length>1;return n||s?(this.emit("add",{shape:this.activeShape,endPoint:this.getActiveShapeLastPointInScreen()}),this.activeShape.creating=!1,void this.update()):void 0}this.emit("dblClick",t)}},n.prototype.handelKeyup=function(t){t.stopPropagation(),this.evt=t,this.lock||this.readonly||(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(t.key)&&this.enableKeyMove?this.handleArrowMove(t.key):this.activeShape.type&&("Escape"===t.key?(this.activeShape.creating?(this.cancelCreate(),this.cancelActive()):this.cancelActive(),this.emit("escape",this.activeShape)):"Backspace"===t.key||"Delete"===t.key?this.emit("deleteByKey",this.activeShape):console.log("按键key:".concat(t.key,", keyCode:").concat(t.keyCode))))},n.prototype.initSetting=function(t){var e=window.devicePixelRatio||1;this.canvas.style.userSelect="none",this.ctx=this.ctx||this.canvas.getContext("2d",{alpha:this.alpha,willReadFrequently:!0}),this.WIDTH=Math.round((null==t?void 0:t.width)||this.canvas.clientWidth),this.HEIGHT=Math.round((null==t?void 0:t.height)||this.canvas.clientHeight),this.canvas.width=this.WIDTH*e,this.canvas.height=this.HEIGHT*e,this.canvas.style.width=this.WIDTH+"px",this.canvas.style.height=this.HEIGHT+"px",this.offScreen.width=this.WIDTH,this.offScreen.height=this.HEIGHT,this.offScreenCtx=this.offScreenCtx||this.offScreen.getContext("2d",{willReadFrequently:!0}),this.buffer=document.createElement("canvas"),this.buffer.width=this.WIDTH,this.buffer.height=this.HEIGHT,this.bufferCtx=this.bufferCtx||this.buffer.getContext("2d",{willReadFrequently:!0}),this.ctx.scale(e,e)},n.prototype.dragRect=function(t,e){var i=a(t,2),n=i[0],s=i[1],o=a(e,2),r=o[0],h=o[1],c=100===this.activeShape.type,l=a(c?this.activeComponentShape.coor:this.activeShape.coor,2),u=a(l[0],2),p=u[0],d=u[1],f=a(l[1],2),v=f[0],g=f[1],m=[];switch(this.ctrlIndex){case 0:m=[[r-n,h-s],[v,g]];break;case 1:m=[[p,h-s],[v,g]];break;case 2:m=[[p,h-s],[r-n,g]];break;case 3:m=[[p,d],[r-n,g]];break;case 4:m=[[p,d],[r-n,h-s]];break;case 5:m=[[p,d],[v,h-s]];break;case 6:m=[[r-n,d],[v,h-s]];break;case 7:m=[[r-n,d],[v,g]]}var y=a(m,2),S=a(y[0],2),b=S[0],I=S[1],x=a(y[1],2),M=x[0],C=x[1];(b<0||M<0||I<0||C<0||M>this.IMAGE_ORIGIN_WIDTH||C>this.IMAGE_ORIGIN_HEIGHT)&&(b<0&&(b=0),M<0&&(M=0),I<0&&(I=0),C<0&&(C=0),M>this.IMAGE_ORIGIN_WIDTH&&(M=this.IMAGE_ORIGIN_WIDTH),C>this.IMAGE_ORIGIN_HEIGHT&&(C=this.IMAGE_ORIGIN_HEIGHT)),c?this.activeComponentShape.coor=m:this.activeShape.coor=m},n.prototype.initEvents=function(){this.canvas.addEventListener("touchstart",this.handleMouseDown),this.canvas.addEventListener("touchmove",this.handleMouseMove),this.canvas.addEventListener("touchend",this.handelMouseUp),this.canvas.addEventListener("contextmenu",this.handleContextmenu,{passive:!1}),this.canvas.addEventListener("mousewheel",this.handleMousewheel,{passive:!1}),this.canvas.addEventListener("wheel",this.handleMousewheel,{passive:!1}),this.canvas.addEventListener("mousedown",this.handleMouseDown),this.canvas.addEventListener("mousemove",this.handleMouseMove),this.canvas.addEventListener("mouseup",this.handelMouseUp),this.canvas.addEventListener("dblclick",this.handelDblclick),document.body.addEventListener("keyup",this.handelKeyup,!0)},n.prototype.setImage=function(t){var e=this;if(!t)return this.emit("load",!1),void this.emit("updated",[]);this.image.setAttribute("crossOrigin","anonymous"),this.image.src=t,this.image.onerror=function(){console.error("图片加载失败",t),e.emit("load",!1)},this.image.onload=function(){e.IMAGE_ORIGIN_WIDTH=e.IMAGE_WIDTH=e.image.width,e.IMAGE_ORIGIN_HEIGHT=e.IMAGE_HEIGHT=e.image.height,e.bufferCtx.drawImage(e.image,0,0,e.WIDTH,e.HEIGHT),e.fitZoom();var t=e.scale,i=Math.min(15,e.ctrlHoverRadius/t);t<.5?e.ctrlHoverRadius=Math.max(e.ctrlHoverRadius,i):t>1&&(e.ct