@idraw/core 0.3.0-beta.7 → 0.3.1
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.
package/dist/index.global.js
CHANGED
package/dist/index.global.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var iDrawCore=function(){"use strict";function t(t,e){let i=-1;return function(...n){i>0||(i=setTimeout((()=>{t(...n),i=-1}),e))}}function e(t){return"string"==typeof t&&/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)}function i(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${t()}${t()}-${t()}-${t()}-${t()}-${t()}${t()}${t()}`}function n(t){return function t(e){const i=(n=e,Object.prototype.toString.call(n).replace(/[\]|\[]{1,1}/gi,"").split(" ")[1]);var n;if(["Null","Number","String","Boolean","Undefined"].indexOf(i)>=0)return e;if("Array"===i){const i=[];return e.forEach((e=>{i.push(t(e))})),i}if("Object"===i){const i={};return Object.keys(e).forEach((n=>{i[n]=t(e[n])})),i}}(t)}function s(t){return(Object.prototype.toString.call(t)||"").replace(/(\[object|\])/gi,"").trim()}const o={type(t,e){const i=s(t);return!0===e?i.toLocaleLowerCase():i},array:t=>"Array"===s(t),json:t=>"Object"===s(t),function:t=>"Function"===s(t),asyncFunction:t=>"AsyncFunction"===s(t),string:t=>"String"===s(t),number:t=>"Number"===s(t),undefined:t=>"Undefined"===s(t),null:t=>"Null"===s(t),promise:t=>"Promise"===s(t)};var r=globalThis&&globalThis.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{a(n.next(t))}catch(t){o(t)}}function l(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,l)}a((n=n.apply(t,e||[])).next())}))};const{Image:l}=window;function a(t){return new Promise(((e,i)=>{const n=new l;n.crossOrigin="anonymous",n.onload=function(){e(n)},n.onabort=i,n.onerror=i,n.src=t}))}function h(t){return r(this,void 0,void 0,(function*(){const e=yield function(t){return new Promise(((e,i)=>{const n=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),s=new FileReader;s.readAsDataURL(n),s.onload=function(t){var i;const n=null===(i=null==t?void 0:t.target)||void 0===i?void 0:i.result;e(n)},s.onerror=function(t){i(t)}}))}(t);return yield a(e)}))}function c(t,e){return r(this,void 0,void 0,(function*(){t=t.replace(/\&/gi,"&");const i=yield function(t,e){const{width:i,height:n}=e;return new Promise(((e,s)=>{const o=new Blob([`\n <svg xmlns="http://www.w3.org/2000/svg" width="${i||""}" height = "${n||""}">\n <foreignObject width="100%" height="100%">\n <div xmlns = "http://www.w3.org/1999/xhtml">\n ${t}\n </div>\n </foreignObject>\n </svg>\n `],{type:"image/svg+xml;charset=utf-8"}),r=new FileReader;r.readAsDataURL(o),r.onload=function(t){var i;const n=null===(i=null==t?void 0:t.target)||void 0===i?void 0:i.result;e(n)},r.onerror=function(t){s(t)}}))}(t,e);return yield a(i)}))}let d=class{constructor(t,e){this._opts=e,this._ctx=t,this._transform={scale:1,scrollX:0,scrollY:0}}getContext(){return this._ctx}resetSize(t){this._opts=Object.assign(Object.assign({},this._opts),t)}calcDeviceNum(t){return t*this._opts.devicePixelRatio}calcScreenNum(t){return t/this._opts.devicePixelRatio}getSize(){return{width:this._opts.width,height:this._opts.height,contextWidth:this._opts.contextWidth,contextHeight:this._opts.contextHeight,devicePixelRatio:this._opts.devicePixelRatio}}setTransform(t){this._transform=Object.assign(Object.assign({},this._transform),t)}getTransform(){return{scale:this._transform.scale,scrollX:this._transform.scrollX,scrollY:this._transform.scrollY}}setFillStyle(t){this._ctx.fillStyle=t}fill(t){return this._ctx.fill(t||"nonzero")}arc(t,e,i,n,s,o){return this._ctx.arc(this._doSize(t),this._doSize(e),this._doSize(i),n,s,o)}rect(t,e,i,n){return this._ctx.rect(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n))}fillRect(t,e,i,n){return this._ctx.fillRect(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n))}clearRect(t,e,i,n){return this._ctx.clearRect(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n))}beginPath(){return this._ctx.beginPath()}closePath(){return this._ctx.closePath()}lineTo(t,e){return this._ctx.lineTo(this._doSize(t),this._doSize(e))}moveTo(t,e){return this._ctx.moveTo(this._doSize(t),this._doSize(e))}arcTo(t,e,i,n,s){return this._ctx.arcTo(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n),this._doSize(s))}setLineWidth(t){return this._ctx.lineWidth=this._doSize(t)}setLineDash(t){return this._ctx.setLineDash(t.map((t=>this._doSize(t))))}isPointInPath(t,e){return this._ctx.isPointInPath(this._doX(t),this._doY(e))}isPointInPathWithoutScroll(t,e){return this._ctx.isPointInPath(this._doSize(t),this._doSize(e))}setStrokeStyle(t){this._ctx.strokeStyle=t}stroke(){return this._ctx.stroke()}translate(t,e){return this._ctx.translate(this._doSize(t),this._doSize(e))}rotate(t){return this._ctx.rotate(t)}drawImage(...t){const e=t[0],i=t[1],n=t[2],s=t[3],o=t[4],r=t[t.length-4],l=t[t.length-3],a=t[t.length-2],h=t[t.length-1];return 9===t.length?this._ctx.drawImage(e,this._doSize(i),this._doSize(n),this._doSize(s),this._doSize(o),this._doSize(r),this._doSize(l),this._doSize(a),this._doSize(h)):this._ctx.drawImage(e,this._doSize(r),this._doSize(l),this._doSize(a),this._doSize(h))}createPattern(t,e){return this._ctx.createPattern(t,e)}measureText(t){return this._ctx.measureText(t)}setTextAlign(t){this._ctx.textAlign=t}fillText(t,e,i,n){return void 0!==n?this._ctx.fillText(t,this._doSize(e),this._doSize(i),this._doSize(n)):this._ctx.fillText(t,this._doSize(e),this._doSize(i))}strokeText(t,e,i,n){return void 0!==n?this._ctx.strokeText(t,this._doSize(e),this._doSize(i),this._doSize(n)):this._ctx.strokeText(t,this._doSize(e),this._doSize(i))}setFont(t){const e=[];"bold"===t.fontWeight&&e.push(`${t.fontWeight}`),e.push(`${this._doSize(t.fontSize||12)}px`),e.push(`${t.fontFamily||"sans-serif"}`),this._ctx.font=`${e.join(" ")}`}setTextBaseline(t){this._ctx.textBaseline=t}setGlobalAlpha(t){this._ctx.globalAlpha=t}save(){this._ctx.save()}restore(){this._ctx.restore()}scale(t,e){this._ctx.scale(t,e)}setShadowColor(t){this._ctx.shadowColor=t}setShadowOffsetX(t){this._ctx.shadowOffsetX=this._doSize(t)}setShadowOffsetY(t){this._ctx.shadowOffsetY=this._doSize(t)}setShadowBlur(t){this._ctx.shadowBlur=this._doSize(t)}ellipse(t,e,i,n,s,o,r,l){this._ctx.ellipse(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n),s,o,r,l)}_doSize(t){return this._opts.devicePixelRatio*t}_doX(t){const{scale:e,scrollX:i}=this._transform,n=(t-i)/e;return this._doSize(n)}_doY(t){const{scale:e,scrollY:i}=this._transform,n=(t-i)/e;return this._doSize(n)}};function u(t){return"number"==typeof t&&(t>0||t<=0)}function g(t){return"number"==typeof t&&t>=0}function m(t){return"string"==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${t}`)}function _(t){return"string"==typeof t&&/^(data:image\/)/.test(`${t}`)}const f={x:function(t){return u(t)},y:function(t){return u(t)},w:g,h:function(t){return"number"==typeof t&&t>=0},angle:function(t){return"number"==typeof t&&t>=-360&&t<=360},number:u,borderWidth:function(t){return g(t)},borderRadius:function(t){return u(t)&&t>=0},color:function(t){return e(t)},imageSrc:function(t){return _(t)||m(t)},imageURL:m,imageBase64:_,svg:function(t){return"string"==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test(`${t}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${t}`.trim())},html:function(t){let e=!1;if("string"==typeof t){let i=document.createElement("div");i.innerHTML=t,i.children.length>0&&(e=!0),i=null}return e},text:function(t){return"string"==typeof t},fontSize:function(t){return u(t)&&t>0},lineHeight:function(t){return u(t)&&t>0},textAlign:function(t){return["center","left","right"].includes(t)},fontFamily:function(t){return"string"==typeof t&&t.length>0},fontWeight:function(t){return["bold"].includes(t)},strokeWidth:function(t){return u(t)&&t>0}};function p(t={}){const{borderColor:e,borderRadius:i,borderWidth:n}=t;return!(t.hasOwnProperty("borderColor")&&!f.color(e))&&(!(t.hasOwnProperty("borderRadius")&&!f.number(i))&&!(t.hasOwnProperty("borderWidth")&&!f.number(n)))}const v={attrs:function(t){const{x:e,y:i,w:n,h:s,angle:o}=t;return!!(f.x(e)&&f.y(i)&&f.w(n)&&f.h(s)&&f.angle(o))&&(o>=-360&&o<=360)},textDesc:function(t){const{text:e,color:i,fontSize:n,lineHeight:s,fontFamily:o,textAlign:r,fontWeight:l,bgColor:a,strokeWidth:h,strokeColor:c}=t;return!!f.text(e)&&(!!f.color(i)&&(!!f.fontSize(n)&&(!(t.hasOwnProperty("bgColor")&&!f.color(a))&&(!(t.hasOwnProperty("fontWeight")&&!f.fontWeight(l))&&(!(t.hasOwnProperty("lineHeight")&&!f.lineHeight(s))&&(!(t.hasOwnProperty("fontFamily")&&!f.fontFamily(o))&&(!(t.hasOwnProperty("textAlign")&&!f.textAlign(r))&&(!(t.hasOwnProperty("strokeWidth")&&!f.strokeWidth(h))&&(!(t.hasOwnProperty("strokeColor")&&!f.color(c))&&!!p(t))))))))))},rectDesc:function(t){const{bgColor:e}=t;return!(t.hasOwnProperty("bgColor")&&!f.color(e))&&!!p(t)},circleDesc:function(t){const{bgColor:e,borderColor:i,borderWidth:n}=t;return!(t.hasOwnProperty("bgColor")&&!f.color(e))&&(!(t.hasOwnProperty("borderColor")&&!f.color(i))&&!(t.hasOwnProperty("borderWidth")&&!f.number(n)))},imageDesc:function(t){const{src:e}=t;return!!f.imageSrc(e)},svgDesc:function(t){const{svg:e}=t;return!!f.svg(e)},htmlDesc:function(t){const{html:e}=t;return!!f.html(e)}},x={is:f,check:v,delay:function(t){return new Promise((e=>{setTimeout((()=>{e()}),t)}))},compose:function(t){return function(e,i){return function n(s){let o=t[s];s===t.length&&i&&(o=i);if(!o)return Promise.resolve();try{return Promise.resolve(o(e,n.bind(null,s+1)))}catch(t){return Promise.reject(t)}}(0)}},throttle:t,loadImage:a,loadSVG:h,loadHTML:c,downloadImageFromCanvas:function(t,e){const{filename:i,type:n="image/jpeg"}=e,s=t.toDataURL(n),o=document.createElement("a");o.href=s,o.download=i;const r=document.createEvent("MouseEvents");r.initEvent("click",!0,!1),o.dispatchEvent(r)},toColorHexStr:function(t){return"#"+t.toString(16)},toColorHexNum:function(t){return parseInt(t.replace(/^\#/,"0x"))},isColorStr:e,createUUID:i,istype:o,deepClone:n,Context:d};class S{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);null==i||i.push(e),this._listeners.set(t,i||[])}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);if(Array.isArray(i))for(let t=0;t<(null==i?void 0:i.length);t++)if(i[t]===e){i.splice(t,1);break}this._listeners.set(t,i||[])}}trigger(t,e){const i=this._listeners.get(t);return!!Array.isArray(i)&&(i.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}}class y{constructor(t,e){this._isMoving=!1,this._temp=new class{constructor(){this._temp={prevClickPoint:null,isHoverCanvas:!1,isDragCanvas:!1,statusMap:{canScrollYPrev:!0,canScrollYNext:!0,canScrollXPrev:!0,canScrollXNext:!0}}}set(t,e){this._temp[t]=e}get(t){return this._temp[t]}clear(){this._temp={prevClickPoint:null,isHoverCanvas:!1,isDragCanvas:!1,statusMap:{canScrollYPrev:!0,canScrollYNext:!0,canScrollXPrev:!0,canScrollXNext:!0}}}},this._container=window,this._canvas=t,this._isMoving=!1,this._initEvent(),this._event=new S}setStatusMap(t){this._temp.set("statusMap",t)}on(t,e){this._event.on(t,e)}off(t,e){this._event.off(t,e)}_initEvent(){const t=this._canvas,e=this._container;e.addEventListener("mousemove",this._listenWindowMove.bind(this),!1),e.addEventListener("mouseup",this._listenWindowMoveEnd.bind(this),!1),t.addEventListener("mousemove",this._listenHover.bind(this),!1),t.addEventListener("mousedown",this._listenMoveStart.bind(this),!1),t.addEventListener("mousemove",this._listenMove.bind(this),!1),t.addEventListener("mouseup",this._listenMoveEnd.bind(this),!1),t.addEventListener("click",this._listenCanvasClick.bind(this),!1),t.addEventListener("wheel",this._listenCanvasWheel.bind(this),!1),t.addEventListener("mousedown",this._listenCanvasMoveStart.bind(this),!0),t.addEventListener("mouseup",this._listenCanvasMoveEnd.bind(this),!0),t.addEventListener("mouseover",this._listenCanvasMoveOver.bind(this),!0),t.addEventListener("mouseleave",this._listenCanvasMoveLeave.bind(this),!0),this._initParentEvent()}_initParentEvent(){try{let t=window;const e=t.origin;for(;t.self!==t.top&&(t.self!==t.parent&&t.origin===e&&t.parent.window.addEventListener("mousemove",this._listSameOriginParentWindow.bind(this),!1),t=t.parent,t););}catch(t){console.warn(t)}}_listenHover(t){t.preventDefault();const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.has("hover")&&this._event.trigger("hover",e),this._isMoving=!0}_listenMoveStart(t){t.preventDefault();const e=this._getPosition(t);this._isVaildPoint(e)&&(this._event.has("point")&&this._event.trigger("point",e),this._event.has("moveStart")&&this._event.trigger("moveStart",e)),this._isMoving=!0}_listenMove(t){if(t.preventDefault(),t.stopPropagation(),this._event.has("move")&&!0===this._isMoving){const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.trigger("move",e)}}_listenMoveEnd(t){if(t.preventDefault(),this._event.has("moveEnd")){const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.trigger("moveEnd",e)}this._isMoving=!1}_listSameOriginParentWindow(){this._temp.get("isHoverCanvas")&&this._event.has("leave")&&this._event.trigger("leave",void 0),this._temp.get("isDragCanvas")&&this._event.has("moveEnd")&&this._event.trigger("moveEnd",{x:NaN,y:NaN}),this._isMoving=!1,this._temp.set("isDragCanvas",!1),this._temp.set("isHoverCanvas",!1)}_listenCanvasMoveStart(){this._temp.get("isHoverCanvas")&&this._temp.set("isDragCanvas",!0)}_listenCanvasMoveEnd(){this._temp.set("isDragCanvas",!1)}_listenCanvasMoveOver(){this._temp.set("isHoverCanvas",!0)}_listenCanvasMoveLeave(){this._temp.set("isHoverCanvas",!1),this._event.has("leave")&&this._event.trigger("leave",void 0)}_listenWindowMove(t){if(!0===this._temp.get("isDragCanvas")&&(t.preventDefault(),t.stopPropagation(),this._event.has("move")&&!0===this._isMoving)){const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.trigger("move",e)}}_listenWindowMoveEnd(t){if(!0!=!this._temp.get("isDragCanvas")){if(t.preventDefault(),this._event.has("moveEnd")){const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.trigger("moveEnd",e)}this._temp.set("isDragCanvas",!1),this._isMoving=!1}}_listenCanvasWheel(t){this._event.has("wheelX")&&(t.deltaX>0||t.deltaX<0)&&this._event.trigger("wheelX",t.deltaX),this._event.has("wheelY")&&(t.deltaY>0||t.deltaY<0)&&this._event.trigger("wheelY",t.deltaY);const{canScrollYNext:e,canScrollYPrev:i}=this._temp.get("statusMap");(t.deltaX>0&&t.deltaX<0||t.deltaY>0&&!0===e||t.deltaY<0&&!0===i)&&t.preventDefault()}_listenCanvasClick(t){t.preventDefault();const e=this._getPosition(t),i=Date.now();if(this._isVaildPoint(e)){const t=this._temp.get("prevClickPoint");t&&i-t.t<=500&&Math.abs(t.x-e.x)<=5&&Math.abs(t.y-e.y)<=5?this._event.has("doubleClick")&&this._event.trigger("doubleClick",{x:e.x,y:e.y}):this._temp.set("prevClickPoint",{x:e.x,y:e.y,t:i})}}_getPosition(t){const e=this._canvas;let i=0,n=0;if(t&&t.touches&&t.touches.length>0){const e=t.touches[0];e&&(i=e.clientX,n=e.clientY)}else i=t.clientX,n=t.clientY;return{x:i-e.getBoundingClientRect().left,y:n-e.getBoundingClientRect().top,t:Date.now()}}_isVaildPoint(t){return w(t.x)&&w(t.y)}}function w(t){return t>0||t<0||0===t}const b={width:12,color:"#000000",showBackground:!0};class E{constructor(t,e){this._displayCtx=t,this._opts=this._getOpts(e)}draw(t){const{width:e,height:i,scrollConfig:n}=this._opts,s=this.calc(t),o=this._displayCtx;s.xSize>0&&(!0===n.showBackground&&(o.globalAlpha=.12,o.fillStyle=s.color,o.fillRect(0,this._doSize(i-s.lineSize),this._doSize(e),this._doSize(s.lineSize))),C(o,{axis:"X",x:this._doSize(s.translateX),y:this._doSize(i-s.lineSize),w:this._doSize(s.xSize),h:this._doSize(s.lineSize),r:this._doSize(s.lineSize/2),color:s.color})),s.ySize>0&&(!0===n.showBackground&&(o.globalAlpha=.12,o.fillStyle=s.color,o.fillRect(this._doSize(e-s.lineSize),0,this._doSize(s.lineSize),this._doSize(i))),C(o,{axis:"Y",x:this._doSize(e-s.lineSize),y:this._doSize(s.translateY),w:this._doSize(s.lineSize),h:this._doSize(s.ySize),r:this._doSize(s.lineSize/2),color:s.color})),o.globalAlpha=1}resetSize(t){this._opts=Object.assign(Object.assign({},this._opts),t)}isPointAtScrollY(t){const{width:e,height:i,scrollConfig:n}=this._opts,s=this._displayCtx;return s.beginPath(),s.rect(this._doSize(e-n.width),0,this._doSize(n.width),this._doSize(i)),s.closePath(),!!s.isPointInPath(this._doSize(t.x),this._doSize(t.y))}isPointAtScrollX(t){const{width:e,height:i,scrollConfig:n}=this._opts,s=this._displayCtx;return s.beginPath(),s.rect(0,this._doSize(i-n.width),this._doSize(e-n.width),this._doSize(n.width)),s.closePath(),!!s.isPointInPath(this._doSize(t.x),this._doSize(t.y))}getLineWidth(){return this._opts.scrollConfig.width}calc(t){const{width:e,height:i,scrollConfig:n}=this._opts,s=2.5*n.width,o=n.width;let r=0,l=0;t.left<=0&&t.right<=0&&(r=Math.max(s,e-(Math.abs(t.left)+Math.abs(t.right))),r>=e&&(r=0)),(t.top<=0||t.bottom<=0)&&(l=Math.max(s,i-(Math.abs(t.top)+Math.abs(t.bottom))),l>=i&&(l=0));let a=0;r>0&&(a=r/2+(e-r)*Math.abs(t.left)/(Math.abs(t.left)+Math.abs(t.right)),a=Math.min(Math.max(0,a-r/2),e-r));let h=0;l>0&&(h=l/2+(i-l)*Math.abs(t.top)/(Math.abs(t.top)+Math.abs(t.bottom)),h=Math.min(Math.max(0,h-l/2),i-l));return{lineSize:o,xSize:r,ySize:l,translateY:h,translateX:a,color:this._opts.scrollConfig.color}}_doSize(t){return t*this._opts.devicePixelRatio}_getOpts(t){var i;const n=Object.assign(Object.assign({},t),{scrollConfig:Object.assign(Object.assign({},b),t.scrollConfig||{})});return n.scrollConfig||(n.scrollConfig=b),(null===(i=null==n?void 0:n.scrollConfig)||void 0===i?void 0:i.width)>0||(n.scrollConfig.width=b.width),n.scrollConfig.width=Math.max(n.scrollConfig.width,b.width),!0!==e(n.scrollConfig.color)&&(n.scrollConfig.color=n.scrollConfig.color),n}}function C(t,e){let{x:i,y:n,h:s,w:o}=e;const{color:r,axis:l}=e;"X"===l?(n=n+s/4+1,s/=2):"Y"===l&&(i=i+o/4+1,o/=2);let a=e.r;a=Math.min(a,o/2,s/2),(o<2*a||s<2*a)&&(a=0),t.globalAlpha=.36,t.beginPath(),t.moveTo(i+a,n),t.arcTo(i+o,n,i+o,n+s,a),t.arcTo(i+o,n+s,i,n+s,a),t.arcTo(i,n+s,i,n,a),t.arcTo(i,n,i+o,n,a),t.closePath(),t.fillStyle=r,t.fill(),t.globalAlpha=1,t.beginPath(),t.lineWidth=1,t.strokeStyle=r,t.moveTo(i+a,n),t.arcTo(i+o,n,i+o,n+s,a),t.arcTo(i+o,n+s,i,n+s,a),t.arcTo(i,n+s,i,n,a),t.arcTo(i,n,i+o,n,a),t.closePath(),t.stroke()}const P=Symbol("_opts"),D=Symbol("_ctx");class L{constructor(t,e){this[P]=e,this[D]=t}resetSize(t){this[P]=Object.assign(Object.assign({},this[P]),t)}calcScreen(){const t=this[D].getTransform().scale,{width:e,height:i,contextWidth:n,contextHeight:s,devicePixelRatio:o}=this[P];let r=!0,l=!0,a=!0,h=!0;n*t<=e&&(this[D].setTransform({scrollX:(e-n*t)/2}),r=!1,l=!1),s*t<=i&&(this[D].setTransform({scrollY:(i-s*t)/2}),a=!1,h=!1),n*t>=e&&this[D].getTransform().scrollX>0&&(this[D].setTransform({scrollX:0}),r=!1),s*t>=i&&this[D].getTransform().scrollY>0&&(this[D].setTransform({scrollY:0}),a=!1);const{scrollX:c,scrollY:d}=this[D].getTransform();c<0&&Math.abs(c)>Math.abs(n*t-e)&&(this[D].setTransform({scrollX:0-Math.abs(n*t-e)}),l=!1),d<0&&Math.abs(d)>Math.abs(s*t-i)&&(this[D].setTransform({scrollY:0-Math.abs(s*t-i)}),h=!1);const{scrollX:u,scrollY:g}=this[D].getTransform();return{size:{x:u*t,y:g*t,w:n*t,h:s*t},position:{top:g,bottom:i-(s*t+g),left:u,right:e-(n*t+u)},deviceSize:{x:u*o,y:g*o,w:n*o*t,h:s*o*t},width:this[P].width,height:this[P].height,devicePixelRatio:this[P].devicePixelRatio,canScrollYPrev:a,canScrollYNext:h,canScrollXPrev:r,canScrollXNext:l}}calcScreenScroll(t,e,i,n,s){let o=t,r=n-i;t<=0&&e<=0&&(r=Math.abs(t)+Math.abs(e));let l=1;return r>0&&(l=r/(n-i)),o=0-l*s,o}}const{throttle:M,Context:I}=x;class z{constructor(t,e){this._hasRendered=!1,this._mount=t,this._canvas=document.createElement("canvas"),this._helperCanvas=document.createElement("canvas"),this._displayCanvas=document.createElement("canvas"),this._mount.appendChild(this._displayCanvas),this._opts=this._parsePrivateOptions(e);const i=this._canvas.getContext("2d"),n=this._displayCanvas.getContext("2d"),s=this._helperCanvas.getContext("2d");this._ctx=new I(i,this._opts),this._helperCtx=new I(s,this._opts),this._screen=new L(this._ctx,this._opts),this._watcher=new y(this._displayCanvas,this._ctx),this._scroller=new E(n,{width:e.width,height:e.height,devicePixelRatio:e.devicePixelRatio||1,scrollConfig:e.scrollConfig}),this._render()}getDisplayContext2D(){return this._displayCanvas.getContext("2d")}getOriginContext2D(){return this._ctx.getContext()}getHelperContext2D(){return this._helperCtx.getContext()}getContext(){return this._ctx}getHelperContext(){return this._helperCtx}scale(t){t>0&&(this._ctx.setTransform({scale:t}),this._helperCtx.setTransform({scale:t}));const{position:e,size:i}=this._screen.calcScreen();return{position:e,size:i}}scrollX(t){this._watcher.setStatusMap({canScrollYPrev:!0,canScrollYNext:!0,canScrollXPrev:!0,canScrollXNext:!0}),(t>=0||t<0)&&(this._ctx.setTransform({scrollX:t}),this._helperCtx.setTransform({scrollX:t}));const{position:e,size:i,canScrollXNext:n,canScrollYNext:s,canScrollXPrev:o,canScrollYPrev:r}=this._screen.calcScreen();return this._watcher.setStatusMap({canScrollYPrev:r,canScrollYNext:s,canScrollXPrev:o,canScrollXNext:n}),{position:e,size:i}}scrollY(t){this._watcher.setStatusMap({canScrollYPrev:!0,canScrollYNext:!0,canScrollXPrev:!0,canScrollXNext:!0}),(t>=0||t<0)&&(this._ctx.setTransform({scrollY:t}),this._helperCtx.setTransform({scrollY:t}));const{position:e,size:i,canScrollXNext:n,canScrollYNext:s,canScrollXPrev:o,canScrollYPrev:r}=this._screen.calcScreen();return this._watcher.setStatusMap({canScrollYPrev:r,canScrollYNext:s,canScrollXPrev:o,canScrollXNext:n}),{position:e,size:i}}getTransform(){return this._ctx.getTransform()}draw(){this.clear();const{position:t,deviceSize:e,size:i}=this._screen.calcScreen(),n=this._displayCanvas.getContext("2d");return null==n||n.drawImage(this._canvas,e.x,e.y,e.w,e.h),null==n||n.drawImage(this._helperCanvas,e.x,e.y,e.w,e.h),!0===this._opts.canScroll&&this._scroller.draw(t),{position:t,size:i}}clear(){const t=this._displayCanvas.getContext("2d");null==t||t.clearRect(0,0,this._displayCanvas.width,this._displayCanvas.height)}on(t,e){this._watcher.on(t,e)}off(t,e){this._watcher.off(t,e)}getScreenInfo(){return this._screen.calcScreen()}setCursor(t){this._displayCanvas.style.cursor=t}resetCursor(){this._displayCanvas.style.cursor="auto"}resetSize(t){this._opts=Object.assign(Object.assign({},this._opts),t),this._resetContext(),this._ctx.resetSize(t),this._helperCtx.resetSize(t),this._screen.resetSize(t),this._scroller.resetSize({width:this._opts.width,height:this._opts.height,devicePixelRatio:this._opts.devicePixelRatio}),this.draw()}getScrollLineWidth(){let t=0;return!0===this._opts.canScroll&&(t=this._scroller.getLineWidth()),t}pointScreenToContext(t){const{scrollX:e,scrollY:i,scale:n}=this.getTransform();return{x:(t.x-e)/n,y:(t.y-i)/n}}pointContextToScreen(t){const{scrollX:e,scrollY:i,scale:n}=this.getTransform();return{x:t.x*n+e,y:t.y*n+i}}_render(){!0!==this._hasRendered&&(this._resetContext(),this._initEvent(),this._hasRendered=!0)}_resetContext(){const{width:t,height:e,contextWidth:i,contextHeight:n,devicePixelRatio:s}=this._opts;this._canvas.width=i*s,this._canvas.height=n*s,this._helperCanvas.width=i*s,this._helperCanvas.height=n*s,this._displayCanvas.width=t*s,this._displayCanvas.height=e*s,function(t,e){const i=function(t){const e={};return(t.getAttribute("style")||"").split(";").forEach((t=>{const i=t.split(":");i[0]&&"string"==typeof i[0]&&(e[i[0]]=i[1]||"")})),e}(t),n=Object.assign(Object.assign({},i),e),s=Object.keys(n);let o="";s.forEach((t=>{o+=`${t}:${n[t]||""};`})),t.setAttribute("style",o)}(this._displayCanvas,{width:`${t}px`,height:`${e}px`})}_parsePrivateOptions(t){return Object.assign(Object.assign({},{devicePixelRatio:1}),t)}_initEvent(){if(!0!==this._hasRendered&&!0===this._opts.canScroll){this.on("wheelX",M((t=>{this._doScrollX(t)}),16)),this.on("wheelY",M((t=>{this._doScrollY(t)}),16));let t=null;this.on("moveStart",M((e=>{this._scroller.isPointAtScrollX(e)?t="x":this._scroller.isPointAtScrollY(e)&&(t="y")}),16)),this.on("move",M((e=>{t&&this._doMoveScroll(t,e)}),16)),this.on("moveEnd",M((e=>{t&&this._doMoveScroll(t,e),t=null}),16))}}_doScrollX(t,e){const{width:i}=this._opts;let n=e;"number"==typeof n&&(n>0||n<=0)||(n=this._ctx.getTransform().scrollX);const{position:s}=this._screen.calcScreen(),{xSize:o}=this._scroller.calc(s),r=this._screen.calcScreenScroll(s.left,s.right,o,i,t);this.scrollX(n+r),this.draw()}_doScrollY(t,e){const{height:i}=this._opts;let n=e;"number"==typeof n&&(n>0||n<=0)||(n=this._ctx.getTransform().scrollY);const{position:s}=this._screen.calcScreen(),{ySize:o}=this._scroller.calc(s),r=this._screen.calcScreenScroll(s.top,s.bottom,o,i,t);this.scrollY(n+r),this.draw()}_doMoveScroll(t,e){if(!t)return;const{position:i}=this._screen.calcScreen(),{xSize:n,ySize:s}=this._scroller.calc(i);"x"===t?this._doScrollX(e.x-n/2,0):"y"===t&&this._doScrollY(e.y-s/2,0)}}function T(t,e,i){const n=function(t){return{x:t.x+t.w/2,y:t.y+t.h/2}}(e);return function(t,e,i,n){e&&(i>0||i<0)&&(t.translate(e.x,e.y),t.rotate(i),t.translate(-e.x,-e.y));n(t),e&&(i>0||i<0)&&(t.translate(e.x,e.y),t.rotate(-i),t.translate(-e.x,-e.y))}(t,n,(e.angle||0)/180*Math.PI||0,i)}function k(t){t.setFillStyle("#000000"),t.setStrokeStyle("#000000"),t.setLineDash([]),t.setGlobalAlpha(1),t.setShadowColor("#00000000"),t.setShadowOffsetX(0),t.setShadowOffsetY(0),t.setShadowBlur(0)}function U(t,i,n){k(t),function(t,i){k(t),T(t,i,(()=>{if(!(i.desc.borderWidth&&i.desc.borderWidth>0))return;const n=i.desc.borderWidth;let s="#000000";!0===e(i.desc.borderColor)&&(s=i.desc.borderColor);const o=i.x-n/2,r=i.y-n/2,l=i.w+n,a=i.h+n;let h=i.desc.borderRadius||0;h=Math.min(h,l/2,a/2),h<l/2&&h<a/2&&(h+=n/2);const{desc:c}=i;void 0!==c.shadowColor&&e(c.shadowColor)&&t.setShadowColor(c.shadowColor),void 0!==c.shadowOffsetX&&f.number(c.shadowOffsetX)&&t.setShadowOffsetX(c.shadowOffsetX),void 0!==c.shadowOffsetY&&f.number(c.shadowOffsetY)&&t.setShadowOffsetY(c.shadowOffsetY),void 0!==c.shadowBlur&&f.number(c.shadowBlur)&&t.setShadowBlur(c.shadowBlur),t.beginPath(),t.setLineWidth(n),t.setStrokeStyle(s),t.moveTo(o+h,r),t.arcTo(o+l,r,o+l,r+a,h),t.arcTo(o+l,r+a,o,r+a,h),t.arcTo(o,r+a,o,r,h),t.arcTo(o,r,o+l,r,h),t.closePath(),t.stroke()}))}(t,i),k(t),T(t,i,(()=>{const{x:e,y:s,w:r,h:l}=i;let a=i.desc.borderRadius||0;a=Math.min(a,r/2,l/2),(r<2*a||l<2*a)&&(a=0),t.beginPath(),t.moveTo(e+a,s),t.arcTo(e+r,s,e+r,s+l,a),t.arcTo(e+r,s+l,e,s+l,a),t.arcTo(e,s+l,e,s,a),t.arcTo(e,s,e+r,s,a),t.closePath(),("string"==typeof n||["CanvasPattern"].includes(o.type(n)))&&t.setFillStyle(n),t.fill()}))}function W(t,e){U(t,e,e.desc.bgColor)}function R(t,e,i){const n=i.getContent(e.uuid);T(t,e,(()=>{n&&t.drawImage(n,e.x,e.y,e.w,e.h)}))}function O(t,e,i){const n=i.getContent(e.uuid);T(t,e,(()=>{n&&t.drawImage(n,e.x,e.y,e.w,e.h)}))}function A(t,e,i){const n=i.getContent(e.uuid);T(t,e,(()=>{n&&t.drawImage(n,e.x,e.y,e.w,e.h)}))}function F(t,i,n){k(t),U(t,i,i.desc.bgColor||"transparent"),T(t,i,(()=>{const n=Object.assign({fontSize:12,fontFamily:"sans-serif",textAlign:"center"},i.desc);t.setFillStyle(i.desc.color),t.setTextBaseline("top"),t.setFont({fontWeight:n.fontWeight,fontSize:n.fontSize,fontFamily:n.fontFamily});const s=n.text.replace(/\r\n/gi,"\n"),o=n.lineHeight||n.fontSize,r=s.split("\n"),l=[];let a=0;r.forEach(((e,n)=>{let s="";if(e.length>0){for(let h=0;h<e.length&&(t.measureText(s+(e[h]||"")).width<t.calcDeviceNum(i.w)?s+=e[h]||"":(l.push({text:s,width:t.calcScreenNum(t.measureText(s).width)}),s=e[h]||"",a++),!((a+1)*o>i.h));h++)if(e.length-1===h&&(a+1)*o<i.h){l.push({text:s,width:t.calcScreenNum(t.measureText(s).width)}),n<r.length-1&&a++;break}}else l.push({text:"",width:0})}));let h=0;l.length*o<i.h&&("top"===i.desc.verticalAlign?h=0:"bottom"===i.desc.verticalAlign?h+=i.h-l.length*o:h+=(i.h-l.length*o)/2);{const s=i.y+h;void 0!==n.textShadowColor&&e(n.textShadowColor)&&t.setShadowColor(n.textShadowColor),void 0!==n.textShadowOffsetX&&f.number(n.textShadowOffsetX)&&t.setShadowOffsetX(n.textShadowOffsetX),void 0!==n.textShadowOffsetY&&f.number(n.textShadowOffsetY)&&t.setShadowOffsetY(n.textShadowOffsetY),void 0!==n.textShadowBlur&&f.number(n.textShadowBlur)&&t.setShadowBlur(n.textShadowBlur),l.forEach(((e,r)=>{let l=i.x;"center"===n.textAlign?l=i.x+(i.w-e.width)/2:"right"===n.textAlign&&(l=i.x+(i.w-e.width)),t.fillText(e.text,l,s+o*r)})),k(t)}if(e(n.strokeColor)&&void 0!==n.strokeWidth&&n.strokeWidth>0){const e=i.y+h;l.forEach(((s,r)=>{let l=i.x;"center"===n.textAlign?l=i.x+(i.w-s.width)/2:"right"===n.textAlign&&(l=i.x+(i.w-s.width)),void 0!==n.strokeColor&&t.setStrokeStyle(n.strokeColor),void 0!==n.strokeWidth&&n.strokeWidth>0&&t.setLineWidth(n.strokeWidth),t.strokeText(s.text,l,e+o*r)}))}}))}function $(t,e){k(t),T(t,e,(t=>{const{x:i,y:n,w:s,h:o,desc:r}=e,{bgColor:l="#000000",borderColor:a="#000000",borderWidth:h=0}=r,c=s/2,d=o/2,u=i+c,g=n+d;if(h&&h>0){const e=h/2+c,i=h/2+d;t.beginPath(),t.setStrokeStyle(a),t.setLineWidth(h),t.ellipse(u,g,e,i,0,0,2*Math.PI),t.closePath(),t.stroke()}t.beginPath(),t.setFillStyle(l),t.ellipse(u,g,c,d,0,0,2*Math.PI),t.closePath(),t.fill()}))}function Y(t,i,n){var s;k(t);const o=t.getSize();if(t.clearRect(0,0,o.contextWidth,o.contextHeight),"string"==typeof i.bgColor&&e(i.bgColor)&&function(t,e){const i=t.getSize();t.setFillStyle(e),t.fillRect(0,0,i.contextWidth,i.contextHeight)}(t,i.bgColor),i.elements.length>0)for(let e=0;e<i.elements.length;e++){const o=i.elements[e];if(!0!==(null===(s=null==o?void 0:o.operation)||void 0===s?void 0:s.invisible))switch(o.type){case"rect":W(t,o);break;case"text":F(t,o);break;case"image":R(t,o,n);break;case"svg":O(t,o,n);break;case"html":A(t,o,n);break;case"circle":$(t,o)}}}class X{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);null==i||i.push(e),this._listeners.set(t,i||[])}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);if(Array.isArray(i))for(let t=0;t<(null==i?void 0:i.length);t++)if(i[t]===e){i.splice(t,1);break}this._listeners.set(t,i||[])}}trigger(t,e){const i=this._listeners.get(t);return!!Array.isArray(i)&&(i.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}}var N,H,B=globalThis&&globalThis.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{a(n.next(t))}catch(t){o(t)}}function l(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,l)}a((n=n.apply(t,e||[])).next())}))};(H=N||(N={})).FREE="free",H.LOADING="loading",H.COMPLETE="complete";class j{constructor(t){this._currentLoadData={},this._currentUUIDQueue=[],this._storageLoadData={},this._status=N.FREE,this._waitingLoadQueue=[],this._opts=t,this._event=new X,this._waitingLoadQueue=[]}load(t,e){const[i,n]=this._resetLoadData(t,e);this._status===N.FREE||this._status===N.COMPLETE?(this._currentUUIDQueue=i,this._currentLoadData=n,this._loadTask()):this._status===N.LOADING&&i.length>0&&this._waitingLoadQueue.push({uuidQueue:i,loadData:n})}on(t,e){this._event.on(t,e)}off(t,e){this._event.off(t,e)}isComplete(){return this._status===N.COMPLETE}getContent(t){var e;return"loaded"===(null===(e=this._storageLoadData[t])||void 0===e?void 0:e.status)?this._storageLoadData[t].content:null}_resetLoadData(t,e){const i={},n=[],s=this._storageLoadData;for(let o=t.elements.length-1;o>=0;o--){const r=t.elements[o];["image","svg","html"].includes(r.type)&&(s[r.uuid]?e.includes(r.uuid)&&(i[r.uuid]=this._createEmptyLoadItem(r),n.push(r.uuid)):(i[r.uuid]=this._createEmptyLoadItem(r),n.push(r.uuid)))}return[n,i]}_createEmptyLoadItem(t){let e="";const i=t.type;let s=t.w,o=t.h;if("image"===t.type){e=t.desc.src||""}else if("svg"===t.type){e=t.desc.svg||""}else if("html"===t.type){const i=t;e=(i.desc.html||"").replace(/<script[\s\S]*?<\/script>/gi,""),s=i.desc.width||t.w,o=i.desc.height||t.h}return{uuid:t.uuid,type:i,status:"null",content:null,source:e,elemW:s,elemH:o,element:n(t)}}_loadTask(){if(this._status===N.LOADING)return;if(this._status=N.LOADING,0===this._currentUUIDQueue.length){if(0===this._waitingLoadQueue.length)return this._status=N.COMPLETE,void this._event.trigger("complete",void 0);{const t=this._waitingLoadQueue.shift();if(t){const{uuidQueue:e,loadData:i}=t;this._currentLoadData=i,this._currentUUIDQueue=e}}}const{maxParallelNum:t}=this._opts,e=this._currentUUIDQueue.splice(0,t);e.forEach(((t,e)=>{}));const i=[],n=()=>{if(i.length>=t)return!1;if(0===e.length)return!0;for(let s=i.length;s<t;s++){const t=e.shift();if(void 0===t)break;i.push(t),this._loadElementSource(this._currentLoadData[t]).then((s=>{var o,r;i.splice(i.indexOf(t),1);const l=n();this._storageLoadData[t]={uuid:t,type:this._currentLoadData[t].type,status:"loaded",content:s,source:this._currentLoadData[t].source,elemW:this._currentLoadData[t].elemW,elemH:this._currentLoadData[t].elemH,element:this._currentLoadData[t].element},0===i.length&&0===e.length&&!0===l&&(this._status=N.FREE,this._loadTask()),this._event.trigger("load",{uuid:null===(o=this._storageLoadData[t])||void 0===o?void 0:o.uuid,type:this._storageLoadData[t].type,status:this._storageLoadData[t].status,content:this._storageLoadData[t].content,source:this._storageLoadData[t].source,elemW:this._storageLoadData[t].elemW,elemH:this._storageLoadData[t].elemH,element:null===(r=this._storageLoadData[t])||void 0===r?void 0:r.element})})).catch((s=>{var o,r,l,a,h,c,d,u,g,m,_,f;console.warn(s),i.splice(i.indexOf(t),1);const p=n();this._currentLoadData[t]&&(this._storageLoadData[t]={uuid:t,type:null===(o=this._currentLoadData[t])||void 0===o?void 0:o.type,status:"fail",content:null,error:s,source:null===(r=this._currentLoadData[t])||void 0===r?void 0:r.source,elemW:null===(l=this._currentLoadData[t])||void 0===l?void 0:l.elemW,elemH:null===(a=this._currentLoadData[t])||void 0===a?void 0:a.elemH,element:null===(h=this._currentLoadData[t])||void 0===h?void 0:h.element}),0===i.length&&0===e.length&&!0===p&&(this._status=N.FREE,this._loadTask()),this._currentLoadData[t]&&this._event.trigger("error",{uuid:t,type:null===(c=this._storageLoadData[t])||void 0===c?void 0:c.type,status:null===(d=this._storageLoadData[t])||void 0===d?void 0:d.status,content:null===(u=this._storageLoadData[t])||void 0===u?void 0:u.content,source:null===(g=this._storageLoadData[t])||void 0===g?void 0:g.source,elemW:null===(m=this._storageLoadData[t])||void 0===m?void 0:m.elemW,elemH:null===(_=this._storageLoadData[t])||void 0===_?void 0:_.elemH,element:null===(f=this._storageLoadData[t])||void 0===f?void 0:f.element})}))}return!1};n()}_loadElementSource(t){return B(this,void 0,void 0,(function*(){if(t&&"image"===t.type){return yield a(t.source)}if(t&&"svg"===t.type){return yield h(t.source)}if(t&&"html"===t.type){return yield c(t.source,{width:t.elemW,height:t.elemH})}throw Error("Element's source is not support!")}))}}class G{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);null==i||i.push(e),this._listeners.set(t,i||[])}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);if(Array.isArray(i))for(let t=0;t<(null==i?void 0:i.length);t++)if(i[t]===e){i.splice(t,1);break}this._listeners.set(t,i||[])}}trigger(t,e){const i=this._listeners.get(t);return!!Array.isArray(i)&&(i.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}}const{requestAnimationFrame:q}=window;var Q,V;(V=Q||(Q={})).NULL="null",V.FREE="free",V.DRAWING="drawing",V.FREEZE="freeze";class Z extends G{constructor(t){super(),this._queue=[],this._ctx=null,this._status=Q.NULL,this._opts=t,this._loader=new j({maxParallelNum:6}),this._loader.on("load",(t=>{this._drawFrame(),this.trigger("load",{element:t.element})})),this._loader.on("error",(t=>{this.trigger("error",{element:t.element,error:t.error})})),this._loader.on("complete",(()=>{this.trigger("loadComplete",{t:Date.now()})}))}render(t,e,s){const{changeResourceUUIDs:o=[]}=s||{};this._status=Q.FREE;const r=n(e);if(Array.isArray(r.elements)&&r.elements.forEach((t=>{"string"==typeof t.uuid&&t.uuid||(t.uuid=i())})),!this._ctx)if(this._opts&&"[object HTMLCanvasElement]"===Object.prototype.toString.call(t)){const{width:e,height:i,contextWidth:n,contextHeight:s,devicePixelRatio:o}=this._opts,r=t;r.width=e*o,r.height=i*o;const l=r.getContext("2d");this._ctx=new d(l,{width:e,height:i,contextWidth:n||e,contextHeight:s||i,devicePixelRatio:o})}else t&&(this._ctx=t);if([Q.FREEZE].includes(this._status))return;const l=n({data:r});this._queue.push(l),this._drawFrame(),this._loader.load(r,o||[])}getContext(){return this._ctx}thaw(){this._status=Q.FREE}_freeze(){this._status=Q.FREEZE}_drawFrame(){this._status!==Q.FREEZE&&q((()=>{if(this._status===Q.FREEZE)return;const t=this._ctx;let e=this._queue[0],i=!1;this._queue.length>1?e=this._queue.shift():i=!0,!0!==this._loader.isComplete()?(this._drawFrame(),e&&t&&Y(t,e.data,this._loader)):e&&t?(Y(t,e.data,this._loader),this._retainQueueOneItem(),i?this._status=Q.FREE:this._drawFrame()):this._status=Q.FREE,this.trigger("drawFrame",{t:Date.now()}),!0===this._loader.isComplete()&&1===this._queue.length&&this._status===Q.FREE&&(t&&this._queue[0]&&this._queue[0].data&&Y(t,this._queue[0].data,this._loader),this.trigger("drawFrameComplete",{t:Date.now()}),this._freeze())}))}_retainQueueOneItem(){if(this._queue.length<=1)return;const t=n(this._queue[this._queue.length-1]);this._queue=[t]}}function J(t){return"number"==typeof t&&(t>0||t<=0)}function K(t){return"number"==typeof t&&t>=0}function tt(t){return"string"==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${t}`)}function et(t){return"string"==typeof t&&/^(data:image\/)/.test(`${t}`)}const it={x:function(t){return J(t)},y:function(t){return J(t)},w:K,h:function(t){return"number"==typeof t&&t>=0},angle:function(t){return"number"==typeof t&&t>=-360&&t<=360},number:J,borderWidth:function(t){return K(t)},borderRadius:function(t){return J(t)&&t>=0},color:function(t){return e(t)},imageSrc:function(t){return et(t)||tt(t)},imageURL:tt,imageBase64:et,svg:function(t){return"string"==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test(`${t}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${t}`.trim())},html:function(t){let e=!1;if("string"==typeof t){let i=document.createElement("div");i.innerHTML=t,i.children.length>0&&(e=!0),i=null}return e},text:function(t){return"string"==typeof t},fontSize:function(t){return J(t)&&t>0},lineHeight:function(t){return J(t)&&t>0},textAlign:function(t){return["center","left","right"].includes(t)},fontFamily:function(t){return"string"==typeof t&&t.length>0},fontWeight:function(t){return["bold"].includes(t)},strokeWidth:function(t){return J(t)&&t>0}};function nt(t={}){const{borderColor:e,borderRadius:i,borderWidth:n}=t;return!(t.hasOwnProperty("borderColor")&&!it.color(e))&&(!(t.hasOwnProperty("borderRadius")&&!it.number(i))&&!(t.hasOwnProperty("borderWidth")&&!it.number(n)))}const st={attrs:function(t){const{x:e,y:i,w:n,h:s,angle:o}=t;return!!(it.x(e)&&it.y(i)&&it.w(n)&&it.h(s)&&it.angle(o))&&(o>=-360&&o<=360)},textDesc:function(t){const{text:e,color:i,fontSize:n,lineHeight:s,fontFamily:o,textAlign:r,fontWeight:l,bgColor:a,strokeWidth:h,strokeColor:c}=t;return!!it.text(e)&&(!!it.color(i)&&(!!it.fontSize(n)&&(!(t.hasOwnProperty("bgColor")&&!it.color(a))&&(!(t.hasOwnProperty("fontWeight")&&!it.fontWeight(l))&&(!(t.hasOwnProperty("lineHeight")&&!it.lineHeight(s))&&(!(t.hasOwnProperty("fontFamily")&&!it.fontFamily(o))&&(!(t.hasOwnProperty("textAlign")&&!it.textAlign(r))&&(!(t.hasOwnProperty("strokeWidth")&&!it.strokeWidth(h))&&(!(t.hasOwnProperty("strokeColor")&&!it.color(c))&&!!nt(t))))))))))},rectDesc:function(t){const{bgColor:e}=t;return!(t.hasOwnProperty("bgColor")&&!it.color(e))&&!!nt(t)},circleDesc:function(t){const{bgColor:e,borderColor:i,borderWidth:n}=t;return!(t.hasOwnProperty("bgColor")&&!it.color(e))&&(!(t.hasOwnProperty("borderColor")&&!it.color(i))&&!(t.hasOwnProperty("borderWidth")&&!it.number(n)))},imageDesc:function(t){const{src:e}=t;return!!it.imageSrc(e)},svgDesc:function(t){const{svg:e}=t;return!!it.svg(e)},htmlDesc:function(t){const{html:e}=t;return!!it.html(e)}};function ot(t){return t/180*Math.PI}function rt(t){return{x:t.x+t.w/2,y:t.y+t.h/2}}function lt(t,e){const i=e.x-t.x,n=t.y-e.y;if(0===i){if(n<0)return Math.PI/2;if(n>0)return 1.5*Math.PI}else if(0===n){if(i<0)return Math.PI;if(i>0)return 0}return i>0&&n<0?Math.atan(Math.abs(n)/Math.abs(i)):i<0&&n<0?Math.PI-Math.atan(Math.abs(n)/Math.abs(i)):i<0&&n>0?Math.PI+Math.atan(Math.abs(n)/Math.abs(i)):i>0&&n>0?2*Math.PI-Math.atan(Math.abs(n)/Math.abs(i)):null}const at={elementWrapper:{color:"#0d85da",lockColor:"#aaaaaa",controllerSize:6,lineWidth:1,lineDash:[4,3]}};class ht{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);null==i||i.push(e),this._listeners.set(t,i||[])}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);if(Array.isArray(i))for(let t=0;t<(null==i?void 0:i.length);t++)if(i[t]===e){i.splice(t,1);break}this._listeners.set(t,i||[])}}trigger(t,e){const i=this._listeners.get(t);return!!Array.isArray(i)&&(i.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}}function ct(t,e){var i,n;return(null==(i=null==t?void 0:t.desc)?void 0:i.src)!==(null==(n=null==e?void 0:e.desc)?void 0:n.src)}function dt(t,e){var i,n;return(null==(i=null==t?void 0:t.desc)?void 0:i.svg)!==(null==(n=null==e?void 0:e.desc)?void 0:n.svg)}function ut(t,e){var i,n,s,o,r,l;return(null==(i=null==t?void 0:t.desc)?void 0:i.html)!==(null==(n=null==e?void 0:e.desc)?void 0:n.html)||(null==(s=null==t?void 0:t.desc)?void 0:s.width)!==(null==(o=null==e?void 0:e.desc)?void 0:o.width)||(null==(r=null==t?void 0:t.desc)?void 0:r.height)!==(null==(l=null==e?void 0:e.desc)?void 0:l.height)}function gt(t,e){let i=null,n=!1;switch(e.type){case"image":n=ct(t,e);break;case"svg":n=dt(t,e);break;case"html":n=ut(t,e)}return!0===n&&(i=e.uuid),i}function mt(t){const e={};return t.elements.forEach((t=>{e[t.uuid]=t})),e}function _t(t,e,i){return ft(t,rt(e),ot(e.angle||0)||0,i)}function ft(t,e,i,n){e&&(i>0||i<0)&&(t.translate(e.x,e.y),t.rotate(i),t.translate(-e.x,-e.y)),n(t),e&&(i>0||i<0)&&(t.translate(e.x,e.y),t.rotate(-i),t.translate(-e.x,-e.y))}function pt(t){const e=t.toFixed(2);return parseFloat(e)}function vt(t){return pt(t%360)}const xt=Object.keys({text:{},rect:{},image:{},svg:{},circle:{},html:{}}),St=15;class yt{constructor(t){this._ctx=t}initData(t){return t.elements.forEach((t=>{t.uuid&&"string"==typeof t.uuid||(t.uuid=i())})),t}isPointInElement(t,e){var i,n;const s=this._ctx;let o=-1,r=null;for(let l=e.elements.length-1;l>=0;l--){const a=e.elements[l];if(!0===(null==(i=a.operation)?void 0:i.invisible))continue;let h=0;if((null==(n=a.desc)?void 0:n.borderWidth)>0&&(h=a.desc.borderWidth),_t(s,a,(()=>{s.beginPath(),s.moveTo(a.x-h,a.y-h),s.lineTo(a.x+a.w+h,a.y-h),s.lineTo(a.x+a.w+h,a.y+a.h+h),s.lineTo(a.x-h,a.y+a.h+h),s.lineTo(a.x-h,a.y-h),s.closePath(),s.isPointInPath(t.x,t.y)&&(o=l,r=a.uuid)})),o>=0)break}return[o,r]}dragElement(t,e,i,n,s){const o=this.getElementIndex(t,e);if(!t.elements[o])return;const r=i.x-n.x,l=i.y-n.y;t.elements[o].x+=r/s,t.elements[o].y+=l/s,this.limitElementAttrs(t.elements[o])}transformElement(t,e,i,n,s,o){var r,l;const a=this.getElementIndex(t,e);if(!t.elements[a])return null;if(!0===(null==(l=null==(r=t.elements[a])?void 0:r.operation)?void 0:l.lock))return null;const h=(i.x-n.x)/s,c=(i.y-n.y)/s,d=t.elements[a];if(["top-left","top","top-right","right","bottom-right","bottom","bottom-left","left"].includes(o)){const t=function(t,e,i,n){var s,o,r,l,a,h,c,d,u,g,m,_,f;const p={x:t.x,y:t.y,w:t.w,h:t.h};if(t.angle,!0===(null==(s=t.operation)?void 0:s.limitRatio)&&["top-left","top-right","bottom-right","bottom-left"].includes(n)){const n=Math.max(Math.abs(e),Math.abs(i));e=(e>=0?1:-1)*n,i=(i>=0?1:-1)*n/t.w*t.h}switch(n){case"top-left":t.w-e>0&&t.h-i>0&&(p.x+=e,p.y+=i,p.w-=e,p.h-=i);break;case"top":if(0===t.angle||Math.abs(t.angle||0)<St)p.h-i>0&&(p.y+=i,p.h-=i,!0===(null==(o=t.operation)?void 0:o.limitRatio)&&(p.x+=i/t.h*t.w/2,p.w-=i/t.h*t.w));else if(void 0!==t.angle&&(t.angle>0||t.angle<0)){const n=t.angle>0?t.angle:Math.max(0,t.angle+360);let s=bt(e,i),o=p.x+t.w/2,l=p.y+t.h/2;if(n<90){s=0-Et(s,i);const t=wt(n),e=s/2;o+=e*Math.sin(t),l-=e*Math.cos(t)}else if(n<180){s=Et(s,e);const t=wt(n-90),i=s/2;o+=i*Math.cos(t),l+=i*Math.sin(t)}else if(n<270){s=Et(s,i);const t=wt(n-180),e=s/2;o-=e*Math.sin(t),l+=e*Math.cos(t)}else if(n<360){s=0-Et(s,e);const t=wt(n-270),i=s/2;o-=i*Math.cos(t),l-=i*Math.sin(t)}p.h+s>0&&(!0===(null==(r=t.operation)?void 0:r.limitRatio)&&(p.w=p.w+s/t.h*t.w),p.h=p.h+s,p.x=o-p.w/2,p.y=l-p.h/2)}else p.h-i>0&&(p.y+=i,p.h-=i,!0===(null==(l=t.operation)?void 0:l.limitRatio)&&(p.x-=e/2,p.w+=e));break;case"top-right":p.h-i>0&&p.w+e>0&&(p.y+=i,p.w+=e,p.h-=i);break;case"right":if(0===t.angle||Math.abs(t.angle||0)<St)t.w+e>0&&(p.w+=e,!0===(null==(a=t.operation)?void 0:a.limitRatio)&&(p.y-=e*t.h/t.w/2,p.h+=e*t.h/t.w));else if(void 0!==t.angle&&(t.angle>0||t.angle<0)){const n=t.angle>0?t.angle:Math.max(0,t.angle+360);let s=bt(e,i),o=p.x+t.w/2,r=p.y+t.h/2;if(n<90){s=Et(s,i);const t=wt(n),e=s/2;o+=e*Math.cos(t),r+=e*Math.sin(t)}else if(n<180){s=Et(s,i);const t=wt(n-90),e=s/2;o-=e*Math.sin(t),r+=e*Math.cos(t)}else if(n<270){s=Et(s,i);const t=wt(n-180),e=s/2;o+=e*Math.cos(t),r+=e*Math.sin(t),s=0-s}else if(n<360){s=Et(s,e);const t=wt(n-270),i=s/2;o+=i*Math.sin(t),r-=i*Math.cos(t)}p.w+s>0&&(!0===(null==(h=t.operation)?void 0:h.limitRatio)&&(p.h=p.h+s/t.w*t.h),p.w=p.w+s,p.x=o-p.w/2,p.y=r-p.h/2)}else t.w+e>0&&(p.w+=e,!0===(null==(c=t.operation)?void 0:c.limitRatio)&&(p.h+=e*t.h/t.w,p.y-=e*t.h/t.w/2));break;case"bottom-right":t.w+e>0&&t.h+i>0&&(p.w+=e,p.h+=i);break;case"bottom":if(0===t.angle||Math.abs(t.angle||0)<St)t.h+i>0&&(p.h+=i,!0===(null==(d=t.operation)?void 0:d.limitRatio)&&(p.x-=i/t.h*t.w/2,p.w+=i/t.h*t.w));else if(void 0!==t.angle&&(t.angle>0||t.angle<0)){const n=t.angle>0?t.angle:Math.max(0,t.angle+360);let s=bt(e,i),o=p.x+t.w/2,r=p.y+t.h/2;if(n<90){s=Et(s,i);const t=wt(n),e=s/2;o-=e*Math.sin(t),r+=e*Math.cos(t)}else if(n<180){s=0-Et(s,e);const t=wt(n-90),i=s/2;o-=i*Math.cos(t),r-=i*Math.sin(t)}else if(n<270){s=Et(s,e);const t=wt(n-180),i=s/2;o+=i*Math.sin(t),r-=i*Math.cos(t)}else if(n<360){s=Et(s,e);const t=wt(n-270),i=s/2;o+=i*Math.cos(t),r+=i*Math.sin(t)}p.h+s>0&&(!0===(null==(u=t.operation)?void 0:u.limitRatio)&&(p.w=p.w+s/t.h*t.w),p.h=p.h+s,p.x=o-p.w/2,p.y=r-p.h/2)}else t.h+i>0&&(p.h+=i,!0===(null==(g=t.operation)?void 0:g.limitRatio)&&(p.x-=i/t.h*t.w/2,p.w+=i/t.h*t.w));break;case"bottom-left":t.w-e>0&&t.h+i>0&&(p.x+=e,p.w-=e,p.h+=i);break;case"left":if(0===t.angle||Math.abs(t.angle||0)<St)t.w-e>0&&(p.x+=e,p.w-=e,!0===(null==(m=t.operation)?void 0:m.limitRatio)&&(p.h-=e/t.w*t.h,p.y+=e/t.w*t.h/2));else if(void 0!==t.angle&&(t.angle>0||t.angle<0)){const n=t.angle>0?t.angle:Math.max(0,t.angle+360);let s=bt(e,i),o=p.x+t.w/2,r=p.y+t.h/2;if(n<90){s=0-Et(s,e);const t=wt(n),i=s/2;o-=i*Math.cos(t),r-=i*Math.sin(t)}else if(n<180){s=Et(s,e);const t=wt(n-90),i=s/2;o+=i*Math.sin(t),r-=i*Math.cos(t)}else if(n<270){s=Et(s,i);const t=wt(n-180),e=s/2;o+=e*Math.cos(t),r+=e*Math.sin(t)}else if(n<360){s=Et(s,i);const t=wt(n-270),e=s/2;o-=e*Math.sin(t),r+=e*Math.cos(t)}p.w+s>0&&(!0===(null==(_=t.operation)?void 0:_.limitRatio)&&(p.h=p.h+s/t.w*t.h),p.w=p.w+s,p.x=o-p.w/2,p.y=r-p.h/2)}else t.w-e>0&&(p.x+=e,p.w-=e,!0===(null==(f=t.operation)?void 0:f.limitRatio)&&(p.h-=e/t.w*t.h,p.y+=e/t.w*t.h/2))}return p}(d,h,c,o);d.x=t.x,d.y=t.y,d.w=t.w,d.h=t.h}else if("rotate"===o){const t=function(t,e,i){const n=lt(t,e),s=lt(t,i);return null!==s&&null!==n?n>3*Math.PI/2&&s<Math.PI/2?s+(2*Math.PI-n):s>3*Math.PI/2&&n<Math.PI/2?n+(2*Math.PI-s):s-n:0}(rt(d),n,i);d.angle=(d.angle||0)+function(t){return t/Math.PI*180}(t)}return this.limitElementAttrs(d),{width:pt(d.w),height:pt(d.h),angle:vt(d.angle||0)}}getElementIndex(t,e){let i=-1;for(let n=0;n<t.elements.length;n++)if(t.elements[n].uuid===e){i=n;break}return i}limitElementAttrs(t){t.x=pt(t.x),t.y=pt(t.y),t.w=pt(t.w),t.h=pt(t.h),t.angle=vt(t.angle||0)}}function wt(t){return t*Math.PI/180}function bt(t,e){return Math.sqrt(t*t+e*e)}function Et(t,e){return e>0?Math.abs(t):0-Math.abs(t)}class Ct{constructor(t,e){this._areaStart={x:0,y:0},this._areaEnd={x:0,y:0},this._board=t,this._ctx=this._board.getContext(),this._coreConfig=e,this._helperConfig={elementIndexMap:{}}}updateConfig(t,e){this._updateElementIndex(t),this._updateSelectedElementWrapper(t,e),this._updateSelectedElementListWrapper(t,e)}getConfig(){return n(this._helperConfig)}getElementIndexByUUID(t){const e=this._helperConfig.elementIndexMap[t];return e>=0?e:null}isPointInElementWrapperController(t,e){var i,s;const o=this._ctx,r=(null==(s=null==(i=this._helperConfig)?void 0:i.selectedElementWrapper)?void 0:s.uuid)||null;let l=null,a=null,h=null;if(!this._helperConfig.selectedElementWrapper)return{uuid:r,selectedControllerDirection:a,directIndex:l,hoverControllerDirection:h};const c=this._helperConfig.selectedElementWrapper,d=[c.controllers.right,c.controllers.topRight,c.controllers.top,c.controllers.topLeft,c.controllers.left,c.controllers.bottomLeft,c.controllers.bottom,c.controllers.bottomRight],u=["right","top-right","top","top-left","left","bottom-left","bottom","bottom-right"];let g=n(u),m=0;if(e&&r){const t=this.getElementIndexByUUID(r);if(null!==t&&t>=0){let i=e.elements[t].angle||0;i<0&&(i+=360),i<45?m=0:i<90?m=1:i<135?m=2:i<180?m=3:i<225?m=4:i<270?m=5:i<315&&(m=6)}}if(m>0&&(g=g.slice(-m).concat(g.slice(0,-m))),ft(o,c.translate,c.radian||0,(()=>{for(let e=0;e<d.length;e++){const i=d[e];if(!0!==i.invisible&&(o.beginPath(),o.arc(i.x,i.y,c.controllerSize,0,2*Math.PI),o.closePath(),o.isPointInPath(t.x,t.y)&&(a=u[e],h=g[e]),a)){l=e;break}}})),null===a){const e=c.controllers.rotate;!0!==e.invisible&&ft(o,c.translate,c.radian||0,(()=>{o.beginPath(),o.arc(e.x,e.y,c.controllerSize,0,2*Math.PI),o.closePath(),o.isPointInPath(t.x,t.y)&&(a="rotate",h="rotate")}))}return{uuid:r,selectedControllerDirection:a,hoverControllerDirection:h,directIndex:l}}isPointInElementList(t,e){var i,n,s;const o=this._ctx;let r=-1,l=null;const a=(null==(i=this._helperConfig)?void 0:i.selectedElementListWrappers)||[];for(let i=0;i<a.length;i++){const h=a[i],c=this._helperConfig.elementIndexMap[h.uuid],d=e.elements[c];if(!d)continue;if(!0===(null==(n=d.operation)?void 0:n.invisible))continue;let u=0;if((null==(s=d.desc)?void 0:s.borderWidth)>0&&(u=d.desc.borderWidth),_t(o,d,(()=>{o.beginPath(),o.moveTo(d.x-u,d.y-u),o.lineTo(d.x+d.w+u,d.y-u),o.lineTo(d.x+d.w+u,d.y+d.h+u),o.lineTo(d.x-u,d.y+d.h+u),o.lineTo(d.x-u,d.y-u),o.closePath(),o.isPointInPath(t.x,t.y)&&(r=i,l=d.uuid)})),r>=0)break}return!!(l&&r>=0)}startSelectArea(t){this._areaStart=t,this._areaEnd=t}changeSelectArea(t){this._areaEnd=t,this._calcSelectedArea()}clearSelectedArea(){this._areaStart={x:0,y:0},this._areaEnd={x:0,y:0},this._calcSelectedArea()}calcSelectedElements(t){const e=this._ctx.getTransform(),{scale:i=1,scrollX:n=0,scrollY:s=0}=e,o=this._areaStart,r=this._areaEnd,l=(Math.min(o.x,r.x)-n)/i,a=(Math.min(o.y,r.y)-s)/i,h=Math.abs(r.x-o.x)/i,c=Math.abs(r.y-o.y)/i,d=[],u=this._ctx;return u.beginPath(),u.moveTo(l,a),u.lineTo(l+h,a),u.lineTo(l+h,a+c),u.lineTo(l,a+c),u.lineTo(l,a),u.closePath(),t.elements.forEach((t=>{var e;if(!0!==(null==(e=null==t?void 0:t.operation)?void 0:e.invisible)){const e=t.x+t.w/2,i=t.y+t.h/2;u.isPointInPathWithoutScroll(e,i)&&d.push(t.uuid)}})),d}_calcSelectedArea(){const t=this._areaStart,e=this._areaEnd,i=this._ctx.getTransform(),{scale:n=1,scrollX:s=0,scrollY:o=0}=i,r=this._coreConfig.elementWrapper,l=r.lineWidth/n,a=r.lineDash.map((t=>t/n));this._helperConfig.selectedAreaWrapper={x:(Math.min(t.x,e.x)-s)/n,y:(Math.min(t.y,e.y)-o)/n,w:Math.abs(e.x-t.x)/n,h:Math.abs(e.y-t.y)/n,startPoint:{x:t.x,y:t.y},endPoint:{x:e.x,y:e.y},lineWidth:l,lineDash:a,color:r.color}}_updateElementIndex(t){this._helperConfig.elementIndexMap={},t.elements.forEach(((t,e)=>{this._helperConfig.elementIndexMap[t.uuid]=e}))}_updateSelectedElementWrapper(t,e){var i;const{selectedUUID:n}=e;if(!("string"==typeof n&&this._helperConfig.elementIndexMap[n]>=0))return void delete this._helperConfig.selectedElementWrapper;const s=this._helperConfig.elementIndexMap[n],o=t.elements[s];if(!0===(null==(i=null==o?void 0:o.operation)?void 0:i.invisible))return;const r=this._createSelectedElementWrapper(o,e);this._helperConfig.selectedElementWrapper=r}_updateSelectedElementListWrapper(t,e){const{selectedUUIDList:i}=e,n=[];t.elements.forEach((t=>{if(null==i?void 0:i.includes(t.uuid)){const i=this._createSelectedElementWrapper(t,e);n.push(i)}})),this._helperConfig.selectedElementListWrappers=n}_createSelectedElementWrapper(t,e){var i,n,s,o,r,l,a,h,c,d,u,g;const{scale:m}=e,_=this._coreConfig.elementWrapper,f=_.controllerSize/m,p=_.lineWidth/m,v=_.lineDash.map((t=>t/m)),x=(null==(i=t.desc)?void 0:i.borderWidth)||0;let S=!1;"number"==typeof t.angle&&Math.abs(t.angle)>15&&(S=!0);const y=p,w={uuid:t.uuid,controllerSize:f,controllerOffset:y,lock:!0===(null==(n=null==t?void 0:t.operation)?void 0:n.lock),controllers:{topLeft:{x:t.x-y-x,y:t.y-y-x,invisible:S||!0===(null==(s=null==t?void 0:t.operation)?void 0:s.disableScale)},top:{x:t.x+t.w/2,y:t.y-y-x,invisible:!0===(null==(o=null==t?void 0:t.operation)?void 0:o.disableScale)},topRight:{x:t.x+t.w+y+x,y:t.y-y-x,invisible:S||!0===(null==(r=null==t?void 0:t.operation)?void 0:r.disableScale)},right:{x:t.x+t.w+y+x,y:t.y+t.h/2,invisible:!0===(null==(l=null==t?void 0:t.operation)?void 0:l.disableScale)},bottomRight:{x:t.x+t.w+y+x,y:t.y+t.h+y+x,invisible:S||!0===(null==(a=null==t?void 0:t.operation)?void 0:a.disableScale)},bottom:{x:t.x+t.w/2,y:t.y+t.h+y+x,invisible:!0===(null==(h=null==t?void 0:t.operation)?void 0:h.disableScale)},bottomLeft:{x:t.x-y-x,y:t.y+t.h+y+x,invisible:S||!0===(null==(c=null==t?void 0:t.operation)?void 0:c.disableScale)},left:{x:t.x-y-x,y:t.y+t.h/2,invisible:!0===(null==(d=null==t?void 0:t.operation)?void 0:d.disableScale)},rotate:{x:t.x+t.w/2,y:t.y-f-(2*f+12)-x,invisible:!0===(null==(u=null==t?void 0:t.operation)?void 0:u.disableRotate)}},lineWidth:p,lineDash:v,color:!0===(null==(g=null==t?void 0:t.operation)?void 0:g.lock)?_.lockColor:_.color};return"number"==typeof t.angle&&(t.angle>0||t.angle<0)&&(w.radian=ot(t.angle),w.translate=rt(t)),w}}const Pt=Symbol("_displayCtx"),Dt=Symbol("_helper"),Lt=Symbol("_element"),Mt=Symbol("_opts");class It{constructor(t){this[Mt]=t,this[Pt]=this[Mt].board,this[Lt]=this[Mt].element,this[Dt]=this[Mt].helper}isEffectivePoint(t){const e=this[Pt].getScrollLineWidth(),i=this[Pt].getScreenInfo();return t.x<=i.width-e&&t.y<=i.height-e}judgePointCursor(t,e){let i="auto",n=null;if(!this.isEffectivePoint(t))return{cursor:i,elementUUID:n};const{uuid:s,hoverControllerDirection:o}=this[Dt].isPointInElementWrapperController(t,e);if(s&&o){switch(o){case"top-right":i="ne-resize";break;case"top-left":i="nw-resize";break;case"top":i="n-resize";break;case"right":i="e-resize";break;case"bottom-right":i="se-resize";break;case"bottom":i="s-resize";break;case"bottom-left":i="sw-resize";break;case"left":i="w-resize";break;case"rotate":i="grab"}s&&(n=s)}else{const[s,o]=this[Lt].isPointInElement(t,e);s>=0&&(i="move"),o&&(n=o)}return{cursor:i,elementUUID:n}}}function zt(t){const e={elements:[]};return Array.isArray(null==t?void 0:t.elements)&&(null==t||t.elements.forEach(((t={})=>{(function(t){if(!(Tt(t.x)&&Tt(t.y)&&Tt(t.w)&&Tt(t.h)))return!1;if("string"!=typeof t.type||!xt.includes(t.type))return!1;return!0})(t)&&e.elements.push(t)}))),"string"==typeof t.bgColor&&(e.bgColor=t.bgColor),e}function Tt(t){return t>=0||t<0}var kt=(t=>(t.NULL="null",t.SELECT_ELEMENT="select-element",t.SELECT_ELEMENT_LIST="select-element-list",t.SELECT_ELEMENT_WRAPPER_CONTROLLER="select-element-wrapper-controller",t.SELECT_AREA="select-area",t))(kt||{}),Ut=(t=>(t.DRAGGING="dragging",t.NULL="null",t))(Ut||{});function Wt(){return{hasInited:!1,mode:kt.NULL,cursorStatus:Ut.NULL,selectedUUID:null,selectedUUIDList:[],hoverUUID:null,selectedControllerDirection:null,hoverControllerDirection:null,prevPoint:null,hasChangedElement:!1}}class Rt{constructor(){this._temp=Wt()}set(t,e){this._temp[t]=e}get(t){return this._temp[t]}clear(){this._temp=Wt()}}class Ot{constructor(t){this._plugins=[];const{board:e,config:i,element:n}=t,s=new Ct(e,i);this._opts=t,this.temp=new Rt,this.helper=s,this._mapper=new It({board:e,helper:s,element:n})}addPlugin(t){this._plugins.push(t)}getHelperConfig(){return this.helper.getConfig()}updateHelperConfig(t){var e;const{board:i,getDataFeekback:n,config:s}=this._opts,o=n(),r=i.getTransform();this.helper.updateConfig(o,{width:t.width,height:t.height,devicePixelRatio:t.devicePixelRatio,canScroll:!0===(null==(e=null==s?void 0:s.scrollWrapper)?void 0:e.use),selectedUUID:this.temp.get("selectedUUID"),selectedUUIDList:this.temp.get("selectedUUIDList"),scale:r.scale,scrollX:r.scrollX,scrollY:r.scrollY})}init(){this._initEvent()}_initEvent(){if(!0===this.temp.get("hasInited"))return;const{board:e}=this._opts;e.on("hover",t(this._handleHover.bind(this),32)),e.on("leave",t(this._handleLeave.bind(this),32)),e.on("point",t(this._handleClick.bind(this),16)),e.on("doubleClick",this._handleDoubleClick.bind(this)),e.on("point",this._handlePoint.bind(this)),e.on("moveStart",this._handleMoveStart.bind(this)),e.on("move",t(this._handleMove.bind(this),16)),e.on("moveEnd",this._handleMoveEnd.bind(this))}_handleDoubleClick(t){var e,i,s;const{element:o,getDataFeekback:r,drawFeekback:l,coreEvent:a}=this._opts,h=r(),[c,d]=o.isPointInElement(t,h);if(c>=0&&d){const t=n(null==(e=h.elements)?void 0:e[c]);!0!==(null==(i=null==t?void 0:t.operation)?void 0:i.invisible)&&a.trigger("screenDoubleClickElement",{index:c,uuid:d,element:n(null==(s=h.elements)?void 0:s[c])})}l()}_handlePoint(t){var e,i,s;if(!this._mapper.isEffectivePoint(t))return;const{element:o,getDataFeekback:r,selectElementByIndex:l,coreEvent:a,emitChangeScreen:h,drawFeekback:c}=this._opts,d=this.helper,u=r();if(d.isPointInElementList(t,u))this.temp.set("mode",kt.SELECT_ELEMENT_LIST);else{const{uuid:r,selectedControllerDirection:c}=d.isPointInElementWrapperController(t,u);if(r&&c)this.temp.set("mode",kt.SELECT_ELEMENT_WRAPPER_CONTROLLER),this.temp.set("selectedControllerDirection",c),this.temp.set("selectedUUID",r);else{const[r,c]=o.isPointInElement(t,u);r>=0&&!0!==(null==(i=null==(e=u.elements[r])?void 0:e.operation)?void 0:i.invisible)?(l(r,{useMode:!0}),"string"==typeof c&&a.has("screenSelectElement")&&(a.trigger("screenSelectElement",{index:r,uuid:c,element:n(null==(s=u.elements)?void 0:s[r])}),h()),this.temp.set("mode",kt.SELECT_ELEMENT)):(this.temp.set("selectedUUIDList",[]),this.temp.set("selectedUUID",null),this.temp.set("mode",kt.SELECT_AREA))}}c()}_handleClick(t){var e;const{element:i,getDataFeekback:s,coreEvent:o,drawFeekback:r}=this._opts,l=s(),[a,h]=i.isPointInElement(t,l);a>=0&&h&&o.trigger("screenClickElement",{index:a,uuid:h,element:n(null==(e=l.elements)?void 0:e[a])}),r()}_handleMoveStart(t){const{element:e,getDataFeekback:i,coreEvent:n}=this._opts,s=i(),o=this.helper;this.temp.set("prevPoint",t);const r=this.temp.get("selectedUUID");this.temp.get("mode")===kt.SELECT_ELEMENT_LIST||(this.temp.get("mode")===kt.SELECT_ELEMENT?"string"==typeof r&&n.has("screenMoveElementStart")&&n.trigger("screenMoveElementStart",{index:e.getElementIndex(s,r),uuid:r,x:t.x,y:t.y}):this.temp.get("mode")===kt.SELECT_AREA&&o.startSelectArea(t))}_handleMove(t){const{drawFeekback:e}=this._opts,i=this.helper;this.temp.get("mode")===kt.SELECT_ELEMENT_LIST?(this.temp.set("hasChangedElement",!0),this._dragElements(this.temp.get("selectedUUIDList"),t,this.temp.get("prevPoint")),e(),this.temp.set("cursorStatus",Ut.DRAGGING)):"string"==typeof this.temp.get("selectedUUID")?this.temp.get("mode")===kt.SELECT_ELEMENT?(this.temp.set("hasChangedElement",!0),this._dragElements([this.temp.get("selectedUUID")],t,this.temp.get("prevPoint")),e(),this.temp.set("cursorStatus",Ut.DRAGGING)):this.temp.get("mode")===kt.SELECT_ELEMENT_WRAPPER_CONTROLLER&&this.temp.get("selectedControllerDirection")&&(this._transfromElement(this.temp.get("selectedUUID"),t,this.temp.get("prevPoint"),this.temp.get("selectedControllerDirection")),this.temp.set("cursorStatus",Ut.DRAGGING)):this.temp.get("mode")===kt.SELECT_AREA&&(i.changeSelectArea(t),e()),this.temp.set("prevPoint",t)}_dragElements(t,e,i){if(!i)return;const{board:n,element:s,getDataFeekback:o,drawFeekback:r}=this._opts,l=o(),a=this.helper;t.forEach((t=>{var o,r;const h=a.getElementIndexByUUID(t);if(null===h)return;const c=l.elements[h];!0!==(null==(o=null==c?void 0:c.operation)?void 0:o.lock)&&!0!==(null==(r=null==c?void 0:c.operation)?void 0:r.invisible)&&s.dragElement(l,t,e,i,n.getContext().getTransform().scale)})),r()}_transfromElement(t,e,i,n){if(!i)return null;const{board:s,element:o,getDataFeekback:r,drawFeekback:l}=this._opts,a=r(),h=o.transformElement(a,t,e,i,s.getContext().getTransform().scale,n);return l(),h}_handleMoveEnd(t){const{element:e,getDataFeekback:i,coreEvent:n,drawFeekback:s,emitChangeData:o}=this._opts,r=i(),l=this.helper,a=this.temp.get("selectedUUID");if("string"==typeof a){const i=e.getElementIndex(r,a),s=r.elements[i];s&&(n.has("screenMoveElementEnd")&&n.trigger("screenMoveElementEnd",{index:i,uuid:a,x:t.x,y:t.y}),n.has("screenChangeElement")&&n.trigger("screenChangeElement",{index:i,uuid:a,width:s.w,height:s.h,angle:s.angle||0}))}else if(this.temp.get("mode")===kt.SELECT_AREA){const t=l.calcSelectedElements(r);t.length>0?(this.temp.set("selectedUUIDList",t),this.temp.set("selectedUUID",null)):this.temp.set("mode",kt.NULL),l.clearSelectedArea(),s()}this.temp.get("mode")!==kt.SELECT_ELEMENT&&this.temp.set("selectedUUID",null),this.temp.set("cursorStatus",Ut.NULL),this.temp.set("mode",kt.NULL),!0===this.temp.get("hasChangedElement")&&(o(),this.temp.set("hasChangedElement",!1))}_handleHover(t){var e,i;let n=!1;const{board:s,getDataFeekback:o,coreEvent:r}=this._opts,l=o(),a=this.helper,h=this._mapper;if(this.temp.get("mode")===kt.SELECT_AREA)s.resetCursor();else if(this.temp.get("cursorStatus")===Ut.NULL){const{cursor:o,elementUUID:c}=h.judgePointCursor(t,l);if(s.setCursor(o),c){const t=a.getElementIndexByUUID(c);if(null!==t&&t>=0){const o=l.elements[t];if(!0===(null==(e=null==o?void 0:o.operation)?void 0:e.lock)||!0===(null==(i=null==o?void 0:o.operation)?void 0:i.invisible))return void s.resetCursor();if(this.temp.get("hoverUUID")!==o.uuid){const t=a.getElementIndexByUUID(this.temp.get("hoverUUID")||"");null!==t&&l.elements[t]&&r.trigger("mouseLeaveElement",{uuid:this.temp.get("hoverUUID"),index:t,element:l.elements[t]})}o&&(r.trigger("mouseOverElement",{uuid:o.uuid,index:t,element:o}),this.temp.set("hoverUUID",o.uuid),n=!0)}}}if(!0!==n&&null!==this.temp.get("hoverUUID")){const t=this.temp.get("hoverUUID"),e=a.getElementIndexByUUID(t||"");null!==e&&r.trigger("mouseLeaveElement",{uuid:t,index:e,element:l.elements[e]}),this.temp.set("hoverUUID",null)}r.has("mouseOverScreen")&&r.trigger("mouseOverScreen",t)}_handleLeave(){const{coreEvent:t}=this._opts;t.has("mouseLeaveScreen")&&t.trigger("mouseLeaveScreen",void 0)}}function At(t){t.setFillStyle("#000000"),t.setStrokeStyle("#000000"),t.setLineDash([]),t.setGlobalAlpha(1),t.setShadowColor("#00000000"),t.setShadowOffsetX(0),t.setShadowOffsetY(0),t.setShadowBlur(0)}class Ft{constructor(t,e,i){var s,o,r;this._coreEvent=new ht,this._tempData=new class{constructor(){this._temp={hasInited:!1}}set(t,e){this._temp[t]=e}get(t){return this._temp[t]}clear(){this._temp={hasInited:!1}}},this.$data={elements:[]},this._opts=e,this._config=function(t){const e=n(at);return t&&t.elementWrapper&&(e.elementWrapper={...e.elementWrapper,...t.elementWrapper}),e}(i||{}),this._board=new z(t,{...this._opts,canScroll:null==(s=null==i?void 0:i.scrollWrapper)?void 0:s.use,scrollConfig:{color:(null==(o=null==i?void 0:i.scrollWrapper)?void 0:o.color)||"#000000",width:(null==(r=null==i?void 0:i.scrollWrapper)?void 0:r.width)||12,...(null==i?void 0:i.scrollWrapper)||{}}}),this._renderer=new Z;const l=()=>{const t=this._board.getHelperContext(),e=this._engine.getHelperConfig();this._board.clear();const{contextWidth:i,contextHeight:n,devicePixelRatio:s}=this._opts;t.clearRect(0,0,i*s,n*s),function(t,e){if(!(null==e?void 0:e.selectedElementWrapper))return;const i=e.selectedElementWrapper;At(t),ft(t,i.translate,i.radian||0,(()=>{t.beginPath(),t.setLineDash(i.lineDash),t.setLineWidth(i.lineWidth),t.setStrokeStyle(i.color),t.moveTo(i.controllers.topLeft.x,i.controllers.topLeft.y),t.lineTo(i.controllers.topRight.x,i.controllers.topRight.y),t.lineTo(i.controllers.bottomRight.x,i.controllers.bottomRight.y),t.lineTo(i.controllers.bottomLeft.x,i.controllers.bottomLeft.y),t.lineTo(i.controllers.topLeft.x,i.controllers.topLeft.y-i.lineWidth/2),t.stroke(),t.closePath(),!0!==i.lock?(!0!==i.controllers.rotate.invisible&&(t.beginPath(),t.moveTo(i.controllers.top.x,i.controllers.top.y),t.lineTo(i.controllers.rotate.x,i.controllers.rotate.y+i.controllerSize),t.stroke(),t.closePath(),t.beginPath(),t.setLineDash([]),t.setLineWidth(i.controllerSize/1.2),t.arc(i.controllers.rotate.x,i.controllers.rotate.y,.8*i.controllerSize,0,2*Math.PI),t.stroke(),t.closePath(),t.setStrokeStyle("#FFFFFF"),t.beginPath(),t.setLineDash([]),t.setLineWidth(i.controllerSize/2.1),t.arc(i.controllers.rotate.x,i.controllers.rotate.y,.8*i.controllerSize,0,2*Math.PI),t.stroke(),t.closePath()),[i.controllers.topLeft,i.controllers.top,i.controllers.topRight,i.controllers.right,i.controllers.bottomRight,i.controllers.bottom,i.controllers.bottomLeft,i.controllers.left].forEach((e=>{!0!==e.invisible&&(t.setFillStyle(i.color),t.beginPath(),t.arc(e.x,e.y,i.controllerSize,0,2*Math.PI),t.fill(),t.closePath(),t.setFillStyle("#FFFFFF"),t.beginPath(),t.arc(e.x,e.y,i.controllerSize-1,0,2*Math.PI),t.fill(),t.closePath())}))):(At(t),t.setStrokeStyle(i.color),[i.controllers.topLeft,i.controllers.top,i.controllers.topRight,i.controllers.right,i.controllers.bottomRight,i.controllers.bottom,i.controllers.bottomLeft,i.controllers.left].forEach((e=>{t.beginPath(),t.moveTo(e.x-i.controllerSize/2,e.y-i.controllerSize/2),t.lineTo(e.x+i.controllerSize/2,e.y+i.controllerSize/2),t.stroke(),t.closePath(),t.beginPath(),t.moveTo(e.x+i.controllerSize/2,e.y-i.controllerSize/2),t.lineTo(e.x-i.controllerSize/2,e.y+i.controllerSize/2),t.stroke(),t.closePath()})))}))}(t,e),function(t,e){if(!(null==e?void 0:e.selectedAreaWrapper))return;const i=e.selectedAreaWrapper;i&&i.w>0&&i.h>0&&(At(t),t.setGlobalAlpha(.3),t.setFillStyle(i.color),t.fillRect(i.x,i.y,i.w,i.h),At(t),t.beginPath(),t.setLineDash(i.lineDash),t.setLineWidth(i.lineWidth),t.setStrokeStyle(i.color),t.moveTo(i.x,i.y),t.lineTo(i.x+i.w,i.y),t.lineTo(i.x+i.w,i.y+i.h),t.lineTo(i.x,i.y+i.h),t.lineTo(i.x,i.y),t.stroke(),t.closePath())}(t,e),function(t,e){if(!Array.isArray(null==e?void 0:e.selectedElementListWrappers))return;const i=e.selectedElementListWrappers;null==i||i.forEach((e=>{At(t),ft(t,e.translate,e.radian||0,(()=>{At(t),t.setGlobalAlpha(.05),t.setFillStyle(e.color),t.fillRect(e.controllers.topLeft.x,e.controllers.topLeft.y,e.controllers.bottomRight.x-e.controllers.topLeft.x,e.controllers.bottomRight.y-e.controllers.topLeft.y),At(t),t.beginPath(),t.setLineDash(e.lineDash),t.setLineWidth(e.lineWidth),t.setStrokeStyle(e.color),t.moveTo(e.controllers.topLeft.x,e.controllers.topLeft.y),t.lineTo(e.controllers.topRight.x,e.controllers.topRight.y),t.lineTo(e.controllers.bottomRight.x,e.controllers.bottomRight.y),t.lineTo(e.controllers.bottomLeft.x,e.controllers.bottomLeft.y),t.lineTo(e.controllers.topLeft.x,e.controllers.topLeft.y-e.lineWidth/2),t.stroke(),t.closePath(),!0===e.lock&&(At(t),t.setStrokeStyle(e.color),[e.controllers.topLeft,e.controllers.top,e.controllers.topRight,e.controllers.right,e.controllers.bottomRight,e.controllers.bottom,e.controllers.bottomLeft,e.controllers.left].forEach((i=>{t.beginPath(),t.moveTo(i.x-e.controllerSize/2,i.y-e.controllerSize/2),t.lineTo(i.x+e.controllerSize/2,i.y+e.controllerSize/2),t.stroke(),t.closePath(),t.beginPath(),t.moveTo(i.x+e.controllerSize/2,i.y-e.controllerSize/2),t.lineTo(i.x-e.controllerSize/2,i.y+e.controllerSize/2),t.stroke(),t.closePath()})))}))}))}(t,e),this._board.draw()};this._renderer.on("drawFrame",(()=>{l()})),this._renderer.on("drawFrameComplete",(()=>{l()})),this._elementHandler=new yt(this._board.getContext()),this._engine=new Ot({coreEvent:this._coreEvent,board:this._board,element:this._elementHandler,config:this._config,drawFeekback:this.$draw.bind(this),getDataFeekback:()=>this.$data,selectElementByIndex:this.selectElementByIndex.bind(this),emitChangeScreen:this._emitChangeScreen.bind(this),emitChangeData:this.$emitChangeData.bind(this)}),this._engine.init(),this._renderer.on("drawFrame",(()=>{this._coreEvent.trigger("drawFrame",void 0)})),this._renderer.on("drawFrameComplete",(()=>{this._coreEvent.trigger("drawFrameComplete",void 0)})),this._tempData.set("hasInited",!0)}_emitChangeScreen(){this._coreEvent.has("changeScreen")&&this._coreEvent.trigger("changeScreen",{...this.getScreenTransform()})}$draw(t){this._engine.updateHelperConfig({width:this._opts.width,height:this._opts.height,devicePixelRatio:this._opts.devicePixelRatio}),this._renderer.thaw(),this._renderer.render(this._board.getContext(),this.$data,{changeResourceUUIDs:(null==t?void 0:t.resourceChangeUUIDs)||[]})}getElement(t){return function(t,e){let i=null;const s=t.getEngine().helper.getElementIndexByUUID(e);return null!==s&&t.$data.elements[s]&&(i=n(t.$data.elements[s])),i}(this,t)}getElementByIndex(t){return function(t,e){let i=null;return e>=0&&t.$data.elements[e]&&(i=n(t.$data.elements[e])),i}(this,t)}selectElementByIndex(t){return function(t,e){if(t.$data.elements[e]){const i=t.$data.elements[e].uuid;t.getEngine().temp.set("mode",kt.NULL),"string"==typeof i&&(t.getEngine().temp.set("selectedUUID",i),t.getEngine().temp.set("selectedUUIDList",[])),t.$draw()}}(this,t)}selectElement(t){return function(t,e){const i=t.getEngine().helper.getElementIndexByUUID(e);"number"==typeof i&&i>=0&&t.selectElementByIndex(i)}(this,t)}cancelElementByIndex(t){return function(t,e){if(t.$data.elements[e]){const i=t.$data.elements[e].uuid,n=t.getEngine().temp.get("selectedUUID");"string"==typeof i&&i===n&&(t.getEngine().temp.set("mode",kt.NULL),t.getEngine().temp.set("selectedUUID",null),t.getEngine().temp.set("selectedUUIDList",[])),t.$draw()}}(this,t)}cancelElement(t){return function(t,e){const i=t.getEngine().helper.getElementIndexByUUID(e);"number"==typeof i&&i>=0&&t.cancelElementByIndex(i)}(this,t)}moveUpElement(t){return function(t,e){const i=t.getEngine().helper.getElementIndexByUUID(e);if("number"==typeof i&&i>=0&&i<t.$data.elements.length-1){const e=t.$data.elements[i];t.$data.elements[i]=t.$data.elements[i+1],t.$data.elements[i+1]=e}t.$emitChangeData(),t.$draw()}(this,t)}moveDownElement(t){return function(t,e){const i=t.getEngine().helper.getElementIndexByUUID(e);if("number"==typeof i&&i>0&&i<t.$data.elements.length){const e=t.$data.elements[i];t.$data.elements[i]=t.$data.elements[i-1],t.$data.elements[i-1]=e}t.$emitChangeData(),t.$draw()}(this,t)}updateElement(t){return function(t,e){var i;const s=n(e),o=t.getData(),r=[];for(let t=0;t<o.elements.length;t++)if(s.uuid===(null==(i=o.elements[t])?void 0:i.uuid)){const e=gt(o.elements[t],s);"string"==typeof e&&r.push(e),o.elements[t]=s;break}t.$emitChangeData(),t.$draw({resourceChangeUUIDs:r})}(this,t)}addElement(t){return function(t,e){const s=n(e);return s.uuid=i(),t.$data.elements.push(s),t.$emitChangeData(),t.$draw(),s.uuid}(this,t)}deleteElement(t){return function(t,e){const i=t.$getElementHandler().getElementIndex(t.getData(),e);i>=0&&(t.$data.elements.splice(i,1),t.$emitChangeData(),t.$draw())}(this,t)}insertElementBefore(t,e){return function(t,e,i){const n=t.getEngine().helper.getElementIndexByUUID(i);return null!==n?t.insertElementBeforeIndex(e,n):null}(this,t,e)}insertElementBeforeIndex(t,e){return function(t,e,s){const o=n(e);return o.uuid=i(),s>=0?(t.$data.elements.splice(s,0,o),t.$emitChangeData(),t.$draw(),o.uuid):null}(this,t,e)}getSelectedElements(){return function(t){const e=[];let i=[];const s=t.getEngine().temp.get("selectedUUID");return"string"==typeof s&&s?i.push(s):i=t.getEngine().temp.get("selectedUUIDList"),i.forEach((i=>{const n=t.getEngine().helper.getElementIndexByUUID(i);if(null!==n&&n>=0){const i=t.$data.elements[n];i&&e.push(i)}})),n(e)}(this)}insertElementAfter(t,e){return function(t,e,i){const n=t.getEngine().helper.getElementIndexByUUID(i);return null!==n?t.insertElementAfterIndex(e,n):null}(this,t,e)}insertElementAfterIndex(t,e){return function(t,e,s){const o=n(e);return o.uuid=i(),s>=0?(t.$data.elements.splice(s+1,0,o),t.$emitChangeData(),t.$draw(),o.uuid):null}(this,t,e)}resetSize(t){this._opts={...this._opts,...t},this._board.resetSize(t),this.$draw()}scale(t){const e=this._board.scale(t);return this.$draw(),this._emitChangeScreen(),e}scrollLeft(t){const e=this._board.scrollX(0-t);return this.$draw(),this._emitChangeScreen(),e}scrollTop(t){const e=this._board.scrollY(0-t);return this.$draw(),this._emitChangeScreen(),e}getScreenTransform(){const t=this._board.getTransform();return{scale:t.scale,scrollTop:Math.max(0,0-t.scrollY),scrollLeft:Math.max(0,0-t.scrollX)}}getData(){return n(this.$data)}setData(t,e){const i=function(t,e){var i;const n=[],s=mt(t),o=mt(e);for(const t in o)if(!0===["image","svg","html"].includes(null==(i=o[t])?void 0:i.type))if(s[t]){let e=!1;switch(s[t].type){case"image":e=ct(s[t],o[t]);break;case"svg":e=dt(s[t],o[t]);break;case"html":e=ut(s[t],o[t])}!0===e&&n.push(t)}else n.push(t);return n}(this.$data,t);this.$data=this._elementHandler.initData(n(zt(t))),e&&!0===e.triggerChangeEvent&&this.$emitChangeData(),this.$draw({resourceChangeUUIDs:i})}clearOperation(){this._tempData.clear(),this.$draw()}on(t,e){this._coreEvent.on(t,e)}off(t,e){this._coreEvent.off(t,e)}getEngine(){return this._engine}pointScreenToContext(t){return this._board.pointScreenToContext(t)}pointContextToScreen(t){return this._board.pointContextToScreen(t)}$getBoardContext(){return this._board.getContext()}$getDisplayContext2D(){return this._board.getDisplayContext2D()}$getOriginContext2D(){return this._board.getOriginContext2D()}$emitChangeData(){this._coreEvent.has("changeData")&&this._coreEvent.trigger("changeData",n(this.$data))}$getElementHandler(){return this._elementHandler}}return Ft.is=it,Ft.check=st,Ft}();
|
|
1
|
+
var iDrawCore=function(){"use strict";function t(t,e){let i=-1;return function(...n){i>0||(i=setTimeout((()=>{t(...n),i=-1}),e))}}function e(t){return"string"==typeof t&&/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)}function i(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${t()}${t()}-${t()}-${t()}-${t()}-${t()}${t()}${t()}`}function n(t){return function t(e){const i=(n=e,Object.prototype.toString.call(n).replace(/[\]|\[]{1,1}/gi,"").split(" ")[1]);var n;if(["Null","Number","String","Boolean","Undefined"].indexOf(i)>=0)return e;if("Array"===i){const i=[];return e.forEach((e=>{i.push(t(e))})),i}if("Object"===i){const i={};return Object.keys(e).forEach((n=>{i[n]=t(e[n])})),i}}(t)}function s(t){return(Object.prototype.toString.call(t)||"").replace(/(\[object|\])/gi,"").trim()}const o={type(t,e){const i=s(t);return!0===e?i.toLocaleLowerCase():i},array:t=>"Array"===s(t),json:t=>"Object"===s(t),function:t=>"Function"===s(t),asyncFunction:t=>"AsyncFunction"===s(t),string:t=>"String"===s(t),number:t=>"Number"===s(t),undefined:t=>"Undefined"===s(t),null:t=>"Null"===s(t),promise:t=>"Promise"===s(t)};var r=globalThis&&globalThis.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{a(n.next(t))}catch(t){o(t)}}function l(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,l)}a((n=n.apply(t,e||[])).next())}))};const{Image:l}=window;function a(t){return new Promise(((e,i)=>{const n=new l;n.crossOrigin="anonymous",n.onload=function(){e(n)},n.onabort=i,n.onerror=i,n.src=t}))}function h(t){return r(this,void 0,void 0,(function*(){const e=yield function(t){return new Promise(((e,i)=>{const n=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),s=new FileReader;s.readAsDataURL(n),s.onload=function(t){var i;const n=null===(i=null==t?void 0:t.target)||void 0===i?void 0:i.result;e(n)},s.onerror=function(t){i(t)}}))}(t);return yield a(e)}))}function c(t,e){return r(this,void 0,void 0,(function*(){t=t.replace(/\&/gi,"&");const i=yield function(t,e){const{width:i,height:n}=e;return new Promise(((e,s)=>{const o=new Blob([`\n <svg xmlns="http://www.w3.org/2000/svg" width="${i||""}" height = "${n||""}">\n <foreignObject width="100%" height="100%">\n <div xmlns = "http://www.w3.org/1999/xhtml">\n ${t}\n </div>\n </foreignObject>\n </svg>\n `],{type:"image/svg+xml;charset=utf-8"}),r=new FileReader;r.readAsDataURL(o),r.onload=function(t){var i;const n=null===(i=null==t?void 0:t.target)||void 0===i?void 0:i.result;e(n)},r.onerror=function(t){s(t)}}))}(t,e);return yield a(i)}))}let d=class{constructor(t,e){this._opts=e,this._ctx=t,this._transform={scale:1,scrollX:0,scrollY:0}}getContext(){return this._ctx}resetSize(t){this._opts=Object.assign(Object.assign({},this._opts),t)}calcDeviceNum(t){return t*this._opts.devicePixelRatio}calcScreenNum(t){return t/this._opts.devicePixelRatio}getSize(){return{width:this._opts.width,height:this._opts.height,contextWidth:this._opts.contextWidth,contextHeight:this._opts.contextHeight,devicePixelRatio:this._opts.devicePixelRatio}}setTransform(t){this._transform=Object.assign(Object.assign({},this._transform),t)}getTransform(){return{scale:this._transform.scale,scrollX:this._transform.scrollX,scrollY:this._transform.scrollY}}setFillStyle(t){this._ctx.fillStyle=t}fill(t){return this._ctx.fill(t||"nonzero")}arc(t,e,i,n,s,o){return this._ctx.arc(this._doSize(t),this._doSize(e),this._doSize(i),n,s,o)}rect(t,e,i,n){return this._ctx.rect(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n))}fillRect(t,e,i,n){return this._ctx.fillRect(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n))}clearRect(t,e,i,n){return this._ctx.clearRect(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n))}beginPath(){return this._ctx.beginPath()}closePath(){return this._ctx.closePath()}lineTo(t,e){return this._ctx.lineTo(this._doSize(t),this._doSize(e))}moveTo(t,e){return this._ctx.moveTo(this._doSize(t),this._doSize(e))}arcTo(t,e,i,n,s){return this._ctx.arcTo(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n),this._doSize(s))}setLineWidth(t){return this._ctx.lineWidth=this._doSize(t)}setLineDash(t){return this._ctx.setLineDash(t.map((t=>this._doSize(t))))}isPointInPath(t,e){return this._ctx.isPointInPath(this._doX(t),this._doY(e))}isPointInPathWithoutScroll(t,e){return this._ctx.isPointInPath(this._doSize(t),this._doSize(e))}setStrokeStyle(t){this._ctx.strokeStyle=t}stroke(){return this._ctx.stroke()}translate(t,e){return this._ctx.translate(this._doSize(t),this._doSize(e))}rotate(t){return this._ctx.rotate(t)}drawImage(...t){const e=t[0],i=t[1],n=t[2],s=t[3],o=t[4],r=t[t.length-4],l=t[t.length-3],a=t[t.length-2],h=t[t.length-1];return 9===t.length?this._ctx.drawImage(e,this._doSize(i),this._doSize(n),this._doSize(s),this._doSize(o),this._doSize(r),this._doSize(l),this._doSize(a),this._doSize(h)):this._ctx.drawImage(e,this._doSize(r),this._doSize(l),this._doSize(a),this._doSize(h))}createPattern(t,e){return this._ctx.createPattern(t,e)}measureText(t){return this._ctx.measureText(t)}setTextAlign(t){this._ctx.textAlign=t}fillText(t,e,i,n){return void 0!==n?this._ctx.fillText(t,this._doSize(e),this._doSize(i),this._doSize(n)):this._ctx.fillText(t,this._doSize(e),this._doSize(i))}strokeText(t,e,i,n){return void 0!==n?this._ctx.strokeText(t,this._doSize(e),this._doSize(i),this._doSize(n)):this._ctx.strokeText(t,this._doSize(e),this._doSize(i))}setFont(t){const e=[];"bold"===t.fontWeight&&e.push(`${t.fontWeight}`),e.push(`${this._doSize(t.fontSize||12)}px`),e.push(`${t.fontFamily||"sans-serif"}`),this._ctx.font=`${e.join(" ")}`}setTextBaseline(t){this._ctx.textBaseline=t}setGlobalAlpha(t){this._ctx.globalAlpha=t}save(){this._ctx.save()}restore(){this._ctx.restore()}scale(t,e){this._ctx.scale(t,e)}setShadowColor(t){this._ctx.shadowColor=t}setShadowOffsetX(t){this._ctx.shadowOffsetX=this._doSize(t)}setShadowOffsetY(t){this._ctx.shadowOffsetY=this._doSize(t)}setShadowBlur(t){this._ctx.shadowBlur=this._doSize(t)}ellipse(t,e,i,n,s,o,r,l){this._ctx.ellipse(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n),s,o,r,l)}_doSize(t){return this._opts.devicePixelRatio*t}_doX(t){const{scale:e,scrollX:i}=this._transform,n=(t-i)/e;return this._doSize(n)}_doY(t){const{scale:e,scrollY:i}=this._transform,n=(t-i)/e;return this._doSize(n)}};function u(t){return"number"==typeof t&&(t>0||t<=0)}function g(t){return"number"==typeof t&&t>=0}function m(t){return"string"==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${t}`)}function _(t){return"string"==typeof t&&/^(data:image\/)/.test(`${t}`)}const f={x:function(t){return u(t)},y:function(t){return u(t)},w:g,h:function(t){return"number"==typeof t&&t>=0},angle:function(t){return"number"==typeof t&&t>=-360&&t<=360},number:u,borderWidth:function(t){return g(t)},borderRadius:function(t){return u(t)&&t>=0},color:function(t){return e(t)},imageSrc:function(t){return _(t)||m(t)},imageURL:m,imageBase64:_,svg:function(t){return"string"==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test(`${t}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${t}`.trim())},html:function(t){let e=!1;if("string"==typeof t){let i=document.createElement("div");i.innerHTML=t,i.children.length>0&&(e=!0),i=null}return e},text:function(t){return"string"==typeof t},fontSize:function(t){return u(t)&&t>0},lineHeight:function(t){return u(t)&&t>0},textAlign:function(t){return["center","left","right"].includes(t)},fontFamily:function(t){return"string"==typeof t&&t.length>0},fontWeight:function(t){return["bold"].includes(t)},strokeWidth:function(t){return u(t)&&t>0}};function p(t={}){const{borderColor:e,borderRadius:i,borderWidth:n}=t;return!(t.hasOwnProperty("borderColor")&&!f.color(e))&&(!(t.hasOwnProperty("borderRadius")&&!f.number(i))&&!(t.hasOwnProperty("borderWidth")&&!f.number(n)))}const v={attrs:function(t){const{x:e,y:i,w:n,h:s,angle:o}=t;return!!(f.x(e)&&f.y(i)&&f.w(n)&&f.h(s)&&f.angle(o))&&(o>=-360&&o<=360)},textDesc:function(t){const{text:e,color:i,fontSize:n,lineHeight:s,fontFamily:o,textAlign:r,fontWeight:l,bgColor:a,strokeWidth:h,strokeColor:c}=t;return!!f.text(e)&&(!!f.color(i)&&(!!f.fontSize(n)&&(!(t.hasOwnProperty("bgColor")&&!f.color(a))&&(!(t.hasOwnProperty("fontWeight")&&!f.fontWeight(l))&&(!(t.hasOwnProperty("lineHeight")&&!f.lineHeight(s))&&(!(t.hasOwnProperty("fontFamily")&&!f.fontFamily(o))&&(!(t.hasOwnProperty("textAlign")&&!f.textAlign(r))&&(!(t.hasOwnProperty("strokeWidth")&&!f.strokeWidth(h))&&(!(t.hasOwnProperty("strokeColor")&&!f.color(c))&&!!p(t))))))))))},rectDesc:function(t){const{bgColor:e}=t;return!(t.hasOwnProperty("bgColor")&&!f.color(e))&&!!p(t)},circleDesc:function(t){const{bgColor:e,borderColor:i,borderWidth:n}=t;return!(t.hasOwnProperty("bgColor")&&!f.color(e))&&(!(t.hasOwnProperty("borderColor")&&!f.color(i))&&!(t.hasOwnProperty("borderWidth")&&!f.number(n)))},imageDesc:function(t){const{src:e}=t;return!!f.imageSrc(e)},svgDesc:function(t){const{svg:e}=t;return!!f.svg(e)},htmlDesc:function(t){const{html:e}=t;return!!f.html(e)}},x={is:f,check:v,delay:function(t){return new Promise((e=>{setTimeout((()=>{e()}),t)}))},compose:function(t){return function(e,i){return function n(s){let o=t[s];s===t.length&&i&&(o=i);if(!o)return Promise.resolve();try{return Promise.resolve(o(e,n.bind(null,s+1)))}catch(t){return Promise.reject(t)}}(0)}},throttle:t,loadImage:a,loadSVG:h,loadHTML:c,downloadImageFromCanvas:function(t,e){const{filename:i,type:n="image/jpeg"}=e,s=t.toDataURL(n),o=document.createElement("a");o.href=s,o.download=i;const r=document.createEvent("MouseEvents");r.initEvent("click",!0,!1),o.dispatchEvent(r)},toColorHexStr:function(t){return"#"+t.toString(16)},toColorHexNum:function(t){return parseInt(t.replace(/^\#/,"0x"))},isColorStr:e,createUUID:i,istype:o,deepClone:n,Context:d};class S{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);null==i||i.push(e),this._listeners.set(t,i||[])}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);if(Array.isArray(i))for(let t=0;t<(null==i?void 0:i.length);t++)if(i[t]===e){i.splice(t,1);break}this._listeners.set(t,i||[])}}trigger(t,e){const i=this._listeners.get(t);return!!Array.isArray(i)&&(i.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}}class y{constructor(t,e){this._isMoving=!1,this._temp=new class{constructor(){this._temp={prevClickPoint:null,isHoverCanvas:!1,isDragCanvas:!1,statusMap:{canScrollYPrev:!0,canScrollYNext:!0,canScrollXPrev:!0,canScrollXNext:!0}}}set(t,e){this._temp[t]=e}get(t){return this._temp[t]}clear(){this._temp={prevClickPoint:null,isHoverCanvas:!1,isDragCanvas:!1,statusMap:{canScrollYPrev:!0,canScrollYNext:!0,canScrollXPrev:!0,canScrollXNext:!0}}}},this._container=window,this._canvas=t,this._isMoving=!1,this._initEvent(),this._event=new S}setStatusMap(t){this._temp.set("statusMap",t)}on(t,e){this._event.on(t,e)}off(t,e){this._event.off(t,e)}_initEvent(){const t=this._canvas,e=this._container;e.addEventListener("mousemove",this._listenWindowMove.bind(this),!1),e.addEventListener("mouseup",this._listenWindowMoveEnd.bind(this),!1),t.addEventListener("mousemove",this._listenHover.bind(this),!1),t.addEventListener("mousedown",this._listenMoveStart.bind(this),!1),t.addEventListener("mousemove",this._listenMove.bind(this),!1),t.addEventListener("mouseup",this._listenMoveEnd.bind(this),!1),t.addEventListener("click",this._listenCanvasClick.bind(this),!1),t.addEventListener("wheel",this._listenCanvasWheel.bind(this),!1),t.addEventListener("mousedown",this._listenCanvasMoveStart.bind(this),!0),t.addEventListener("mouseup",this._listenCanvasMoveEnd.bind(this),!0),t.addEventListener("mouseover",this._listenCanvasMoveOver.bind(this),!0),t.addEventListener("mouseleave",this._listenCanvasMoveLeave.bind(this),!0),this._initParentEvent()}_initParentEvent(){try{let t=window;const e=t.origin;for(;t.self!==t.top&&(t.self!==t.parent&&t.origin===e&&t.parent.window.addEventListener("mousemove",this._listSameOriginParentWindow.bind(this),!1),t=t.parent,t););}catch(t){console.warn(t)}}_listenHover(t){t.preventDefault();const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.has("hover")&&this._event.trigger("hover",e),this._isMoving=!0}_listenMoveStart(t){t.preventDefault();const e=this._getPosition(t);this._isVaildPoint(e)&&(this._event.has("point")&&this._event.trigger("point",e),this._event.has("moveStart")&&this._event.trigger("moveStart",e)),this._isMoving=!0}_listenMove(t){if(t.preventDefault(),t.stopPropagation(),this._event.has("move")&&!0===this._isMoving){const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.trigger("move",e)}}_listenMoveEnd(t){if(t.preventDefault(),this._event.has("moveEnd")){const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.trigger("moveEnd",e)}this._isMoving=!1}_listSameOriginParentWindow(){this._temp.get("isHoverCanvas")&&this._event.has("leave")&&this._event.trigger("leave",void 0),this._temp.get("isDragCanvas")&&this._event.has("moveEnd")&&this._event.trigger("moveEnd",{x:NaN,y:NaN}),this._isMoving=!1,this._temp.set("isDragCanvas",!1),this._temp.set("isHoverCanvas",!1)}_listenCanvasMoveStart(){this._temp.get("isHoverCanvas")&&this._temp.set("isDragCanvas",!0)}_listenCanvasMoveEnd(){this._temp.set("isDragCanvas",!1)}_listenCanvasMoveOver(){this._temp.set("isHoverCanvas",!0)}_listenCanvasMoveLeave(){this._temp.set("isHoverCanvas",!1),this._event.has("leave")&&this._event.trigger("leave",void 0)}_listenWindowMove(t){if(!0===this._temp.get("isDragCanvas")&&(t.preventDefault(),t.stopPropagation(),this._event.has("move")&&!0===this._isMoving)){const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.trigger("move",e)}}_listenWindowMoveEnd(t){if(!0!=!this._temp.get("isDragCanvas")){if(t.preventDefault(),this._event.has("moveEnd")){const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.trigger("moveEnd",e)}this._temp.set("isDragCanvas",!1),this._isMoving=!1}}_listenCanvasWheel(t){this._event.has("wheelX")&&(t.deltaX>0||t.deltaX<0)&&this._event.trigger("wheelX",t.deltaX),this._event.has("wheelY")&&(t.deltaY>0||t.deltaY<0)&&this._event.trigger("wheelY",t.deltaY);const{canScrollYNext:e,canScrollYPrev:i}=this._temp.get("statusMap");(t.deltaX>0&&t.deltaX<0||t.deltaY>0&&!0===e||t.deltaY<0&&!0===i)&&t.preventDefault()}_listenCanvasClick(t){t.preventDefault();const e=this._getPosition(t),i=Date.now();if(this._isVaildPoint(e)){const t=this._temp.get("prevClickPoint");t&&i-t.t<=500&&Math.abs(t.x-e.x)<=5&&Math.abs(t.y-e.y)<=5?this._event.has("doubleClick")&&this._event.trigger("doubleClick",{x:e.x,y:e.y}):this._temp.set("prevClickPoint",{x:e.x,y:e.y,t:i})}}_getPosition(t){const e=this._canvas;let i=0,n=0;if(t&&t.touches&&t.touches.length>0){const e=t.touches[0];e&&(i=e.clientX,n=e.clientY)}else i=t.clientX,n=t.clientY;return{x:i-e.getBoundingClientRect().left,y:n-e.getBoundingClientRect().top,t:Date.now()}}_isVaildPoint(t){return w(t.x)&&w(t.y)}}function w(t){return t>0||t<0||0===t}const b={width:12,color:"#000000",showBackground:!0};class E{constructor(t,e){this._displayCtx=t,this._opts=this._getOpts(e)}draw(t){const{width:e,height:i,scrollConfig:n}=this._opts,s=this.calc(t),o=this._displayCtx;s.xSize>0&&(!0===n.showBackground&&(o.globalAlpha=.12,o.fillStyle=s.color,o.fillRect(0,this._doSize(i-s.lineSize),this._doSize(e),this._doSize(s.lineSize))),C(o,{axis:"X",x:this._doSize(s.translateX),y:this._doSize(i-s.lineSize),w:this._doSize(s.xSize),h:this._doSize(s.lineSize),r:this._doSize(s.lineSize/2),color:s.color})),s.ySize>0&&(!0===n.showBackground&&(o.globalAlpha=.12,o.fillStyle=s.color,o.fillRect(this._doSize(e-s.lineSize),0,this._doSize(s.lineSize),this._doSize(i))),C(o,{axis:"Y",x:this._doSize(e-s.lineSize),y:this._doSize(s.translateY),w:this._doSize(s.lineSize),h:this._doSize(s.ySize),r:this._doSize(s.lineSize/2),color:s.color})),o.globalAlpha=1}resetSize(t){this._opts=Object.assign(Object.assign({},this._opts),t)}isPointAtScrollY(t){const{width:e,height:i,scrollConfig:n}=this._opts,s=this._displayCtx;return s.beginPath(),s.rect(this._doSize(e-n.width),0,this._doSize(n.width),this._doSize(i)),s.closePath(),!!s.isPointInPath(this._doSize(t.x),this._doSize(t.y))}isPointAtScrollX(t){const{width:e,height:i,scrollConfig:n}=this._opts,s=this._displayCtx;return s.beginPath(),s.rect(0,this._doSize(i-n.width),this._doSize(e-n.width),this._doSize(n.width)),s.closePath(),!!s.isPointInPath(this._doSize(t.x),this._doSize(t.y))}getLineWidth(){return this._opts.scrollConfig.width}calc(t){const{width:e,height:i,scrollConfig:n}=this._opts,s=2.5*n.width,o=n.width;let r=0,l=0;t.left<=0&&t.right<=0&&(r=Math.max(s,e-(Math.abs(t.left)+Math.abs(t.right))),r>=e&&(r=0)),(t.top<=0||t.bottom<=0)&&(l=Math.max(s,i-(Math.abs(t.top)+Math.abs(t.bottom))),l>=i&&(l=0));let a=0;r>0&&(a=r/2+(e-r)*Math.abs(t.left)/(Math.abs(t.left)+Math.abs(t.right)),a=Math.min(Math.max(0,a-r/2),e-r));let h=0;l>0&&(h=l/2+(i-l)*Math.abs(t.top)/(Math.abs(t.top)+Math.abs(t.bottom)),h=Math.min(Math.max(0,h-l/2),i-l));return{lineSize:o,xSize:r,ySize:l,translateY:h,translateX:a,color:this._opts.scrollConfig.color}}_doSize(t){return t*this._opts.devicePixelRatio}_getOpts(t){var i;const n=Object.assign(Object.assign({},t),{scrollConfig:Object.assign(Object.assign({},b),t.scrollConfig||{})});return n.scrollConfig||(n.scrollConfig=b),(null===(i=null==n?void 0:n.scrollConfig)||void 0===i?void 0:i.width)>0||(n.scrollConfig.width=b.width),n.scrollConfig.width=Math.max(n.scrollConfig.width,b.width),!0!==e(n.scrollConfig.color)&&(n.scrollConfig.color=n.scrollConfig.color),n}}function C(t,e){let{x:i,y:n,h:s,w:o}=e;const{color:r,axis:l}=e;"X"===l?(n=n+s/4+1,s/=2):"Y"===l&&(i=i+o/4+1,o/=2);let a=e.r;a=Math.min(a,o/2,s/2),(o<2*a||s<2*a)&&(a=0),t.globalAlpha=.36,t.beginPath(),t.moveTo(i+a,n),t.arcTo(i+o,n,i+o,n+s,a),t.arcTo(i+o,n+s,i,n+s,a),t.arcTo(i,n+s,i,n,a),t.arcTo(i,n,i+o,n,a),t.closePath(),t.fillStyle=r,t.fill(),t.globalAlpha=1,t.beginPath(),t.lineWidth=1,t.strokeStyle=r,t.moveTo(i+a,n),t.arcTo(i+o,n,i+o,n+s,a),t.arcTo(i+o,n+s,i,n+s,a),t.arcTo(i,n+s,i,n,a),t.arcTo(i,n,i+o,n,a),t.closePath(),t.stroke()}const P=Symbol("_opts"),D=Symbol("_ctx");class L{constructor(t,e){this[P]=e,this[D]=t}resetSize(t){this[P]=Object.assign(Object.assign({},this[P]),t)}calcScreen(){const t=this[D].getTransform().scale,{width:e,height:i,contextWidth:n,contextHeight:s,devicePixelRatio:o}=this[P];let r=!0,l=!0,a=!0,h=!0;n*t<=e&&(this[D].setTransform({scrollX:(e-n*t)/2}),r=!1,l=!1),s*t<=i&&(this[D].setTransform({scrollY:(i-s*t)/2}),a=!1,h=!1),n*t>=e&&this[D].getTransform().scrollX>0&&(this[D].setTransform({scrollX:0}),r=!1),s*t>=i&&this[D].getTransform().scrollY>0&&(this[D].setTransform({scrollY:0}),a=!1);const{scrollX:c,scrollY:d}=this[D].getTransform();c<0&&Math.abs(c)>Math.abs(n*t-e)&&(this[D].setTransform({scrollX:0-Math.abs(n*t-e)}),l=!1),d<0&&Math.abs(d)>Math.abs(s*t-i)&&(this[D].setTransform({scrollY:0-Math.abs(s*t-i)}),h=!1);const{scrollX:u,scrollY:g}=this[D].getTransform();return{size:{x:u*t,y:g*t,w:n*t,h:s*t},position:{top:g,bottom:i-(s*t+g),left:u,right:e-(n*t+u)},deviceSize:{x:u*o,y:g*o,w:n*o*t,h:s*o*t},width:this[P].width,height:this[P].height,devicePixelRatio:this[P].devicePixelRatio,canScrollYPrev:a,canScrollYNext:h,canScrollXPrev:r,canScrollXNext:l}}calcScreenScroll(t,e,i,n,s){let o=t,r=n-i;t<=0&&e<=0&&(r=Math.abs(t)+Math.abs(e));let l=1;return r>0&&(l=r/(n-i)),o=0-l*s,o}}const{throttle:M,Context:I}=x;class z{constructor(t,e){this._hasRendered=!1,this._mount=t,this._canvas=document.createElement("canvas"),this._helperCanvas=document.createElement("canvas"),this._displayCanvas=document.createElement("canvas"),this._mount.appendChild(this._displayCanvas),this._opts=this._parsePrivateOptions(e);const i=this._canvas.getContext("2d"),n=this._displayCanvas.getContext("2d"),s=this._helperCanvas.getContext("2d");this._ctx=new I(i,this._opts),this._helperCtx=new I(s,this._opts),this._screen=new L(this._ctx,this._opts),this._watcher=new y(this._displayCanvas,this._ctx),this._scroller=new E(n,{width:e.width,height:e.height,devicePixelRatio:e.devicePixelRatio||1,scrollConfig:e.scrollConfig}),this._render()}getDisplayContext2D(){return this._displayCanvas.getContext("2d")}getOriginContext2D(){return this._ctx.getContext()}getHelperContext2D(){return this._helperCtx.getContext()}getContext(){return this._ctx}getHelperContext(){return this._helperCtx}scale(t){t>0&&(this._ctx.setTransform({scale:t}),this._helperCtx.setTransform({scale:t}));const{position:e,size:i}=this._screen.calcScreen();return{position:e,size:i}}scrollX(t){this._watcher.setStatusMap({canScrollYPrev:!0,canScrollYNext:!0,canScrollXPrev:!0,canScrollXNext:!0}),(t>=0||t<0)&&(this._ctx.setTransform({scrollX:t}),this._helperCtx.setTransform({scrollX:t}));const{position:e,size:i,canScrollXNext:n,canScrollYNext:s,canScrollXPrev:o,canScrollYPrev:r}=this._screen.calcScreen();return this._watcher.setStatusMap({canScrollYPrev:r,canScrollYNext:s,canScrollXPrev:o,canScrollXNext:n}),{position:e,size:i}}scrollY(t){this._watcher.setStatusMap({canScrollYPrev:!0,canScrollYNext:!0,canScrollXPrev:!0,canScrollXNext:!0}),(t>=0||t<0)&&(this._ctx.setTransform({scrollY:t}),this._helperCtx.setTransform({scrollY:t}));const{position:e,size:i,canScrollXNext:n,canScrollYNext:s,canScrollXPrev:o,canScrollYPrev:r}=this._screen.calcScreen();return this._watcher.setStatusMap({canScrollYPrev:r,canScrollYNext:s,canScrollXPrev:o,canScrollXNext:n}),{position:e,size:i}}getTransform(){return this._ctx.getTransform()}draw(){this.clear();const{position:t,deviceSize:e,size:i}=this._screen.calcScreen(),n=this._displayCanvas.getContext("2d");return null==n||n.drawImage(this._canvas,e.x,e.y,e.w,e.h),null==n||n.drawImage(this._helperCanvas,e.x,e.y,e.w,e.h),!0===this._opts.canScroll&&this._scroller.draw(t),{position:t,size:i}}clear(){const t=this._displayCanvas.getContext("2d");null==t||t.clearRect(0,0,this._displayCanvas.width,this._displayCanvas.height)}on(t,e){this._watcher.on(t,e)}off(t,e){this._watcher.off(t,e)}getScreenInfo(){return this._screen.calcScreen()}setCursor(t){this._displayCanvas.style.cursor=t}resetCursor(){this._displayCanvas.style.cursor="auto"}resetSize(t){this._opts=Object.assign(Object.assign({},this._opts),t),this._resetContext(),this._ctx.resetSize(t),this._helperCtx.resetSize(t),this._screen.resetSize(t),this._scroller.resetSize({width:this._opts.width,height:this._opts.height,devicePixelRatio:this._opts.devicePixelRatio}),this.draw()}getScrollLineWidth(){let t=0;return!0===this._opts.canScroll&&(t=this._scroller.getLineWidth()),t}pointScreenToContext(t){const{scrollX:e,scrollY:i,scale:n}=this.getTransform();return{x:(t.x-e)/n,y:(t.y-i)/n}}pointContextToScreen(t){const{scrollX:e,scrollY:i,scale:n}=this.getTransform();return{x:t.x*n+e,y:t.y*n+i}}_render(){!0!==this._hasRendered&&(this._resetContext(),this._initEvent(),this._hasRendered=!0)}_resetContext(){const{width:t,height:e,contextWidth:i,contextHeight:n,devicePixelRatio:s}=this._opts;this._canvas.width=i*s,this._canvas.height=n*s,this._helperCanvas.width=i*s,this._helperCanvas.height=n*s,this._displayCanvas.width=t*s,this._displayCanvas.height=e*s,function(t,e){const i=function(t){const e={};return(t.getAttribute("style")||"").split(";").forEach((t=>{const i=t.split(":");i[0]&&"string"==typeof i[0]&&(e[i[0]]=i[1]||"")})),e}(t),n=Object.assign(Object.assign({},i),e),s=Object.keys(n);let o="";s.forEach((t=>{o+=`${t}:${n[t]||""};`})),t.setAttribute("style",o)}(this._displayCanvas,{width:`${t}px`,height:`${e}px`})}_parsePrivateOptions(t){return Object.assign(Object.assign({},{devicePixelRatio:1}),t)}_initEvent(){if(!0!==this._hasRendered&&!0===this._opts.canScroll){this.on("wheelX",M((t=>{this._doScrollX(t)}),16)),this.on("wheelY",M((t=>{this._doScrollY(t)}),16));let t=null;this.on("moveStart",M((e=>{this._scroller.isPointAtScrollX(e)?t="x":this._scroller.isPointAtScrollY(e)&&(t="y")}),16)),this.on("move",M((e=>{t&&this._doMoveScroll(t,e)}),16)),this.on("moveEnd",M((e=>{t&&this._doMoveScroll(t,e),t=null}),16))}}_doScrollX(t,e){const{width:i}=this._opts;let n=e;"number"==typeof n&&(n>0||n<=0)||(n=this._ctx.getTransform().scrollX);const{position:s}=this._screen.calcScreen(),{xSize:o}=this._scroller.calc(s),r=this._screen.calcScreenScroll(s.left,s.right,o,i,t);this.scrollX(n+r),this.draw()}_doScrollY(t,e){const{height:i}=this._opts;let n=e;"number"==typeof n&&(n>0||n<=0)||(n=this._ctx.getTransform().scrollY);const{position:s}=this._screen.calcScreen(),{ySize:o}=this._scroller.calc(s),r=this._screen.calcScreenScroll(s.top,s.bottom,o,i,t);this.scrollY(n+r),this.draw()}_doMoveScroll(t,e){if(!t)return;const{position:i}=this._screen.calcScreen(),{xSize:n,ySize:s}=this._scroller.calc(i);"x"===t?this._doScrollX(e.x-n/2,0):"y"===t&&this._doScrollY(e.y-s/2,0)}}function T(t,e,i){const n=function(t){return{x:t.x+t.w/2,y:t.y+t.h/2}}(e);return function(t,e,i,n){e&&(i>0||i<0)&&(t.translate(e.x,e.y),t.rotate(i),t.translate(-e.x,-e.y));n(t),e&&(i>0||i<0)&&(t.translate(e.x,e.y),t.rotate(-i),t.translate(-e.x,-e.y))}(t,n,(e.angle||0)/180*Math.PI||0,i)}function k(t){t.setFillStyle("#000000"),t.setStrokeStyle("#000000"),t.setLineDash([]),t.setGlobalAlpha(1),t.setShadowColor("#00000000"),t.setShadowOffsetX(0),t.setShadowOffsetY(0),t.setShadowBlur(0)}function U(t,i,n){k(t),function(t,i){k(t),T(t,i,(()=>{if(!(i.desc.borderWidth&&i.desc.borderWidth>0))return;const n=i.desc.borderWidth;let s="#000000";!0===e(i.desc.borderColor)&&(s=i.desc.borderColor);const o=i.x-n/2,r=i.y-n/2,l=i.w+n,a=i.h+n;let h=i.desc.borderRadius||0;h=Math.min(h,l/2,a/2),h<l/2&&h<a/2&&(h+=n/2);const{desc:c}=i;void 0!==c.shadowColor&&e(c.shadowColor)&&t.setShadowColor(c.shadowColor),void 0!==c.shadowOffsetX&&f.number(c.shadowOffsetX)&&t.setShadowOffsetX(c.shadowOffsetX),void 0!==c.shadowOffsetY&&f.number(c.shadowOffsetY)&&t.setShadowOffsetY(c.shadowOffsetY),void 0!==c.shadowBlur&&f.number(c.shadowBlur)&&t.setShadowBlur(c.shadowBlur),t.beginPath(),t.setLineWidth(n),t.setStrokeStyle(s),t.moveTo(o+h,r),t.arcTo(o+l,r,o+l,r+a,h),t.arcTo(o+l,r+a,o,r+a,h),t.arcTo(o,r+a,o,r,h),t.arcTo(o,r,o+l,r,h),t.closePath(),t.stroke()}))}(t,i),k(t),T(t,i,(()=>{const{x:e,y:s,w:r,h:l}=i;let a=i.desc.borderRadius||0;a=Math.min(a,r/2,l/2),(r<2*a||l<2*a)&&(a=0),t.beginPath(),t.moveTo(e+a,s),t.arcTo(e+r,s,e+r,s+l,a),t.arcTo(e+r,s+l,e,s+l,a),t.arcTo(e,s+l,e,s,a),t.arcTo(e,s,e+r,s,a),t.closePath(),("string"==typeof n||["CanvasPattern"].includes(o.type(n)))&&t.setFillStyle(n),t.fill()}))}function W(t,e){U(t,e,e.desc.bgColor)}function R(t,e,i){const n=i.getContent(e.uuid);T(t,e,(()=>{n&&t.drawImage(n,e.x,e.y,e.w,e.h)}))}function O(t,e,i){const n=i.getContent(e.uuid);T(t,e,(()=>{n&&t.drawImage(n,e.x,e.y,e.w,e.h)}))}function A(t,e,i){const n=i.getContent(e.uuid);T(t,e,(()=>{n&&t.drawImage(n,e.x,e.y,e.w,e.h)}))}function F(t,i,n){k(t),U(t,i,i.desc.bgColor||"transparent"),T(t,i,(()=>{const n=Object.assign({fontSize:12,fontFamily:"sans-serif",textAlign:"center"},i.desc);t.setFillStyle(i.desc.color),t.setTextBaseline("top"),t.setFont({fontWeight:n.fontWeight,fontSize:n.fontSize,fontFamily:n.fontFamily});const s=n.text.replace(/\r\n/gi,"\n"),o=n.lineHeight||n.fontSize,r=s.split("\n"),l=[];let a=0;r.forEach(((e,n)=>{let s="";if(e.length>0){for(let h=0;h<e.length&&(t.measureText(s+(e[h]||"")).width<t.calcDeviceNum(i.w)?s+=e[h]||"":(l.push({text:s,width:t.calcScreenNum(t.measureText(s).width)}),s=e[h]||"",a++),!((a+1)*o>i.h));h++)if(e.length-1===h&&(a+1)*o<i.h){l.push({text:s,width:t.calcScreenNum(t.measureText(s).width)}),n<r.length-1&&a++;break}}else l.push({text:"",width:0})}));let h=0;l.length*o<i.h&&("top"===i.desc.verticalAlign?h=0:"bottom"===i.desc.verticalAlign?h+=i.h-l.length*o:h+=(i.h-l.length*o)/2);{const s=i.y+h;void 0!==n.textShadowColor&&e(n.textShadowColor)&&t.setShadowColor(n.textShadowColor),void 0!==n.textShadowOffsetX&&f.number(n.textShadowOffsetX)&&t.setShadowOffsetX(n.textShadowOffsetX),void 0!==n.textShadowOffsetY&&f.number(n.textShadowOffsetY)&&t.setShadowOffsetY(n.textShadowOffsetY),void 0!==n.textShadowBlur&&f.number(n.textShadowBlur)&&t.setShadowBlur(n.textShadowBlur),l.forEach(((e,r)=>{let l=i.x;"center"===n.textAlign?l=i.x+(i.w-e.width)/2:"right"===n.textAlign&&(l=i.x+(i.w-e.width)),t.fillText(e.text,l,s+o*r)})),k(t)}if(e(n.strokeColor)&&void 0!==n.strokeWidth&&n.strokeWidth>0){const e=i.y+h;l.forEach(((s,r)=>{let l=i.x;"center"===n.textAlign?l=i.x+(i.w-s.width)/2:"right"===n.textAlign&&(l=i.x+(i.w-s.width)),void 0!==n.strokeColor&&t.setStrokeStyle(n.strokeColor),void 0!==n.strokeWidth&&n.strokeWidth>0&&t.setLineWidth(n.strokeWidth),t.strokeText(s.text,l,e+o*r)}))}}))}function $(t,e){k(t),T(t,e,(t=>{const{x:i,y:n,w:s,h:o,desc:r}=e,{bgColor:l="#000000",borderColor:a="#000000",borderWidth:h=0}=r,c=s/2,d=o/2,u=i+c,g=n+d;if(h&&h>0){const e=h/2+c,i=h/2+d;t.beginPath(),t.setStrokeStyle(a),t.setLineWidth(h),t.ellipse(u,g,e,i,0,0,2*Math.PI),t.closePath(),t.stroke()}t.beginPath(),t.setFillStyle(l),t.ellipse(u,g,c,d,0,0,2*Math.PI),t.closePath(),t.fill()}))}function Y(t,i,n){var s;k(t);const o=t.getSize();if(t.clearRect(0,0,o.contextWidth,o.contextHeight),"string"==typeof i.bgColor&&e(i.bgColor)&&function(t,e){const i=t.getSize();t.setFillStyle(e),t.fillRect(0,0,i.contextWidth,i.contextHeight)}(t,i.bgColor),i.elements.length>0)for(let e=0;e<i.elements.length;e++){const o=i.elements[e];if(!0!==(null===(s=null==o?void 0:o.operation)||void 0===s?void 0:s.invisible))switch(o.type){case"rect":W(t,o);break;case"text":F(t,o);break;case"image":R(t,o,n);break;case"svg":O(t,o,n);break;case"html":A(t,o,n);break;case"circle":$(t,o)}}}class X{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);null==i||i.push(e),this._listeners.set(t,i||[])}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);if(Array.isArray(i))for(let t=0;t<(null==i?void 0:i.length);t++)if(i[t]===e){i.splice(t,1);break}this._listeners.set(t,i||[])}}trigger(t,e){const i=this._listeners.get(t);return!!Array.isArray(i)&&(i.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}}var N,H,B=globalThis&&globalThis.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{a(n.next(t))}catch(t){o(t)}}function l(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,l)}a((n=n.apply(t,e||[])).next())}))};(H=N||(N={})).FREE="free",H.LOADING="loading",H.COMPLETE="complete";class j{constructor(t){this._currentLoadData={},this._currentUUIDQueue=[],this._storageLoadData={},this._status=N.FREE,this._waitingLoadQueue=[],this._opts=t,this._event=new X,this._waitingLoadQueue=[]}load(t,e){const[i,n]=this._resetLoadData(t,e);this._status===N.FREE||this._status===N.COMPLETE?(this._currentUUIDQueue=i,this._currentLoadData=n,this._loadTask()):this._status===N.LOADING&&i.length>0&&this._waitingLoadQueue.push({uuidQueue:i,loadData:n})}on(t,e){this._event.on(t,e)}off(t,e){this._event.off(t,e)}isComplete(){return this._status===N.COMPLETE}getContent(t){var e;return"loaded"===(null===(e=this._storageLoadData[t])||void 0===e?void 0:e.status)?this._storageLoadData[t].content:null}_resetLoadData(t,e){const i={},n=[],s=this._storageLoadData;for(let o=t.elements.length-1;o>=0;o--){const r=t.elements[o];["image","svg","html"].includes(r.type)&&(s[r.uuid]?e.includes(r.uuid)&&(i[r.uuid]=this._createEmptyLoadItem(r),n.push(r.uuid)):(i[r.uuid]=this._createEmptyLoadItem(r),n.push(r.uuid)))}return[n,i]}_createEmptyLoadItem(t){let e="";const i=t.type;let s=t.w,o=t.h;if("image"===t.type){e=t.desc.src||""}else if("svg"===t.type){e=t.desc.svg||""}else if("html"===t.type){const i=t;e=(i.desc.html||"").replace(/<script[\s\S]*?<\/script>/gi,""),s=i.desc.width||t.w,o=i.desc.height||t.h}return{uuid:t.uuid,type:i,status:"null",content:null,source:e,elemW:s,elemH:o,element:n(t)}}_loadTask(){if(this._status===N.LOADING)return;if(this._status=N.LOADING,0===this._currentUUIDQueue.length){if(0===this._waitingLoadQueue.length)return this._status=N.COMPLETE,void this._event.trigger("complete",void 0);{const t=this._waitingLoadQueue.shift();if(t){const{uuidQueue:e,loadData:i}=t;this._currentLoadData=i,this._currentUUIDQueue=e}}}const{maxParallelNum:t}=this._opts,e=this._currentUUIDQueue.splice(0,t);e.forEach(((t,e)=>{}));const i=[],n=()=>{if(i.length>=t)return!1;if(0===e.length)return!0;for(let s=i.length;s<t;s++){const t=e.shift();if(void 0===t)break;i.push(t),this._loadElementSource(this._currentLoadData[t]).then((s=>{var o,r;i.splice(i.indexOf(t),1);const l=n();this._storageLoadData[t]={uuid:t,type:this._currentLoadData[t].type,status:"loaded",content:s,source:this._currentLoadData[t].source,elemW:this._currentLoadData[t].elemW,elemH:this._currentLoadData[t].elemH,element:this._currentLoadData[t].element},0===i.length&&0===e.length&&!0===l&&(this._status=N.FREE,this._loadTask()),this._event.trigger("load",{uuid:null===(o=this._storageLoadData[t])||void 0===o?void 0:o.uuid,type:this._storageLoadData[t].type,status:this._storageLoadData[t].status,content:this._storageLoadData[t].content,source:this._storageLoadData[t].source,elemW:this._storageLoadData[t].elemW,elemH:this._storageLoadData[t].elemH,element:null===(r=this._storageLoadData[t])||void 0===r?void 0:r.element})})).catch((s=>{var o,r,l,a,h,c,d,u,g,m,_,f;console.warn(s),i.splice(i.indexOf(t),1);const p=n();this._currentLoadData[t]&&(this._storageLoadData[t]={uuid:t,type:null===(o=this._currentLoadData[t])||void 0===o?void 0:o.type,status:"fail",content:null,error:s,source:null===(r=this._currentLoadData[t])||void 0===r?void 0:r.source,elemW:null===(l=this._currentLoadData[t])||void 0===l?void 0:l.elemW,elemH:null===(a=this._currentLoadData[t])||void 0===a?void 0:a.elemH,element:null===(h=this._currentLoadData[t])||void 0===h?void 0:h.element}),0===i.length&&0===e.length&&!0===p&&(this._status=N.FREE,this._loadTask()),this._currentLoadData[t]&&this._event.trigger("error",{uuid:t,type:null===(c=this._storageLoadData[t])||void 0===c?void 0:c.type,status:null===(d=this._storageLoadData[t])||void 0===d?void 0:d.status,content:null===(u=this._storageLoadData[t])||void 0===u?void 0:u.content,source:null===(g=this._storageLoadData[t])||void 0===g?void 0:g.source,elemW:null===(m=this._storageLoadData[t])||void 0===m?void 0:m.elemW,elemH:null===(_=this._storageLoadData[t])||void 0===_?void 0:_.elemH,element:null===(f=this._storageLoadData[t])||void 0===f?void 0:f.element})}))}return!1};n()}_loadElementSource(t){return B(this,void 0,void 0,(function*(){if(t&&"image"===t.type){return yield a(t.source)}if(t&&"svg"===t.type){return yield h(t.source)}if(t&&"html"===t.type){return yield c(t.source,{width:t.elemW,height:t.elemH})}throw Error("Element's source is not support!")}))}}class G{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);null==i||i.push(e),this._listeners.set(t,i||[])}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);if(Array.isArray(i))for(let t=0;t<(null==i?void 0:i.length);t++)if(i[t]===e){i.splice(t,1);break}this._listeners.set(t,i||[])}}trigger(t,e){const i=this._listeners.get(t);return!!Array.isArray(i)&&(i.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}}const{requestAnimationFrame:q}=window;var Q,V;(V=Q||(Q={})).NULL="null",V.FREE="free",V.DRAWING="drawing",V.FREEZE="freeze";class Z extends G{constructor(t){super(),this._queue=[],this._ctx=null,this._status=Q.NULL,this._opts=t,this._loader=new j({maxParallelNum:6}),this._loader.on("load",(t=>{this._drawFrame(),this.trigger("load",{element:t.element})})),this._loader.on("error",(t=>{this.trigger("error",{element:t.element,error:t.error})})),this._loader.on("complete",(()=>{this.trigger("loadComplete",{t:Date.now()})}))}render(t,e,s){const{changeResourceUUIDs:o=[]}=s||{};this._status=Q.FREE;const r=n(e);if(Array.isArray(r.elements)&&r.elements.forEach((t=>{"string"==typeof t.uuid&&t.uuid||(t.uuid=i())})),!this._ctx)if(this._opts&&"[object HTMLCanvasElement]"===Object.prototype.toString.call(t)){const{width:e,height:i,contextWidth:n,contextHeight:s,devicePixelRatio:o}=this._opts,r=t;r.width=e*o,r.height=i*o;const l=r.getContext("2d");this._ctx=new d(l,{width:e,height:i,contextWidth:n||e,contextHeight:s||i,devicePixelRatio:o})}else t&&(this._ctx=t);if([Q.FREEZE].includes(this._status))return;const l=n({data:r});this._queue.push(l),this._drawFrame(),this._loader.load(r,o||[])}getContext(){return this._ctx}thaw(){this._status=Q.FREE}_freeze(){this._status=Q.FREEZE}_drawFrame(){this._status!==Q.FREEZE&&q((()=>{if(this._status===Q.FREEZE)return;const t=this._ctx;let e=this._queue[0],i=!1;this._queue.length>1?e=this._queue.shift():i=!0,!0!==this._loader.isComplete()?(this._drawFrame(),e&&t&&Y(t,e.data,this._loader)):e&&t?(Y(t,e.data,this._loader),this._retainQueueOneItem(),i?this._status=Q.FREE:this._drawFrame()):this._status=Q.FREE,this.trigger("drawFrame",{t:Date.now()}),!0===this._loader.isComplete()&&1===this._queue.length&&this._status===Q.FREE&&(t&&this._queue[0]&&this._queue[0].data&&Y(t,this._queue[0].data,this._loader),this.trigger("drawFrameComplete",{t:Date.now()}),this._freeze())}))}_retainQueueOneItem(){if(this._queue.length<=1)return;const t=n(this._queue[this._queue.length-1]);this._queue=[t]}}function J(t){return"number"==typeof t&&(t>0||t<=0)}function K(t){return"number"==typeof t&&t>=0}function tt(t){return"string"==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${t}`)}function et(t){return"string"==typeof t&&/^(data:image\/)/.test(`${t}`)}const it={x:function(t){return J(t)},y:function(t){return J(t)},w:K,h:function(t){return"number"==typeof t&&t>=0},angle:function(t){return"number"==typeof t&&t>=-360&&t<=360},number:J,borderWidth:function(t){return K(t)},borderRadius:function(t){return J(t)&&t>=0},color:function(t){return e(t)},imageSrc:function(t){return et(t)||tt(t)},imageURL:tt,imageBase64:et,svg:function(t){return"string"==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test(`${t}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${t}`.trim())},html:function(t){let e=!1;if("string"==typeof t){let i=document.createElement("div");i.innerHTML=t,i.children.length>0&&(e=!0),i=null}return e},text:function(t){return"string"==typeof t},fontSize:function(t){return J(t)&&t>0},lineHeight:function(t){return J(t)&&t>0},textAlign:function(t){return["center","left","right"].includes(t)},fontFamily:function(t){return"string"==typeof t&&t.length>0},fontWeight:function(t){return["bold"].includes(t)},strokeWidth:function(t){return J(t)&&t>0}};function nt(t={}){const{borderColor:e,borderRadius:i,borderWidth:n}=t;return!(t.hasOwnProperty("borderColor")&&!it.color(e))&&(!(t.hasOwnProperty("borderRadius")&&!it.number(i))&&!(t.hasOwnProperty("borderWidth")&&!it.number(n)))}const st={attrs:function(t){const{x:e,y:i,w:n,h:s,angle:o}=t;return!!(it.x(e)&&it.y(i)&&it.w(n)&&it.h(s)&&it.angle(o))&&(o>=-360&&o<=360)},textDesc:function(t){const{text:e,color:i,fontSize:n,lineHeight:s,fontFamily:o,textAlign:r,fontWeight:l,bgColor:a,strokeWidth:h,strokeColor:c}=t;return!!it.text(e)&&(!!it.color(i)&&(!!it.fontSize(n)&&(!(t.hasOwnProperty("bgColor")&&!it.color(a))&&(!(t.hasOwnProperty("fontWeight")&&!it.fontWeight(l))&&(!(t.hasOwnProperty("lineHeight")&&!it.lineHeight(s))&&(!(t.hasOwnProperty("fontFamily")&&!it.fontFamily(o))&&(!(t.hasOwnProperty("textAlign")&&!it.textAlign(r))&&(!(t.hasOwnProperty("strokeWidth")&&!it.strokeWidth(h))&&(!(t.hasOwnProperty("strokeColor")&&!it.color(c))&&!!nt(t))))))))))},rectDesc:function(t){const{bgColor:e}=t;return!(t.hasOwnProperty("bgColor")&&!it.color(e))&&!!nt(t)},circleDesc:function(t){const{bgColor:e,borderColor:i,borderWidth:n}=t;return!(t.hasOwnProperty("bgColor")&&!it.color(e))&&(!(t.hasOwnProperty("borderColor")&&!it.color(i))&&!(t.hasOwnProperty("borderWidth")&&!it.number(n)))},imageDesc:function(t){const{src:e}=t;return!!it.imageSrc(e)},svgDesc:function(t){const{svg:e}=t;return!!it.svg(e)},htmlDesc:function(t){const{html:e}=t;return!!it.html(e)}};function ot(t){return t/180*Math.PI}function rt(t){return{x:t.x+t.w/2,y:t.y+t.h/2}}function lt(t,e){const i=e.x-t.x,n=t.y-e.y;if(0===i){if(n<0)return Math.PI/2;if(n>0)return 1.5*Math.PI}else if(0===n){if(i<0)return Math.PI;if(i>0)return 0}return i>0&&n<0?Math.atan(Math.abs(n)/Math.abs(i)):i<0&&n<0?Math.PI-Math.atan(Math.abs(n)/Math.abs(i)):i<0&&n>0?Math.PI+Math.atan(Math.abs(n)/Math.abs(i)):i>0&&n>0?2*Math.PI-Math.atan(Math.abs(n)/Math.abs(i)):null}const at={elementWrapper:{color:"#0d85da",lockColor:"#aaaaaa",controllerSize:6,lineWidth:1,lineDash:[4,3]}};class ht{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);null==i||i.push(e),this._listeners.set(t,i||[])}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);if(Array.isArray(i))for(let t=0;t<(null==i?void 0:i.length);t++)if(i[t]===e){i.splice(t,1);break}this._listeners.set(t,i||[])}}trigger(t,e){const i=this._listeners.get(t);return!!Array.isArray(i)&&(i.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}}function ct(t,e){var i,n;return(null==(i=null==t?void 0:t.desc)?void 0:i.src)!==(null==(n=null==e?void 0:e.desc)?void 0:n.src)}function dt(t,e){var i,n;return(null==(i=null==t?void 0:t.desc)?void 0:i.svg)!==(null==(n=null==e?void 0:e.desc)?void 0:n.svg)}function ut(t,e){var i,n,s,o,r,l;return(null==(i=null==t?void 0:t.desc)?void 0:i.html)!==(null==(n=null==e?void 0:e.desc)?void 0:n.html)||(null==(s=null==t?void 0:t.desc)?void 0:s.width)!==(null==(o=null==e?void 0:e.desc)?void 0:o.width)||(null==(r=null==t?void 0:t.desc)?void 0:r.height)!==(null==(l=null==e?void 0:e.desc)?void 0:l.height)}function gt(t,e){let i=null,n=!1;switch(e.type){case"image":n=ct(t,e);break;case"svg":n=dt(t,e);break;case"html":n=ut(t,e)}return!0===n&&(i=e.uuid),i}function mt(t){const e={};return t.elements.forEach((t=>{e[t.uuid]=t})),e}function _t(t,e,i){return ft(t,rt(e),ot(e.angle||0)||0,i)}function ft(t,e,i,n){e&&(i>0||i<0)&&(t.translate(e.x,e.y),t.rotate(i),t.translate(-e.x,-e.y)),n(t),e&&(i>0||i<0)&&(t.translate(e.x,e.y),t.rotate(-i),t.translate(-e.x,-e.y))}function pt(t){const e=t.toFixed(2);return parseFloat(e)}function vt(t){return pt(t%360)}const xt=Object.keys({text:{},rect:{},image:{},svg:{},circle:{},html:{}}),St=15;class yt{constructor(t){this._ctx=t}initData(t){return t.elements.forEach((t=>{t.uuid&&"string"==typeof t.uuid||(t.uuid=i())})),t}isPointInElement(t,e){var i,n;const s=this._ctx;let o=-1,r=null;for(let l=e.elements.length-1;l>=0;l--){const a=e.elements[l];if(!0===(null==(i=a.operation)?void 0:i.invisible))continue;let h=0;if((null==(n=a.desc)?void 0:n.borderWidth)>0&&(h=a.desc.borderWidth),_t(s,a,(()=>{s.beginPath(),s.moveTo(a.x-h,a.y-h),s.lineTo(a.x+a.w+h,a.y-h),s.lineTo(a.x+a.w+h,a.y+a.h+h),s.lineTo(a.x-h,a.y+a.h+h),s.lineTo(a.x-h,a.y-h),s.closePath(),s.isPointInPath(t.x,t.y)&&(o=l,r=a.uuid)})),o>=0)break}return[o,r]}dragElement(t,e,i,n,s){const o=this.getElementIndex(t,e);if(!t.elements[o])return;const r=i.x-n.x,l=i.y-n.y;t.elements[o].x+=r/s,t.elements[o].y+=l/s,this.limitElementAttrs(t.elements[o])}transformElement(t,e,i,n,s,o){var r,l;const a=this.getElementIndex(t,e);if(!t.elements[a])return null;if(!0===(null==(l=null==(r=t.elements[a])?void 0:r.operation)?void 0:l.lock))return null;const h=(i.x-n.x)/s,c=(i.y-n.y)/s,d=t.elements[a];if(["top-left","top","top-right","right","bottom-right","bottom","bottom-left","left"].includes(o)){const t=function(t,e,i,n){var s,o,r,l,a,h,c,d,u,g,m,_,f;const p={x:t.x,y:t.y,w:t.w,h:t.h};if(t.angle,!0===(null==(s=t.operation)?void 0:s.limitRatio)&&["top-left","top-right","bottom-right","bottom-left"].includes(n)){const n=Math.max(Math.abs(e),Math.abs(i));e=(e>=0?1:-1)*n,i=(i>=0?1:-1)*n/t.w*t.h}switch(n){case"top-left":t.w-e>0&&t.h-i>0&&(p.x+=e,p.y+=i,p.w-=e,p.h-=i);break;case"top":if(0===t.angle||Math.abs(t.angle||0)<St)p.h-i>0&&(p.y+=i,p.h-=i,!0===(null==(o=t.operation)?void 0:o.limitRatio)&&(p.x+=i/t.h*t.w/2,p.w-=i/t.h*t.w));else if(void 0!==t.angle&&(t.angle>0||t.angle<0)){const n=t.angle>0?t.angle:Math.max(0,t.angle+360);let s=bt(e,i),o=p.x+t.w/2,l=p.y+t.h/2;if(n<90){s=0-Et(s,i);const t=wt(n),e=s/2;o+=e*Math.sin(t),l-=e*Math.cos(t)}else if(n<180){s=Et(s,e);const t=wt(n-90),i=s/2;o+=i*Math.cos(t),l+=i*Math.sin(t)}else if(n<270){s=Et(s,i);const t=wt(n-180),e=s/2;o-=e*Math.sin(t),l+=e*Math.cos(t)}else if(n<360){s=0-Et(s,e);const t=wt(n-270),i=s/2;o-=i*Math.cos(t),l-=i*Math.sin(t)}p.h+s>0&&(!0===(null==(r=t.operation)?void 0:r.limitRatio)&&(p.w=p.w+s/t.h*t.w),p.h=p.h+s,p.x=o-p.w/2,p.y=l-p.h/2)}else p.h-i>0&&(p.y+=i,p.h-=i,!0===(null==(l=t.operation)?void 0:l.limitRatio)&&(p.x-=e/2,p.w+=e));break;case"top-right":p.h-i>0&&p.w+e>0&&(p.y+=i,p.w+=e,p.h-=i);break;case"right":if(0===t.angle||Math.abs(t.angle||0)<St)t.w+e>0&&(p.w+=e,!0===(null==(a=t.operation)?void 0:a.limitRatio)&&(p.y-=e*t.h/t.w/2,p.h+=e*t.h/t.w));else if(void 0!==t.angle&&(t.angle>0||t.angle<0)){const n=t.angle>0?t.angle:Math.max(0,t.angle+360);let s=bt(e,i),o=p.x+t.w/2,r=p.y+t.h/2;if(n<90){s=Et(s,i);const t=wt(n),e=s/2;o+=e*Math.cos(t),r+=e*Math.sin(t)}else if(n<180){s=Et(s,i);const t=wt(n-90),e=s/2;o-=e*Math.sin(t),r+=e*Math.cos(t)}else if(n<270){s=Et(s,i);const t=wt(n-180),e=s/2;o+=e*Math.cos(t),r+=e*Math.sin(t),s=0-s}else if(n<360){s=Et(s,e);const t=wt(n-270),i=s/2;o+=i*Math.sin(t),r-=i*Math.cos(t)}p.w+s>0&&(!0===(null==(h=t.operation)?void 0:h.limitRatio)&&(p.h=p.h+s/t.w*t.h),p.w=p.w+s,p.x=o-p.w/2,p.y=r-p.h/2)}else t.w+e>0&&(p.w+=e,!0===(null==(c=t.operation)?void 0:c.limitRatio)&&(p.h+=e*t.h/t.w,p.y-=e*t.h/t.w/2));break;case"bottom-right":t.w+e>0&&t.h+i>0&&(p.w+=e,p.h+=i);break;case"bottom":if(0===t.angle||Math.abs(t.angle||0)<St)t.h+i>0&&(p.h+=i,!0===(null==(d=t.operation)?void 0:d.limitRatio)&&(p.x-=i/t.h*t.w/2,p.w+=i/t.h*t.w));else if(void 0!==t.angle&&(t.angle>0||t.angle<0)){const n=t.angle>0?t.angle:Math.max(0,t.angle+360);let s=bt(e,i),o=p.x+t.w/2,r=p.y+t.h/2;if(n<90){s=Et(s,i);const t=wt(n),e=s/2;o-=e*Math.sin(t),r+=e*Math.cos(t)}else if(n<180){s=0-Et(s,e);const t=wt(n-90),i=s/2;o-=i*Math.cos(t),r-=i*Math.sin(t)}else if(n<270){s=Et(s,e);const t=wt(n-180),i=s/2;o+=i*Math.sin(t),r-=i*Math.cos(t)}else if(n<360){s=Et(s,e);const t=wt(n-270),i=s/2;o+=i*Math.cos(t),r+=i*Math.sin(t)}p.h+s>0&&(!0===(null==(u=t.operation)?void 0:u.limitRatio)&&(p.w=p.w+s/t.h*t.w),p.h=p.h+s,p.x=o-p.w/2,p.y=r-p.h/2)}else t.h+i>0&&(p.h+=i,!0===(null==(g=t.operation)?void 0:g.limitRatio)&&(p.x-=i/t.h*t.w/2,p.w+=i/t.h*t.w));break;case"bottom-left":t.w-e>0&&t.h+i>0&&(p.x+=e,p.w-=e,p.h+=i);break;case"left":if(0===t.angle||Math.abs(t.angle||0)<St)t.w-e>0&&(p.x+=e,p.w-=e,!0===(null==(m=t.operation)?void 0:m.limitRatio)&&(p.h-=e/t.w*t.h,p.y+=e/t.w*t.h/2));else if(void 0!==t.angle&&(t.angle>0||t.angle<0)){const n=t.angle>0?t.angle:Math.max(0,t.angle+360);let s=bt(e,i),o=p.x+t.w/2,r=p.y+t.h/2;if(n<90){s=0-Et(s,e);const t=wt(n),i=s/2;o-=i*Math.cos(t),r-=i*Math.sin(t)}else if(n<180){s=Et(s,e);const t=wt(n-90),i=s/2;o+=i*Math.sin(t),r-=i*Math.cos(t)}else if(n<270){s=Et(s,i);const t=wt(n-180),e=s/2;o+=e*Math.cos(t),r+=e*Math.sin(t)}else if(n<360){s=Et(s,i);const t=wt(n-270),e=s/2;o-=e*Math.sin(t),r+=e*Math.cos(t)}p.w+s>0&&(!0===(null==(_=t.operation)?void 0:_.limitRatio)&&(p.h=p.h+s/t.w*t.h),p.w=p.w+s,p.x=o-p.w/2,p.y=r-p.h/2)}else t.w-e>0&&(p.x+=e,p.w-=e,!0===(null==(f=t.operation)?void 0:f.limitRatio)&&(p.h-=e/t.w*t.h,p.y+=e/t.w*t.h/2))}return p}(d,h,c,o);d.x=t.x,d.y=t.y,d.w=t.w,d.h=t.h}else if("rotate"===o){const t=function(t,e,i){const n=lt(t,e),s=lt(t,i);return null!==s&&null!==n?n>3*Math.PI/2&&s<Math.PI/2?s+(2*Math.PI-n):s>3*Math.PI/2&&n<Math.PI/2?n+(2*Math.PI-s):s-n:0}(rt(d),n,i);d.angle=(d.angle||0)+function(t){return t/Math.PI*180}(t)}return this.limitElementAttrs(d),{width:pt(d.w),height:pt(d.h),angle:vt(d.angle||0)}}getElementIndex(t,e){let i=-1;for(let n=0;n<t.elements.length;n++)if(t.elements[n].uuid===e){i=n;break}return i}limitElementAttrs(t){t.x=pt(t.x),t.y=pt(t.y),t.w=pt(t.w),t.h=pt(t.h),t.angle=vt(t.angle||0)}}function wt(t){return t*Math.PI/180}function bt(t,e){return Math.sqrt(t*t+e*e)}function Et(t,e){return e>0?Math.abs(t):0-Math.abs(t)}class Ct{constructor(t,e){this._areaStart={x:0,y:0},this._areaEnd={x:0,y:0},this._board=t,this._ctx=this._board.getContext(),this._coreConfig=e,this._helperConfig={elementIndexMap:{}}}updateConfig(t,e){this._updateElementIndex(t),this._updateSelectedElementWrapper(t,e),this._updateSelectedElementListWrapper(t,e)}getConfig(){return n(this._helperConfig)}getElementIndexByUUID(t){const e=this._helperConfig.elementIndexMap[t];return e>=0?e:null}isPointInElementWrapperController(t,e){var i,s;const o=this._ctx,r=(null==(s=null==(i=this._helperConfig)?void 0:i.selectedElementWrapper)?void 0:s.uuid)||null;let l=null,a=null,h=null;if(!this._helperConfig.selectedElementWrapper)return{uuid:r,selectedControllerDirection:a,directIndex:l,hoverControllerDirection:h};const c=this._helperConfig.selectedElementWrapper,d=[c.controllers.right,c.controllers.topRight,c.controllers.top,c.controllers.topLeft,c.controllers.left,c.controllers.bottomLeft,c.controllers.bottom,c.controllers.bottomRight],u=["right","top-right","top","top-left","left","bottom-left","bottom","bottom-right"];let g=n(u),m=0;if(e&&r){const t=this.getElementIndexByUUID(r);if(null!==t&&t>=0){let i=e.elements[t].angle||0;i<0&&(i+=360),i<45?m=0:i<90?m=1:i<135?m=2:i<180?m=3:i<225?m=4:i<270?m=5:i<315&&(m=6)}}if(m>0&&(g=g.slice(-m).concat(g.slice(0,-m))),ft(o,c.translate,c.radian||0,(()=>{for(let e=0;e<d.length;e++){const i=d[e];if(!0!==i.invisible&&(o.beginPath(),o.arc(i.x,i.y,c.controllerSize,0,2*Math.PI),o.closePath(),o.isPointInPath(t.x,t.y)&&(a=u[e],h=g[e]),a)){l=e;break}}})),null===a){const e=c.controllers.rotate;!0!==e.invisible&&ft(o,c.translate,c.radian||0,(()=>{o.beginPath(),o.arc(e.x,e.y,c.controllerSize,0,2*Math.PI),o.closePath(),o.isPointInPath(t.x,t.y)&&(a="rotate",h="rotate")}))}return{uuid:r,selectedControllerDirection:a,hoverControllerDirection:h,directIndex:l}}isPointInElementList(t,e){var i,n,s;const o=this._ctx;let r=-1,l=null;const a=(null==(i=this._helperConfig)?void 0:i.selectedElementListWrappers)||[];for(let i=0;i<a.length;i++){const h=a[i],c=this._helperConfig.elementIndexMap[h.uuid],d=e.elements[c];if(!d)continue;if(!0===(null==(n=d.operation)?void 0:n.invisible))continue;let u=0;if((null==(s=d.desc)?void 0:s.borderWidth)>0&&(u=d.desc.borderWidth),_t(o,d,(()=>{o.beginPath(),o.moveTo(d.x-u,d.y-u),o.lineTo(d.x+d.w+u,d.y-u),o.lineTo(d.x+d.w+u,d.y+d.h+u),o.lineTo(d.x-u,d.y+d.h+u),o.lineTo(d.x-u,d.y-u),o.closePath(),o.isPointInPath(t.x,t.y)&&(r=i,l=d.uuid)})),r>=0)break}return!!(l&&r>=0)}startSelectArea(t){this._areaStart=t,this._areaEnd=t}changeSelectArea(t){this._areaEnd=t,this._calcSelectedArea()}clearSelectedArea(){this._areaStart={x:0,y:0},this._areaEnd={x:0,y:0},this._calcSelectedArea()}calcSelectedElements(t){const e=this._ctx.getTransform(),{scale:i=1,scrollX:n=0,scrollY:s=0}=e,o=this._areaStart,r=this._areaEnd,l=(Math.min(o.x,r.x)-n)/i,a=(Math.min(o.y,r.y)-s)/i,h=Math.abs(r.x-o.x)/i,c=Math.abs(r.y-o.y)/i,d=[],u=this._ctx;return u.beginPath(),u.moveTo(l,a),u.lineTo(l+h,a),u.lineTo(l+h,a+c),u.lineTo(l,a+c),u.lineTo(l,a),u.closePath(),t.elements.forEach((t=>{var e;if(!0!==(null==(e=null==t?void 0:t.operation)?void 0:e.invisible)){const e=t.x+t.w/2,i=t.y+t.h/2;u.isPointInPathWithoutScroll(e,i)&&d.push(t.uuid)}})),d}_calcSelectedArea(){const t=this._areaStart,e=this._areaEnd,i=this._ctx.getTransform(),{scale:n=1,scrollX:s=0,scrollY:o=0}=i,r=this._coreConfig.elementWrapper,l=r.lineWidth/n,a=r.lineDash.map((t=>t/n));this._helperConfig.selectedAreaWrapper={x:(Math.min(t.x,e.x)-s)/n,y:(Math.min(t.y,e.y)-o)/n,w:Math.abs(e.x-t.x)/n,h:Math.abs(e.y-t.y)/n,startPoint:{x:t.x,y:t.y},endPoint:{x:e.x,y:e.y},lineWidth:l,lineDash:a,color:r.color}}_updateElementIndex(t){this._helperConfig.elementIndexMap={},t.elements.forEach(((t,e)=>{this._helperConfig.elementIndexMap[t.uuid]=e}))}_updateSelectedElementWrapper(t,e){var i;const{selectedUUID:n}=e;if(!("string"==typeof n&&this._helperConfig.elementIndexMap[n]>=0))return void delete this._helperConfig.selectedElementWrapper;const s=this._helperConfig.elementIndexMap[n],o=t.elements[s];if(!0===(null==(i=null==o?void 0:o.operation)?void 0:i.invisible))return;const r=this._createSelectedElementWrapper(o,e);this._helperConfig.selectedElementWrapper=r}_updateSelectedElementListWrapper(t,e){const{selectedUUIDList:i}=e,n=[];t.elements.forEach((t=>{if(null==i?void 0:i.includes(t.uuid)){const i=this._createSelectedElementWrapper(t,e);n.push(i)}})),this._helperConfig.selectedElementListWrappers=n}_createSelectedElementWrapper(t,e){var i,n,s,o,r,l,a,h,c,d,u,g;const{scale:m}=e,_=this._coreConfig.elementWrapper,f=_.controllerSize/m,p=_.lineWidth/m,v=_.lineDash.map((t=>t/m)),x=(null==(i=t.desc)?void 0:i.borderWidth)||0;let S=!1;"number"==typeof t.angle&&Math.abs(t.angle)>15&&(S=!0);const y=p,w={uuid:t.uuid,controllerSize:f,controllerOffset:y,lock:!0===(null==(n=null==t?void 0:t.operation)?void 0:n.lock),controllers:{topLeft:{x:t.x-y-x,y:t.y-y-x,invisible:S||!0===(null==(s=null==t?void 0:t.operation)?void 0:s.disableScale)},top:{x:t.x+t.w/2,y:t.y-y-x,invisible:!0===(null==(o=null==t?void 0:t.operation)?void 0:o.disableScale)},topRight:{x:t.x+t.w+y+x,y:t.y-y-x,invisible:S||!0===(null==(r=null==t?void 0:t.operation)?void 0:r.disableScale)},right:{x:t.x+t.w+y+x,y:t.y+t.h/2,invisible:!0===(null==(l=null==t?void 0:t.operation)?void 0:l.disableScale)},bottomRight:{x:t.x+t.w+y+x,y:t.y+t.h+y+x,invisible:S||!0===(null==(a=null==t?void 0:t.operation)?void 0:a.disableScale)},bottom:{x:t.x+t.w/2,y:t.y+t.h+y+x,invisible:!0===(null==(h=null==t?void 0:t.operation)?void 0:h.disableScale)},bottomLeft:{x:t.x-y-x,y:t.y+t.h+y+x,invisible:S||!0===(null==(c=null==t?void 0:t.operation)?void 0:c.disableScale)},left:{x:t.x-y-x,y:t.y+t.h/2,invisible:!0===(null==(d=null==t?void 0:t.operation)?void 0:d.disableScale)},rotate:{x:t.x+t.w/2,y:t.y-f-(2*f+12)-x,invisible:!0===(null==(u=null==t?void 0:t.operation)?void 0:u.disableRotate)}},lineWidth:p,lineDash:v,color:!0===(null==(g=null==t?void 0:t.operation)?void 0:g.lock)?_.lockColor:_.color};return"number"==typeof t.angle&&(t.angle>0||t.angle<0)&&(w.radian=ot(t.angle),w.translate=rt(t)),w}}const Pt=Symbol("_displayCtx"),Dt=Symbol("_helper"),Lt=Symbol("_element"),Mt=Symbol("_opts");class It{constructor(t){this[Mt]=t,this[Pt]=this[Mt].board,this[Lt]=this[Mt].element,this[Dt]=this[Mt].helper}isEffectivePoint(t){const e=this[Pt].getScrollLineWidth(),i=this[Pt].getScreenInfo();return t.x<=i.width-e&&t.y<=i.height-e}judgePointCursor(t,e){let i="auto",n=null;if(!this.isEffectivePoint(t))return{cursor:i,elementUUID:n};const{uuid:s,hoverControllerDirection:o}=this[Dt].isPointInElementWrapperController(t,e);if(s&&o){switch(o){case"top-right":i="ne-resize";break;case"top-left":i="nw-resize";break;case"top":i="n-resize";break;case"right":i="e-resize";break;case"bottom-right":i="se-resize";break;case"bottom":i="s-resize";break;case"bottom-left":i="sw-resize";break;case"left":i="w-resize";break;case"rotate":i="grab"}s&&(n=s)}else{const[s,o]=this[Lt].isPointInElement(t,e);s>=0&&(i="move"),o&&(n=o)}return{cursor:i,elementUUID:n}}}function zt(t){const e={elements:[]};return Array.isArray(null==t?void 0:t.elements)&&(null==t||t.elements.forEach(((t={})=>{(function(t){if(!(Tt(t.x)&&Tt(t.y)&&Tt(t.w)&&Tt(t.h)))return!1;if("string"!=typeof t.type||!xt.includes(t.type))return!1;return!0})(t)&&e.elements.push(t)}))),"string"==typeof t.bgColor&&(e.bgColor=t.bgColor),e}function Tt(t){return t>=0||t<0}var kt=(t=>(t.NULL="null",t.SELECT_ELEMENT="select-element",t.SELECT_ELEMENT_LIST="select-element-list",t.SELECT_ELEMENT_WRAPPER_CONTROLLER="select-element-wrapper-controller",t.SELECT_AREA="select-area",t))(kt||{}),Ut=(t=>(t.DRAGGING="dragging",t.NULL="null",t))(Ut||{});function Wt(){return{hasInited:!1,mode:kt.NULL,cursorStatus:Ut.NULL,selectedUUID:null,selectedUUIDList:[],hoverUUID:null,selectedControllerDirection:null,hoverControllerDirection:null,prevPoint:null,hasChangedElement:!1}}class Rt{constructor(){this._temp=Wt()}set(t,e){this._temp[t]=e}get(t){return this._temp[t]}clear(){this._temp=Wt()}}class Ot{constructor(t){this._plugins=[];const{board:e,config:i,element:n}=t,s=new Ct(e,i);this._opts=t,this.temp=new Rt,this.helper=s,this._mapper=new It({board:e,helper:s,element:n})}addPlugin(t){this._plugins.push(t)}getHelperConfig(){return this.helper.getConfig()}updateHelperConfig(t){var e;const{board:i,getDataFeekback:n,config:s}=this._opts,o=n(),r=i.getTransform();this.helper.updateConfig(o,{width:t.width,height:t.height,devicePixelRatio:t.devicePixelRatio,canScroll:!0===(null==(e=null==s?void 0:s.scrollWrapper)?void 0:e.use),selectedUUID:this.temp.get("selectedUUID"),selectedUUIDList:this.temp.get("selectedUUIDList"),scale:r.scale,scrollX:r.scrollX,scrollY:r.scrollY})}init(){this._initEvent()}_initEvent(){if(!0===this.temp.get("hasInited"))return;const{board:e}=this._opts;e.on("hover",t(this._handleHover.bind(this),32)),e.on("leave",t(this._handleLeave.bind(this),32)),e.on("point",t(this._handleClick.bind(this),16)),e.on("doubleClick",this._handleDoubleClick.bind(this)),e.on("point",this._handlePoint.bind(this)),e.on("moveStart",this._handleMoveStart.bind(this)),e.on("move",t(this._handleMove.bind(this),16)),e.on("moveEnd",this._handleMoveEnd.bind(this))}_handleDoubleClick(t){var e,i,s;const{element:o,getDataFeekback:r,drawFeekback:l,coreEvent:a}=this._opts,h=r(),[c,d]=o.isPointInElement(t,h);if(c>=0&&d){const t=n(null==(e=h.elements)?void 0:e[c]);!0!==(null==(i=null==t?void 0:t.operation)?void 0:i.invisible)&&a.trigger("screenDoubleClickElement",{index:c,uuid:d,element:n(null==(s=h.elements)?void 0:s[c])})}l()}_handlePoint(t){var e,i,s;if(!this._mapper.isEffectivePoint(t))return;const{element:o,getDataFeekback:r,selectElementByIndex:l,coreEvent:a,emitChangeScreen:h,drawFeekback:c}=this._opts,d=this.helper,u=r();if(d.isPointInElementList(t,u))this.temp.set("mode",kt.SELECT_ELEMENT_LIST);else{const{uuid:r,selectedControllerDirection:c}=d.isPointInElementWrapperController(t,u);if(r&&c)this.temp.set("mode",kt.SELECT_ELEMENT_WRAPPER_CONTROLLER),this.temp.set("selectedControllerDirection",c),this.temp.set("selectedUUID",r);else{const[r,c]=o.isPointInElement(t,u);r>=0&&!0!==(null==(i=null==(e=u.elements[r])?void 0:e.operation)?void 0:i.invisible)?(l(r,{useMode:!0}),"string"==typeof c&&a.has("screenSelectElement")&&(a.trigger("screenSelectElement",{index:r,uuid:c,element:n(null==(s=u.elements)?void 0:s[r])}),h()),this.temp.set("mode",kt.SELECT_ELEMENT)):(this.temp.set("selectedUUIDList",[]),this.temp.set("selectedUUID",null),this.temp.set("mode",kt.SELECT_AREA))}}c()}_handleClick(t){var e;const{element:i,getDataFeekback:s,coreEvent:o,drawFeekback:r}=this._opts,l=s(),[a,h]=i.isPointInElement(t,l);a>=0&&h&&o.trigger("screenClickElement",{index:a,uuid:h,element:n(null==(e=l.elements)?void 0:e[a])}),r()}_handleMoveStart(t){const{element:e,getDataFeekback:i,coreEvent:n}=this._opts,s=i(),o=this.helper;this.temp.set("prevPoint",t);const r=this.temp.get("selectedUUID");this.temp.get("mode")===kt.SELECT_ELEMENT_LIST||(this.temp.get("mode")===kt.SELECT_ELEMENT?"string"==typeof r&&n.has("screenMoveElementStart")&&n.trigger("screenMoveElementStart",{index:e.getElementIndex(s,r),uuid:r,x:t.x,y:t.y}):this.temp.get("mode")===kt.SELECT_AREA&&o.startSelectArea(t))}_handleMove(t){const{drawFeekback:e}=this._opts,i=this.helper;this.temp.get("mode")===kt.SELECT_ELEMENT_LIST?(this.temp.set("hasChangedElement",!0),this._dragElements(this.temp.get("selectedUUIDList"),t,this.temp.get("prevPoint")),e(),this.temp.set("cursorStatus",Ut.DRAGGING)):"string"==typeof this.temp.get("selectedUUID")?this.temp.get("mode")===kt.SELECT_ELEMENT?(this.temp.set("hasChangedElement",!0),this._dragElements([this.temp.get("selectedUUID")],t,this.temp.get("prevPoint")),e(),this.temp.set("cursorStatus",Ut.DRAGGING)):this.temp.get("mode")===kt.SELECT_ELEMENT_WRAPPER_CONTROLLER&&this.temp.get("selectedControllerDirection")&&(this._transfromElement(this.temp.get("selectedUUID"),t,this.temp.get("prevPoint"),this.temp.get("selectedControllerDirection")),this.temp.set("cursorStatus",Ut.DRAGGING)):this.temp.get("mode")===kt.SELECT_AREA&&(i.changeSelectArea(t),e()),this.temp.set("prevPoint",t)}_dragElements(t,e,i){if(!i)return;const{board:n,element:s,getDataFeekback:o,drawFeekback:r}=this._opts,l=o(),a=this.helper;t.forEach((t=>{var o,r;const h=a.getElementIndexByUUID(t);if(null===h)return;const c=l.elements[h];!0!==(null==(o=null==c?void 0:c.operation)?void 0:o.lock)&&!0!==(null==(r=null==c?void 0:c.operation)?void 0:r.invisible)&&s.dragElement(l,t,e,i,n.getContext().getTransform().scale)})),r()}_transfromElement(t,e,i,n){if(!i)return null;const{board:s,element:o,getDataFeekback:r,drawFeekback:l}=this._opts,a=r(),h=o.transformElement(a,t,e,i,s.getContext().getTransform().scale,n);return l(),h}_handleMoveEnd(t){const{element:e,getDataFeekback:i,coreEvent:n,drawFeekback:s,emitChangeData:o}=this._opts,r=i(),l=this.helper,a=this.temp.get("selectedUUID");if("string"==typeof a){const i=e.getElementIndex(r,a),s=r.elements[i];s&&(n.has("screenMoveElementEnd")&&n.trigger("screenMoveElementEnd",{index:i,uuid:a,x:t.x,y:t.y}),n.has("screenChangeElement")&&n.trigger("screenChangeElement",{index:i,uuid:a,width:s.w,height:s.h,angle:s.angle||0}))}else if(this.temp.get("mode")===kt.SELECT_AREA){const t=l.calcSelectedElements(r);t.length>0?(this.temp.set("selectedUUIDList",t),this.temp.set("selectedUUID",null)):this.temp.set("mode",kt.NULL),l.clearSelectedArea(),s()}this.temp.get("mode")!==kt.SELECT_ELEMENT&&this.temp.set("selectedUUID",null),this.temp.set("cursorStatus",Ut.NULL),this.temp.set("mode",kt.NULL),!0===this.temp.get("hasChangedElement")&&(o(),this.temp.set("hasChangedElement",!1))}_handleHover(t){var e,i;let n=!1;const{board:s,getDataFeekback:o,coreEvent:r}=this._opts,l=o(),a=this.helper,h=this._mapper;if(this.temp.get("mode")===kt.SELECT_AREA)s.resetCursor();else if(this.temp.get("cursorStatus")===Ut.NULL){const{cursor:o,elementUUID:c}=h.judgePointCursor(t,l);if(s.setCursor(o),c){const t=a.getElementIndexByUUID(c);if(null!==t&&t>=0){const o=l.elements[t];if(!0===(null==(e=null==o?void 0:o.operation)?void 0:e.lock)||!0===(null==(i=null==o?void 0:o.operation)?void 0:i.invisible))return void s.resetCursor();if(this.temp.get("hoverUUID")!==o.uuid){const t=a.getElementIndexByUUID(this.temp.get("hoverUUID")||"");null!==t&&l.elements[t]&&r.trigger("mouseLeaveElement",{uuid:this.temp.get("hoverUUID"),index:t,element:l.elements[t]})}o&&(r.trigger("mouseOverElement",{uuid:o.uuid,index:t,element:o}),this.temp.set("hoverUUID",o.uuid),n=!0)}}}if(!0!==n&&null!==this.temp.get("hoverUUID")){const t=this.temp.get("hoverUUID"),e=a.getElementIndexByUUID(t||"");null!==e&&r.trigger("mouseLeaveElement",{uuid:t,index:e,element:l.elements[e]}),this.temp.set("hoverUUID",null)}r.has("mouseOverScreen")&&r.trigger("mouseOverScreen",t)}_handleLeave(){const{coreEvent:t}=this._opts;t.has("mouseLeaveScreen")&&t.trigger("mouseLeaveScreen",void 0)}}function At(t){t.setFillStyle("#000000"),t.setStrokeStyle("#000000"),t.setLineDash([]),t.setGlobalAlpha(1),t.setShadowColor("#00000000"),t.setShadowOffsetX(0),t.setShadowOffsetY(0),t.setShadowBlur(0)}class Ft{constructor(t,e,i){var s,o,r;this._coreEvent=new ht,this._tempData=new class{constructor(){this._temp={hasInited:!1}}set(t,e){this._temp[t]=e}get(t){return this._temp[t]}clear(){this._temp={hasInited:!1}}},this.$data={elements:[]},this._opts=e,this._config=function(t){const e=n(at);return t&&t.elementWrapper&&(e.elementWrapper={...e.elementWrapper,...t.elementWrapper}),e}(i||{}),this._board=new z(t,{...this._opts,canScroll:null==(s=null==i?void 0:i.scrollWrapper)?void 0:s.use,scrollConfig:{color:(null==(o=null==i?void 0:i.scrollWrapper)?void 0:o.color)||"#000000",width:(null==(r=null==i?void 0:i.scrollWrapper)?void 0:r.width)||12,...(null==i?void 0:i.scrollWrapper)||{}}}),this._renderer=new Z;const l=()=>{const t=this._board.getHelperContext(),e=this._engine.getHelperConfig();this._board.clear();const{contextWidth:i,contextHeight:n,devicePixelRatio:s}=this._opts;t.clearRect(0,0,i*s,n*s),function(t,e){if(!(null==e?void 0:e.selectedElementWrapper))return;const i=e.selectedElementWrapper;At(t),ft(t,i.translate,i.radian||0,(()=>{t.beginPath(),t.setLineDash(i.lineDash),t.setLineWidth(i.lineWidth),t.setStrokeStyle(i.color),t.moveTo(i.controllers.topLeft.x,i.controllers.topLeft.y),t.lineTo(i.controllers.topRight.x,i.controllers.topRight.y),t.lineTo(i.controllers.bottomRight.x,i.controllers.bottomRight.y),t.lineTo(i.controllers.bottomLeft.x,i.controllers.bottomLeft.y),t.lineTo(i.controllers.topLeft.x,i.controllers.topLeft.y-i.lineWidth/2),t.stroke(),t.closePath(),!0!==i.lock?(!0!==i.controllers.rotate.invisible&&(t.beginPath(),t.moveTo(i.controllers.top.x,i.controllers.top.y),t.lineTo(i.controllers.rotate.x,i.controllers.rotate.y+i.controllerSize),t.stroke(),t.closePath(),t.beginPath(),t.setLineDash([]),t.setLineWidth(i.controllerSize/1.2),t.arc(i.controllers.rotate.x,i.controllers.rotate.y,.8*i.controllerSize,0,2*Math.PI),t.stroke(),t.closePath(),t.setStrokeStyle("#FFFFFF"),t.beginPath(),t.setLineDash([]),t.setLineWidth(i.controllerSize/2.1),t.arc(i.controllers.rotate.x,i.controllers.rotate.y,.8*i.controllerSize,0,2*Math.PI),t.stroke(),t.closePath()),[i.controllers.topLeft,i.controllers.top,i.controllers.topRight,i.controllers.right,i.controllers.bottomRight,i.controllers.bottom,i.controllers.bottomLeft,i.controllers.left].forEach((e=>{!0!==e.invisible&&(t.setFillStyle(i.color),t.beginPath(),t.arc(e.x,e.y,i.controllerSize,0,2*Math.PI),t.fill(),t.closePath(),t.setFillStyle("#FFFFFF"),t.beginPath(),t.arc(e.x,e.y,i.controllerSize-1,0,2*Math.PI),t.fill(),t.closePath())}))):(At(t),t.setStrokeStyle(i.color),[i.controllers.topLeft,i.controllers.top,i.controllers.topRight,i.controllers.right,i.controllers.bottomRight,i.controllers.bottom,i.controllers.bottomLeft,i.controllers.left].forEach((e=>{t.beginPath(),t.moveTo(e.x-i.controllerSize/2,e.y-i.controllerSize/2),t.lineTo(e.x+i.controllerSize/2,e.y+i.controllerSize/2),t.stroke(),t.closePath(),t.beginPath(),t.moveTo(e.x+i.controllerSize/2,e.y-i.controllerSize/2),t.lineTo(e.x-i.controllerSize/2,e.y+i.controllerSize/2),t.stroke(),t.closePath()})))}))}(t,e),function(t,e){if(!(null==e?void 0:e.selectedAreaWrapper))return;const i=e.selectedAreaWrapper;i&&i.w>0&&i.h>0&&(At(t),t.setGlobalAlpha(.3),t.setFillStyle(i.color),t.fillRect(i.x,i.y,i.w,i.h),At(t),t.beginPath(),t.setLineDash(i.lineDash),t.setLineWidth(i.lineWidth),t.setStrokeStyle(i.color),t.moveTo(i.x,i.y),t.lineTo(i.x+i.w,i.y),t.lineTo(i.x+i.w,i.y+i.h),t.lineTo(i.x,i.y+i.h),t.lineTo(i.x,i.y),t.stroke(),t.closePath())}(t,e),function(t,e){if(!Array.isArray(null==e?void 0:e.selectedElementListWrappers))return;const i=e.selectedElementListWrappers;null==i||i.forEach((e=>{At(t),ft(t,e.translate,e.radian||0,(()=>{At(t),t.setGlobalAlpha(.05),t.setFillStyle(e.color),t.fillRect(e.controllers.topLeft.x,e.controllers.topLeft.y,e.controllers.bottomRight.x-e.controllers.topLeft.x,e.controllers.bottomRight.y-e.controllers.topLeft.y),At(t),t.beginPath(),t.setLineDash(e.lineDash),t.setLineWidth(e.lineWidth),t.setStrokeStyle(e.color),t.moveTo(e.controllers.topLeft.x,e.controllers.topLeft.y),t.lineTo(e.controllers.topRight.x,e.controllers.topRight.y),t.lineTo(e.controllers.bottomRight.x,e.controllers.bottomRight.y),t.lineTo(e.controllers.bottomLeft.x,e.controllers.bottomLeft.y),t.lineTo(e.controllers.topLeft.x,e.controllers.topLeft.y-e.lineWidth/2),t.stroke(),t.closePath(),!0===e.lock&&(At(t),t.setStrokeStyle(e.color),[e.controllers.topLeft,e.controllers.top,e.controllers.topRight,e.controllers.right,e.controllers.bottomRight,e.controllers.bottom,e.controllers.bottomLeft,e.controllers.left].forEach((i=>{t.beginPath(),t.moveTo(i.x-e.controllerSize/2,i.y-e.controllerSize/2),t.lineTo(i.x+e.controllerSize/2,i.y+e.controllerSize/2),t.stroke(),t.closePath(),t.beginPath(),t.moveTo(i.x+e.controllerSize/2,i.y-e.controllerSize/2),t.lineTo(i.x-e.controllerSize/2,i.y+e.controllerSize/2),t.stroke(),t.closePath()})))}))}))}(t,e),this._board.draw()};this._renderer.on("drawFrame",(()=>{l()})),this._renderer.on("drawFrameComplete",(()=>{l()})),this._elementHandler=new yt(this._board.getContext()),this._engine=new Ot({coreEvent:this._coreEvent,board:this._board,element:this._elementHandler,config:this._config,drawFeekback:this.$draw.bind(this),getDataFeekback:()=>this.$data,selectElementByIndex:this.selectElementByIndex.bind(this),emitChangeScreen:this._emitChangeScreen.bind(this),emitChangeData:this.$emitChangeData.bind(this)}),this._engine.init(),this._renderer.on("drawFrame",(()=>{this._coreEvent.trigger("drawFrame",void 0)})),this._renderer.on("drawFrameComplete",(()=>{this._coreEvent.trigger("drawFrameComplete",void 0)})),this._tempData.set("hasInited",!0)}_emitChangeScreen(){this._coreEvent.has("changeScreen")&&this._coreEvent.trigger("changeScreen",{...this.getScreenTransform()})}$draw(t){this._engine.updateHelperConfig({width:this._opts.width,height:this._opts.height,devicePixelRatio:this._opts.devicePixelRatio}),this._renderer.thaw(),this._renderer.render(this._board.getContext(),this.$data,{changeResourceUUIDs:(null==t?void 0:t.resourceChangeUUIDs)||[]})}getElement(t){return function(t,e){let i=null;const s=t.getEngine().helper.getElementIndexByUUID(e);return null!==s&&t.$data.elements[s]&&(i=n(t.$data.elements[s])),i}(this,t)}getElementByIndex(t){return function(t,e){let i=null;return e>=0&&t.$data.elements[e]&&(i=n(t.$data.elements[e])),i}(this,t)}selectElementByIndex(t){return function(t,e){if(t.$data.elements[e]){const i=t.$data.elements[e].uuid;t.getEngine().temp.set("mode",kt.NULL),"string"==typeof i&&(t.getEngine().temp.set("selectedUUID",i),t.getEngine().temp.set("selectedUUIDList",[])),t.$draw()}}(this,t)}selectElement(t){return function(t,e){const i=t.getEngine().helper.getElementIndexByUUID(e);"number"==typeof i&&i>=0&&t.selectElementByIndex(i)}(this,t)}cancelElementByIndex(t){return function(t,e){if(t.$data.elements[e]){const i=t.$data.elements[e].uuid,n=t.getEngine().temp.get("selectedUUID");"string"==typeof i&&i===n&&(t.getEngine().temp.set("mode",kt.NULL),t.getEngine().temp.set("selectedUUID",null),t.getEngine().temp.set("selectedUUIDList",[])),t.$draw()}}(this,t)}cancelElement(t){return function(t,e){const i=t.getEngine().helper.getElementIndexByUUID(e);"number"==typeof i&&i>=0&&t.cancelElementByIndex(i)}(this,t)}moveUpElement(t){return function(t,e){const i=t.getEngine().helper.getElementIndexByUUID(e);if("number"==typeof i&&i>=0&&i<t.$data.elements.length-1){const e=t.$data.elements[i];t.$data.elements[i]=t.$data.elements[i+1],t.$data.elements[i+1]=e}t.$emitChangeData(),t.$draw()}(this,t)}moveDownElement(t){return function(t,e){const i=t.getEngine().helper.getElementIndexByUUID(e);if("number"==typeof i&&i>0&&i<t.$data.elements.length){const e=t.$data.elements[i];t.$data.elements[i]=t.$data.elements[i-1],t.$data.elements[i-1]=e}t.$emitChangeData(),t.$draw()}(this,t)}updateElement(t){return function(t,e){var i;const s=n(e),o=t.getData(),r=[];for(let e=0;e<o.elements.length;e++)if(s.uuid===(null==(i=o.elements[e])?void 0:i.uuid)){const i=gt(o.elements[e],s);"string"==typeof i&&r.push(i),o.elements[e]=s,t.setData(o);break}t.$emitChangeData(),t.$draw({resourceChangeUUIDs:r})}(this,t)}addElement(t){return function(t,e){const s=n(e);return s.uuid=i(),t.$data.elements.push(s),t.$emitChangeData(),t.$draw(),s.uuid}(this,t)}deleteElement(t){return function(t,e){const i=t.$getElementHandler().getElementIndex(t.getData(),e);i>=0&&(t.$data.elements.splice(i,1),t.$emitChangeData(),t.$draw())}(this,t)}insertElementBefore(t,e){return function(t,e,i){const n=t.getEngine().helper.getElementIndexByUUID(i);return null!==n?t.insertElementBeforeIndex(e,n):null}(this,t,e)}insertElementBeforeIndex(t,e){return function(t,e,s){const o=n(e);return o.uuid=i(),s>=0?(t.$data.elements.splice(s,0,o),t.$emitChangeData(),t.$draw(),o.uuid):null}(this,t,e)}getSelectedElements(){return function(t){const e=[];let i=[];const s=t.getEngine().temp.get("selectedUUID");return"string"==typeof s&&s?i.push(s):i=t.getEngine().temp.get("selectedUUIDList"),i.forEach((i=>{const n=t.getEngine().helper.getElementIndexByUUID(i);if(null!==n&&n>=0){const i=t.$data.elements[n];i&&e.push(i)}})),n(e)}(this)}insertElementAfter(t,e){return function(t,e,i){const n=t.getEngine().helper.getElementIndexByUUID(i);return null!==n?t.insertElementAfterIndex(e,n):null}(this,t,e)}insertElementAfterIndex(t,e){return function(t,e,s){const o=n(e);return o.uuid=i(),s>=0?(t.$data.elements.splice(s+1,0,o),t.$emitChangeData(),t.$draw(),o.uuid):null}(this,t,e)}resetSize(t){this._opts={...this._opts,...t},this._board.resetSize(t),this.$draw()}scale(t){const e=this._board.scale(t);return this.$draw(),this._emitChangeScreen(),e}scrollLeft(t){const e=this._board.scrollX(0-t);return this.$draw(),this._emitChangeScreen(),e}scrollTop(t){const e=this._board.scrollY(0-t);return this.$draw(),this._emitChangeScreen(),e}getScreenTransform(){const t=this._board.getTransform();return{scale:t.scale,scrollTop:Math.max(0,0-t.scrollY),scrollLeft:Math.max(0,0-t.scrollX)}}getData(){return n(this.$data)}setData(t,e){const i=function(t,e){var i;const n=[],s=mt(t),o=mt(e);for(const t in o)if(!0===["image","svg","html"].includes(null==(i=o[t])?void 0:i.type))if(s[t]){let e=!1;switch(s[t].type){case"image":e=ct(s[t],o[t]);break;case"svg":e=dt(s[t],o[t]);break;case"html":e=ut(s[t],o[t])}!0===e&&n.push(t)}else n.push(t);return n}(this.$data,t);this.$data=this._elementHandler.initData(n(zt(t))),e&&!0===e.triggerChangeEvent&&this.$emitChangeData(),this.$draw({resourceChangeUUIDs:i})}clearOperation(){this._tempData.clear(),this.$draw()}on(t,e){this._coreEvent.on(t,e)}off(t,e){this._coreEvent.off(t,e)}getEngine(){return this._engine}pointScreenToContext(t){return this._board.pointScreenToContext(t)}pointContextToScreen(t){return this._board.pointContextToScreen(t)}$getBoardContext(){return this._board.getContext()}$getDisplayContext2D(){return this._board.getDisplayContext2D()}$getOriginContext2D(){return this._board.getOriginContext2D()}$emitChangeData(){this._coreEvent.has("changeData")&&this._coreEvent.trigger("changeData",n(this.$data))}$getElementHandler(){return this._elementHandler}}return Ft.is=it,Ft.check=st,Ft}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idraw/core",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/esm/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"author": "chenshenhai",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@idraw/types": "^0.3.
|
|
24
|
+
"@idraw/types": "^0.3.1"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@idraw/board": "^0.3.
|
|
28
|
-
"@idraw/renderer": "^0.3.
|
|
29
|
-
"@idraw/util": "^0.3.
|
|
27
|
+
"@idraw/board": "^0.3.1",
|
|
28
|
+
"@idraw/renderer": "^0.3.1",
|
|
29
|
+
"@idraw/util": "^0.3.1"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "7c831450d14f34e2eb0d937bccdd4896b2c4b4b8"
|
|
35
35
|
}
|