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