@idraw/core 0.3.1 → 0.4.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.d.ts +19 -55
- package/dist/esm/index.js +52 -188
- package/dist/esm/lib/cursor-image.d.ts +2 -0
- package/dist/esm/lib/cursor-image.js +2 -0
- package/dist/esm/lib/cursor.d.ts +16 -0
- package/dist/esm/lib/cursor.js +121 -0
- package/dist/esm/middleware/scaler/index.d.ts +2 -0
- package/dist/esm/middleware/scaler/index.js +22 -0
- package/dist/esm/middleware/scroller/config.d.ts +6 -0
- package/dist/esm/middleware/scroller/config.js +6 -0
- package/dist/esm/middleware/scroller/index.d.ts +2 -0
- package/dist/esm/middleware/scroller/index.js +97 -0
- package/dist/esm/middleware/scroller/util.d.ts +12 -0
- package/dist/esm/middleware/scroller/util.js +192 -0
- package/dist/esm/middleware/selector/config.d.ts +20 -0
- package/dist/esm/middleware/selector/config.js +20 -0
- package/dist/esm/middleware/selector/draw-wrapper.d.ts +22 -0
- package/dist/esm/middleware/selector/draw-wrapper.js +111 -0
- package/dist/esm/middleware/selector/index.d.ts +3 -0
- package/dist/esm/middleware/selector/index.js +454 -0
- package/dist/esm/middleware/selector/types.d.ts +40 -0
- package/dist/esm/middleware/selector/types.js +1 -0
- package/dist/esm/middleware/selector/util.d.ts +53 -0
- package/dist/esm/middleware/selector/util.js +789 -0
- package/dist/index.global.js +3825 -3991
- package/dist/index.global.min.js +1 -1
- package/package.json +7 -7
- package/LICENSE +0 -21
- package/dist/esm/constant/element.d.ts +0 -2
- package/dist/esm/constant/element.js +0 -10
- package/dist/esm/constant/static.d.ts +0 -11
- package/dist/esm/constant/static.js +0 -13
- package/dist/esm/lib/calculate.d.ts +0 -5
- package/dist/esm/lib/calculate.js +0 -64
- package/dist/esm/lib/check.d.ts +0 -28
- package/dist/esm/lib/check.js +0 -115
- package/dist/esm/lib/config.d.ts +0 -3
- package/dist/esm/lib/config.js +0 -20
- package/dist/esm/lib/core-event.d.ts +0 -49
- package/dist/esm/lib/core-event.js +0 -50
- package/dist/esm/lib/diff.d.ts +0 -6
- package/dist/esm/lib/diff.js +0 -82
- package/dist/esm/lib/draw/base.d.ts +0 -5
- package/dist/esm/lib/draw/base.js +0 -90
- package/dist/esm/lib/draw/wrapper.d.ts +0 -4
- package/dist/esm/lib/draw/wrapper.js +0 -168
- package/dist/esm/lib/element.d.ts +0 -15
- package/dist/esm/lib/element.js +0 -442
- package/dist/esm/lib/engine-temp.d.ts +0 -22
- package/dist/esm/lib/engine-temp.js +0 -29
- package/dist/esm/lib/engine.d.ts +0 -47
- package/dist/esm/lib/engine.js +0 -323
- package/dist/esm/lib/helper.d.ts +0 -30
- package/dist/esm/lib/helper.js +0 -363
- package/dist/esm/lib/index.d.ts +0 -13
- package/dist/esm/lib/index.js +0 -13
- package/dist/esm/lib/is.d.ts +0 -26
- package/dist/esm/lib/is.js +0 -100
- package/dist/esm/lib/mapper.d.ts +0 -26
- package/dist/esm/lib/mapper.js +0 -89
- package/dist/esm/lib/parse.d.ts +0 -2
- package/dist/esm/lib/parse.js +0 -32
- package/dist/esm/lib/temp.d.ts +0 -11
- package/dist/esm/lib/temp.js +0 -19
- package/dist/esm/lib/transform.d.ts +0 -4
- package/dist/esm/lib/transform.js +0 -20
- package/dist/esm/lib/value.d.ts +0 -2
- package/dist/esm/lib/value.js +0 -7
- package/dist/esm/mixins/element.d.ts +0 -18
- package/dist/esm/mixins/element.js +0 -168
- package/dist/esm/plugins/helper.d.ts +0 -12
- package/dist/esm/plugins/helper.js +0 -16
- package/dist/esm/util/filter.d.ts +0 -1
- package/dist/esm/util/filter.js +0 -3
package/dist/index.global.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var iDrawCore=function(){"use strict";function t(t,e){let i=-1;return function(...n){i>0||(i=setTimeout((()=>{t(...n),i=-1}),e))}}function e(t){return"string"==typeof t&&/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(t)}function i(){function t(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${t()}${t()}-${t()}-${t()}-${t()}-${t()}${t()}${t()}`}function n(t){return function t(e){const i=(n=e,Object.prototype.toString.call(n).replace(/[\]|\[]{1,1}/gi,"").split(" ")[1]);var n;if(["Null","Number","String","Boolean","Undefined"].indexOf(i)>=0)return e;if("Array"===i){const i=[];return e.forEach((e=>{i.push(t(e))})),i}if("Object"===i){const i={};return Object.keys(e).forEach((n=>{i[n]=t(e[n])})),i}}(t)}function s(t){return(Object.prototype.toString.call(t)||"").replace(/(\[object|\])/gi,"").trim()}const o={type(t,e){const i=s(t);return!0===e?i.toLocaleLowerCase():i},array:t=>"Array"===s(t),json:t=>"Object"===s(t),function:t=>"Function"===s(t),asyncFunction:t=>"AsyncFunction"===s(t),string:t=>"String"===s(t),number:t=>"Number"===s(t),undefined:t=>"Undefined"===s(t),null:t=>"Null"===s(t),promise:t=>"Promise"===s(t)};var r=globalThis&&globalThis.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{a(n.next(t))}catch(t){o(t)}}function l(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,l)}a((n=n.apply(t,e||[])).next())}))};const{Image:l}=window;function a(t){return new Promise(((e,i)=>{const n=new l;n.crossOrigin="anonymous",n.onload=function(){e(n)},n.onabort=i,n.onerror=i,n.src=t}))}function h(t){return r(this,void 0,void 0,(function*(){const e=yield function(t){return new Promise(((e,i)=>{const n=new Blob([t],{type:"image/svg+xml;charset=utf-8"}),s=new FileReader;s.readAsDataURL(n),s.onload=function(t){var i;const n=null===(i=null==t?void 0:t.target)||void 0===i?void 0:i.result;e(n)},s.onerror=function(t){i(t)}}))}(t);return yield a(e)}))}function c(t,e){return r(this,void 0,void 0,(function*(){t=t.replace(/\&/gi,"&");const i=yield function(t,e){const{width:i,height:n}=e;return new Promise(((e,s)=>{const o=new Blob([`\n <svg xmlns="http://www.w3.org/2000/svg" width="${i||""}" height = "${n||""}">\n <foreignObject width="100%" height="100%">\n <div xmlns = "http://www.w3.org/1999/xhtml">\n ${t}\n </div>\n </foreignObject>\n </svg>\n `],{type:"image/svg+xml;charset=utf-8"}),r=new FileReader;r.readAsDataURL(o),r.onload=function(t){var i;const n=null===(i=null==t?void 0:t.target)||void 0===i?void 0:i.result;e(n)},r.onerror=function(t){s(t)}}))}(t,e);return yield a(i)}))}let d=class{constructor(t,e){this._opts=e,this._ctx=t,this._transform={scale:1,scrollX:0,scrollY:0}}getContext(){return this._ctx}resetSize(t){this._opts=Object.assign(Object.assign({},this._opts),t)}calcDeviceNum(t){return t*this._opts.devicePixelRatio}calcScreenNum(t){return t/this._opts.devicePixelRatio}getSize(){return{width:this._opts.width,height:this._opts.height,contextWidth:this._opts.contextWidth,contextHeight:this._opts.contextHeight,devicePixelRatio:this._opts.devicePixelRatio}}setTransform(t){this._transform=Object.assign(Object.assign({},this._transform),t)}getTransform(){return{scale:this._transform.scale,scrollX:this._transform.scrollX,scrollY:this._transform.scrollY}}setFillStyle(t){this._ctx.fillStyle=t}fill(t){return this._ctx.fill(t||"nonzero")}arc(t,e,i,n,s,o){return this._ctx.arc(this._doSize(t),this._doSize(e),this._doSize(i),n,s,o)}rect(t,e,i,n){return this._ctx.rect(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n))}fillRect(t,e,i,n){return this._ctx.fillRect(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n))}clearRect(t,e,i,n){return this._ctx.clearRect(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n))}beginPath(){return this._ctx.beginPath()}closePath(){return this._ctx.closePath()}lineTo(t,e){return this._ctx.lineTo(this._doSize(t),this._doSize(e))}moveTo(t,e){return this._ctx.moveTo(this._doSize(t),this._doSize(e))}arcTo(t,e,i,n,s){return this._ctx.arcTo(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n),this._doSize(s))}setLineWidth(t){return this._ctx.lineWidth=this._doSize(t)}setLineDash(t){return this._ctx.setLineDash(t.map((t=>this._doSize(t))))}isPointInPath(t,e){return this._ctx.isPointInPath(this._doX(t),this._doY(e))}isPointInPathWithoutScroll(t,e){return this._ctx.isPointInPath(this._doSize(t),this._doSize(e))}setStrokeStyle(t){this._ctx.strokeStyle=t}stroke(){return this._ctx.stroke()}translate(t,e){return this._ctx.translate(this._doSize(t),this._doSize(e))}rotate(t){return this._ctx.rotate(t)}drawImage(...t){const e=t[0],i=t[1],n=t[2],s=t[3],o=t[4],r=t[t.length-4],l=t[t.length-3],a=t[t.length-2],h=t[t.length-1];return 9===t.length?this._ctx.drawImage(e,this._doSize(i),this._doSize(n),this._doSize(s),this._doSize(o),this._doSize(r),this._doSize(l),this._doSize(a),this._doSize(h)):this._ctx.drawImage(e,this._doSize(r),this._doSize(l),this._doSize(a),this._doSize(h))}createPattern(t,e){return this._ctx.createPattern(t,e)}measureText(t){return this._ctx.measureText(t)}setTextAlign(t){this._ctx.textAlign=t}fillText(t,e,i,n){return void 0!==n?this._ctx.fillText(t,this._doSize(e),this._doSize(i),this._doSize(n)):this._ctx.fillText(t,this._doSize(e),this._doSize(i))}strokeText(t,e,i,n){return void 0!==n?this._ctx.strokeText(t,this._doSize(e),this._doSize(i),this._doSize(n)):this._ctx.strokeText(t,this._doSize(e),this._doSize(i))}setFont(t){const e=[];"bold"===t.fontWeight&&e.push(`${t.fontWeight}`),e.push(`${this._doSize(t.fontSize||12)}px`),e.push(`${t.fontFamily||"sans-serif"}`),this._ctx.font=`${e.join(" ")}`}setTextBaseline(t){this._ctx.textBaseline=t}setGlobalAlpha(t){this._ctx.globalAlpha=t}save(){this._ctx.save()}restore(){this._ctx.restore()}scale(t,e){this._ctx.scale(t,e)}setShadowColor(t){this._ctx.shadowColor=t}setShadowOffsetX(t){this._ctx.shadowOffsetX=this._doSize(t)}setShadowOffsetY(t){this._ctx.shadowOffsetY=this._doSize(t)}setShadowBlur(t){this._ctx.shadowBlur=this._doSize(t)}ellipse(t,e,i,n,s,o,r,l){this._ctx.ellipse(this._doSize(t),this._doSize(e),this._doSize(i),this._doSize(n),s,o,r,l)}_doSize(t){return this._opts.devicePixelRatio*t}_doX(t){const{scale:e,scrollX:i}=this._transform,n=(t-i)/e;return this._doSize(n)}_doY(t){const{scale:e,scrollY:i}=this._transform,n=(t-i)/e;return this._doSize(n)}};function u(t){return"number"==typeof t&&(t>0||t<=0)}function g(t){return"number"==typeof t&&t>=0}function m(t){return"string"==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${t}`)}function _(t){return"string"==typeof t&&/^(data:image\/)/.test(`${t}`)}const f={x:function(t){return u(t)},y:function(t){return u(t)},w:g,h:function(t){return"number"==typeof t&&t>=0},angle:function(t){return"number"==typeof t&&t>=-360&&t<=360},number:u,borderWidth:function(t){return g(t)},borderRadius:function(t){return u(t)&&t>=0},color:function(t){return e(t)},imageSrc:function(t){return _(t)||m(t)},imageURL:m,imageBase64:_,svg:function(t){return"string"==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test(`${t}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${t}`.trim())},html:function(t){let e=!1;if("string"==typeof t){let i=document.createElement("div");i.innerHTML=t,i.children.length>0&&(e=!0),i=null}return e},text:function(t){return"string"==typeof t},fontSize:function(t){return u(t)&&t>0},lineHeight:function(t){return u(t)&&t>0},textAlign:function(t){return["center","left","right"].includes(t)},fontFamily:function(t){return"string"==typeof t&&t.length>0},fontWeight:function(t){return["bold"].includes(t)},strokeWidth:function(t){return u(t)&&t>0}};function p(t={}){const{borderColor:e,borderRadius:i,borderWidth:n}=t;return!(t.hasOwnProperty("borderColor")&&!f.color(e))&&(!(t.hasOwnProperty("borderRadius")&&!f.number(i))&&!(t.hasOwnProperty("borderWidth")&&!f.number(n)))}const v={attrs:function(t){const{x:e,y:i,w:n,h:s,angle:o}=t;return!!(f.x(e)&&f.y(i)&&f.w(n)&&f.h(s)&&f.angle(o))&&(o>=-360&&o<=360)},textDesc:function(t){const{text:e,color:i,fontSize:n,lineHeight:s,fontFamily:o,textAlign:r,fontWeight:l,bgColor:a,strokeWidth:h,strokeColor:c}=t;return!!f.text(e)&&(!!f.color(i)&&(!!f.fontSize(n)&&(!(t.hasOwnProperty("bgColor")&&!f.color(a))&&(!(t.hasOwnProperty("fontWeight")&&!f.fontWeight(l))&&(!(t.hasOwnProperty("lineHeight")&&!f.lineHeight(s))&&(!(t.hasOwnProperty("fontFamily")&&!f.fontFamily(o))&&(!(t.hasOwnProperty("textAlign")&&!f.textAlign(r))&&(!(t.hasOwnProperty("strokeWidth")&&!f.strokeWidth(h))&&(!(t.hasOwnProperty("strokeColor")&&!f.color(c))&&!!p(t))))))))))},rectDesc:function(t){const{bgColor:e}=t;return!(t.hasOwnProperty("bgColor")&&!f.color(e))&&!!p(t)},circleDesc:function(t){const{bgColor:e,borderColor:i,borderWidth:n}=t;return!(t.hasOwnProperty("bgColor")&&!f.color(e))&&(!(t.hasOwnProperty("borderColor")&&!f.color(i))&&!(t.hasOwnProperty("borderWidth")&&!f.number(n)))},imageDesc:function(t){const{src:e}=t;return!!f.imageSrc(e)},svgDesc:function(t){const{svg:e}=t;return!!f.svg(e)},htmlDesc:function(t){const{html:e}=t;return!!f.html(e)}},x={is:f,check:v,delay:function(t){return new Promise((e=>{setTimeout((()=>{e()}),t)}))},compose:function(t){return function(e,i){return function n(s){let o=t[s];s===t.length&&i&&(o=i);if(!o)return Promise.resolve();try{return Promise.resolve(o(e,n.bind(null,s+1)))}catch(t){return Promise.reject(t)}}(0)}},throttle:t,loadImage:a,loadSVG:h,loadHTML:c,downloadImageFromCanvas:function(t,e){const{filename:i,type:n="image/jpeg"}=e,s=t.toDataURL(n),o=document.createElement("a");o.href=s,o.download=i;const r=document.createEvent("MouseEvents");r.initEvent("click",!0,!1),o.dispatchEvent(r)},toColorHexStr:function(t){return"#"+t.toString(16)},toColorHexNum:function(t){return parseInt(t.replace(/^\#/,"0x"))},isColorStr:e,createUUID:i,istype:o,deepClone:n,Context:d};class S{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);null==i||i.push(e),this._listeners.set(t,i||[])}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);if(Array.isArray(i))for(let t=0;t<(null==i?void 0:i.length);t++)if(i[t]===e){i.splice(t,1);break}this._listeners.set(t,i||[])}}trigger(t,e){const i=this._listeners.get(t);return!!Array.isArray(i)&&(i.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}}class y{constructor(t,e){this._isMoving=!1,this._temp=new class{constructor(){this._temp={prevClickPoint:null,isHoverCanvas:!1,isDragCanvas:!1,statusMap:{canScrollYPrev:!0,canScrollYNext:!0,canScrollXPrev:!0,canScrollXNext:!0}}}set(t,e){this._temp[t]=e}get(t){return this._temp[t]}clear(){this._temp={prevClickPoint:null,isHoverCanvas:!1,isDragCanvas:!1,statusMap:{canScrollYPrev:!0,canScrollYNext:!0,canScrollXPrev:!0,canScrollXNext:!0}}}},this._container=window,this._canvas=t,this._isMoving=!1,this._initEvent(),this._event=new S}setStatusMap(t){this._temp.set("statusMap",t)}on(t,e){this._event.on(t,e)}off(t,e){this._event.off(t,e)}_initEvent(){const t=this._canvas,e=this._container;e.addEventListener("mousemove",this._listenWindowMove.bind(this),!1),e.addEventListener("mouseup",this._listenWindowMoveEnd.bind(this),!1),t.addEventListener("mousemove",this._listenHover.bind(this),!1),t.addEventListener("mousedown",this._listenMoveStart.bind(this),!1),t.addEventListener("mousemove",this._listenMove.bind(this),!1),t.addEventListener("mouseup",this._listenMoveEnd.bind(this),!1),t.addEventListener("click",this._listenCanvasClick.bind(this),!1),t.addEventListener("wheel",this._listenCanvasWheel.bind(this),!1),t.addEventListener("mousedown",this._listenCanvasMoveStart.bind(this),!0),t.addEventListener("mouseup",this._listenCanvasMoveEnd.bind(this),!0),t.addEventListener("mouseover",this._listenCanvasMoveOver.bind(this),!0),t.addEventListener("mouseleave",this._listenCanvasMoveLeave.bind(this),!0),this._initParentEvent()}_initParentEvent(){try{let t=window;const e=t.origin;for(;t.self!==t.top&&(t.self!==t.parent&&t.origin===e&&t.parent.window.addEventListener("mousemove",this._listSameOriginParentWindow.bind(this),!1),t=t.parent,t););}catch(t){console.warn(t)}}_listenHover(t){t.preventDefault();const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.has("hover")&&this._event.trigger("hover",e),this._isMoving=!0}_listenMoveStart(t){t.preventDefault();const e=this._getPosition(t);this._isVaildPoint(e)&&(this._event.has("point")&&this._event.trigger("point",e),this._event.has("moveStart")&&this._event.trigger("moveStart",e)),this._isMoving=!0}_listenMove(t){if(t.preventDefault(),t.stopPropagation(),this._event.has("move")&&!0===this._isMoving){const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.trigger("move",e)}}_listenMoveEnd(t){if(t.preventDefault(),this._event.has("moveEnd")){const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.trigger("moveEnd",e)}this._isMoving=!1}_listSameOriginParentWindow(){this._temp.get("isHoverCanvas")&&this._event.has("leave")&&this._event.trigger("leave",void 0),this._temp.get("isDragCanvas")&&this._event.has("moveEnd")&&this._event.trigger("moveEnd",{x:NaN,y:NaN}),this._isMoving=!1,this._temp.set("isDragCanvas",!1),this._temp.set("isHoverCanvas",!1)}_listenCanvasMoveStart(){this._temp.get("isHoverCanvas")&&this._temp.set("isDragCanvas",!0)}_listenCanvasMoveEnd(){this._temp.set("isDragCanvas",!1)}_listenCanvasMoveOver(){this._temp.set("isHoverCanvas",!0)}_listenCanvasMoveLeave(){this._temp.set("isHoverCanvas",!1),this._event.has("leave")&&this._event.trigger("leave",void 0)}_listenWindowMove(t){if(!0===this._temp.get("isDragCanvas")&&(t.preventDefault(),t.stopPropagation(),this._event.has("move")&&!0===this._isMoving)){const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.trigger("move",e)}}_listenWindowMoveEnd(t){if(!0!=!this._temp.get("isDragCanvas")){if(t.preventDefault(),this._event.has("moveEnd")){const e=this._getPosition(t);this._isVaildPoint(e)&&this._event.trigger("moveEnd",e)}this._temp.set("isDragCanvas",!1),this._isMoving=!1}}_listenCanvasWheel(t){this._event.has("wheelX")&&(t.deltaX>0||t.deltaX<0)&&this._event.trigger("wheelX",t.deltaX),this._event.has("wheelY")&&(t.deltaY>0||t.deltaY<0)&&this._event.trigger("wheelY",t.deltaY);const{canScrollYNext:e,canScrollYPrev:i}=this._temp.get("statusMap");(t.deltaX>0&&t.deltaX<0||t.deltaY>0&&!0===e||t.deltaY<0&&!0===i)&&t.preventDefault()}_listenCanvasClick(t){t.preventDefault();const e=this._getPosition(t),i=Date.now();if(this._isVaildPoint(e)){const t=this._temp.get("prevClickPoint");t&&i-t.t<=500&&Math.abs(t.x-e.x)<=5&&Math.abs(t.y-e.y)<=5?this._event.has("doubleClick")&&this._event.trigger("doubleClick",{x:e.x,y:e.y}):this._temp.set("prevClickPoint",{x:e.x,y:e.y,t:i})}}_getPosition(t){const e=this._canvas;let i=0,n=0;if(t&&t.touches&&t.touches.length>0){const e=t.touches[0];e&&(i=e.clientX,n=e.clientY)}else i=t.clientX,n=t.clientY;return{x:i-e.getBoundingClientRect().left,y:n-e.getBoundingClientRect().top,t:Date.now()}}_isVaildPoint(t){return w(t.x)&&w(t.y)}}function w(t){return t>0||t<0||0===t}const b={width:12,color:"#000000",showBackground:!0};class E{constructor(t,e){this._displayCtx=t,this._opts=this._getOpts(e)}draw(t){const{width:e,height:i,scrollConfig:n}=this._opts,s=this.calc(t),o=this._displayCtx;s.xSize>0&&(!0===n.showBackground&&(o.globalAlpha=.12,o.fillStyle=s.color,o.fillRect(0,this._doSize(i-s.lineSize),this._doSize(e),this._doSize(s.lineSize))),C(o,{axis:"X",x:this._doSize(s.translateX),y:this._doSize(i-s.lineSize),w:this._doSize(s.xSize),h:this._doSize(s.lineSize),r:this._doSize(s.lineSize/2),color:s.color})),s.ySize>0&&(!0===n.showBackground&&(o.globalAlpha=.12,o.fillStyle=s.color,o.fillRect(this._doSize(e-s.lineSize),0,this._doSize(s.lineSize),this._doSize(i))),C(o,{axis:"Y",x:this._doSize(e-s.lineSize),y:this._doSize(s.translateY),w:this._doSize(s.lineSize),h:this._doSize(s.ySize),r:this._doSize(s.lineSize/2),color:s.color})),o.globalAlpha=1}resetSize(t){this._opts=Object.assign(Object.assign({},this._opts),t)}isPointAtScrollY(t){const{width:e,height:i,scrollConfig:n}=this._opts,s=this._displayCtx;return s.beginPath(),s.rect(this._doSize(e-n.width),0,this._doSize(n.width),this._doSize(i)),s.closePath(),!!s.isPointInPath(this._doSize(t.x),this._doSize(t.y))}isPointAtScrollX(t){const{width:e,height:i,scrollConfig:n}=this._opts,s=this._displayCtx;return s.beginPath(),s.rect(0,this._doSize(i-n.width),this._doSize(e-n.width),this._doSize(n.width)),s.closePath(),!!s.isPointInPath(this._doSize(t.x),this._doSize(t.y))}getLineWidth(){return this._opts.scrollConfig.width}calc(t){const{width:e,height:i,scrollConfig:n}=this._opts,s=2.5*n.width,o=n.width;let r=0,l=0;t.left<=0&&t.right<=0&&(r=Math.max(s,e-(Math.abs(t.left)+Math.abs(t.right))),r>=e&&(r=0)),(t.top<=0||t.bottom<=0)&&(l=Math.max(s,i-(Math.abs(t.top)+Math.abs(t.bottom))),l>=i&&(l=0));let a=0;r>0&&(a=r/2+(e-r)*Math.abs(t.left)/(Math.abs(t.left)+Math.abs(t.right)),a=Math.min(Math.max(0,a-r/2),e-r));let h=0;l>0&&(h=l/2+(i-l)*Math.abs(t.top)/(Math.abs(t.top)+Math.abs(t.bottom)),h=Math.min(Math.max(0,h-l/2),i-l));return{lineSize:o,xSize:r,ySize:l,translateY:h,translateX:a,color:this._opts.scrollConfig.color}}_doSize(t){return t*this._opts.devicePixelRatio}_getOpts(t){var i;const n=Object.assign(Object.assign({},t),{scrollConfig:Object.assign(Object.assign({},b),t.scrollConfig||{})});return n.scrollConfig||(n.scrollConfig=b),(null===(i=null==n?void 0:n.scrollConfig)||void 0===i?void 0:i.width)>0||(n.scrollConfig.width=b.width),n.scrollConfig.width=Math.max(n.scrollConfig.width,b.width),!0!==e(n.scrollConfig.color)&&(n.scrollConfig.color=n.scrollConfig.color),n}}function C(t,e){let{x:i,y:n,h:s,w:o}=e;const{color:r,axis:l}=e;"X"===l?(n=n+s/4+1,s/=2):"Y"===l&&(i=i+o/4+1,o/=2);let a=e.r;a=Math.min(a,o/2,s/2),(o<2*a||s<2*a)&&(a=0),t.globalAlpha=.36,t.beginPath(),t.moveTo(i+a,n),t.arcTo(i+o,n,i+o,n+s,a),t.arcTo(i+o,n+s,i,n+s,a),t.arcTo(i,n+s,i,n,a),t.arcTo(i,n,i+o,n,a),t.closePath(),t.fillStyle=r,t.fill(),t.globalAlpha=1,t.beginPath(),t.lineWidth=1,t.strokeStyle=r,t.moveTo(i+a,n),t.arcTo(i+o,n,i+o,n+s,a),t.arcTo(i+o,n+s,i,n+s,a),t.arcTo(i,n+s,i,n,a),t.arcTo(i,n,i+o,n,a),t.closePath(),t.stroke()}const P=Symbol("_opts"),D=Symbol("_ctx");class L{constructor(t,e){this[P]=e,this[D]=t}resetSize(t){this[P]=Object.assign(Object.assign({},this[P]),t)}calcScreen(){const t=this[D].getTransform().scale,{width:e,height:i,contextWidth:n,contextHeight:s,devicePixelRatio:o}=this[P];let r=!0,l=!0,a=!0,h=!0;n*t<=e&&(this[D].setTransform({scrollX:(e-n*t)/2}),r=!1,l=!1),s*t<=i&&(this[D].setTransform({scrollY:(i-s*t)/2}),a=!1,h=!1),n*t>=e&&this[D].getTransform().scrollX>0&&(this[D].setTransform({scrollX:0}),r=!1),s*t>=i&&this[D].getTransform().scrollY>0&&(this[D].setTransform({scrollY:0}),a=!1);const{scrollX:c,scrollY:d}=this[D].getTransform();c<0&&Math.abs(c)>Math.abs(n*t-e)&&(this[D].setTransform({scrollX:0-Math.abs(n*t-e)}),l=!1),d<0&&Math.abs(d)>Math.abs(s*t-i)&&(this[D].setTransform({scrollY:0-Math.abs(s*t-i)}),h=!1);const{scrollX:u,scrollY:g}=this[D].getTransform();return{size:{x:u*t,y:g*t,w:n*t,h:s*t},position:{top:g,bottom:i-(s*t+g),left:u,right:e-(n*t+u)},deviceSize:{x:u*o,y:g*o,w:n*o*t,h:s*o*t},width:this[P].width,height:this[P].height,devicePixelRatio:this[P].devicePixelRatio,canScrollYPrev:a,canScrollYNext:h,canScrollXPrev:r,canScrollXNext:l}}calcScreenScroll(t,e,i,n,s){let o=t,r=n-i;t<=0&&e<=0&&(r=Math.abs(t)+Math.abs(e));let l=1;return r>0&&(l=r/(n-i)),o=0-l*s,o}}const{throttle:M,Context:I}=x;class z{constructor(t,e){this._hasRendered=!1,this._mount=t,this._canvas=document.createElement("canvas"),this._helperCanvas=document.createElement("canvas"),this._displayCanvas=document.createElement("canvas"),this._mount.appendChild(this._displayCanvas),this._opts=this._parsePrivateOptions(e);const i=this._canvas.getContext("2d"),n=this._displayCanvas.getContext("2d"),s=this._helperCanvas.getContext("2d");this._ctx=new I(i,this._opts),this._helperCtx=new I(s,this._opts),this._screen=new L(this._ctx,this._opts),this._watcher=new y(this._displayCanvas,this._ctx),this._scroller=new E(n,{width:e.width,height:e.height,devicePixelRatio:e.devicePixelRatio||1,scrollConfig:e.scrollConfig}),this._render()}getDisplayContext2D(){return this._displayCanvas.getContext("2d")}getOriginContext2D(){return this._ctx.getContext()}getHelperContext2D(){return this._helperCtx.getContext()}getContext(){return this._ctx}getHelperContext(){return this._helperCtx}scale(t){t>0&&(this._ctx.setTransform({scale:t}),this._helperCtx.setTransform({scale:t}));const{position:e,size:i}=this._screen.calcScreen();return{position:e,size:i}}scrollX(t){this._watcher.setStatusMap({canScrollYPrev:!0,canScrollYNext:!0,canScrollXPrev:!0,canScrollXNext:!0}),(t>=0||t<0)&&(this._ctx.setTransform({scrollX:t}),this._helperCtx.setTransform({scrollX:t}));const{position:e,size:i,canScrollXNext:n,canScrollYNext:s,canScrollXPrev:o,canScrollYPrev:r}=this._screen.calcScreen();return this._watcher.setStatusMap({canScrollYPrev:r,canScrollYNext:s,canScrollXPrev:o,canScrollXNext:n}),{position:e,size:i}}scrollY(t){this._watcher.setStatusMap({canScrollYPrev:!0,canScrollYNext:!0,canScrollXPrev:!0,canScrollXNext:!0}),(t>=0||t<0)&&(this._ctx.setTransform({scrollY:t}),this._helperCtx.setTransform({scrollY:t}));const{position:e,size:i,canScrollXNext:n,canScrollYNext:s,canScrollXPrev:o,canScrollYPrev:r}=this._screen.calcScreen();return this._watcher.setStatusMap({canScrollYPrev:r,canScrollYNext:s,canScrollXPrev:o,canScrollXNext:n}),{position:e,size:i}}getTransform(){return this._ctx.getTransform()}draw(){this.clear();const{position:t,deviceSize:e,size:i}=this._screen.calcScreen(),n=this._displayCanvas.getContext("2d");return null==n||n.drawImage(this._canvas,e.x,e.y,e.w,e.h),null==n||n.drawImage(this._helperCanvas,e.x,e.y,e.w,e.h),!0===this._opts.canScroll&&this._scroller.draw(t),{position:t,size:i}}clear(){const t=this._displayCanvas.getContext("2d");null==t||t.clearRect(0,0,this._displayCanvas.width,this._displayCanvas.height)}on(t,e){this._watcher.on(t,e)}off(t,e){this._watcher.off(t,e)}getScreenInfo(){return this._screen.calcScreen()}setCursor(t){this._displayCanvas.style.cursor=t}resetCursor(){this._displayCanvas.style.cursor="auto"}resetSize(t){this._opts=Object.assign(Object.assign({},this._opts),t),this._resetContext(),this._ctx.resetSize(t),this._helperCtx.resetSize(t),this._screen.resetSize(t),this._scroller.resetSize({width:this._opts.width,height:this._opts.height,devicePixelRatio:this._opts.devicePixelRatio}),this.draw()}getScrollLineWidth(){let t=0;return!0===this._opts.canScroll&&(t=this._scroller.getLineWidth()),t}pointScreenToContext(t){const{scrollX:e,scrollY:i,scale:n}=this.getTransform();return{x:(t.x-e)/n,y:(t.y-i)/n}}pointContextToScreen(t){const{scrollX:e,scrollY:i,scale:n}=this.getTransform();return{x:t.x*n+e,y:t.y*n+i}}_render(){!0!==this._hasRendered&&(this._resetContext(),this._initEvent(),this._hasRendered=!0)}_resetContext(){const{width:t,height:e,contextWidth:i,contextHeight:n,devicePixelRatio:s}=this._opts;this._canvas.width=i*s,this._canvas.height=n*s,this._helperCanvas.width=i*s,this._helperCanvas.height=n*s,this._displayCanvas.width=t*s,this._displayCanvas.height=e*s,function(t,e){const i=function(t){const e={};return(t.getAttribute("style")||"").split(";").forEach((t=>{const i=t.split(":");i[0]&&"string"==typeof i[0]&&(e[i[0]]=i[1]||"")})),e}(t),n=Object.assign(Object.assign({},i),e),s=Object.keys(n);let o="";s.forEach((t=>{o+=`${t}:${n[t]||""};`})),t.setAttribute("style",o)}(this._displayCanvas,{width:`${t}px`,height:`${e}px`})}_parsePrivateOptions(t){return Object.assign(Object.assign({},{devicePixelRatio:1}),t)}_initEvent(){if(!0!==this._hasRendered&&!0===this._opts.canScroll){this.on("wheelX",M((t=>{this._doScrollX(t)}),16)),this.on("wheelY",M((t=>{this._doScrollY(t)}),16));let t=null;this.on("moveStart",M((e=>{this._scroller.isPointAtScrollX(e)?t="x":this._scroller.isPointAtScrollY(e)&&(t="y")}),16)),this.on("move",M((e=>{t&&this._doMoveScroll(t,e)}),16)),this.on("moveEnd",M((e=>{t&&this._doMoveScroll(t,e),t=null}),16))}}_doScrollX(t,e){const{width:i}=this._opts;let n=e;"number"==typeof n&&(n>0||n<=0)||(n=this._ctx.getTransform().scrollX);const{position:s}=this._screen.calcScreen(),{xSize:o}=this._scroller.calc(s),r=this._screen.calcScreenScroll(s.left,s.right,o,i,t);this.scrollX(n+r),this.draw()}_doScrollY(t,e){const{height:i}=this._opts;let n=e;"number"==typeof n&&(n>0||n<=0)||(n=this._ctx.getTransform().scrollY);const{position:s}=this._screen.calcScreen(),{ySize:o}=this._scroller.calc(s),r=this._screen.calcScreenScroll(s.top,s.bottom,o,i,t);this.scrollY(n+r),this.draw()}_doMoveScroll(t,e){if(!t)return;const{position:i}=this._screen.calcScreen(),{xSize:n,ySize:s}=this._scroller.calc(i);"x"===t?this._doScrollX(e.x-n/2,0):"y"===t&&this._doScrollY(e.y-s/2,0)}}function T(t,e,i){const n=function(t){return{x:t.x+t.w/2,y:t.y+t.h/2}}(e);return function(t,e,i,n){e&&(i>0||i<0)&&(t.translate(e.x,e.y),t.rotate(i),t.translate(-e.x,-e.y));n(t),e&&(i>0||i<0)&&(t.translate(e.x,e.y),t.rotate(-i),t.translate(-e.x,-e.y))}(t,n,(e.angle||0)/180*Math.PI||0,i)}function k(t){t.setFillStyle("#000000"),t.setStrokeStyle("#000000"),t.setLineDash([]),t.setGlobalAlpha(1),t.setShadowColor("#00000000"),t.setShadowOffsetX(0),t.setShadowOffsetY(0),t.setShadowBlur(0)}function U(t,i,n){k(t),function(t,i){k(t),T(t,i,(()=>{if(!(i.desc.borderWidth&&i.desc.borderWidth>0))return;const n=i.desc.borderWidth;let s="#000000";!0===e(i.desc.borderColor)&&(s=i.desc.borderColor);const o=i.x-n/2,r=i.y-n/2,l=i.w+n,a=i.h+n;let h=i.desc.borderRadius||0;h=Math.min(h,l/2,a/2),h<l/2&&h<a/2&&(h+=n/2);const{desc:c}=i;void 0!==c.shadowColor&&e(c.shadowColor)&&t.setShadowColor(c.shadowColor),void 0!==c.shadowOffsetX&&f.number(c.shadowOffsetX)&&t.setShadowOffsetX(c.shadowOffsetX),void 0!==c.shadowOffsetY&&f.number(c.shadowOffsetY)&&t.setShadowOffsetY(c.shadowOffsetY),void 0!==c.shadowBlur&&f.number(c.shadowBlur)&&t.setShadowBlur(c.shadowBlur),t.beginPath(),t.setLineWidth(n),t.setStrokeStyle(s),t.moveTo(o+h,r),t.arcTo(o+l,r,o+l,r+a,h),t.arcTo(o+l,r+a,o,r+a,h),t.arcTo(o,r+a,o,r,h),t.arcTo(o,r,o+l,r,h),t.closePath(),t.stroke()}))}(t,i),k(t),T(t,i,(()=>{const{x:e,y:s,w:r,h:l}=i;let a=i.desc.borderRadius||0;a=Math.min(a,r/2,l/2),(r<2*a||l<2*a)&&(a=0),t.beginPath(),t.moveTo(e+a,s),t.arcTo(e+r,s,e+r,s+l,a),t.arcTo(e+r,s+l,e,s+l,a),t.arcTo(e,s+l,e,s,a),t.arcTo(e,s,e+r,s,a),t.closePath(),("string"==typeof n||["CanvasPattern"].includes(o.type(n)))&&t.setFillStyle(n),t.fill()}))}function W(t,e){U(t,e,e.desc.bgColor)}function R(t,e,i){const n=i.getContent(e.uuid);T(t,e,(()=>{n&&t.drawImage(n,e.x,e.y,e.w,e.h)}))}function O(t,e,i){const n=i.getContent(e.uuid);T(t,e,(()=>{n&&t.drawImage(n,e.x,e.y,e.w,e.h)}))}function A(t,e,i){const n=i.getContent(e.uuid);T(t,e,(()=>{n&&t.drawImage(n,e.x,e.y,e.w,e.h)}))}function F(t,i,n){k(t),U(t,i,i.desc.bgColor||"transparent"),T(t,i,(()=>{const n=Object.assign({fontSize:12,fontFamily:"sans-serif",textAlign:"center"},i.desc);t.setFillStyle(i.desc.color),t.setTextBaseline("top"),t.setFont({fontWeight:n.fontWeight,fontSize:n.fontSize,fontFamily:n.fontFamily});const s=n.text.replace(/\r\n/gi,"\n"),o=n.lineHeight||n.fontSize,r=s.split("\n"),l=[];let a=0;r.forEach(((e,n)=>{let s="";if(e.length>0){for(let h=0;h<e.length&&(t.measureText(s+(e[h]||"")).width<t.calcDeviceNum(i.w)?s+=e[h]||"":(l.push({text:s,width:t.calcScreenNum(t.measureText(s).width)}),s=e[h]||"",a++),!((a+1)*o>i.h));h++)if(e.length-1===h&&(a+1)*o<i.h){l.push({text:s,width:t.calcScreenNum(t.measureText(s).width)}),n<r.length-1&&a++;break}}else l.push({text:"",width:0})}));let h=0;l.length*o<i.h&&("top"===i.desc.verticalAlign?h=0:"bottom"===i.desc.verticalAlign?h+=i.h-l.length*o:h+=(i.h-l.length*o)/2);{const s=i.y+h;void 0!==n.textShadowColor&&e(n.textShadowColor)&&t.setShadowColor(n.textShadowColor),void 0!==n.textShadowOffsetX&&f.number(n.textShadowOffsetX)&&t.setShadowOffsetX(n.textShadowOffsetX),void 0!==n.textShadowOffsetY&&f.number(n.textShadowOffsetY)&&t.setShadowOffsetY(n.textShadowOffsetY),void 0!==n.textShadowBlur&&f.number(n.textShadowBlur)&&t.setShadowBlur(n.textShadowBlur),l.forEach(((e,r)=>{let l=i.x;"center"===n.textAlign?l=i.x+(i.w-e.width)/2:"right"===n.textAlign&&(l=i.x+(i.w-e.width)),t.fillText(e.text,l,s+o*r)})),k(t)}if(e(n.strokeColor)&&void 0!==n.strokeWidth&&n.strokeWidth>0){const e=i.y+h;l.forEach(((s,r)=>{let l=i.x;"center"===n.textAlign?l=i.x+(i.w-s.width)/2:"right"===n.textAlign&&(l=i.x+(i.w-s.width)),void 0!==n.strokeColor&&t.setStrokeStyle(n.strokeColor),void 0!==n.strokeWidth&&n.strokeWidth>0&&t.setLineWidth(n.strokeWidth),t.strokeText(s.text,l,e+o*r)}))}}))}function $(t,e){k(t),T(t,e,(t=>{const{x:i,y:n,w:s,h:o,desc:r}=e,{bgColor:l="#000000",borderColor:a="#000000",borderWidth:h=0}=r,c=s/2,d=o/2,u=i+c,g=n+d;if(h&&h>0){const e=h/2+c,i=h/2+d;t.beginPath(),t.setStrokeStyle(a),t.setLineWidth(h),t.ellipse(u,g,e,i,0,0,2*Math.PI),t.closePath(),t.stroke()}t.beginPath(),t.setFillStyle(l),t.ellipse(u,g,c,d,0,0,2*Math.PI),t.closePath(),t.fill()}))}function Y(t,i,n){var s;k(t);const o=t.getSize();if(t.clearRect(0,0,o.contextWidth,o.contextHeight),"string"==typeof i.bgColor&&e(i.bgColor)&&function(t,e){const i=t.getSize();t.setFillStyle(e),t.fillRect(0,0,i.contextWidth,i.contextHeight)}(t,i.bgColor),i.elements.length>0)for(let e=0;e<i.elements.length;e++){const o=i.elements[e];if(!0!==(null===(s=null==o?void 0:o.operation)||void 0===s?void 0:s.invisible))switch(o.type){case"rect":W(t,o);break;case"text":F(t,o);break;case"image":R(t,o,n);break;case"svg":O(t,o,n);break;case"html":A(t,o,n);break;case"circle":$(t,o)}}}class X{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);null==i||i.push(e),this._listeners.set(t,i||[])}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);if(Array.isArray(i))for(let t=0;t<(null==i?void 0:i.length);t++)if(i[t]===e){i.splice(t,1);break}this._listeners.set(t,i||[])}}trigger(t,e){const i=this._listeners.get(t);return!!Array.isArray(i)&&(i.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}}var N,H,B=globalThis&&globalThis.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(s,o){function r(t){try{a(n.next(t))}catch(t){o(t)}}function l(t){try{a(n.throw(t))}catch(t){o(t)}}function a(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(r,l)}a((n=n.apply(t,e||[])).next())}))};(H=N||(N={})).FREE="free",H.LOADING="loading",H.COMPLETE="complete";class j{constructor(t){this._currentLoadData={},this._currentUUIDQueue=[],this._storageLoadData={},this._status=N.FREE,this._waitingLoadQueue=[],this._opts=t,this._event=new X,this._waitingLoadQueue=[]}load(t,e){const[i,n]=this._resetLoadData(t,e);this._status===N.FREE||this._status===N.COMPLETE?(this._currentUUIDQueue=i,this._currentLoadData=n,this._loadTask()):this._status===N.LOADING&&i.length>0&&this._waitingLoadQueue.push({uuidQueue:i,loadData:n})}on(t,e){this._event.on(t,e)}off(t,e){this._event.off(t,e)}isComplete(){return this._status===N.COMPLETE}getContent(t){var e;return"loaded"===(null===(e=this._storageLoadData[t])||void 0===e?void 0:e.status)?this._storageLoadData[t].content:null}_resetLoadData(t,e){const i={},n=[],s=this._storageLoadData;for(let o=t.elements.length-1;o>=0;o--){const r=t.elements[o];["image","svg","html"].includes(r.type)&&(s[r.uuid]?e.includes(r.uuid)&&(i[r.uuid]=this._createEmptyLoadItem(r),n.push(r.uuid)):(i[r.uuid]=this._createEmptyLoadItem(r),n.push(r.uuid)))}return[n,i]}_createEmptyLoadItem(t){let e="";const i=t.type;let s=t.w,o=t.h;if("image"===t.type){e=t.desc.src||""}else if("svg"===t.type){e=t.desc.svg||""}else if("html"===t.type){const i=t;e=(i.desc.html||"").replace(/<script[\s\S]*?<\/script>/gi,""),s=i.desc.width||t.w,o=i.desc.height||t.h}return{uuid:t.uuid,type:i,status:"null",content:null,source:e,elemW:s,elemH:o,element:n(t)}}_loadTask(){if(this._status===N.LOADING)return;if(this._status=N.LOADING,0===this._currentUUIDQueue.length){if(0===this._waitingLoadQueue.length)return this._status=N.COMPLETE,void this._event.trigger("complete",void 0);{const t=this._waitingLoadQueue.shift();if(t){const{uuidQueue:e,loadData:i}=t;this._currentLoadData=i,this._currentUUIDQueue=e}}}const{maxParallelNum:t}=this._opts,e=this._currentUUIDQueue.splice(0,t);e.forEach(((t,e)=>{}));const i=[],n=()=>{if(i.length>=t)return!1;if(0===e.length)return!0;for(let s=i.length;s<t;s++){const t=e.shift();if(void 0===t)break;i.push(t),this._loadElementSource(this._currentLoadData[t]).then((s=>{var o,r;i.splice(i.indexOf(t),1);const l=n();this._storageLoadData[t]={uuid:t,type:this._currentLoadData[t].type,status:"loaded",content:s,source:this._currentLoadData[t].source,elemW:this._currentLoadData[t].elemW,elemH:this._currentLoadData[t].elemH,element:this._currentLoadData[t].element},0===i.length&&0===e.length&&!0===l&&(this._status=N.FREE,this._loadTask()),this._event.trigger("load",{uuid:null===(o=this._storageLoadData[t])||void 0===o?void 0:o.uuid,type:this._storageLoadData[t].type,status:this._storageLoadData[t].status,content:this._storageLoadData[t].content,source:this._storageLoadData[t].source,elemW:this._storageLoadData[t].elemW,elemH:this._storageLoadData[t].elemH,element:null===(r=this._storageLoadData[t])||void 0===r?void 0:r.element})})).catch((s=>{var o,r,l,a,h,c,d,u,g,m,_,f;console.warn(s),i.splice(i.indexOf(t),1);const p=n();this._currentLoadData[t]&&(this._storageLoadData[t]={uuid:t,type:null===(o=this._currentLoadData[t])||void 0===o?void 0:o.type,status:"fail",content:null,error:s,source:null===(r=this._currentLoadData[t])||void 0===r?void 0:r.source,elemW:null===(l=this._currentLoadData[t])||void 0===l?void 0:l.elemW,elemH:null===(a=this._currentLoadData[t])||void 0===a?void 0:a.elemH,element:null===(h=this._currentLoadData[t])||void 0===h?void 0:h.element}),0===i.length&&0===e.length&&!0===p&&(this._status=N.FREE,this._loadTask()),this._currentLoadData[t]&&this._event.trigger("error",{uuid:t,type:null===(c=this._storageLoadData[t])||void 0===c?void 0:c.type,status:null===(d=this._storageLoadData[t])||void 0===d?void 0:d.status,content:null===(u=this._storageLoadData[t])||void 0===u?void 0:u.content,source:null===(g=this._storageLoadData[t])||void 0===g?void 0:g.source,elemW:null===(m=this._storageLoadData[t])||void 0===m?void 0:m.elemW,elemH:null===(_=this._storageLoadData[t])||void 0===_?void 0:_.elemH,element:null===(f=this._storageLoadData[t])||void 0===f?void 0:f.element})}))}return!1};n()}_loadElementSource(t){return B(this,void 0,void 0,(function*(){if(t&&"image"===t.type){return yield a(t.source)}if(t&&"svg"===t.type){return yield h(t.source)}if(t&&"html"===t.type){return yield c(t.source,{width:t.elemW,height:t.elemH})}throw Error("Element's source is not support!")}))}}class G{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);null==i||i.push(e),this._listeners.set(t,i||[])}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);if(Array.isArray(i))for(let t=0;t<(null==i?void 0:i.length);t++)if(i[t]===e){i.splice(t,1);break}this._listeners.set(t,i||[])}}trigger(t,e){const i=this._listeners.get(t);return!!Array.isArray(i)&&(i.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}}const{requestAnimationFrame:q}=window;var Q,V;(V=Q||(Q={})).NULL="null",V.FREE="free",V.DRAWING="drawing",V.FREEZE="freeze";class Z extends G{constructor(t){super(),this._queue=[],this._ctx=null,this._status=Q.NULL,this._opts=t,this._loader=new j({maxParallelNum:6}),this._loader.on("load",(t=>{this._drawFrame(),this.trigger("load",{element:t.element})})),this._loader.on("error",(t=>{this.trigger("error",{element:t.element,error:t.error})})),this._loader.on("complete",(()=>{this.trigger("loadComplete",{t:Date.now()})}))}render(t,e,s){const{changeResourceUUIDs:o=[]}=s||{};this._status=Q.FREE;const r=n(e);if(Array.isArray(r.elements)&&r.elements.forEach((t=>{"string"==typeof t.uuid&&t.uuid||(t.uuid=i())})),!this._ctx)if(this._opts&&"[object HTMLCanvasElement]"===Object.prototype.toString.call(t)){const{width:e,height:i,contextWidth:n,contextHeight:s,devicePixelRatio:o}=this._opts,r=t;r.width=e*o,r.height=i*o;const l=r.getContext("2d");this._ctx=new d(l,{width:e,height:i,contextWidth:n||e,contextHeight:s||i,devicePixelRatio:o})}else t&&(this._ctx=t);if([Q.FREEZE].includes(this._status))return;const l=n({data:r});this._queue.push(l),this._drawFrame(),this._loader.load(r,o||[])}getContext(){return this._ctx}thaw(){this._status=Q.FREE}_freeze(){this._status=Q.FREEZE}_drawFrame(){this._status!==Q.FREEZE&&q((()=>{if(this._status===Q.FREEZE)return;const t=this._ctx;let e=this._queue[0],i=!1;this._queue.length>1?e=this._queue.shift():i=!0,!0!==this._loader.isComplete()?(this._drawFrame(),e&&t&&Y(t,e.data,this._loader)):e&&t?(Y(t,e.data,this._loader),this._retainQueueOneItem(),i?this._status=Q.FREE:this._drawFrame()):this._status=Q.FREE,this.trigger("drawFrame",{t:Date.now()}),!0===this._loader.isComplete()&&1===this._queue.length&&this._status===Q.FREE&&(t&&this._queue[0]&&this._queue[0].data&&Y(t,this._queue[0].data,this._loader),this.trigger("drawFrameComplete",{t:Date.now()}),this._freeze())}))}_retainQueueOneItem(){if(this._queue.length<=1)return;const t=n(this._queue[this._queue.length-1]);this._queue=[t]}}function J(t){return"number"==typeof t&&(t>0||t<=0)}function K(t){return"number"==typeof t&&t>=0}function tt(t){return"string"==typeof t&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${t}`)}function et(t){return"string"==typeof t&&/^(data:image\/)/.test(`${t}`)}const it={x:function(t){return J(t)},y:function(t){return J(t)},w:K,h:function(t){return"number"==typeof t&&t>=0},angle:function(t){return"number"==typeof t&&t>=-360&&t<=360},number:J,borderWidth:function(t){return K(t)},borderRadius:function(t){return J(t)&&t>=0},color:function(t){return e(t)},imageSrc:function(t){return et(t)||tt(t)},imageURL:tt,imageBase64:et,svg:function(t){return"string"==typeof t&&/^(<svg[\s]{1,}|<svg>)/i.test(`${t}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${t}`.trim())},html:function(t){let e=!1;if("string"==typeof t){let i=document.createElement("div");i.innerHTML=t,i.children.length>0&&(e=!0),i=null}return e},text:function(t){return"string"==typeof t},fontSize:function(t){return J(t)&&t>0},lineHeight:function(t){return J(t)&&t>0},textAlign:function(t){return["center","left","right"].includes(t)},fontFamily:function(t){return"string"==typeof t&&t.length>0},fontWeight:function(t){return["bold"].includes(t)},strokeWidth:function(t){return J(t)&&t>0}};function nt(t={}){const{borderColor:e,borderRadius:i,borderWidth:n}=t;return!(t.hasOwnProperty("borderColor")&&!it.color(e))&&(!(t.hasOwnProperty("borderRadius")&&!it.number(i))&&!(t.hasOwnProperty("borderWidth")&&!it.number(n)))}const st={attrs:function(t){const{x:e,y:i,w:n,h:s,angle:o}=t;return!!(it.x(e)&&it.y(i)&&it.w(n)&&it.h(s)&&it.angle(o))&&(o>=-360&&o<=360)},textDesc:function(t){const{text:e,color:i,fontSize:n,lineHeight:s,fontFamily:o,textAlign:r,fontWeight:l,bgColor:a,strokeWidth:h,strokeColor:c}=t;return!!it.text(e)&&(!!it.color(i)&&(!!it.fontSize(n)&&(!(t.hasOwnProperty("bgColor")&&!it.color(a))&&(!(t.hasOwnProperty("fontWeight")&&!it.fontWeight(l))&&(!(t.hasOwnProperty("lineHeight")&&!it.lineHeight(s))&&(!(t.hasOwnProperty("fontFamily")&&!it.fontFamily(o))&&(!(t.hasOwnProperty("textAlign")&&!it.textAlign(r))&&(!(t.hasOwnProperty("strokeWidth")&&!it.strokeWidth(h))&&(!(t.hasOwnProperty("strokeColor")&&!it.color(c))&&!!nt(t))))))))))},rectDesc:function(t){const{bgColor:e}=t;return!(t.hasOwnProperty("bgColor")&&!it.color(e))&&!!nt(t)},circleDesc:function(t){const{bgColor:e,borderColor:i,borderWidth:n}=t;return!(t.hasOwnProperty("bgColor")&&!it.color(e))&&(!(t.hasOwnProperty("borderColor")&&!it.color(i))&&!(t.hasOwnProperty("borderWidth")&&!it.number(n)))},imageDesc:function(t){const{src:e}=t;return!!it.imageSrc(e)},svgDesc:function(t){const{svg:e}=t;return!!it.svg(e)},htmlDesc:function(t){const{html:e}=t;return!!it.html(e)}};function ot(t){return t/180*Math.PI}function rt(t){return{x:t.x+t.w/2,y:t.y+t.h/2}}function lt(t,e){const i=e.x-t.x,n=t.y-e.y;if(0===i){if(n<0)return Math.PI/2;if(n>0)return 1.5*Math.PI}else if(0===n){if(i<0)return Math.PI;if(i>0)return 0}return i>0&&n<0?Math.atan(Math.abs(n)/Math.abs(i)):i<0&&n<0?Math.PI-Math.atan(Math.abs(n)/Math.abs(i)):i<0&&n>0?Math.PI+Math.atan(Math.abs(n)/Math.abs(i)):i>0&&n>0?2*Math.PI-Math.atan(Math.abs(n)/Math.abs(i)):null}const at={elementWrapper:{color:"#0d85da",lockColor:"#aaaaaa",controllerSize:6,lineWidth:1,lineDash:[4,3]}};class ht{constructor(){this._listeners=new Map}on(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);null==i||i.push(e),this._listeners.set(t,i||[])}else this._listeners.set(t,[e])}off(t,e){if(this._listeners.has(t)){const i=this._listeners.get(t);if(Array.isArray(i))for(let t=0;t<(null==i?void 0:i.length);t++)if(i[t]===e){i.splice(t,1);break}this._listeners.set(t,i||[])}}trigger(t,e){const i=this._listeners.get(t);return!!Array.isArray(i)&&(i.forEach((t=>{t(e)})),!0)}has(t){if(this._listeners.has(t)){const e=this._listeners.get(t);if(Array.isArray(e)&&e.length>0)return!0}return!1}}function ct(t,e){var i,n;return(null==(i=null==t?void 0:t.desc)?void 0:i.src)!==(null==(n=null==e?void 0:e.desc)?void 0:n.src)}function dt(t,e){var i,n;return(null==(i=null==t?void 0:t.desc)?void 0:i.svg)!==(null==(n=null==e?void 0:e.desc)?void 0:n.svg)}function ut(t,e){var i,n,s,o,r,l;return(null==(i=null==t?void 0:t.desc)?void 0:i.html)!==(null==(n=null==e?void 0:e.desc)?void 0:n.html)||(null==(s=null==t?void 0:t.desc)?void 0:s.width)!==(null==(o=null==e?void 0:e.desc)?void 0:o.width)||(null==(r=null==t?void 0:t.desc)?void 0:r.height)!==(null==(l=null==e?void 0:e.desc)?void 0:l.height)}function gt(t,e){let i=null,n=!1;switch(e.type){case"image":n=ct(t,e);break;case"svg":n=dt(t,e);break;case"html":n=ut(t,e)}return!0===n&&(i=e.uuid),i}function mt(t){const e={};return t.elements.forEach((t=>{e[t.uuid]=t})),e}function _t(t,e,i){return ft(t,rt(e),ot(e.angle||0)||0,i)}function ft(t,e,i,n){e&&(i>0||i<0)&&(t.translate(e.x,e.y),t.rotate(i),t.translate(-e.x,-e.y)),n(t),e&&(i>0||i<0)&&(t.translate(e.x,e.y),t.rotate(-i),t.translate(-e.x,-e.y))}function pt(t){const e=t.toFixed(2);return parseFloat(e)}function vt(t){return pt(t%360)}const xt=Object.keys({text:{},rect:{},image:{},svg:{},circle:{},html:{}}),St=15;class yt{constructor(t){this._ctx=t}initData(t){return t.elements.forEach((t=>{t.uuid&&"string"==typeof t.uuid||(t.uuid=i())})),t}isPointInElement(t,e){var i,n;const s=this._ctx;let o=-1,r=null;for(let l=e.elements.length-1;l>=0;l--){const a=e.elements[l];if(!0===(null==(i=a.operation)?void 0:i.invisible))continue;let h=0;if((null==(n=a.desc)?void 0:n.borderWidth)>0&&(h=a.desc.borderWidth),_t(s,a,(()=>{s.beginPath(),s.moveTo(a.x-h,a.y-h),s.lineTo(a.x+a.w+h,a.y-h),s.lineTo(a.x+a.w+h,a.y+a.h+h),s.lineTo(a.x-h,a.y+a.h+h),s.lineTo(a.x-h,a.y-h),s.closePath(),s.isPointInPath(t.x,t.y)&&(o=l,r=a.uuid)})),o>=0)break}return[o,r]}dragElement(t,e,i,n,s){const o=this.getElementIndex(t,e);if(!t.elements[o])return;const r=i.x-n.x,l=i.y-n.y;t.elements[o].x+=r/s,t.elements[o].y+=l/s,this.limitElementAttrs(t.elements[o])}transformElement(t,e,i,n,s,o){var r,l;const a=this.getElementIndex(t,e);if(!t.elements[a])return null;if(!0===(null==(l=null==(r=t.elements[a])?void 0:r.operation)?void 0:l.lock))return null;const h=(i.x-n.x)/s,c=(i.y-n.y)/s,d=t.elements[a];if(["top-left","top","top-right","right","bottom-right","bottom","bottom-left","left"].includes(o)){const t=function(t,e,i,n){var s,o,r,l,a,h,c,d,u,g,m,_,f;const p={x:t.x,y:t.y,w:t.w,h:t.h};if(t.angle,!0===(null==(s=t.operation)?void 0:s.limitRatio)&&["top-left","top-right","bottom-right","bottom-left"].includes(n)){const n=Math.max(Math.abs(e),Math.abs(i));e=(e>=0?1:-1)*n,i=(i>=0?1:-1)*n/t.w*t.h}switch(n){case"top-left":t.w-e>0&&t.h-i>0&&(p.x+=e,p.y+=i,p.w-=e,p.h-=i);break;case"top":if(0===t.angle||Math.abs(t.angle||0)<St)p.h-i>0&&(p.y+=i,p.h-=i,!0===(null==(o=t.operation)?void 0:o.limitRatio)&&(p.x+=i/t.h*t.w/2,p.w-=i/t.h*t.w));else if(void 0!==t.angle&&(t.angle>0||t.angle<0)){const n=t.angle>0?t.angle:Math.max(0,t.angle+360);let s=bt(e,i),o=p.x+t.w/2,l=p.y+t.h/2;if(n<90){s=0-Et(s,i);const t=wt(n),e=s/2;o+=e*Math.sin(t),l-=e*Math.cos(t)}else if(n<180){s=Et(s,e);const t=wt(n-90),i=s/2;o+=i*Math.cos(t),l+=i*Math.sin(t)}else if(n<270){s=Et(s,i);const t=wt(n-180),e=s/2;o-=e*Math.sin(t),l+=e*Math.cos(t)}else if(n<360){s=0-Et(s,e);const t=wt(n-270),i=s/2;o-=i*Math.cos(t),l-=i*Math.sin(t)}p.h+s>0&&(!0===(null==(r=t.operation)?void 0:r.limitRatio)&&(p.w=p.w+s/t.h*t.w),p.h=p.h+s,p.x=o-p.w/2,p.y=l-p.h/2)}else p.h-i>0&&(p.y+=i,p.h-=i,!0===(null==(l=t.operation)?void 0:l.limitRatio)&&(p.x-=e/2,p.w+=e));break;case"top-right":p.h-i>0&&p.w+e>0&&(p.y+=i,p.w+=e,p.h-=i);break;case"right":if(0===t.angle||Math.abs(t.angle||0)<St)t.w+e>0&&(p.w+=e,!0===(null==(a=t.operation)?void 0:a.limitRatio)&&(p.y-=e*t.h/t.w/2,p.h+=e*t.h/t.w));else if(void 0!==t.angle&&(t.angle>0||t.angle<0)){const n=t.angle>0?t.angle:Math.max(0,t.angle+360);let s=bt(e,i),o=p.x+t.w/2,r=p.y+t.h/2;if(n<90){s=Et(s,i);const t=wt(n),e=s/2;o+=e*Math.cos(t),r+=e*Math.sin(t)}else if(n<180){s=Et(s,i);const t=wt(n-90),e=s/2;o-=e*Math.sin(t),r+=e*Math.cos(t)}else if(n<270){s=Et(s,i);const t=wt(n-180),e=s/2;o+=e*Math.cos(t),r+=e*Math.sin(t),s=0-s}else if(n<360){s=Et(s,e);const t=wt(n-270),i=s/2;o+=i*Math.sin(t),r-=i*Math.cos(t)}p.w+s>0&&(!0===(null==(h=t.operation)?void 0:h.limitRatio)&&(p.h=p.h+s/t.w*t.h),p.w=p.w+s,p.x=o-p.w/2,p.y=r-p.h/2)}else t.w+e>0&&(p.w+=e,!0===(null==(c=t.operation)?void 0:c.limitRatio)&&(p.h+=e*t.h/t.w,p.y-=e*t.h/t.w/2));break;case"bottom-right":t.w+e>0&&t.h+i>0&&(p.w+=e,p.h+=i);break;case"bottom":if(0===t.angle||Math.abs(t.angle||0)<St)t.h+i>0&&(p.h+=i,!0===(null==(d=t.operation)?void 0:d.limitRatio)&&(p.x-=i/t.h*t.w/2,p.w+=i/t.h*t.w));else if(void 0!==t.angle&&(t.angle>0||t.angle<0)){const n=t.angle>0?t.angle:Math.max(0,t.angle+360);let s=bt(e,i),o=p.x+t.w/2,r=p.y+t.h/2;if(n<90){s=Et(s,i);const t=wt(n),e=s/2;o-=e*Math.sin(t),r+=e*Math.cos(t)}else if(n<180){s=0-Et(s,e);const t=wt(n-90),i=s/2;o-=i*Math.cos(t),r-=i*Math.sin(t)}else if(n<270){s=Et(s,e);const t=wt(n-180),i=s/2;o+=i*Math.sin(t),r-=i*Math.cos(t)}else if(n<360){s=Et(s,e);const t=wt(n-270),i=s/2;o+=i*Math.cos(t),r+=i*Math.sin(t)}p.h+s>0&&(!0===(null==(u=t.operation)?void 0:u.limitRatio)&&(p.w=p.w+s/t.h*t.w),p.h=p.h+s,p.x=o-p.w/2,p.y=r-p.h/2)}else t.h+i>0&&(p.h+=i,!0===(null==(g=t.operation)?void 0:g.limitRatio)&&(p.x-=i/t.h*t.w/2,p.w+=i/t.h*t.w));break;case"bottom-left":t.w-e>0&&t.h+i>0&&(p.x+=e,p.w-=e,p.h+=i);break;case"left":if(0===t.angle||Math.abs(t.angle||0)<St)t.w-e>0&&(p.x+=e,p.w-=e,!0===(null==(m=t.operation)?void 0:m.limitRatio)&&(p.h-=e/t.w*t.h,p.y+=e/t.w*t.h/2));else if(void 0!==t.angle&&(t.angle>0||t.angle<0)){const n=t.angle>0?t.angle:Math.max(0,t.angle+360);let s=bt(e,i),o=p.x+t.w/2,r=p.y+t.h/2;if(n<90){s=0-Et(s,e);const t=wt(n),i=s/2;o-=i*Math.cos(t),r-=i*Math.sin(t)}else if(n<180){s=Et(s,e);const t=wt(n-90),i=s/2;o+=i*Math.sin(t),r-=i*Math.cos(t)}else if(n<270){s=Et(s,i);const t=wt(n-180),e=s/2;o+=e*Math.cos(t),r+=e*Math.sin(t)}else if(n<360){s=Et(s,i);const t=wt(n-270),e=s/2;o-=e*Math.sin(t),r+=e*Math.cos(t)}p.w+s>0&&(!0===(null==(_=t.operation)?void 0:_.limitRatio)&&(p.h=p.h+s/t.w*t.h),p.w=p.w+s,p.x=o-p.w/2,p.y=r-p.h/2)}else t.w-e>0&&(p.x+=e,p.w-=e,!0===(null==(f=t.operation)?void 0:f.limitRatio)&&(p.h-=e/t.w*t.h,p.y+=e/t.w*t.h/2))}return p}(d,h,c,o);d.x=t.x,d.y=t.y,d.w=t.w,d.h=t.h}else if("rotate"===o){const t=function(t,e,i){const n=lt(t,e),s=lt(t,i);return null!==s&&null!==n?n>3*Math.PI/2&&s<Math.PI/2?s+(2*Math.PI-n):s>3*Math.PI/2&&n<Math.PI/2?n+(2*Math.PI-s):s-n:0}(rt(d),n,i);d.angle=(d.angle||0)+function(t){return t/Math.PI*180}(t)}return this.limitElementAttrs(d),{width:pt(d.w),height:pt(d.h),angle:vt(d.angle||0)}}getElementIndex(t,e){let i=-1;for(let n=0;n<t.elements.length;n++)if(t.elements[n].uuid===e){i=n;break}return i}limitElementAttrs(t){t.x=pt(t.x),t.y=pt(t.y),t.w=pt(t.w),t.h=pt(t.h),t.angle=vt(t.angle||0)}}function wt(t){return t*Math.PI/180}function bt(t,e){return Math.sqrt(t*t+e*e)}function Et(t,e){return e>0?Math.abs(t):0-Math.abs(t)}class Ct{constructor(t,e){this._areaStart={x:0,y:0},this._areaEnd={x:0,y:0},this._board=t,this._ctx=this._board.getContext(),this._coreConfig=e,this._helperConfig={elementIndexMap:{}}}updateConfig(t,e){this._updateElementIndex(t),this._updateSelectedElementWrapper(t,e),this._updateSelectedElementListWrapper(t,e)}getConfig(){return n(this._helperConfig)}getElementIndexByUUID(t){const e=this._helperConfig.elementIndexMap[t];return e>=0?e:null}isPointInElementWrapperController(t,e){var i,s;const o=this._ctx,r=(null==(s=null==(i=this._helperConfig)?void 0:i.selectedElementWrapper)?void 0:s.uuid)||null;let l=null,a=null,h=null;if(!this._helperConfig.selectedElementWrapper)return{uuid:r,selectedControllerDirection:a,directIndex:l,hoverControllerDirection:h};const c=this._helperConfig.selectedElementWrapper,d=[c.controllers.right,c.controllers.topRight,c.controllers.top,c.controllers.topLeft,c.controllers.left,c.controllers.bottomLeft,c.controllers.bottom,c.controllers.bottomRight],u=["right","top-right","top","top-left","left","bottom-left","bottom","bottom-right"];let g=n(u),m=0;if(e&&r){const t=this.getElementIndexByUUID(r);if(null!==t&&t>=0){let i=e.elements[t].angle||0;i<0&&(i+=360),i<45?m=0:i<90?m=1:i<135?m=2:i<180?m=3:i<225?m=4:i<270?m=5:i<315&&(m=6)}}if(m>0&&(g=g.slice(-m).concat(g.slice(0,-m))),ft(o,c.translate,c.radian||0,(()=>{for(let e=0;e<d.length;e++){const i=d[e];if(!0!==i.invisible&&(o.beginPath(),o.arc(i.x,i.y,c.controllerSize,0,2*Math.PI),o.closePath(),o.isPointInPath(t.x,t.y)&&(a=u[e],h=g[e]),a)){l=e;break}}})),null===a){const e=c.controllers.rotate;!0!==e.invisible&&ft(o,c.translate,c.radian||0,(()=>{o.beginPath(),o.arc(e.x,e.y,c.controllerSize,0,2*Math.PI),o.closePath(),o.isPointInPath(t.x,t.y)&&(a="rotate",h="rotate")}))}return{uuid:r,selectedControllerDirection:a,hoverControllerDirection:h,directIndex:l}}isPointInElementList(t,e){var i,n,s;const o=this._ctx;let r=-1,l=null;const a=(null==(i=this._helperConfig)?void 0:i.selectedElementListWrappers)||[];for(let i=0;i<a.length;i++){const h=a[i],c=this._helperConfig.elementIndexMap[h.uuid],d=e.elements[c];if(!d)continue;if(!0===(null==(n=d.operation)?void 0:n.invisible))continue;let u=0;if((null==(s=d.desc)?void 0:s.borderWidth)>0&&(u=d.desc.borderWidth),_t(o,d,(()=>{o.beginPath(),o.moveTo(d.x-u,d.y-u),o.lineTo(d.x+d.w+u,d.y-u),o.lineTo(d.x+d.w+u,d.y+d.h+u),o.lineTo(d.x-u,d.y+d.h+u),o.lineTo(d.x-u,d.y-u),o.closePath(),o.isPointInPath(t.x,t.y)&&(r=i,l=d.uuid)})),r>=0)break}return!!(l&&r>=0)}startSelectArea(t){this._areaStart=t,this._areaEnd=t}changeSelectArea(t){this._areaEnd=t,this._calcSelectedArea()}clearSelectedArea(){this._areaStart={x:0,y:0},this._areaEnd={x:0,y:0},this._calcSelectedArea()}calcSelectedElements(t){const e=this._ctx.getTransform(),{scale:i=1,scrollX:n=0,scrollY:s=0}=e,o=this._areaStart,r=this._areaEnd,l=(Math.min(o.x,r.x)-n)/i,a=(Math.min(o.y,r.y)-s)/i,h=Math.abs(r.x-o.x)/i,c=Math.abs(r.y-o.y)/i,d=[],u=this._ctx;return u.beginPath(),u.moveTo(l,a),u.lineTo(l+h,a),u.lineTo(l+h,a+c),u.lineTo(l,a+c),u.lineTo(l,a),u.closePath(),t.elements.forEach((t=>{var e;if(!0!==(null==(e=null==t?void 0:t.operation)?void 0:e.invisible)){const e=t.x+t.w/2,i=t.y+t.h/2;u.isPointInPathWithoutScroll(e,i)&&d.push(t.uuid)}})),d}_calcSelectedArea(){const t=this._areaStart,e=this._areaEnd,i=this._ctx.getTransform(),{scale:n=1,scrollX:s=0,scrollY:o=0}=i,r=this._coreConfig.elementWrapper,l=r.lineWidth/n,a=r.lineDash.map((t=>t/n));this._helperConfig.selectedAreaWrapper={x:(Math.min(t.x,e.x)-s)/n,y:(Math.min(t.y,e.y)-o)/n,w:Math.abs(e.x-t.x)/n,h:Math.abs(e.y-t.y)/n,startPoint:{x:t.x,y:t.y},endPoint:{x:e.x,y:e.y},lineWidth:l,lineDash:a,color:r.color}}_updateElementIndex(t){this._helperConfig.elementIndexMap={},t.elements.forEach(((t,e)=>{this._helperConfig.elementIndexMap[t.uuid]=e}))}_updateSelectedElementWrapper(t,e){var i;const{selectedUUID:n}=e;if(!("string"==typeof n&&this._helperConfig.elementIndexMap[n]>=0))return void delete this._helperConfig.selectedElementWrapper;const s=this._helperConfig.elementIndexMap[n],o=t.elements[s];if(!0===(null==(i=null==o?void 0:o.operation)?void 0:i.invisible))return;const r=this._createSelectedElementWrapper(o,e);this._helperConfig.selectedElementWrapper=r}_updateSelectedElementListWrapper(t,e){const{selectedUUIDList:i}=e,n=[];t.elements.forEach((t=>{if(null==i?void 0:i.includes(t.uuid)){const i=this._createSelectedElementWrapper(t,e);n.push(i)}})),this._helperConfig.selectedElementListWrappers=n}_createSelectedElementWrapper(t,e){var i,n,s,o,r,l,a,h,c,d,u,g;const{scale:m}=e,_=this._coreConfig.elementWrapper,f=_.controllerSize/m,p=_.lineWidth/m,v=_.lineDash.map((t=>t/m)),x=(null==(i=t.desc)?void 0:i.borderWidth)||0;let S=!1;"number"==typeof t.angle&&Math.abs(t.angle)>15&&(S=!0);const y=p,w={uuid:t.uuid,controllerSize:f,controllerOffset:y,lock:!0===(null==(n=null==t?void 0:t.operation)?void 0:n.lock),controllers:{topLeft:{x:t.x-y-x,y:t.y-y-x,invisible:S||!0===(null==(s=null==t?void 0:t.operation)?void 0:s.disableScale)},top:{x:t.x+t.w/2,y:t.y-y-x,invisible:!0===(null==(o=null==t?void 0:t.operation)?void 0:o.disableScale)},topRight:{x:t.x+t.w+y+x,y:t.y-y-x,invisible:S||!0===(null==(r=null==t?void 0:t.operation)?void 0:r.disableScale)},right:{x:t.x+t.w+y+x,y:t.y+t.h/2,invisible:!0===(null==(l=null==t?void 0:t.operation)?void 0:l.disableScale)},bottomRight:{x:t.x+t.w+y+x,y:t.y+t.h+y+x,invisible:S||!0===(null==(a=null==t?void 0:t.operation)?void 0:a.disableScale)},bottom:{x:t.x+t.w/2,y:t.y+t.h+y+x,invisible:!0===(null==(h=null==t?void 0:t.operation)?void 0:h.disableScale)},bottomLeft:{x:t.x-y-x,y:t.y+t.h+y+x,invisible:S||!0===(null==(c=null==t?void 0:t.operation)?void 0:c.disableScale)},left:{x:t.x-y-x,y:t.y+t.h/2,invisible:!0===(null==(d=null==t?void 0:t.operation)?void 0:d.disableScale)},rotate:{x:t.x+t.w/2,y:t.y-f-(2*f+12)-x,invisible:!0===(null==(u=null==t?void 0:t.operation)?void 0:u.disableRotate)}},lineWidth:p,lineDash:v,color:!0===(null==(g=null==t?void 0:t.operation)?void 0:g.lock)?_.lockColor:_.color};return"number"==typeof t.angle&&(t.angle>0||t.angle<0)&&(w.radian=ot(t.angle),w.translate=rt(t)),w}}const Pt=Symbol("_displayCtx"),Dt=Symbol("_helper"),Lt=Symbol("_element"),Mt=Symbol("_opts");class It{constructor(t){this[Mt]=t,this[Pt]=this[Mt].board,this[Lt]=this[Mt].element,this[Dt]=this[Mt].helper}isEffectivePoint(t){const e=this[Pt].getScrollLineWidth(),i=this[Pt].getScreenInfo();return t.x<=i.width-e&&t.y<=i.height-e}judgePointCursor(t,e){let i="auto",n=null;if(!this.isEffectivePoint(t))return{cursor:i,elementUUID:n};const{uuid:s,hoverControllerDirection:o}=this[Dt].isPointInElementWrapperController(t,e);if(s&&o){switch(o){case"top-right":i="ne-resize";break;case"top-left":i="nw-resize";break;case"top":i="n-resize";break;case"right":i="e-resize";break;case"bottom-right":i="se-resize";break;case"bottom":i="s-resize";break;case"bottom-left":i="sw-resize";break;case"left":i="w-resize";break;case"rotate":i="grab"}s&&(n=s)}else{const[s,o]=this[Lt].isPointInElement(t,e);s>=0&&(i="move"),o&&(n=o)}return{cursor:i,elementUUID:n}}}function zt(t){const e={elements:[]};return Array.isArray(null==t?void 0:t.elements)&&(null==t||t.elements.forEach(((t={})=>{(function(t){if(!(Tt(t.x)&&Tt(t.y)&&Tt(t.w)&&Tt(t.h)))return!1;if("string"!=typeof t.type||!xt.includes(t.type))return!1;return!0})(t)&&e.elements.push(t)}))),"string"==typeof t.bgColor&&(e.bgColor=t.bgColor),e}function Tt(t){return t>=0||t<0}var kt=(t=>(t.NULL="null",t.SELECT_ELEMENT="select-element",t.SELECT_ELEMENT_LIST="select-element-list",t.SELECT_ELEMENT_WRAPPER_CONTROLLER="select-element-wrapper-controller",t.SELECT_AREA="select-area",t))(kt||{}),Ut=(t=>(t.DRAGGING="dragging",t.NULL="null",t))(Ut||{});function Wt(){return{hasInited:!1,mode:kt.NULL,cursorStatus:Ut.NULL,selectedUUID:null,selectedUUIDList:[],hoverUUID:null,selectedControllerDirection:null,hoverControllerDirection:null,prevPoint:null,hasChangedElement:!1}}class Rt{constructor(){this._temp=Wt()}set(t,e){this._temp[t]=e}get(t){return this._temp[t]}clear(){this._temp=Wt()}}class Ot{constructor(t){this._plugins=[];const{board:e,config:i,element:n}=t,s=new Ct(e,i);this._opts=t,this.temp=new Rt,this.helper=s,this._mapper=new It({board:e,helper:s,element:n})}addPlugin(t){this._plugins.push(t)}getHelperConfig(){return this.helper.getConfig()}updateHelperConfig(t){var e;const{board:i,getDataFeekback:n,config:s}=this._opts,o=n(),r=i.getTransform();this.helper.updateConfig(o,{width:t.width,height:t.height,devicePixelRatio:t.devicePixelRatio,canScroll:!0===(null==(e=null==s?void 0:s.scrollWrapper)?void 0:e.use),selectedUUID:this.temp.get("selectedUUID"),selectedUUIDList:this.temp.get("selectedUUIDList"),scale:r.scale,scrollX:r.scrollX,scrollY:r.scrollY})}init(){this._initEvent()}_initEvent(){if(!0===this.temp.get("hasInited"))return;const{board:e}=this._opts;e.on("hover",t(this._handleHover.bind(this),32)),e.on("leave",t(this._handleLeave.bind(this),32)),e.on("point",t(this._handleClick.bind(this),16)),e.on("doubleClick",this._handleDoubleClick.bind(this)),e.on("point",this._handlePoint.bind(this)),e.on("moveStart",this._handleMoveStart.bind(this)),e.on("move",t(this._handleMove.bind(this),16)),e.on("moveEnd",this._handleMoveEnd.bind(this))}_handleDoubleClick(t){var e,i,s;const{element:o,getDataFeekback:r,drawFeekback:l,coreEvent:a}=this._opts,h=r(),[c,d]=o.isPointInElement(t,h);if(c>=0&&d){const t=n(null==(e=h.elements)?void 0:e[c]);!0!==(null==(i=null==t?void 0:t.operation)?void 0:i.invisible)&&a.trigger("screenDoubleClickElement",{index:c,uuid:d,element:n(null==(s=h.elements)?void 0:s[c])})}l()}_handlePoint(t){var e,i,s;if(!this._mapper.isEffectivePoint(t))return;const{element:o,getDataFeekback:r,selectElementByIndex:l,coreEvent:a,emitChangeScreen:h,drawFeekback:c}=this._opts,d=this.helper,u=r();if(d.isPointInElementList(t,u))this.temp.set("mode",kt.SELECT_ELEMENT_LIST);else{const{uuid:r,selectedControllerDirection:c}=d.isPointInElementWrapperController(t,u);if(r&&c)this.temp.set("mode",kt.SELECT_ELEMENT_WRAPPER_CONTROLLER),this.temp.set("selectedControllerDirection",c),this.temp.set("selectedUUID",r);else{const[r,c]=o.isPointInElement(t,u);r>=0&&!0!==(null==(i=null==(e=u.elements[r])?void 0:e.operation)?void 0:i.invisible)?(l(r,{useMode:!0}),"string"==typeof c&&a.has("screenSelectElement")&&(a.trigger("screenSelectElement",{index:r,uuid:c,element:n(null==(s=u.elements)?void 0:s[r])}),h()),this.temp.set("mode",kt.SELECT_ELEMENT)):(this.temp.set("selectedUUIDList",[]),this.temp.set("selectedUUID",null),this.temp.set("mode",kt.SELECT_AREA))}}c()}_handleClick(t){var e;const{element:i,getDataFeekback:s,coreEvent:o,drawFeekback:r}=this._opts,l=s(),[a,h]=i.isPointInElement(t,l);a>=0&&h&&o.trigger("screenClickElement",{index:a,uuid:h,element:n(null==(e=l.elements)?void 0:e[a])}),r()}_handleMoveStart(t){const{element:e,getDataFeekback:i,coreEvent:n}=this._opts,s=i(),o=this.helper;this.temp.set("prevPoint",t);const r=this.temp.get("selectedUUID");this.temp.get("mode")===kt.SELECT_ELEMENT_LIST||(this.temp.get("mode")===kt.SELECT_ELEMENT?"string"==typeof r&&n.has("screenMoveElementStart")&&n.trigger("screenMoveElementStart",{index:e.getElementIndex(s,r),uuid:r,x:t.x,y:t.y}):this.temp.get("mode")===kt.SELECT_AREA&&o.startSelectArea(t))}_handleMove(t){const{drawFeekback:e}=this._opts,i=this.helper;this.temp.get("mode")===kt.SELECT_ELEMENT_LIST?(this.temp.set("hasChangedElement",!0),this._dragElements(this.temp.get("selectedUUIDList"),t,this.temp.get("prevPoint")),e(),this.temp.set("cursorStatus",Ut.DRAGGING)):"string"==typeof this.temp.get("selectedUUID")?this.temp.get("mode")===kt.SELECT_ELEMENT?(this.temp.set("hasChangedElement",!0),this._dragElements([this.temp.get("selectedUUID")],t,this.temp.get("prevPoint")),e(),this.temp.set("cursorStatus",Ut.DRAGGING)):this.temp.get("mode")===kt.SELECT_ELEMENT_WRAPPER_CONTROLLER&&this.temp.get("selectedControllerDirection")&&(this._transfromElement(this.temp.get("selectedUUID"),t,this.temp.get("prevPoint"),this.temp.get("selectedControllerDirection")),this.temp.set("cursorStatus",Ut.DRAGGING)):this.temp.get("mode")===kt.SELECT_AREA&&(i.changeSelectArea(t),e()),this.temp.set("prevPoint",t)}_dragElements(t,e,i){if(!i)return;const{board:n,element:s,getDataFeekback:o,drawFeekback:r}=this._opts,l=o(),a=this.helper;t.forEach((t=>{var o,r;const h=a.getElementIndexByUUID(t);if(null===h)return;const c=l.elements[h];!0!==(null==(o=null==c?void 0:c.operation)?void 0:o.lock)&&!0!==(null==(r=null==c?void 0:c.operation)?void 0:r.invisible)&&s.dragElement(l,t,e,i,n.getContext().getTransform().scale)})),r()}_transfromElement(t,e,i,n){if(!i)return null;const{board:s,element:o,getDataFeekback:r,drawFeekback:l}=this._opts,a=r(),h=o.transformElement(a,t,e,i,s.getContext().getTransform().scale,n);return l(),h}_handleMoveEnd(t){const{element:e,getDataFeekback:i,coreEvent:n,drawFeekback:s,emitChangeData:o}=this._opts,r=i(),l=this.helper,a=this.temp.get("selectedUUID");if("string"==typeof a){const i=e.getElementIndex(r,a),s=r.elements[i];s&&(n.has("screenMoveElementEnd")&&n.trigger("screenMoveElementEnd",{index:i,uuid:a,x:t.x,y:t.y}),n.has("screenChangeElement")&&n.trigger("screenChangeElement",{index:i,uuid:a,width:s.w,height:s.h,angle:s.angle||0}))}else if(this.temp.get("mode")===kt.SELECT_AREA){const t=l.calcSelectedElements(r);t.length>0?(this.temp.set("selectedUUIDList",t),this.temp.set("selectedUUID",null)):this.temp.set("mode",kt.NULL),l.clearSelectedArea(),s()}this.temp.get("mode")!==kt.SELECT_ELEMENT&&this.temp.set("selectedUUID",null),this.temp.set("cursorStatus",Ut.NULL),this.temp.set("mode",kt.NULL),!0===this.temp.get("hasChangedElement")&&(o(),this.temp.set("hasChangedElement",!1))}_handleHover(t){var e,i;let n=!1;const{board:s,getDataFeekback:o,coreEvent:r}=this._opts,l=o(),a=this.helper,h=this._mapper;if(this.temp.get("mode")===kt.SELECT_AREA)s.resetCursor();else if(this.temp.get("cursorStatus")===Ut.NULL){const{cursor:o,elementUUID:c}=h.judgePointCursor(t,l);if(s.setCursor(o),c){const t=a.getElementIndexByUUID(c);if(null!==t&&t>=0){const o=l.elements[t];if(!0===(null==(e=null==o?void 0:o.operation)?void 0:e.lock)||!0===(null==(i=null==o?void 0:o.operation)?void 0:i.invisible))return void s.resetCursor();if(this.temp.get("hoverUUID")!==o.uuid){const t=a.getElementIndexByUUID(this.temp.get("hoverUUID")||"");null!==t&&l.elements[t]&&r.trigger("mouseLeaveElement",{uuid:this.temp.get("hoverUUID"),index:t,element:l.elements[t]})}o&&(r.trigger("mouseOverElement",{uuid:o.uuid,index:t,element:o}),this.temp.set("hoverUUID",o.uuid),n=!0)}}}if(!0!==n&&null!==this.temp.get("hoverUUID")){const t=this.temp.get("hoverUUID"),e=a.getElementIndexByUUID(t||"");null!==e&&r.trigger("mouseLeaveElement",{uuid:t,index:e,element:l.elements[e]}),this.temp.set("hoverUUID",null)}r.has("mouseOverScreen")&&r.trigger("mouseOverScreen",t)}_handleLeave(){const{coreEvent:t}=this._opts;t.has("mouseLeaveScreen")&&t.trigger("mouseLeaveScreen",void 0)}}function At(t){t.setFillStyle("#000000"),t.setStrokeStyle("#000000"),t.setLineDash([]),t.setGlobalAlpha(1),t.setShadowColor("#00000000"),t.setShadowOffsetX(0),t.setShadowOffsetY(0),t.setShadowBlur(0)}class Ft{constructor(t,e,i){var s,o,r;this._coreEvent=new ht,this._tempData=new class{constructor(){this._temp={hasInited:!1}}set(t,e){this._temp[t]=e}get(t){return this._temp[t]}clear(){this._temp={hasInited:!1}}},this.$data={elements:[]},this._opts=e,this._config=function(t){const e=n(at);return t&&t.elementWrapper&&(e.elementWrapper={...e.elementWrapper,...t.elementWrapper}),e}(i||{}),this._board=new z(t,{...this._opts,canScroll:null==(s=null==i?void 0:i.scrollWrapper)?void 0:s.use,scrollConfig:{color:(null==(o=null==i?void 0:i.scrollWrapper)?void 0:o.color)||"#000000",width:(null==(r=null==i?void 0:i.scrollWrapper)?void 0:r.width)||12,...(null==i?void 0:i.scrollWrapper)||{}}}),this._renderer=new Z;const l=()=>{const t=this._board.getHelperContext(),e=this._engine.getHelperConfig();this._board.clear();const{contextWidth:i,contextHeight:n,devicePixelRatio:s}=this._opts;t.clearRect(0,0,i*s,n*s),function(t,e){if(!(null==e?void 0:e.selectedElementWrapper))return;const i=e.selectedElementWrapper;At(t),ft(t,i.translate,i.radian||0,(()=>{t.beginPath(),t.setLineDash(i.lineDash),t.setLineWidth(i.lineWidth),t.setStrokeStyle(i.color),t.moveTo(i.controllers.topLeft.x,i.controllers.topLeft.y),t.lineTo(i.controllers.topRight.x,i.controllers.topRight.y),t.lineTo(i.controllers.bottomRight.x,i.controllers.bottomRight.y),t.lineTo(i.controllers.bottomLeft.x,i.controllers.bottomLeft.y),t.lineTo(i.controllers.topLeft.x,i.controllers.topLeft.y-i.lineWidth/2),t.stroke(),t.closePath(),!0!==i.lock?(!0!==i.controllers.rotate.invisible&&(t.beginPath(),t.moveTo(i.controllers.top.x,i.controllers.top.y),t.lineTo(i.controllers.rotate.x,i.controllers.rotate.y+i.controllerSize),t.stroke(),t.closePath(),t.beginPath(),t.setLineDash([]),t.setLineWidth(i.controllerSize/1.2),t.arc(i.controllers.rotate.x,i.controllers.rotate.y,.8*i.controllerSize,0,2*Math.PI),t.stroke(),t.closePath(),t.setStrokeStyle("#FFFFFF"),t.beginPath(),t.setLineDash([]),t.setLineWidth(i.controllerSize/2.1),t.arc(i.controllers.rotate.x,i.controllers.rotate.y,.8*i.controllerSize,0,2*Math.PI),t.stroke(),t.closePath()),[i.controllers.topLeft,i.controllers.top,i.controllers.topRight,i.controllers.right,i.controllers.bottomRight,i.controllers.bottom,i.controllers.bottomLeft,i.controllers.left].forEach((e=>{!0!==e.invisible&&(t.setFillStyle(i.color),t.beginPath(),t.arc(e.x,e.y,i.controllerSize,0,2*Math.PI),t.fill(),t.closePath(),t.setFillStyle("#FFFFFF"),t.beginPath(),t.arc(e.x,e.y,i.controllerSize-1,0,2*Math.PI),t.fill(),t.closePath())}))):(At(t),t.setStrokeStyle(i.color),[i.controllers.topLeft,i.controllers.top,i.controllers.topRight,i.controllers.right,i.controllers.bottomRight,i.controllers.bottom,i.controllers.bottomLeft,i.controllers.left].forEach((e=>{t.beginPath(),t.moveTo(e.x-i.controllerSize/2,e.y-i.controllerSize/2),t.lineTo(e.x+i.controllerSize/2,e.y+i.controllerSize/2),t.stroke(),t.closePath(),t.beginPath(),t.moveTo(e.x+i.controllerSize/2,e.y-i.controllerSize/2),t.lineTo(e.x-i.controllerSize/2,e.y+i.controllerSize/2),t.stroke(),t.closePath()})))}))}(t,e),function(t,e){if(!(null==e?void 0:e.selectedAreaWrapper))return;const i=e.selectedAreaWrapper;i&&i.w>0&&i.h>0&&(At(t),t.setGlobalAlpha(.3),t.setFillStyle(i.color),t.fillRect(i.x,i.y,i.w,i.h),At(t),t.beginPath(),t.setLineDash(i.lineDash),t.setLineWidth(i.lineWidth),t.setStrokeStyle(i.color),t.moveTo(i.x,i.y),t.lineTo(i.x+i.w,i.y),t.lineTo(i.x+i.w,i.y+i.h),t.lineTo(i.x,i.y+i.h),t.lineTo(i.x,i.y),t.stroke(),t.closePath())}(t,e),function(t,e){if(!Array.isArray(null==e?void 0:e.selectedElementListWrappers))return;const i=e.selectedElementListWrappers;null==i||i.forEach((e=>{At(t),ft(t,e.translate,e.radian||0,(()=>{At(t),t.setGlobalAlpha(.05),t.setFillStyle(e.color),t.fillRect(e.controllers.topLeft.x,e.controllers.topLeft.y,e.controllers.bottomRight.x-e.controllers.topLeft.x,e.controllers.bottomRight.y-e.controllers.topLeft.y),At(t),t.beginPath(),t.setLineDash(e.lineDash),t.setLineWidth(e.lineWidth),t.setStrokeStyle(e.color),t.moveTo(e.controllers.topLeft.x,e.controllers.topLeft.y),t.lineTo(e.controllers.topRight.x,e.controllers.topRight.y),t.lineTo(e.controllers.bottomRight.x,e.controllers.bottomRight.y),t.lineTo(e.controllers.bottomLeft.x,e.controllers.bottomLeft.y),t.lineTo(e.controllers.topLeft.x,e.controllers.topLeft.y-e.lineWidth/2),t.stroke(),t.closePath(),!0===e.lock&&(At(t),t.setStrokeStyle(e.color),[e.controllers.topLeft,e.controllers.top,e.controllers.topRight,e.controllers.right,e.controllers.bottomRight,e.controllers.bottom,e.controllers.bottomLeft,e.controllers.left].forEach((i=>{t.beginPath(),t.moveTo(i.x-e.controllerSize/2,i.y-e.controllerSize/2),t.lineTo(i.x+e.controllerSize/2,i.y+e.controllerSize/2),t.stroke(),t.closePath(),t.beginPath(),t.moveTo(i.x+e.controllerSize/2,i.y-e.controllerSize/2),t.lineTo(i.x-e.controllerSize/2,i.y+e.controllerSize/2),t.stroke(),t.closePath()})))}))}))}(t,e),this._board.draw()};this._renderer.on("drawFrame",(()=>{l()})),this._renderer.on("drawFrameComplete",(()=>{l()})),this._elementHandler=new yt(this._board.getContext()),this._engine=new Ot({coreEvent:this._coreEvent,board:this._board,element:this._elementHandler,config:this._config,drawFeekback:this.$draw.bind(this),getDataFeekback:()=>this.$data,selectElementByIndex:this.selectElementByIndex.bind(this),emitChangeScreen:this._emitChangeScreen.bind(this),emitChangeData:this.$emitChangeData.bind(this)}),this._engine.init(),this._renderer.on("drawFrame",(()=>{this._coreEvent.trigger("drawFrame",void 0)})),this._renderer.on("drawFrameComplete",(()=>{this._coreEvent.trigger("drawFrameComplete",void 0)})),this._tempData.set("hasInited",!0)}_emitChangeScreen(){this._coreEvent.has("changeScreen")&&this._coreEvent.trigger("changeScreen",{...this.getScreenTransform()})}$draw(t){this._engine.updateHelperConfig({width:this._opts.width,height:this._opts.height,devicePixelRatio:this._opts.devicePixelRatio}),this._renderer.thaw(),this._renderer.render(this._board.getContext(),this.$data,{changeResourceUUIDs:(null==t?void 0:t.resourceChangeUUIDs)||[]})}getElement(t){return function(t,e){let i=null;const s=t.getEngine().helper.getElementIndexByUUID(e);return null!==s&&t.$data.elements[s]&&(i=n(t.$data.elements[s])),i}(this,t)}getElementByIndex(t){return function(t,e){let i=null;return e>=0&&t.$data.elements[e]&&(i=n(t.$data.elements[e])),i}(this,t)}selectElementByIndex(t){return function(t,e){if(t.$data.elements[e]){const i=t.$data.elements[e].uuid;t.getEngine().temp.set("mode",kt.NULL),"string"==typeof i&&(t.getEngine().temp.set("selectedUUID",i),t.getEngine().temp.set("selectedUUIDList",[])),t.$draw()}}(this,t)}selectElement(t){return function(t,e){const i=t.getEngine().helper.getElementIndexByUUID(e);"number"==typeof i&&i>=0&&t.selectElementByIndex(i)}(this,t)}cancelElementByIndex(t){return function(t,e){if(t.$data.elements[e]){const i=t.$data.elements[e].uuid,n=t.getEngine().temp.get("selectedUUID");"string"==typeof i&&i===n&&(t.getEngine().temp.set("mode",kt.NULL),t.getEngine().temp.set("selectedUUID",null),t.getEngine().temp.set("selectedUUIDList",[])),t.$draw()}}(this,t)}cancelElement(t){return function(t,e){const i=t.getEngine().helper.getElementIndexByUUID(e);"number"==typeof i&&i>=0&&t.cancelElementByIndex(i)}(this,t)}moveUpElement(t){return function(t,e){const i=t.getEngine().helper.getElementIndexByUUID(e);if("number"==typeof i&&i>=0&&i<t.$data.elements.length-1){const e=t.$data.elements[i];t.$data.elements[i]=t.$data.elements[i+1],t.$data.elements[i+1]=e}t.$emitChangeData(),t.$draw()}(this,t)}moveDownElement(t){return function(t,e){const i=t.getEngine().helper.getElementIndexByUUID(e);if("number"==typeof i&&i>0&&i<t.$data.elements.length){const e=t.$data.elements[i];t.$data.elements[i]=t.$data.elements[i-1],t.$data.elements[i-1]=e}t.$emitChangeData(),t.$draw()}(this,t)}updateElement(t){return function(t,e){var i;const s=n(e),o=t.getData(),r=[];for(let e=0;e<o.elements.length;e++)if(s.uuid===(null==(i=o.elements[e])?void 0:i.uuid)){const i=gt(o.elements[e],s);"string"==typeof i&&r.push(i),o.elements[e]=s,t.setData(o);break}t.$emitChangeData(),t.$draw({resourceChangeUUIDs:r})}(this,t)}addElement(t){return function(t,e){const s=n(e);return s.uuid=i(),t.$data.elements.push(s),t.$emitChangeData(),t.$draw(),s.uuid}(this,t)}deleteElement(t){return function(t,e){const i=t.$getElementHandler().getElementIndex(t.getData(),e);i>=0&&(t.$data.elements.splice(i,1),t.$emitChangeData(),t.$draw())}(this,t)}insertElementBefore(t,e){return function(t,e,i){const n=t.getEngine().helper.getElementIndexByUUID(i);return null!==n?t.insertElementBeforeIndex(e,n):null}(this,t,e)}insertElementBeforeIndex(t,e){return function(t,e,s){const o=n(e);return o.uuid=i(),s>=0?(t.$data.elements.splice(s,0,o),t.$emitChangeData(),t.$draw(),o.uuid):null}(this,t,e)}getSelectedElements(){return function(t){const e=[];let i=[];const s=t.getEngine().temp.get("selectedUUID");return"string"==typeof s&&s?i.push(s):i=t.getEngine().temp.get("selectedUUIDList"),i.forEach((i=>{const n=t.getEngine().helper.getElementIndexByUUID(i);if(null!==n&&n>=0){const i=t.$data.elements[n];i&&e.push(i)}})),n(e)}(this)}insertElementAfter(t,e){return function(t,e,i){const n=t.getEngine().helper.getElementIndexByUUID(i);return null!==n?t.insertElementAfterIndex(e,n):null}(this,t,e)}insertElementAfterIndex(t,e){return function(t,e,s){const o=n(e);return o.uuid=i(),s>=0?(t.$data.elements.splice(s+1,0,o),t.$emitChangeData(),t.$draw(),o.uuid):null}(this,t,e)}resetSize(t){this._opts={...this._opts,...t},this._board.resetSize(t),this.$draw()}scale(t){const e=this._board.scale(t);return this.$draw(),this._emitChangeScreen(),e}scrollLeft(t){const e=this._board.scrollX(0-t);return this.$draw(),this._emitChangeScreen(),e}scrollTop(t){const e=this._board.scrollY(0-t);return this.$draw(),this._emitChangeScreen(),e}getScreenTransform(){const t=this._board.getTransform();return{scale:t.scale,scrollTop:Math.max(0,0-t.scrollY),scrollLeft:Math.max(0,0-t.scrollX)}}getData(){return n(this.$data)}setData(t,e){const i=function(t,e){var i;const n=[],s=mt(t),o=mt(e);for(const t in o)if(!0===["image","svg","html"].includes(null==(i=o[t])?void 0:i.type))if(s[t]){let e=!1;switch(s[t].type){case"image":e=ct(s[t],o[t]);break;case"svg":e=dt(s[t],o[t]);break;case"html":e=ut(s[t],o[t])}!0===e&&n.push(t)}else n.push(t);return n}(this.$data,t);this.$data=this._elementHandler.initData(n(zt(t))),e&&!0===e.triggerChangeEvent&&this.$emitChangeData(),this.$draw({resourceChangeUUIDs:i})}clearOperation(){this._tempData.clear(),this.$draw()}on(t,e){this._coreEvent.on(t,e)}off(t,e){this._coreEvent.off(t,e)}getEngine(){return this._engine}pointScreenToContext(t){return this._board.pointScreenToContext(t)}pointContextToScreen(t){return this._board.pointContextToScreen(t)}$getBoardContext(){return this._board.getContext()}$getDisplayContext2D(){return this._board.getDisplayContext2D()}$getOriginContext2D(){return this._board.getOriginContext2D()}$emitChangeData(){this._coreEvent.has("changeData")&&this._coreEvent.trigger("changeData",n(this.$data))}$getElementHandler(){return this._elementHandler}}return Ft.is=it,Ft.check=st,Ft}();
|
|
1
|
+
var iDrawCore=function(e){"use strict";function t(e,t){let i=-1;return function(...o){i>0||(i=setTimeout((()=>{e(...o),i=-1}),t))}}function i(e){return"string"==typeof e&&(/^\#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(e)||/^[a-z]{1,}$/i.test(e))}function o(){function e(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${e()}${e()}-${e()}-${e()}-${e()}-${e()}${e()}${e()}`}function n(e){return function e(t){const i=function(e){return Object.prototype.toString.call(e).replace(/[\]|\[]{1,1}/gi,"").split(" ")[1]}(t);if(["Null","Number","String","Boolean","Undefined"].indexOf(i)>=0)return t;if("Array"===i){const i=[];return t.forEach((t=>{i.push(e(t))})),i}if("Object"===i){const i={};Object.keys(t).forEach((o=>{i[o]=e(t[o])}));return Object.getOwnPropertySymbols(t).forEach((o=>{i[o]=e(t[o])})),i}}(e)}function a(e){return(Object.prototype.toString.call(e)||"").replace(/(\[object|\])/gi,"").trim()}const r={type(e,t){const i=a(e);return!0===t?i.toLocaleLowerCase():i},array:e=>"Array"===a(e),json:e=>"Object"===a(e),function:e=>"Function"===a(e),asyncFunction:e=>"AsyncFunction"===a(e),string:e=>"String"===a(e),number:e=>"Number"===a(e),undefined:e=>"Undefined"===a(e),null:e=>"Null"===a(e),promise:e=>"Promise"===a(e)};var s=globalThis&&globalThis.__awaiter||function(e,t,i,o){return new(i||(i=Promise))((function(n,a){function r(e){try{l(o.next(e))}catch(e){a(e)}}function s(e){try{l(o.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,s)}l((o=o.apply(e,t||[])).next())}))};const{Image:l}=window;function h(e){return new Promise(((t,i)=>{const o=new l;o.crossOrigin="anonymous",o.onload=function(){t(o)},o.onabort=i,o.onerror=i,o.src=e}))}function c(e){return s(this,void 0,void 0,(function*(){const t=yield function(e){return new Promise(((t,i)=>{const o=new Blob([e],{type:"image/svg+xml;charset=utf-8"}),n=new FileReader;n.readAsDataURL(o),n.onload=function(e){var i;const o=null===(i=null==e?void 0:e.target)||void 0===i?void 0:i.result;t(o)},n.onerror=function(e){i(e)}}))}(e);return yield h(t)}))}function d(e,t){return s(this,void 0,void 0,(function*(){e=e.replace(/\&/gi,"&");const i=yield function(e,t){const{width:i,height:o}=t;return new Promise(((t,n)=>{const a=new Blob([`\n <svg \n xmlns="http://www.w3.org/2000/svg" \n width="${i||""}" \n height = "${o||""}">\n <foreignObject width="100%" height="100%">\n <div xmlns = "http://www.w3.org/1999/xhtml">\n ${e}\n </div>\n </foreignObject>\n </svg>\n `],{type:"image/svg+xml;charset=utf-8"}),r=new FileReader;r.readAsDataURL(a),r.onload=function(e){var i;const o=null===(i=null==e?void 0:e.target)||void 0===i?void 0:i.result;t(o)},r.onerror=function(e){n(e)}}))}(e,t);return yield h(i)}))}function u(e){return"number"==typeof e&&(e>0||e<=0)}function g(e){return"number"==typeof e&&e>=0}function f(e){return"string"==typeof e&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${e}`)}function v(e){return"string"==typeof e&&/^(data:image\/)/.test(`${e}`)}const w={x:function(e){return u(e)},y:function(e){return u(e)},w:g,h:function(e){return"number"==typeof e&&e>=0},angle:function(e){return"number"==typeof e&&e>=-360&&e<=360},number:u,numberStr:function(e){return/^(-?\d+(?:\.\d+)?)$/.test(`${e}`)},borderWidth:function(e){return g(e)},borderRadius:function(e){return u(e)&&e>=0},color:function(e){return i(e)},imageSrc:function(e){return v(e)||f(e)},imageURL:f,imageBase64:v,svg:function(e){return"string"==typeof e&&/^(<svg[\s]{1,}|<svg>)/i.test(`${e}`.trim())&&/<\/[\s]{0,}svg>$/i.test(`${e}`.trim())},html:function(e){let t=!1;if("string"==typeof e){let i=document.createElement("div");i.innerHTML=e,i.children.length>0&&(t=!0),i=null}return t},text:function(e){return"string"==typeof e},fontSize:function(e){return u(e)&&e>0},lineHeight:function(e){return u(e)&&e>0},textAlign:function(e){return["center","left","right"].includes(e)},fontFamily:function(e){return"string"==typeof e&&e.length>0},fontWeight:function(e){return["bold"].includes(e)},strokeWidth:function(e){return u(e)&&e>0}};class x{constructor(e,t){this._devicePixelRatio=1;const{devicePixelRatio:i=1}=t;this._ctx=e,this._devicePixelRatio=i}$undoPixelRatio(e){return e/this._devicePixelRatio}$doPixelRatio(e){return this._devicePixelRatio*e}$getContext(){return this._ctx}$setFont(e){const t=[];e.fontWeight&&t.push(`${e.fontWeight}`),t.push(`${this.$doPixelRatio(e.fontSize||12)}px`),t.push(`${e.fontFamily||"sans-serif"}`),this._ctx.font=`${t.join(" ")}`}$resize(e){const{width:t,height:i,devicePixelRatio:o}=e,{canvas:n}=this._ctx;n.width=t*o,n.height=i*o,this._devicePixelRatio=o}get canvas(){return this._ctx.canvas}get fillStyle(){return this._ctx.fillStyle}set fillStyle(e){this._ctx.fillStyle=e}get strokeStyle(){return this._ctx.strokeStyle}set strokeStyle(e){this._ctx.strokeStyle=e}get lineWidth(){return this.$undoPixelRatio(this._ctx.lineWidth)}set lineWidth(e){this._ctx.lineWidth=this.$doPixelRatio(e)}get textAlign(){return this._ctx.textAlign}set textAlign(e){this._ctx.textAlign=e}get textBaseline(){return this._ctx.textBaseline}set textBaseline(e){this._ctx.textBaseline=e}get globalAlpha(){return this._ctx.globalAlpha}set globalAlpha(e){this._ctx.globalAlpha=e}get shadowColor(){return this._ctx.shadowColor}set shadowColor(e){this._ctx.shadowColor=e}get shadowOffsetX(){return this.$undoPixelRatio(this._ctx.shadowOffsetX)}set shadowOffsetX(e){this._ctx.shadowOffsetX=this.$doPixelRatio(e)}get shadowOffsetY(){return this.$undoPixelRatio(this._ctx.shadowOffsetY)}set shadowOffsetY(e){this._ctx.shadowOffsetY=this.$doPixelRatio(e)}get shadowBlur(){return this.$undoPixelRatio(this._ctx.shadowBlur)}set shadowBlur(e){this._ctx.shadowBlur=this.$doPixelRatio(e)}get lineCap(){return this._ctx.lineCap}set lineCap(e){this._ctx.lineCap=e}get globalCompositeOperation(){return this._ctx.globalCompositeOperation}set globalCompositeOperation(e){this._ctx.globalCompositeOperation=e}fill(...e){return this._ctx.fill(...e)}arc(e,t,i,o,n,a){return this._ctx.arc(this.$doPixelRatio(e),this.$doPixelRatio(t),this.$doPixelRatio(i),o,n,a)}rect(e,t,i,o){return this._ctx.rect(this.$doPixelRatio(e),this.$doPixelRatio(t),this.$doPixelRatio(i),this.$doPixelRatio(o))}fillRect(e,t,i,o){return this._ctx.fillRect(this.$doPixelRatio(e),this.$doPixelRatio(t),this.$doPixelRatio(i),this.$doPixelRatio(o))}clearRect(e,t,i,o){return this._ctx.clearRect(this.$doPixelRatio(e),this.$doPixelRatio(t),this.$doPixelRatio(i),this.$doPixelRatio(o))}beginPath(){return this._ctx.beginPath()}closePath(){return this._ctx.closePath()}lineTo(e,t){return this._ctx.lineTo(this.$doPixelRatio(e),this.$doPixelRatio(t))}moveTo(e,t){return this._ctx.moveTo(this.$doPixelRatio(e),this.$doPixelRatio(t))}arcTo(e,t,i,o,n){return this._ctx.arcTo(this.$doPixelRatio(e),this.$doPixelRatio(t),this.$doPixelRatio(i),this.$doPixelRatio(o),this.$doPixelRatio(n))}getLineDash(){return this._ctx.getLineDash()}setLineDash(e){return this._ctx.setLineDash(e.map((e=>this.$doPixelRatio(e))))}stroke(e){return e?this._ctx.stroke(e):this._ctx.stroke()}translate(e,t){return this._ctx.translate(this.$doPixelRatio(e),this.$doPixelRatio(t))}rotate(e){return this._ctx.rotate(e)}drawImage(...e){const t=e[0],i=e[1],o=e[2],n=e[3],a=e[4],r=e[e.length-4],s=e[e.length-3],l=e[e.length-2],h=e[e.length-1];return 9===e.length?this._ctx.drawImage(t,this.$doPixelRatio(i),this.$doPixelRatio(o),this.$doPixelRatio(n),this.$doPixelRatio(a),this.$doPixelRatio(r),this.$doPixelRatio(s),this.$doPixelRatio(l),this.$doPixelRatio(h)):this._ctx.drawImage(t,this.$doPixelRatio(r),this.$doPixelRatio(s),this.$doPixelRatio(l),this.$doPixelRatio(h))}createPattern(e,t){return this._ctx.createPattern(e,t)}measureText(e){return this._ctx.measureText(e)}fillText(e,t,i,o){return void 0!==o?this._ctx.fillText(e,this.$doPixelRatio(t),this.$doPixelRatio(i),this.$doPixelRatio(o)):this._ctx.fillText(e,this.$doPixelRatio(t),this.$doPixelRatio(i))}strokeText(e,t,i,o){return void 0!==o?this._ctx.strokeText(e,this.$doPixelRatio(t),this.$doPixelRatio(i),this.$doPixelRatio(o)):this._ctx.strokeText(e,this.$doPixelRatio(t),this.$doPixelRatio(i))}save(){this._ctx.save()}restore(){this._ctx.restore()}scale(e,t){this._ctx.scale(e,t)}circle(e,t,i,o,n,a,r,s){this._ctx.ellipse(this.$doPixelRatio(e),this.$doPixelRatio(t),this.$doPixelRatio(i),this.$doPixelRatio(o),n,a,r,s)}isPointInPath(e,t){return this._ctx.isPointInPath(this.$doPixelRatio(e),this.$doPixelRatio(t))}clip(...e){return this._ctx.clip(...e)}setTransform(e,t,i,o,n,a){return this._ctx.setTransform(e,t,i,o,n,a)}getTransform(){return this._ctx.getTransform()}createLinearGradient(e,t,i,o){return this._ctx.createLinearGradient(this.$doPixelRatio(e),this.$doPixelRatio(t),this.$doPixelRatio(i),this.$doPixelRatio(o))}createRadialGradient(e,t,i,o,n,a){return this._ctx.createRadialGradient(this.$doPixelRatio(e),this.$doPixelRatio(t),this.$doPixelRatio(i),this.$doPixelRatio(o),this.$doPixelRatio(n),this.$doPixelRatio(a))}createConicGradient(e,t,i){return this._ctx.createConicGradient(e,this.$doPixelRatio(t),this.$doPixelRatio(i))}}function S(e){const{width:t,height:i,ctx:o,devicePixelRatio:n}=e;let a=o;if(!a){const e=document.createElement("canvas");e.width=t*n,e.height=i*n,a=e.getContext("2d")}return new x(a,e)}class m{constructor(){this._listeners=new Map}on(e,t){if(this._listeners.has(e)){const i=this._listeners.get(e)||[];null==i||i.push(t),this._listeners.set(e,i)}else this._listeners.set(e,[t])}off(e,t){if(this._listeners.has(e)){const i=this._listeners.get(e);if(Array.isArray(i))for(let e=0;e<(null==i?void 0:i.length);e++)if(i[e]===t){i.splice(e,1);break}this._listeners.set(e,i||[])}}trigger(e,t){const i=this._listeners.get(e);return!!Array.isArray(i)&&(i.forEach((e=>{e(t)})),!0)}has(e){if(this._listeners.has(e)){const t=this._listeners.get(e);if(Array.isArray(t)&&t.length>0)return!0}return!1}}function y(e,t){return{x:e.x+(t.x-e.x)/2,y:e.y+(t.y-e.y)/2}}class p{constructor(e){this._backUpDefaultStorage=n(e.defaultStorage),this._temp=this._createTempStorage()}set(e,t){this._temp[e]=t}get(e){return this._temp[e]}getSnapshot(){return n(this._temp)}clear(){this._temp=this._createTempStorage()}_createTempStorage(){return n(this._backUpDefaultStorage)}}function b(e){return e/180*Math.PI}function I(e,t,i){const o=M(t),n=b(t.angle||0);o&&(n>0||n<0)&&(e.translate(o.x,o.y),e.rotate(n),e.translate(-o.x,-o.y)),i(e),o&&(n>0||n<0)&&(e.translate(o.x,o.y),e.rotate(-n),e.translate(-o.x,-o.y))}function M(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}function A(e){const t=Math.min(e[0].x,e[1].x,e[2].x,e[3].x),i=Math.min(e[0].y,e[1].y,e[2].y,e[3].y);return M({x:t,y:i,w:Math.max(e[0].x,e[1].x,e[2].x,e[3].x)-t,h:Math.max(e[0].y,e[1].y,e[2].y,e[3].y)-i})}function _(e,t,i){const o=function(e,t){const i=t.x-e.x,o=t.y-e.y;if(0===i){if(o<0)return 0;if(o>0)return Math.PI}else if(0===o){if(i<0)return 3*Math.PI/2;if(i>0)return Math.PI/2}return i>0&&o<0?Math.atan(Math.abs(i)/Math.abs(o)):i>0&&o>0?Math.PI-Math.atan(Math.abs(i)/Math.abs(o)):i<0&&o>0?Math.PI+Math.atan(Math.abs(i)/Math.abs(o)):i<0&&o<0?2*Math.PI-Math.atan(Math.abs(i)/Math.abs(o)):0}(e,t);let n=o+i;n>2*Math.PI?n-=2*Math.PI:n<0-2*Math.PI&&(n+=2*Math.PI),n<0&&(n+=2*Math.PI);const a=function(e,t){const i=(e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y);return 0===i?i:Math.sqrt(i)}(e,t);let r=0,s=0;return 0===n?(r=0,s=0-a):n>0&&n<Math.PI/2?(r=Math.sin(n)*a,s=0-Math.cos(n)*a):n===Math.PI/2?(r=a,s=0):n>Math.PI/2&&n<Math.PI?(r=Math.sin(Math.PI-n)*a,s=Math.cos(Math.PI-n)*a):n===Math.PI?(r=0,s=a):n>Math.PI&&n<1.5*Math.PI?(r=0-Math.sin(n-Math.PI)*a,s=Math.cos(n-Math.PI)*a):n===1.5*Math.PI?(r=0-a,s=0):n>1.5*Math.PI&&n<2*Math.PI?(r=0-Math.sin(2*Math.PI-n)*a,s=0-Math.cos(2*Math.PI-n)*a):n===2*Math.PI&&(r=0,s=0-a),r+=e.x,s+=e.y,{x:r,y:s}}function z(e,t){if((null==t?void 0:t.length)>0){let i=e.x,o=e.y;return t.forEach((e=>{const{x:t,y:n,w:a,h:r,angle:s=0}=e,l=_(M({x:t,y:n,w:a,h:r,angle:s}),{x:i,y:o},b(s));i=l.x,o=l.y})),{x:i,y:o}}return e}function R(e,t,i){const{x:o,y:n,w:a,h:r}=e;let s={x:o,y:n},l={x:o+a,y:n},h={x:o+a,y:n+r},c={x:o,y:n+r};if(i&&(i>0||i<0)){const e=b(O(i));s=_(t,s,e),l=_(t,l,e),h=_(t,h,e),c=_(t,c,e)}return[s,l,h,c]}function P(e){const{angle:t=0}=e;return R(e,M(e),t)}function T(e,t,i){return[_(e,{x:t[0].x,y:t[0].y},i),_(e,{x:t[1].x,y:t[1].y},i),_(e,{x:t[2].x,y:t[2].y},i),_(e,{x:t[3].x,y:t[3].y},i)]}function O(e){if(!(e>0||e<0)||0===e)return 0;let t=e%360;return t<0&&(t+=360),t}function E(e){let t=!0;if(Array.isArray(e)){const i=[];e.forEach((e=>{var o;"string"==typeof e.uuid&&e.uuid?i.includes(e.uuid)?(t=!1,console.warn(`Duplicate uuids: ${e.uuid}`)):i.push(e.uuid):(t=!1,console.warn("Element missing uuid",e)),"group"===e.type&&(t=E(null===(o=null==e?void 0:e.detail)||void 0===o?void 0:o.children))}))}return t}function j(e,t){const i={x:0,y:0,w:0,h:0};e.forEach((e=>{const t={x:e.x,y:e.y,w:e.w,h:e.h,angle:e.angle};if(t.angle&&(t.angle>0||t.angle<0)){const e=P(t);if(4===e.length){const i=[e[0].x,e[1].x,e[2].x,e[3].x],o=[e[0].y,e[1].y,e[2].y,e[3].y];t.x=Math.min(...i),t.y=Math.min(...o),t.w=Math.abs(Math.max(...i)-Math.min(...i)),t.h=Math.abs(Math.max(...o)-Math.min(...o))}}const o=Math.min(t.x,i.x),n=Math.min(t.y,i.y),a=Math.max(t.x+t.w,i.x+i.w),r=Math.max(t.y+t.h,i.y+i.h);i.x=o,i.y=n,i.w=Math.abs(a-o),i.h=Math.abs(r-n)})),(null==t?void 0:t.extend)&&(i.x=Math.min(i.x,0),i.y=Math.min(i.y,0));const o={contextWidth:i.w,contextHeight:i.h};return(null==t?void 0:t.viewWidth)&&(null==t?void 0:t.viewHeight)&&(null==t?void 0:t.viewWidth)>0&&(null==t?void 0:t.viewHeight)>0&&(t.viewWidth>i.x+i.w&&(o.contextWidth=t.viewWidth-i.x),t.viewHeight>i.y+i.h&&(o.contextHeight=t.viewHeight-i.y)),o}function W(e,t){const{viewScaleInfo:i}=t,{x:o,y:n,w:a,h:r,angle:s}=e,{scale:l,offsetTop:h,offsetLeft:c}=i;return{x:o*l+c,y:n*l+h,w:a*l,h:r*l,angle:s}}function L(e,t){const{viewScaleInfo:i}=t,{x:o,y:n}=e,{scale:a,offsetTop:r,offsetLeft:s}=i;return{x:o*a+s,y:n*a+r}}function C(e,t){return[L(e[0],t),L(e[1],t),L(e[2],t),L(e[3],t)]}function D(e,t){const{context2d:i,element:o,viewScaleInfo:n,viewSizeInfo:a}=t,{angle:r=0}=o,{x:s,y:l,w:h,h:c}=W(o,{viewScaleInfo:n,viewSizeInfo:a}),d=P({x:s,y:l,w:h,h:c,angle:r});if(d.length>=2){i.beginPath(),i.moveTo(d[0].x,d[0].y);for(let e=1;e<d.length;e++)i.lineTo(d[e].x,d[e].y);i.closePath()}return!!i.isPointInPath(e.x,e.y)}function Y(e){const{x:t,y:i,h:o,w:n}=e;return[{x:t,y:i},{x:t+n,y:i},{x:t+n,y:i+o},{x:t,y:i+o}]}function G(e){const{x:t,y:i,w:o,h:n,angle:a=0}=e;return 0===a?Y(e):R(e,M({x:t,y:i,w:o,h:n,angle:a}),a)}function k(e){const t=[];let i=0,o=0;const n=[],a=[...e];for(let e=0;e<a.length;e++){const{x:r,y:s,w:l,h:h,angle:c=0}=a[e];let d;if(i+=r,o+=s,0===e){const e={x:i,y:o,w:l,h:h,angle:c};d=G({x:r,y:s,w:l,h:h,angle:c}),n.push({center:M(e),angle:c,radian:b(c)})}else{d=Y({x:i,y:o,w:l,h:h,angle:c});for(let e=0;e<n.length;e++){const{center:t,radian:i}=n[e];d=T(t,d,i)}const e=A(d);if(c>0||c<0){d=T(e,d,b(c))}n.push({center:e,angle:c,radian:b(c)})}t.push(d)}return t}function F(e,t){const i=function(e,t){const{groupQueue:i}=t;return i.length>0?k([...i,e]):[G(e)]}(e,t);return i.pop()||null}function B(e,t){const{x:i,y:o}=e,{size:n,angle:a}=t;return{x:i-n/2,y:o-n/2,w:n,h:n,angle:a}}function Z(e,t){const{groupQueue:i,controllerSize:n,viewScaleInfo:a}=t,r=(n&&n>0?n:8)/a.scale,{x:s,y:l,w:h,h:c,angle:d=0}=e,u=[{uuid:o(),x:s,y:l,w:h,h:c,angle:d,type:"group",detail:{children:[]}},...i];let g=0;u.forEach((({angle:e=0})=>{g+=e}));const f=F(e,{groupQueue:i}),v=y(f[0],f[1]),w=y(f[1],f[2]),x=y(f[2],f[3]),S=y(f[3],f[0]),m=f[0],p=f[1],b=f[2],I=f[3],M=B(v,{size:r,angle:g}),A=B(w,{size:r,angle:g}),_=B(x,{size:r,angle:g}),z=B(S,{size:r,angle:g}),R=B(m,{size:r,angle:g}),P=B(p,{size:r,angle:g}),T=B(I,{size:r,angle:g}),O=B(b,{size:r,angle:g});return{elementWrapper:f,left:{type:"left",vertexes:G(z),center:S},right:{type:"right",vertexes:G(A),center:w},top:{type:"top",vertexes:G(M),center:v},bottom:{type:"bottom",vertexes:G(_),center:x},topLeft:{type:"top-left",vertexes:G(R),center:m},topRight:{type:"top-right",vertexes:G(P),center:p},bottomLeft:{type:"bottom-left",vertexes:G(T),center:I},bottomRight:{type:"bottom-right",vertexes:G(O),center:b}}}function X(e){let t="";return e.forEach((e=>{t+=e.type+e.params.join(" ")})),t}function N(e,t,o){var n,a;void 0!==(null===(n=null==t?void 0:t.detail)||void 0===n?void 0:n.opacity)&&(null===(a=null==t?void 0:t.detail)||void 0===a?void 0:a.opacity)>0?e.globalAlpha=t.detail.opacity:e.globalAlpha=1;const{pattern:s,renderContent:l,originElem:h,calcElemSize:c,viewScaleInfo:d,viewSizeInfo:u}=o||{};!function(e,t,i){const{renderContent:o,originElem:n,calcElemSize:a,viewScaleInfo:r,viewSizeInfo:s}=i,l=r.scale*s.devicePixelRatio,{clipPath:h}=(null==n?void 0:n.detail)||{};if(h&&a&&h.commands){const{x:i,y:n,w:r,h:s}=a,{originW:c,originH:d,originX:u,originY:g}=h,f=r/c,v=s/d;let w=i-u*f,x=n-g*v;e.save(),e.translate(w,x),e.scale(l*f,l*v);const S=X(h.commands||[]),m=new Path2D(S);e.clip(m),e.translate(0-w,0-x),e.setTransform(1,0,0,1,0,0),I(e,Object.assign({},t),(()=>{null==o||o()})),e.restore()}else null==o||o()}(e,t,{originElem:h,calcElemSize:c,viewScaleInfo:d,viewSizeInfo:u,renderContent:()=>{!function(e,t,o){if(!i(t.detail.borderColor))return;const{viewScaleInfo:n}=o;let a="#000000";!0===i(t.detail.borderColor)&&(a=t.detail.borderColor);const{borderWidth:r,borderRadius:s,borderDash:l}=t.detail;let h=0;"number"==typeof r&&(h=r||1);h*=n.scale;let c=s||0;e.strokeStyle=a,e.setLineDash(l||[]);let d=0,u=0,g=0,f=0;Array.isArray(r)&&(d=r[0]||0,u=r[1]||0,g=r[2]||0,f=r[3]||0);if(f||u||d||g){const{x:i,y:o,w:a,h:r}=t;f&&(e.beginPath(),e.lineWidth=f*n.scale,e.moveTo(i,o),e.lineTo(i,o+r),e.closePath(),e.stroke()),u&&(e.beginPath(),e.lineWidth=u*n.scale,e.moveTo(i+a,o),e.lineTo(i+a,o+r),e.closePath(),e.stroke()),d&&(e.beginPath(),e.lineWidth=d*n.scale,e.moveTo(i,o),e.lineTo(i+a,o),e.closePath(),e.stroke()),g&&(e.beginPath(),e.lineWidth=g*n.scale,e.moveTo(i,o+r),e.lineTo(i+a,o+r),e.closePath(),e.stroke())}else{let{x:i,y:o,w:n,h:a}=t;const{boxSizing:r}=t.detail;"border-box"===r?(i=t.x,o=t.y,n=t.w,a=t.h):(i=t.x-h,o=t.y-h,n=t.w+2*h,a=t.h+2*h),c=Math.min(c,n/2,a/2),c<n/2&&c<a/2&&(c+=h/2),e.beginPath(),e.lineWidth=h,e.moveTo(i+c,o),e.arcTo(i+n,o,i+n,o+a,c),e.arcTo(i+n,o+a,i,o+a,c),e.arcTo(i,o+a,i,o,c),e.arcTo(i,o,i+n,o,c),e.closePath(),e.stroke()}}(e,t,{viewScaleInfo:d,viewSizeInfo:u}),function(e,t,i){var o,n;const{pattern:a,viewScaleInfo:s}=i;let l=[];if(t.detail.background||a){const{x:i,y:h,w:c,h:d}=t;let u=(t.detail.borderRadius||0)*s.scale;if(u=Math.min(u,c/2,d/2),(c<2*u||d<2*u)&&(u=0),e.beginPath(),e.moveTo(i+u,h),e.arcTo(i+c,h,i+c,h+d,u),e.arcTo(i+c,h+d,i,h+d,u),e.arcTo(i,h+d,i,h,u),e.arcTo(i,h,i+c,h,u),e.closePath(),"string"==typeof a)e.fillStyle=a;else if(["CanvasPattern"].includes(r.type(a)))e.fillStyle=a;else if("string"==typeof t.detail.background)e.fillStyle=t.detail.background;else if("linearGradient"===(null===(o=t.detail.background)||void 0===o?void 0:o.type)){const{start:o,end:n,stops:a}=t.detail.background,r={x:o.x+i,y:o.y+h},s={x:n.x+i,y:n.y+h},l=e.createLinearGradient(r.x,r.y,s.x,s.y);a.forEach((e=>{l.addColorStop(e.offset,e.color)})),e.fillStyle=l}else if("radialGradient"===(null===(n=t.detail.background)||void 0===n?void 0:n.type)){const{inner:o,outer:n,stops:a}=t.detail.background;l=t.detail.background.transform||[];const r={x:o.x,y:o.y,radius:o.radius*s.scale},c={x:n.x,y:n.y,radius:n.radius*s.scale},d=e.createRadialGradient(r.x,r.y,r.radius,c.x,c.y,c.radius);if(a.forEach((e=>{d.addColorStop(e.offset,e.color)})),e.fillStyle=d,l&&l.length>0)for(let t=0;t<(null==l?void 0:l.length);t++){const o=l[t];"translate"===o.method?e.translate(o.args[0]+i,o.args[1]+h):"rotate"===o.method?e.rotate(...o.args):"scale"===o.method&&e.scale(...o.args)}}e.fill(),l&&l.length>0&&e.setTransform(1,0,0,1,0,0)}}(e,t,{pattern:s,viewScaleInfo:d,viewSizeInfo:u}),null==l||l()}}),e.globalAlpha=1}function V(e,t,i){const{detail:o}=t,{viewScaleInfo:n,renderContent:a}=i,{shadowColor:r,shadowOffsetX:s,shadowOffsetY:l,shadowBlur:h}=o;w.number(h)?(e.save(),e.shadowColor=r||"#000000",e.shadowOffsetX=(s||0)*n.scale,e.shadowOffsetY=(l||0)*n.scale,e.shadowBlur=(h||0)*n.scale,a(),e.restore()):a()}function H(e,t,o){var n;if(!0!==(null===(n=null==t?void 0:t.operations)||void 0===n?void 0:n.invisible))try{switch(t.type){case"rect":!function(e,t,i){const{calculator:o,viewScaleInfo:n,viewSizeInfo:a}=i;let{x:r,y:s,w:l,h:h,angle:c}=o.elementSize(t,n,a);const d=Object.assign(Object.assign({},t),{x:r,y:s,w:l,h:h,angle:c});I(e,{x:r,y:s,w:l,h:h,angle:c},(()=>{V(e,d,{viewScaleInfo:n,viewSizeInfo:a,renderContent:()=>{N(e,d,{originElem:t,calcElemSize:{x:r,y:s,w:l,h:h,angle:c},viewScaleInfo:n,viewSizeInfo:a,renderContent:()=>{}})}})}))}(e,t,o);break;case"circle":!function(e,t,i){const{detail:o,angle:n}=t,{background:a="#000000",borderColor:r="#000000",borderWidth:s=0}=o,{calculator:l,viewScaleInfo:h,viewSizeInfo:c}=i,{x:d,y:u,w:g,h:f}=l.elementSize({x:t.x,y:t.y,w:t.w,h:t.h},h,c);I(e,{x:d,y:u,w:g,h:f,angle:n},(()=>{const t=g/2,i=f/2,o=d+t,n=u+i;if(s&&s>0){const a=s/2+t,l=s/2+i;e.beginPath(),e.strokeStyle=r,e.lineWidth=s,e.circle(o,n,a,l,0,0,2*Math.PI),e.closePath(),e.stroke()}e.beginPath(),e.fillStyle=a,e.circle(o,n,t,i,0,0,2*Math.PI),e.closePath(),e.fill()}))}(e,t,o);break;case"text":!function(e,t,o){const{calculator:n,viewScaleInfo:a,viewSizeInfo:r}=o,{x:s,y:l,w:h,h:c,angle:d}=n.elementSize(t,a,r),u=Object.assign(Object.assign({},t),{x:s,y:l,w:h,h:c,angle:d});I(e,{x:s,y:l,w:h,h:c,angle:d},(()=>{N(e,u,{originElem:t,calcElemSize:{x:s,y:l,w:h,h:c,angle:d},viewScaleInfo:a,viewSizeInfo:r,renderContent:()=>{const o=Object.assign({fontSize:12,fontFamily:"sans-serif",textAlign:"center"},t.detail),n=o.fontSize*a.scale,r=o.lineHeight?o.lineHeight*a.scale:n;e.fillStyle=t.detail.color,e.textBaseline="top",e.$setFont({fontWeight:o.fontWeight,fontSize:n,fontFamily:o.fontFamily});const d=o.text.replace(/\r\n/gi,"\n"),u=r,g=d.split("\n"),f=[];let v=0;g.forEach(((t,i)=>{let o="";if(t.length>0){for(let n=0;n<t.length&&(e.measureText(o+(t[n]||"")).width<e.$doPixelRatio(h)?o+=t[n]||"":(f.push({text:o,width:e.$undoPixelRatio(e.measureText(o).width)}),o=t[n]||"",v++),!((v+1)*u>c));n++)if(t.length-1===n&&(v+1)*u<c){f.push({text:o,width:e.$undoPixelRatio(e.measureText(o).width)}),i<g.length-1&&v++;break}}else f.push({text:"",width:0})}));let x=0;f.length*u<c&&("top"===t.detail.verticalAlign?x=0:"bottom"===t.detail.verticalAlign?x+=c-f.length*u:x+=(c-f.length*u)/2);{const t=l+x;void 0!==o.textShadowColor&&i(o.textShadowColor)&&(e.shadowColor=o.textShadowColor),void 0!==o.textShadowOffsetX&&w.number(o.textShadowOffsetX)&&(e.shadowOffsetX=o.textShadowOffsetX),void 0!==o.textShadowOffsetY&&w.number(o.textShadowOffsetY)&&(e.shadowOffsetY=o.textShadowOffsetY),void 0!==o.textShadowBlur&&w.number(o.textShadowBlur)&&(e.shadowBlur=o.textShadowBlur),f.forEach(((i,n)=>{let a=s;"center"===o.textAlign?a=s+(h-i.width)/2:"right"===o.textAlign&&(a=s+(h-i.width)),e.fillText(i.text,a,t+u*n)}))}}})}))}(e,t,o);break;case"image":!function(e,t,i){const o=i.loader.getContent(t.uuid),{calculator:n,viewScaleInfo:a,viewSizeInfo:r}=i,{x:s,y:l,w:h,h:c,angle:d}=n.elementSize(t,a,r);I(e,{x:s,y:l,w:h,h:c,angle:d},(()=>{o||i.loader.load(t,i.elementAssets||{}),"image"===t.type&&o&&e.drawImage(o,s,l,h,c)}))}(e,t,o);break;case"svg":!function(e,t,i){const o=i.loader.getContent(t.uuid),{calculator:n,viewScaleInfo:a,viewSizeInfo:r}=i,{x:s,y:l,w:h,h:c,angle:d}=n.elementSize(t,a,r);I(e,{x:s,y:l,w:h,h:c,angle:d},(()=>{o||i.loader.load(t,i.elementAssets||{}),"svg"===t.type&&o&&e.drawImage(o,s,l,h,c)}))}(e,t,o);break;case"html":!function(e,t,i){const o=i.loader.getContent(t.uuid),{calculator:n,viewScaleInfo:a,viewSizeInfo:r}=i,{x:s,y:l,w:h,h:c,angle:d}=n.elementSize(t,a,r);I(e,{x:s,y:l,w:h,h:c,angle:d},(()=>{o||i.loader.load(t),"html"===t.type&&o&&e.drawImage(o,s,l,h,c)}))}(e,t,o);break;case"path":!function(e,t,i){const{detail:o}=t,{originX:n,originY:a,originW:r,originH:s}=o,{calculator:l,viewScaleInfo:h,viewSizeInfo:c}=i,{x:d,y:u,w:g,h:f,angle:v}=l.elementSize(t,h,c),w=g/r,x=f/s,S=d-n*w,m=u-a*x,y=h.scale*c.devicePixelRatio,p=Object.assign(Object.assign({},t),{x:d,y:u,w:g,h:f,angle:v});I(e,{x:d,y:u,w:g,h:f,angle:v},(()=>{N(e,p,{originElem:t,calcElemSize:{x:d,y:u,w:g,h:f,angle:v},viewScaleInfo:h,viewSizeInfo:c,renderContent:()=>{V(e,p,{viewScaleInfo:h,viewSizeInfo:c,renderContent:()=>{e.save(),e.translate(S,m),e.scale(y*w/h.scale,y*x/h.scale);const t=X(o.commands||[]),i=new Path2D(t);o.fill&&(e.fillStyle=o.fill,e.fill(i)),o.stroke&&0!==o.strokeWidth&&(e.strokeStyle=o.stroke,e.lineWidth=(o.strokeWidth||1)/c.devicePixelRatio,e.lineCap=o.strokeLineCap||"square",e.stroke(i)),e.translate(-S,-m),e.restore()}})}})}))}(e,t,o);break;case"group":!function(e,t,i){const{calculator:o,viewScaleInfo:n,viewSizeInfo:a}=i,{x:r,y:s,w:l,h:h,angle:c}=o.elementSize({x:t.x,y:t.y,w:t.w,h:t.h,angle:t.angle},n,a),d=Object.assign(Object.assign({},t),{x:r,y:s,w:l,h:h,angle:c});I(e,{x:r,y:s,w:l,h:h,angle:c},(()=>{N(e,d,{originElem:t,calcElemSize:{x:r,y:s,w:l,h:h,angle:c},viewScaleInfo:n,viewSizeInfo:a,renderContent:()=>{if(Array.isArray(t.detail.children)){const{parentElementSize:o}=i,n={x:o.x+t.x,y:o.y+t.y,w:t.w||o.w,h:t.h||o.h,angle:t.angle},{calculator:a}=i;"hidden"===t.detail.overflow&&(e.save(),e.beginPath(),e.moveTo(r,s),e.lineTo(r+l,s),e.lineTo(r+l,s+h),e.lineTo(r,s+h),e.closePath(),e.clip());for(let o=0;o<t.detail.children.length;o++){let r=t.detail.children[o];if(r=Object.assign(Object.assign({},r),{x:n.x+r.x,y:n.y+r.y}),a.isElementInView(r,i.viewScaleInfo,i.viewSizeInfo))try{H(e,r,Object.assign({},i))}catch(e){console.error(e)}}e.restore()}}})}))}(e,t,o)}}catch(e){console.error(e)}}var $=globalThis&&globalThis.__awaiter||function(e,t,i,o){return new(i||(i=Promise))((function(n,a){function r(e){try{l(o.next(e))}catch(e){a(e)}}function s(e){try{l(o.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,s)}l((o=o.apply(e,t||[])).next())}))};const Q=["image","svg","html"];class U extends m{constructor(){super(),this._loadFuncMap={},this._currentLoadItemMap={},this._storageLoadItemMap={},this._registerLoadFunc("image",((e,t)=>$(this,void 0,void 0,(function*(){var i;const o=(null===(i=t[e.detail.src])||void 0===i?void 0:i.value)||e.detail.src,n=yield h(o);return{uuid:e.uuid,lastModified:Date.now(),content:n}})))),this._registerLoadFunc("html",((e,t)=>$(this,void 0,void 0,(function*(){var i;const o=(null===(i=t[e.detail.html])||void 0===i?void 0:i.value)||e.detail.html,n=yield d(o,{width:e.detail.width||e.w,height:e.detail.height||e.h});return{uuid:e.uuid,lastModified:Date.now(),content:n}})))),this._registerLoadFunc("svg",((e,t)=>$(this,void 0,void 0,(function*(){var i;const o=(null===(i=t[e.detail.svg])||void 0===i?void 0:i.value)||e.detail.svg,n=yield c(o);return{uuid:e.uuid,lastModified:Date.now(),content:n}}))))}_registerLoadFunc(e,t){this._loadFuncMap[e]=t}_getLoadElementSource(e){var t,i,o;let n=null;return"image"===e.type?n=(null===(t=null==e?void 0:e.detail)||void 0===t?void 0:t.src)||null:"svg"===e.type?n=(null===(i=null==e?void 0:e.detail)||void 0===i?void 0:i.svg)||null:"html"===e.type&&(n=(null===(o=null==e?void 0:e.detail)||void 0===o?void 0:o.html)||null),n}_createLoadItem(e){return{element:e,status:"null",content:null,error:null,startTime:-1,endTime:-1,source:this._getLoadElementSource(e)}}_emitLoad(e){const t=e.element.uuid,i=this._storageLoadItemMap[t];i?i.startTime<e.startTime&&(this._storageLoadItemMap[t]=e,this.trigger("load",Object.assign(Object.assign({},e),{countTime:e.endTime-e.startTime}))):(this._storageLoadItemMap[t]=e,this.trigger("load",Object.assign(Object.assign({},e),{countTime:e.endTime-e.startTime})))}_emitError(e){const t=e.element.uuid,i=this._storageLoadItemMap[t];i?i.startTime<e.startTime&&(this._storageLoadItemMap[t]=e,this.trigger("error",Object.assign(Object.assign({},e),{countTime:e.endTime-e.startTime}))):(this._storageLoadItemMap[t]=e,this.trigger("error",Object.assign(Object.assign({},e),{countTime:e.endTime-e.startTime})))}_loadResource(e,t){const i=this._createLoadItem(e);this._currentLoadItemMap[e.uuid]=i;const o=this._loadFuncMap[e.type];"function"==typeof o&&(i.startTime=Date.now(),o(e,t).then((e=>{i.content=e.content,i.endTime=Date.now(),i.status="load",this._emitLoad(i)})).catch((t=>{console.warn(`Load element source "${i.source}" fail`,t,e),i.endTime=Date.now(),i.status="error",i.error=t,this._emitError(i)})))}_isExistingErrorStorage(e){var t;const i=null===(t=this._currentLoadItemMap)||void 0===t?void 0:t[null==e?void 0:e.uuid];return!(!i||"error"!==i.status||!i.source||i.source!==this._getLoadElementSource(e))}load(e,t){if(!this._isExistingErrorStorage(e)&&Q.includes(e.type)){const i=n(e);this._loadResource(i,t)}}getContent(e){var t,i;return(null===(i=null===(t=this._storageLoadItemMap)||void 0===t?void 0:t[e])||void 0===i?void 0:i.content)||null}}class J extends m{constructor(e){super(),this._loader=new U,this._opts=e,this._init()}_init(){const{_loader:e}=this;e.on("load",(e=>{this.trigger("load",e)})),e.on("error",(()=>{}))}updateOptions(e){this._opts=e}drawData(e,t){const{_loader:i}=this,{calculator:o}=this._opts,{viewContext:n}=this._opts.viewContent;n.clearRect(0,0,n.canvas.width,n.canvas.height);const a={x:0,y:0,w:t.viewSizeInfo.width,h:t.viewSizeInfo.height};!function(e,t,i){const{elements:o=[]}=t;for(let t=0;t<o.length;t++){const n=o[t];if(i.calculator.isElementInView(n,i.viewScaleInfo,i.viewSizeInfo))try{H(e,n,i)}catch(e){console.error(e)}}}(n,e,Object.assign({loader:i,calculator:o,parentElementSize:a,elementAssets:e.assets},t))}scale(e){const{sharer:t}=this._opts,{data:i,offsetTop:o,offsetBottom:n,offsetLeft:a,offsetRight:r,width:s,height:l,contextHeight:h,contextWidth:c,devicePixelRatio:d}=t.getActiveStoreSnapshot();i&&this.drawData(i,{viewScaleInfo:{scale:e,offsetTop:o,offsetBottom:n,offsetLeft:a,offsetRight:r},viewSizeInfo:{width:s,height:l,contextHeight:h,contextWidth:c,devicePixelRatio:d}})}}class K{constructor(e){this._opts=e}elementSize(e,t,i){return W(e,{viewScaleInfo:t,viewSizeInfo:i})}isElementInView(e,t,i){return function(e,t){const{viewSizeInfo:i,viewScaleInfo:o}=t,{width:n,height:a}=i,{angle:r}=e,{x:s,y:l,w:h,h:c}=W(e,{viewScaleInfo:o,viewSizeInfo:i}),d=P({x:s,y:l,w:h,h:c,angle:r}),u={x:0,y:0,w:n,h:a},g=Math.min(d[0].x,d[1].x,d[2].x,d[3].x),f=Math.min(d[0].y,d[1].y,d[2].y,d[3].y);return function(e,t){const i=e.x,o=e.y,n=e.x+e.w,a=e.y+e.h,r=t.x,s=t.y,l=t.x+t.w,h=t.y+t.h;return i<=l&&n>=r&&o<=h&&a>=s}(u,{x:g,y:f,w:Math.max(d[0].x,d[1].x,d[2].x,d[3].x)-g,h:Math.max(d[0].y,d[1].y,d[2].y,d[3].y)-f})}(e,{viewScaleInfo:t,viewSizeInfo:i})}isPointInElement(e,t,i,o){return D(e,{context2d:this._opts.viewContent.boardContext,element:t,viewScaleInfo:i,viewSizeInfo:o})}getPointElement(e,t){const i=this._opts.viewContent.boardContext;return function(e,t){var i,o,n;const{context2d:a,data:r,viewScaleInfo:s,viewSizeInfo:l,groupQueue:h}=t,c={index:-1,element:null,groupQueueIndex:-1};if(h&&Array.isArray(h)&&(null==h?void 0:h.length)>0)for(let t=h.length-1;t>=0;t--){let n=0,r=0,d=0;for(let e=0;e<=t;e++)n+=h[e].x,r+=h[e].y,d+=h[e].angle||0;const u=h[t];if(u&&"group"===u.type&&Array.isArray(null===(i=u.detail)||void 0===i?void 0:i.children))for(let i=0;i<u.detail.children.length;i++){const g=u.detail.children[i];if(!0!==(null===(o=null==g?void 0:g.operations)||void 0===o?void 0:o.invisible)){if(!g)break;if(D(e,{context2d:a,element:{x:n+g.x,y:r+g.y,w:g.w,h:g.h,angle:d+(g.angle||0)},viewScaleInfo:s,viewSizeInfo:l})){c.element=g,(t<h.length-1||"group"!==g.type)&&(c.groupQueueIndex=t);break}}}if(c.element)break}if(c.element)return c;for(let t=r.elements.length-1;t>=0;t--){const i=r.elements[t];if(!0!==(null===(n=null==i?void 0:i.operations)||void 0===n?void 0:n.invisible)&&D(e,{context2d:a,element:i,viewScaleInfo:s,viewSizeInfo:l})){c.index=t,c.element=i;break}}return c}(e,Object.assign(Object.assign({},t),{context2d:i}))}}function q(e){return e>0||e<0||0===e}class ee extends m{constructor(e){super();const t=new p({defaultStorage:{hasPointDown:!1,prevClickPoint:null}});this._store=t,this._opts=e,this._init()}_init(){const e=window;e.addEventListener("mousemove",(e=>{if(!this._isInTarget(e))return;e.preventDefault();const t=this._getPoint(e);this._isVaildPoint(t)&&this.trigger("hover",{point:t})})),e.addEventListener("mousedown",(e=>{if(!this._isInTarget(e))return;e.preventDefault();const t=this._getPoint(e);this._isVaildPoint(t)&&(this._store.set("hasPointDown",!0),this.trigger("pointStart",{point:t}))})),e.addEventListener("mousemove",(e=>{if(!this._isInTarget(e))return;e.preventDefault(),e.stopPropagation();const t=this._getPoint(e);this._isVaildPoint(t)?!0===this._store.get("hasPointDown")&&this.trigger("pointMove",{point:t}):this._store.get("hasPointDown")&&(this.trigger("pointLeave",{point:t}),this._store.set("hasPointDown",!1))})),e.addEventListener("mouseup",(e=>{if(this._store.set("hasPointDown",!1),!this._isInTarget(e))return;e.preventDefault();const t=this._getPoint(e);this.trigger("pointEnd",{point:t})})),e.addEventListener("mouseleave",(e=>{if(this._store.set("hasPointDown",!1),!this._isInTarget(e))return;e.preventDefault();const t=this._getPoint(e);this.trigger("pointLeave",{point:t})})),e.addEventListener("wheel",(e=>{if(!this._isInTarget(e))return;const t=this._getPoint(e);if(!this._isVaildPoint(t))return;e.preventDefault();const i=e.deltaX>0||e.deltaX<0?e.deltaX:0,o=e.deltaY>0||e.deltaY<0?e.deltaY:0;!0===e.ctrlKey&&this.has("wheelScale")?this.trigger("wheelScale",{deltaX:i,deltaY:o,point:t}):this.has("wheelX")&&0!==i?this.trigger("wheelX",{deltaX:i,point:t}):this.has("wheelY")&&0!==o&&this.trigger("wheelY",{deltaY:o,point:t})}),{passive:!1}),e.addEventListener("click",(e=>{if(!this._isInTarget(e))return;e.preventDefault();const t=this._getPoint(e);if(!this._isVaildPoint(t))return;const i=Date.now(),o=this._store.get("prevClickPoint");o&&i-o.t<=500&&Math.abs(o.x-t.x)<=5&&Math.abs(o.y-t.y)<=5?this.trigger("doubleClick",{point:t}):this._store.set("prevClickPoint",t)})),e.addEventListener("contextmenu",(e=>{if(!this._isInTarget(e))return;e.preventDefault();const t=this._getPoint(e);this._isVaildPoint(t)}))}_isInTarget(e){return e.target===this._opts.viewContent.boardContext.canvas}_getPoint(e){const t=this._opts.viewContent.boardContext.canvas.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top,t:Date.now()}}_isVaildPoint(e){const t=this._opts.sharer.getActiveViewSizeInfo(),{width:i,height:o}=t;return!!(q(e.x)&&q(e.y)&&e.x<=i&&e.y<=o)}}const te={width:0,height:0,devicePixelRatio:1,contextWidth:0,contextHeight:0,data:null,scale:1,offsetLeft:0,offsetRight:0,offsetTop:0,offsetBottom:0};class ie{constructor(){const e=new p({defaultStorage:te}),t=new p({defaultStorage:{}});this._activeStore=e,this._sharedStore=t}getActiveStorage(e){return this._activeStore.get(e)}setActiveStorage(e,t){return this._activeStore.set(e,t)}getActiveStoreSnapshot(){return this._activeStore.getSnapshot()}getSharedStorage(e){return this._sharedStore.get(e)}setSharedStorage(e,t){return this._sharedStore.set(e,t)}getSharedStoreSnapshot(){return this._sharedStore.getSnapshot()}getActiveViewScaleInfo(){return{scale:this._activeStore.get("scale"),offsetTop:this._activeStore.get("offsetTop"),offsetBottom:this._activeStore.get("offsetBottom"),offsetLeft:this._activeStore.get("offsetLeft"),offsetRight:this._activeStore.get("offsetRight")}}setActiveViewScaleInfo(e){const{scale:t,offsetTop:i,offsetBottom:o,offsetLeft:n,offsetRight:a}=e;this._activeStore.set("scale",t),this._activeStore.set("offsetTop",i),this._activeStore.set("offsetBottom",o),this._activeStore.set("offsetLeft",n),this._activeStore.set("offsetRight",a)}setActiveViewSizeInfo(e){this._activeStore.set("width",e.width),this._activeStore.set("height",e.height),this._activeStore.set("devicePixelRatio",e.devicePixelRatio),this._activeStore.set("contextWidth",e.contextWidth),this._activeStore.set("contextHeight",e.contextHeight)}getActiveViewSizeInfo(){return{width:this._activeStore.get("width"),height:this._activeStore.get("height"),devicePixelRatio:this._activeStore.get("devicePixelRatio"),contextWidth:this._activeStore.get("contextWidth"),contextHeight:this._activeStore.get("contextHeight")}}}const{requestAnimationFrame:oe}=window;class ne extends m{constructor(e){super(),this._drawFrameSnapshotQueue=[],this._drawFrameStatus="FREE",this._opts=e,this._init()}_init(){const{renderer:e}=this._opts;e.on("load",(()=>{this.drawFrame()}))}_drawAnimationFrame(){if("DRAWING"===this._drawFrameStatus||0===this._drawFrameSnapshotQueue.length)return;this._drawFrameStatus="DRAWING";const e=this._drawFrameSnapshotQueue.shift(),{renderer:t,viewContent:i,beforeDrawFrame:o,afterDrawFrame:n}=this._opts;if(e){const{scale:a,offsetTop:r,offsetBottom:s,offsetLeft:l,offsetRight:h,width:c,height:d,contextHeight:u,contextWidth:g,devicePixelRatio:f}=e.activeStore,{viewContext:v,helperContext:w,boardContext:x}=i;(null==e?void 0:e.activeStore.data)&&t.drawData(e.activeStore.data,{viewScaleInfo:{scale:a,offsetTop:r,offsetBottom:s,offsetLeft:l,offsetRight:h},viewSizeInfo:{width:c,height:d,contextHeight:u,contextWidth:g,devicePixelRatio:f}}),o({snapshot:e}),x.clearRect(0,0,c,d),x.drawImage(v.canvas,0,0,c,d),x.drawImage(w.canvas,0,0,c,d),v.clearRect(0,0,c,d),w.clearRect(0,0,c,d),n({snapshot:e})}0!==this._drawFrameSnapshotQueue.length?(this._drawFrameStatus="DRAWING")&&oe((()=>{this._drawAnimationFrame()})):this._drawFrameStatus="COMPLETE"}drawFrame(){const{sharer:e}=this._opts,t=e.getActiveStoreSnapshot(),i=e.getSharedStoreSnapshot();this._drawFrameSnapshotQueue.push({activeStore:t,sharedStore:i}),this._drawAnimationFrame()}scale(e){const{scale:t,point:i}=e,{sharer:o}=this._opts,{moveX:n,moveY:a}=function(e){const{scale:t,point:i,viewScaleInfo:o}=e,{offsetLeft:n,offsetTop:a}=o,r=t/o.scale,s=i.x,l=i.y;return{moveX:s-s*r+(n*r-n),moveY:l-l*r+(a*r-a)}}({scale:t,point:i,viewScaleInfo:o.getActiveViewScaleInfo(),viewSizeInfo:o.getActiveViewSizeInfo()});return o.setActiveStorage("scale",t),{moveX:n,moveY:a}}scroll(e){const{sharer:t}=this._opts,i=t.getActiveViewScaleInfo(),{moveX:o,moveY:n}=e,a=function(e){const{moveX:t=0,moveY:i=0,viewScaleInfo:o,viewSizeInfo:n}=e,{scale:a}=o,{width:r,height:s,contextWidth:l,contextHeight:h}=n;let c=o.offsetLeft,d=o.offsetRight,u=o.offsetTop,g=o.offsetBottom;return c+=t,u+=i,d=r-(l*a+c),g=s-(h*a+u),{scale:a,offsetTop:u,offsetLeft:c,offsetRight:d,offsetBottom:g}}({moveX:o,moveY:n,viewScaleInfo:i,viewSizeInfo:t.getActiveViewSizeInfo()});return t.setActiveViewScaleInfo(a),a}resize(e={}){const{sharer:t}=this._opts,i=t.getActiveViewSizeInfo(),o=Object.assign(Object.assign({},i),e),{width:n,height:a,devicePixelRatio:r}=o,{boardContext:s,helperContext:l,viewContext:h}=this._opts.viewContent;return s.canvas.width=n*r,s.canvas.height=a*r,s.canvas.style.width=`${n}px`,s.canvas.style.height=`${a}px`,l.canvas.width=n*r,l.canvas.height=a*r,h.canvas.width=n*r,h.canvas.height=a*r,t.setActiveViewSizeInfo(o),o}}const ae=["RULER"];class re{constructor(e){this._middlewares=[],this._middlewareObjs=[],this._activeMiddlewareObjs=[],this._eventHub=new m,this._activeMode="SELECT";const{viewContent:t}=e,i=new ie,o=new K({viewContent:t}),n=new ee({viewContent:t,sharer:i}),a=new J({viewContent:t,sharer:i,calculator:o});this._opts=e,this._sharer=i,this._renderer=a,this._watcher=n,this._calculator=o,this._viewer=new ne({viewContent:e.viewContent,sharer:i,renderer:a,calculator:o,beforeDrawFrame:e=>{this._handleBeforeDrawFrame(e)},afterDrawFrame:e=>{this._handleAfterDrawFrame(e)}}),this._init(),this._resetActiveMiddlewareObjs()}_init(){this._watcher.on("pointStart",this._handlePointStart.bind(this)),this._watcher.on("pointEnd",this._handlePointEnd.bind(this)),this._watcher.on("pointMove",t((e=>{this._handlePointMove(e)}),16)),this._watcher.on("hover",t((e=>{this._handleHover(e)}),16)),this._watcher.on("wheelX",t((e=>{this._handleWheelX(e)}),16)),this._watcher.on("wheelY",t((e=>{this._handleWheelY(e)}),16)),this._watcher.on("wheelScale",t((e=>{this._handleWheelScale(e)}),16)),this._watcher.on("scrollX",this._handleScrollX.bind(this)),this._watcher.on("scrollY",this._handleScrollY.bind(this)),this._watcher.on("resize",this._handleResize.bind(this)),this._watcher.on("doubleClick",this._handleDoubleClick.bind(this))}_handlePointStart(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.pointStart)||void 0===t?void 0:t.call(o,e)))return}}_handlePointEnd(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.pointEnd)||void 0===t?void 0:t.call(o,e)))return}}_handlePointMove(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.pointMove)||void 0===t?void 0:t.call(o,e)))return}}_handleHover(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.hover)||void 0===t?void 0:t.call(o,e)))return}}_handleDoubleClick(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.doubleClick)||void 0===t?void 0:t.call(o,e)))return}}_handleWheelX(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.wheelX)||void 0===t?void 0:t.call(o,e)))return}}_handleWheelY(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.wheelY)||void 0===t?void 0:t.call(o,e)))return}}_handleWheelScale(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.wheelScale)||void 0===t?void 0:t.call(o,e)))return}}_handleScrollX(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.scrollX)||void 0===t?void 0:t.call(o,e)))return}}_handleScrollY(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.scrollY)||void 0===t?void 0:t.call(o,e)))return}}_handleResize(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.resize)||void 0===t?void 0:t.call(o,e)))return}}_handleClear(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.clear)||void 0===t?void 0:t.call(o,e)))return}}_handleBeforeDrawFrame(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.beforeDrawFrame)||void 0===t?void 0:t.call(o,e)))return}}_handleAfterDrawFrame(e){var t;for(let i=0;i<this._activeMiddlewareObjs.length;i++){const o=this._activeMiddlewareObjs[i];if(!1===(null===(t=null==o?void 0:o.afterDrawFrame)||void 0===t?void 0:t.call(o,e)))return}}_resetActiveMiddlewareObjs(){const{_activeMode:e}=this,t=[...ae,e],i=[];this._middlewareObjs.forEach((e=>{(!0===e.isDefault||t.includes(e.mode))&&i.push(e)})),this._activeMiddlewareObjs=i}getSharer(){return this._sharer}setData(e){const t=this._sharer;this._sharer.setActiveStorage("data",e);const i=t.getActiveViewSizeInfo(),o=j(e.elements,{viewWidth:i.width,viewHeight:i.height,extend:!0});this._viewer.drawFrame();const n=Object.assign(Object.assign({},i),o);return this._sharer.setActiveViewSizeInfo(n),{viewSizeInfo:n}}getData(){const{data:e}=this._sharer.getActiveStoreSnapshot();return e}use(e){const{viewContent:t}=this._opts,{_sharer:i,_viewer:o,_calculator:n,_eventHub:a}=this,r=e({viewContent:t,sharer:i,viewer:o,calculator:n,eventHub:a});this._middlewares.push(e),this._activeMiddlewareObjs.push(r)}scale(e){const{_viewer:t}=this,{moveX:i,moveY:o}=t.scale(e);t.scroll({moveX:i,moveY:o})}scroll(e){return this._viewer.scroll(e)}resize(e){const t=this._viewer.resize(e),{width:i,height:o,devicePixelRatio:n}=e,{viewContent:a}=this._opts;a.viewContext.$resize({width:i,height:o,devicePixelRatio:n});const r=a.viewContext.canvas;r.style.width=`${i}px`,r.style.height=`${o}px`,a.helperContext.$resize({width:i,height:o,devicePixelRatio:n}),a.boardContext.$resize({width:i,height:o,devicePixelRatio:n}),this._viewer.drawFrame(),this._watcher.trigger("resize",t),this._sharer.setActiveViewSizeInfo(e)}clear(){const{viewContent:e}=this._opts,{helperContext:t,viewContext:i,boardContext:o}=e;t.clearRect(0,0,t.canvas.width,t.canvas.height),i.clearRect(0,0,i.canvas.width,i.canvas.height),o.clearRect(0,0,o.canvas.width,o.canvas.height),this._handleClear()}getEventHub(){return this._eventHub}}const se="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAApCAYAAABHomvIAAAACXBIWXMAAAsTAAALEwEAmpwYAAAF92lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNi4wLWMwMDYgNzkuMTY0NzUzLCAyMDIxLzAyLzE1LTExOjUyOjEzICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cGhvdG9zaG9wPSJodHRwOi8vbnMuYWRvYmUuY29tL3Bob3Rvc2hvcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RFdnQ9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZUV2ZW50IyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgMjIuMyAoTWFjaW50b3NoKSIgeG1wOkNyZWF0ZURhdGU9IjIwMjMtMDktMTdUMTY6MzE6MjMrMDg6MDAiIHhtcDpNb2RpZnlEYXRlPSIyMDIzLTA5LTE3VDE2OjQ0OjIyKzA4OjAwIiB4bXA6TWV0YWRhdGFEYXRlPSIyMDIzLTA5LTE3VDE2OjQ0OjIyKzA4OjAwIiBkYzpmb3JtYXQ9ImltYWdlL3BuZyIgcGhvdG9zaG9wOkNvbG9yTW9kZT0iMyIgcGhvdG9zaG9wOklDQ1Byb2ZpbGU9InNSR0IgSUVDNjE5NjYtMi4xIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjY0MTBhYjUzLWM0ZjEtNDVhNS04MjhkLTIxOTczOWFjOTk3MSIgeG1wTU06RG9jdW1lbnRJRD0iYWRvYmU6ZG9jaWQ6cGhvdG9zaG9wOjBkMDNmNjM5LTE5MzctY2Y0MC1hMTg0LTIyMjg0NzczNWNmYSIgeG1wTU06T3JpZ2luYWxEb2N1bWVudElEPSJ4bXAuZGlkOjgyYjQwZGRmLWE0ZGEtNDY3MC1iYzc2LTBhYjY3ZmI5M2I0ZSI+IDx4bXBNTTpIaXN0b3J5PiA8cmRmOlNlcT4gPHJkZjpsaSBzdEV2dDphY3Rpb249ImNyZWF0ZWQiIHN0RXZ0Omluc3RhbmNlSUQ9InhtcC5paWQ6ODJiNDBkZGYtYTRkYS00NjcwLWJjNzYtMGFiNjdmYjkzYjRlIiBzdEV2dDp3aGVuPSIyMDIzLTA5LTE3VDE2OjMxOjIzKzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgMjIuMyAoTWFjaW50b3NoKSIvPiA8cmRmOmxpIHN0RXZ0OmFjdGlvbj0ic2F2ZWQiIHN0RXZ0Omluc3RhbmNlSUQ9InhtcC5paWQ6NjQxMGFiNTMtYzRmMS00NWE1LTgyOGQtMjE5NzM5YWM5OTcxIiBzdEV2dDp3aGVuPSIyMDIzLTA5LTE3VDE2OjQ0OjIyKzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgMjIuMyAoTWFjaW50b3NoKSIgc3RFdnQ6Y2hhbmdlZD0iLyIvPiA8L3JkZjpTZXE+IDwveG1wTU06SGlzdG9yeT4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz57vRudAAAEk0lEQVRYhe3ZW0jbVxzA8e8/MX+NYnG9uI4xE3bvoLt0FzradRfGBtsYo32YdAhb6WQyBqV7KOylpYjzZShDGfjmyxgbgjjwyRm16SYMhgiNKDhbL3VtNF4xJOnf3x7+59i/Wf4aTbInf3AwJMdzPjnnf/n9/jFEhGzDMIxMb3uAIsDs6ek5urS05Dtz5syE+uwekAQS6u89YD19gC0NIpJ1c8GZQHlXV9fJRCIxGo/HxxoaGj4CngWOAEGgEihXfT07MeQC3MB1dna+lkgkRkXF6urq3xcuXPgUOAE8DzwGPOiGLARwEy4ej4+JiITD4elr167NiIgsLi7eqq2trQPeBI4Bj7sh8w10xZmmeds0zdn+/v5/RERisdjUuXPnvgLeAl50Q+YTaAA+oKy7u/uE3laNAwSQ4uLiu6FQ6G4G5DG13YeAMjWWkU+gBygJhULHNe769etTTpwDGXUiz58//yXwujp5qoAHgBLAk0+gNxKJHEulUiMKN2ma5gwgPp/vjhOXjlxYWJisq6urBV5RW30IKAW8eQPGYrGjlmXdEBEZHBy8aZrmFCCmac729fVtAHt7e6MO5N2+vr47IiJLS0s3L126dBZ4Sh2LZUBRwVdwYGBgVuwOYh/zsoF0bnPBVzDTMRgOh6dFhROokSIi8/Pz0+pEeaPQx+DGWdzV1XVSX2LcgCIic3NzMzU1NV8D7wIvq9WrLNRZvOk62NHRccqJTAdGo9Hb1dXV3wAfYt9VjgAPFfI66EQWAxU9PT0fuwEvXrzYBJwF3gFeAAJAhfrfrO4k/7lxZxnr2JlJqry8POnWyePx6H4JR0vhktVkHGOXQI20SkpKLLcOhmGsA5YCaZiVLS5XoADi9XpdkznDMERhnE0fCgUHZhvOW+CO4/8A5hR7wFxjD5hr7AFzjZyBlmVlrOYdYaS1HUUuQA/gWV9fd51URDyqn1c1j6MVFGjoidfW1oq2ABrYj0V82OmVzwHNajVdB88C5wOKTdM87NaxsrKyQsFKHC2BnTDo+/TWt8Bd5INeVC44NDT0xXYZdXNz8w/AaeyS8yjwCPdzQu92ht2m/OUjIyOfS1pkAoqItLS0fA+8D7wKPA0cxs6qC1O4T0xMfKYnb21tnXEDNjc3z+nXbW1t3wFvYz9dCAL7KUThHovFPtGTNjU1jQFSX18/lg68cuXKLUAaGxs3vkB7e/u3wHHgCQpUdnpTqdQvesJgMDisUVevXh3Xry9fvnxTv66qqprQ/cfHx/vVNj/J/couv0DAv7q6+pMDeYPNSalkwkUikX7s4ukl4FHgAODPN1CXnPsWFxd/dCAjW+GGhoZCwAfYpeczwMPAPjVW3gv3IvXN98disZ8dyBGNCwQC4/r94eHhfuy6+JS6zATUCeJXY+W9cNfIUuDAwsLCr05kIBDYeBQ8Ojr6h8Lpx25BtbWlGpfv62BG5PLy8m+SFpOTk38C76mVe84NVyhgOvLgysrK7xoXjUb/Uqt2XG1rEDiYCbcd0MgwsWtk+J1EI03An0wmw5Zlefx+/2n1eRKIO5r+rWTTpFsZ/gWFrGMmeObuqwAAAABJRU5ErkJggg==";class le{constructor(e,t){this._cursorType=null,this._resizeCursorBaseImage=null,this._cursorImageMap={auto:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAF92lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNi4wLWMwMDYgNzkuMTY0NzUzLCAyMDIxLzAyLzE1LTExOjUyOjEzICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cGhvdG9zaG9wPSJodHRwOi8vbnMuYWRvYmUuY29tL3Bob3Rvc2hvcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RFdnQ9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZUV2ZW50IyIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgMjIuMyAoTWFjaW50b3NoKSIgeG1wOkNyZWF0ZURhdGU9IjIwMjMtMDktMTdUMTY6MDc6MjYrMDg6MDAiIHhtcDpNb2RpZnlEYXRlPSIyMDIzLTA5LTE3VDE2OjEyOjUwKzA4OjAwIiB4bXA6TWV0YWRhdGFEYXRlPSIyMDIzLTA5LTE3VDE2OjEyOjUwKzA4OjAwIiBkYzpmb3JtYXQ9ImltYWdlL3BuZyIgcGhvdG9zaG9wOkNvbG9yTW9kZT0iMyIgcGhvdG9zaG9wOklDQ1Byb2ZpbGU9InNSR0IgSUVDNjE5NjYtMi4xIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjliMGM0MzI2LWU4ZTQtNDlkNy04MmUzLTgxODkwYTE2ZmU1YSIgeG1wTU06RG9jdW1lbnRJRD0iYWRvYmU6ZG9jaWQ6cGhvdG9zaG9wOjMzOGFhZDBmLWZkZjMtODE0MS1iMTZmLWNiZWIzNTQyYTJhMCIgeG1wTU06T3JpZ2luYWxEb2N1bWVudElEPSJ4bXAuZGlkOjUwODAxNzc1LWZlNGEtNDQyMy05NDQ3LThkYWRhNzZhYTllOSI+IDx4bXBNTTpIaXN0b3J5PiA8cmRmOlNlcT4gPHJkZjpsaSBzdEV2dDphY3Rpb249ImNyZWF0ZWQiIHN0RXZ0Omluc3RhbmNlSUQ9InhtcC5paWQ6NTA4MDE3NzUtZmU0YS00NDIzLTk0NDctOGRhZGE3NmFhOWU5IiBzdEV2dDp3aGVuPSIyMDIzLTA5LTE3VDE2OjA3OjI2KzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgMjIuMyAoTWFjaW50b3NoKSIvPiA8cmRmOmxpIHN0RXZ0OmFjdGlvbj0ic2F2ZWQiIHN0RXZ0Omluc3RhbmNlSUQ9InhtcC5paWQ6OWIwYzQzMjYtZThlNC00OWQ3LTgyZTMtODE4OTBhMTZmZTVhIiBzdEV2dDp3aGVuPSIyMDIzLTA5LTE3VDE2OjEyOjUwKzA4OjAwIiBzdEV2dDpzb2Z0d2FyZUFnZW50PSJBZG9iZSBQaG90b3Nob3AgMjIuMyAoTWFjaW50b3NoKSIgc3RFdnQ6Y2hhbmdlZD0iLyIvPiA8L3JkZjpTZXE+IDwveG1wTU06SGlzdG9yeT4gPC9yZGY6RGVzY3JpcHRpb24+IDwvcmRmOlJERj4gPC94OnhtcG1ldGE+IDw/eHBhY2tldCBlbmQ9InIiPz7W6XrzAAAGLklEQVRYhb2Xf2iUdRzHX/txtfXLplZ6Wblm6fzRmG6r7Uou1AxKRjQKYUqgaLBACFogppcK1h8aLRkMSYaJIA5hYMomZpskEfPOufCaDpZ6t7rbre263U3vzn3643meu+eu3XNzvz7w4bbdc/e89nl/Pu/v50HUCAQCx1tbW0uAx4CHgSwggxkKERkziUQif2mQ0WjU53a7vwSeBB4BTEDmTICmBBwYGDivVlDjlFAo9KvT6dwIPAHkANkq6MwDXr169bCISENDg9TX14s+BgcHf2hubi5mBmRPCXj06NFPREQ6OjoEkPLycrl06VIMMhKJeFwu1xdMs+wpAYuLi9eIiIyOjkpeXp4AAsj27dvF7/fHQIPB4C9dXV0fME2ypwQEXvX7/bdFRNauXRsDBMRkMsnhw4cTZB8YGGhsamp6hSmW3Qhw1Y0bN86LiNTW1iYAallWViZtbW162ftcLtdO/i/7tAAWtba2ficicvLkyTEBtdy6dasMDg7GQIeHh9s7OzvfBx5nkrIbAS7du3fvxyIiPT09hoBa1tXVJcv+fWNj4zLgUeAhJiC7EeDLwOsiMioisnDhwnFBrlixQi5evKiX/c6tW7c+R5E9lweU3QjwReDV/v7+bhGRqqqqcQFquWnTJvH5fHrZLzocjkoSZU9bTSPA54GV165daxYROXDgwAMBannw4MFk2RsaGhqWME7ZjQDNwIrTp09/JSLS0tIyIUBACgoK5MKFCzHIcDj85+3btz8FZpFGdiPAZ4DCmpqaTSIiPp9vwoBaVlVVidfr1ct+/sqVK+9iILsR4FzgJcASDoeHRUSKioomDQnI/v37E2T3+Xz1hw4dWjSW7EaAeUA+UNbX12cXEdmyZcuUAAJiNpvlzJkzetl73G53rVrN2EmUCjATuA9EgYjL5eoGKCkpGatNHijmz5/Pxo0b2blzJ2azOfZ3k8lUYDabv45Go/Y7d+6sIY0VZQOjGqDT6bxeWlrKqlWrJgRlsVhYv349FRUVWCwWcnJyEt4PBoOuoaEhu9frvdzR0fHTtm3buolvRpLqe3OBp4EllZWV74mIRKNRyc3NTSvf7Nmzpbq6Wk6cOCFut1uSY2RkJOB0Ou3Nzc3Ha2trPwPWAGXAEuBZFFPPAbKMevBhYA6wCKgIBoP9IiKrV682hLPZbP8DEpH7vb29N1paWn602WwHFyxYsAX4EKgE3gIsQBFQgOIeT6j3z0wFqEkc60OPx9Odn58/t6SkhPb29jFLbrVa2bNnDwBer7fv5s2bPQ6Ho7upqcnZ1tbmASJq3gPC6utdYESXYfWeo6mkBaUHRQ/odrv/yM/Pt5SWlqb8kAbncDh+W7lyZYN683u6DOvAwipsOOnniA4wZf9lqhdoVYzY7fbrQMpBsdlsWK1WRkZGAtXV1d8D/wA+wKNLr5o+YEC9ZggIAEHiFbyfDhCUCcoFngIWFxYWrtMaat68eQl9V15eHmu2+vr6OuAd4A2gGFgMLERp/mdQ+noWyuadi9Jr2aQ4k42GBPXDs1Ga97WhoaFbIiIbNmxIANTWq87Ozp9VuApgGfACihPkoRjwI+p3mlSgtA9ZRkYNYwwKJBr2rl27sFqthEKhwZqamqOAX5f/AsPE5btLvM/GJWO6yFb/82eBonPnztWJiJw9e1YAWb58eUzaI0eOfAO8CbwCPIfiZZN+eEoncSaKLPOApbt3794uIuL1ehOktdvtF4C3gRKURXcOSn9lTRRsvIAZKI4+l/gjQFREZMeOHSIiEggE+tetW/cRitkuRhmERxnnxjxZQFDWnzzURwCv1+vUHxHHjh37lri0C1Am9KGpgDMC1G8SQnxxCHs8Hqf2RldX10+bN28+i+JjwyT62KSaP13oAfWTHO7t7f0dIBQK/b1v375GlEnVjPYuyoQaHlNTDahVMALca29vdwBcvnz5+KlTp26OATft1UuODBS7yEOxj0K/329HOSWWopjxlE1tchhtM7FriPfgXSDDbrfXo0gbJr4QzIi0WiRPYBbKZJrUV23b0dYn7XSYcsBkS9EiO/k6lApq1cwiPjzaAM1Y9cYC1G6uAWrPCtrvMwoHqU02Q5caIEzj1KaS+D+vIjxtLug31gAAAABJRU5ErkJggg==","rotate-0":se},this._container=e,this._eventHub=t.eventHub,this._init(),this._loadResizeCursorBaseImage()}_init(){const{_eventHub:e}=this;this._resetCursor("auto"),e.on("cursor",(e=>{var t;"over-element"!==e.type&&e.type&&"string"==typeof e.type&&(null==(t=e.type)?void 0:t.startsWith("resize-"))?this._setCursorResize(e):this._resetCursor("auto")}))}_loadResizeCursorBaseImage(){h(se).then((e=>{this._resizeCursorBaseImage=e})).catch((e=>{console.error(e)}))}_resetCursor(e){if(this._cursorType===e)return;this._cursorType=e;const t=this._cursorImageMap[this._cursorType]||this._cursorImageMap.auto;let i=0,o=0;e.startsWith("rotate-")&&this._cursorImageMap[this._cursorType]&&(i=10,o=10),this._container.style.cursor=`image-set(url(${t})2x) ${i} ${o}, auto`}_setCursorResize(e){var t;let i=0;"resize-top"===e.type?i+=0:"resize-top-right"===e.type?i+=45:"resize-right"===e.type?i+=90:"resize-bottom-right"===e.type?i+=135:"resize-bottom"===e.type?i+=180:"resize-bottom-left"===e.type?i+=225:"resize-left"===e.type?i+=270:"resize-top-left"===e.type&&(i+=315),i+=O((null==(t=null==e?void 0:e.element)?void 0:t.angle)||0),Array.isArray(e.groupQueue)&&e.groupQueue.length>0&&e.groupQueue.forEach((e=>{i+=O(e.angle||0)})),i=O(i);const o=this._appendRotateResizeImage(i);this._resetCursor(o)}_appendRotateResizeImage(e){const t=`rotate-${e}`;if(!this._cursorImageMap[t]){const i=this._resizeCursorBaseImage;if(i){const o=document.createElement("canvas"),n=i.width,a=i.height,r={x:n/2,y:a/2};o.width=n,o.height=a;const s=o.getContext("2d"),l=b(e);s.translate(r.x,r.y),s.rotate(l),s.translate(-r.x,-r.y),s.drawImage(i,0,0,n,a),s.translate(r.x,r.y),s.rotate(-l),s.translate(-r.x,-r.y);const h=o.toDataURL("image/png");this._cursorImageMap[t]=h}}return t}}const he="SELECT",ce=Symbol(`${he}_actionType`),de=Symbol(`${he}_resizeType`),ue=Symbol(`${he}_areaStart`),ge=Symbol(`${he}_areaEnd`),fe=Symbol(`${he}_hoverElement`),ve=Symbol(`${he}_hoverElementVertexes`),we=Symbol(`${he}_selectedElementList`),xe=Symbol(`${he}_selectedElementListVertexes`),Se=Symbol(`${he}_selectedElementController`),me=Symbol(`${he}_groupQueue`),ye=Symbol(`${he}_groupQueueVertexesList`),pe="#1973ba";function be(e,t,i){const{borderColor:o,borderWidth:n,background:a,lineDash:r}=i;e.setLineDash([]),e.lineWidth=n,e.strokeStyle=o,e.fillStyle=a,e.setLineDash(r),e.beginPath(),e.moveTo(t[0].x,t[0].y),e.lineTo(t[1].x,t[1].y),e.lineTo(t[2].x,t[2].y),e.lineTo(t[3].x,t[3].y),e.lineTo(t[0].x,t[0].y),e.closePath(),e.stroke(),e.fill()}function Ie(e,t,i){if(!t)return;const o={borderColor:pe,borderWidth:1,background:"transparent",lineDash:[]};be(e,C(t,i),o)}function Me(e,t,i){if(!t)return;const{elementWrapper:o,left:n,right:a,top:r,bottom:s,topLeft:l,topRight:h,bottomLeft:c,bottomRight:d}=t,u={borderColor:pe,borderWidth:1,background:"transparent",lineDash:[]},g={...u,borderWidth:2,background:"#FFFFFF"};be(e,C(o,i),u),be(e,C(n.vertexes,i),g),be(e,C(a.vertexes,i),g),be(e,C(r.vertexes,i),g),be(e,C(s.vertexes,i),g),be(e,C(l.vertexes,i),g),be(e,C(h.vertexes,i),g),be(e,C(c.vertexes,i),g),be(e,C(d.vertexes,i),g)}function Ae(e){return e*Math.PI/180}function _e(e,t){return Math.sqrt(e*e+t*t)}function ze(e,t){return t>0?Math.abs(e):0-Math.abs(e)}function Re(e,t){const{ctx:i,viewScaleInfo:o,viewSizeInfo:n,vertexes:a}=t,r=L(a[0],{viewScaleInfo:o,viewSizeInfo:n}),s=L(a[1],{viewScaleInfo:o,viewSizeInfo:n}),l=L(a[2],{viewScaleInfo:o,viewSizeInfo:n}),h=L(a[3],{viewScaleInfo:o,viewSizeInfo:n});return i.beginPath(),i.moveTo(r.x,r.y),i.lineTo(s.x,s.y),i.lineTo(l.x,l.y),i.lineTo(h.x,h.y),i.lineTo(r.x,r.y),i.closePath(),!!i.isPointInPath(e.x,e.y)}function Pe(e,t){const{ctx:i,viewScaleInfo:o,viewSizeInfo:n,groupQueue:a}=t;if(!(a&&(null==a?void 0:a.length)>0))return!1;const r=k(a),s=r[r.length-1];return!!s&&Re(e,{ctx:i,vertexes:s,viewScaleInfo:o,viewSizeInfo:n})}function Te(e,t){var i,o,n;const a={type:null,elements:[],elementVertexesList:[],groupQueue:[],groupQueueVertexesList:[]},{ctx:r,data:s,calculator:l,selectedElements:h,viewScaleInfo:c,viewSizeInfo:d,areaSize:u,groupQueue:g,selectedElementController:f}=t;if(f){const{left:t,right:i,top:o,bottom:n,topLeft:s,topRight:l,bottomLeft:u,bottomRight:v}=f,w=[t,i,o,n,s,l,u,v];for(let t=0;t<w.length;t++){const i=w[t];if(Re(e,{ctx:r,vertexes:i.vertexes,viewSizeInfo:d,viewScaleInfo:c})){a.type=`resize-${i.type}`,h&&(null==h?void 0:h.length)>0&&(a.groupQueue=g||[],a.elements=[h[0]]);break}}}if(g&&Array.isArray(g)&&g.length>0){const t=g[g.length-1];if((null==(i=null==t?void 0:t.detail)?void 0:i.children)&&Array.isArray(null==(o=null==t?void 0:t.detail)?void 0:o.children))for(let i=t.detail.children.length-1;i>=0;i--){const o=t.detail.children[i],n=F(o,{groupQueue:g});if(n&&Re(e,{ctx:r,vertexes:n,viewScaleInfo:c,viewSizeInfo:d}))return a.type||(a.type="over-element"),a.groupQueue=g,a.elements=[o],a}return a}if(null!==a.type)return a;if(u&&Array.isArray(h)&&(null==h?void 0:h.length)>1){const{x:t,y:i,w:o,h:n}=u;if(e.x>=t&&e.x<=t+o&&e.y>=i&&e.y<=i+n)return a.type="list-area",a.elements=h,a}if(s){const{index:t,element:i}=l.getPointElement(e,{data:s,viewScaleInfo:c,viewSizeInfo:d});if(t>=0&&i&&!0!==(null==(n=null==i?void 0:i.operations)?void 0:n.invisible))return a.elements=[i],a.type="over-element",a}return a}function Oe(e,t){var i;if(!Array.isArray(e))return null;const o={x:0,y:0,w:0,h:0},{calculator:n,viewScaleInfo:a,viewSizeInfo:r}=t;let s=null;for(let t=0;t<e.length;t++){const l=e[t];if(null==(i=null==l?void 0:l.operations)?void 0:i.invisible)continue;const h=n.elementSize(l,a,r);if(h.angle&&(h.angle>0||h.angle<0)){const e=P(h);if(4===e.length){const t=[e[0].x,e[1].x,e[2].x,e[3].x],i=[e[0].y,e[1].y,e[2].y,e[3].y];h.x=Math.min(...t),h.y=Math.min(...i),h.w=Math.abs(Math.max(...t)-Math.min(...t)),h.h=Math.abs(Math.max(...i)-Math.min(...i))}}if(s){const e=Math.min(h.x,o.x),t=Math.min(h.y,o.y),i=Math.max(h.x+h.w,o.x+o.w),n=Math.max(h.y+h.h,o.y+o.h);o.x=e,o.y=t,o.w=Math.abs(i-e),o.h=Math.abs(n-t)}else o.x=h.x,o.y=h.y,o.w=h.w,o.h=h.h;s=h}return o}const Ee="SCROLL",je=Symbol(`${Ee}_xThumbRect`),We=Symbol(`${Ee}_yThumbRect`),Le=Symbol(`${Ee}_prevPoint`),Ce=Symbol(`${Ee}_activePoint`),De=Symbol(`${Ee}_activeThumbType`),Ye=16,Ge=.12,ke=.36;function Fe(e,t,i){const o=e,{x:n,y:a,w:r,h:s}=i;return o.beginPath(),o.rect(n,a,r,s),o.closePath(),!!o.isPointInPath(t.x,t.y)}function Be(e,t){let{x:i,y:o,h:n,w:a}=t;const{color:r,axis:s}=t;"X"===s?(o=o+n/4+0,n/=2):"Y"===s&&(i=i+a/4+0,a/=2);let l=t.r;l=Math.min(l,a/2,n/2),(a<2*l||n<2*l)&&(l=0),e.globalAlpha=ke,e.beginPath(),e.moveTo(i+l,o),e.arcTo(i+a,o,i+a,o+n,l),e.arcTo(i+a,o+n,i,o+n,l),e.arcTo(i,o+n,i,o,l),e.arcTo(i,o,i+a,o,l),e.closePath(),e.fillStyle=r,e.fill(),e.globalAlpha=1,e.beginPath(),e.lineWidth=1,e.strokeStyle=r,e.setLineDash([]),e.moveTo(i+l,o),e.arcTo(i+a,o,i+a,o+n,l),e.arcTo(i+a,o+n,i,o+n,l),e.arcTo(i,o+n,i,o,l),e.arcTo(i,o,i+a,o,l),e.closePath(),e.stroke()}function Ze(e,t){const i=e,{viewScaleInfo:o,viewSizeInfo:n,scrollInfo:a}=t,{activeThumbType:r,prevPoint:s,activePoint:l}=a,{width:h,height:c}=n,d=function(e,t){const{width:i,height:o}=t,{offsetTop:n,offsetBottom:a,offsetLeft:r,offsetRight:s}=e,l=2.5*Ye,h=Ye;let c=0,d=0;c=Math.max(l,i-(Math.abs(r)+Math.abs(s))),c>=i&&(c=i),d=Math.max(l,o-(Math.abs(n)+Math.abs(a))),d>=o&&(d=o);const u=h/2;let g=u;r>0?g=u:s>0?g=i-c-h:r<=0&&c>0&&(0!==r||0!==s)&&(g=c/2+(i-c)*Math.abs(r)/(Math.abs(r)+Math.abs(s)),g=Math.min(Math.max(0,g-c/2),i-c));const f=h/2;let v=f;return n>0?v=f:a>0?v=o-d-h:n<=0&&d>0&&(0!==n||0!==a)&&(v=d/2+(o-d)*Math.abs(n)/(Math.abs(n)+Math.abs(a)),v=Math.min(Math.max(0,v-d/2),o-d)),{lineSize:h,xSize:c,ySize:d,translateY:v,translateX:g,color:"#0000007A",xThumbRect:{x:g,y:o-h,w:c,h:h},yThumbRect:{x:i-h,y:v,w:h,h:d}}}(o,n);let u={...d.xThumbRect},g={...d.yThumbRect};return r&&s&&l&&("X"===r&&a.xThumbRect?(u={...a.xThumbRect},u.x=u.x+(l.x-s.x)):"Y"===r&&a.yThumbRect&&(g={...a.yThumbRect},g.y=g.y+(l.y-s.y))),i.globalAlpha=Ge,i.fillStyle=d.color,i.fillRect(0,c-d.lineSize,h,d.lineSize),Be(i,{axis:"X",...u,r:d.lineSize/2,color:d.color}),i.globalAlpha=Ge,i.fillStyle=d.color,i.fillRect(h-d.lineSize,0,d.lineSize,c),Be(i,{axis:"Y",...g,r:d.lineSize/2,color:d.color}),i.globalAlpha=1,{xThumbRect:u,yThumbRect:g}}function Xe(e,t){const{snapshot:i}=t,o=function(e){const{activeStore:t}=e;return{devicePixelRatio:t.devicePixelRatio,width:null==t?void 0:t.width,height:null==t?void 0:t.height,contextWidth:null==t?void 0:t.contextWidth,contextHeight:null==t?void 0:t.contextHeight}}(i),n=function(e){const{activeStore:t}=e;return{scale:null==t?void 0:t.scale,offsetTop:null==t?void 0:t.offsetTop,offsetBottom:null==t?void 0:t.offsetBottom,offsetLeft:null==t?void 0:t.offsetLeft,offsetRight:null==t?void 0:t.offsetRight}}(i),a=function(e){const{sharedStore:t}=e;return{activePoint:t[Ce]||null,prevPoint:t[Le]||null,activeThumbType:t[De]||null,xThumbRect:t[je]||null,yThumbRect:t[We]||null}}(i),{xThumbRect:r,yThumbRect:s}=Ze(e,{viewSizeInfo:o,viewScaleInfo:n,scrollInfo:a});return{xThumbRect:r,yThumbRect:s}}return e.Core=class{constructor(e,t){const{devicePixelRatio:i=1,width:o,height:n}=t;this._opts=t,this._container=e;const a=document.createElement("canvas");this._canvas=a,e.appendChild(a);const r=function(e,t){const i={width:e.canvas.width,height:e.canvas.height,devicePixelRatio:(null==t?void 0:t.devicePixelRatio)||1};return{viewContext:S(i),helperContext:S(i),boardContext:S(Object.assign({ctx:e},i))}}(a.getContext("2d"),{devicePixelRatio:i}),s=new re({viewContent:r}),l=s.getSharer();l.setActiveViewSizeInfo({width:o,height:n,devicePixelRatio:i,contextWidth:o,contextHeight:n}),this._board=s,this.resize(l.getActiveViewSizeInfo());const h=s.getEventHub();new le(e,{eventHub:h})}use(e){this._board.use(e)}setData(e){E((null==e?void 0:e.elements)||[]),this._board.setData(e)}getData(){return this._board.getData()}scale(e){this._board.scale(e)}resize(e){const{_board:t}=this,i=t.getSharer().getActiveViewSizeInfo();t.resize({...i,...e})}clear(){this._board.clear()}on(e,t){this._board.getEventHub().on(e,t)}off(e,t){this._board.getEventHub().off(e,t)}trigger(e,t){this._board.getEventHub().trigger(e,t)}},e.MiddlewareScaler=e=>{const{viewer:t,sharer:i}=e;return{mode:"SCALE",isDefault:!0,wheelScale(e){const{deltaY:o,point:n}=e,{scale:a}=i.getActiveViewScaleInfo();let r=a;o<0?r=1.1*a:o>0&&(r=.9*a);const{moveX:s,moveY:l}=t.scale({scale:r,point:n});t.scroll({moveX:s,moveY:l}),t.drawFrame()}}},e.MiddlewareScroller=e=>{const{viewer:t,viewContent:i,sharer:o}=e,{helperContext:n}=i;o.setSharedStorage(je,null),o.setSharedStorage(We,null);const a=()=>{o.setSharedStorage(Le,null),o.setSharedStorage(Ce,null),o.setSharedStorage(De,null)};a();const r=e=>function(e,t,i){let o=null;const{xThumbRect:n,yThumbRect:a}=i;return n&&Fe(e,t,n)?o="X":a&&Fe(e,t,a)&&(o="Y"),o}(n,e,{xThumbRect:o.getSharedStorage(je),yThumbRect:o.getSharedStorage(We)});return{mode:Ee,wheelX:e=>{(e.deltaX>=0||e.deltaX<0)&&(t.scroll({moveX:0-e.deltaX}),t.drawFrame())},wheelY:e=>{(e.deltaY>=0||e.deltaY<0)&&(t.scroll({moveY:0-e.deltaY}),t.drawFrame())},pointStart:e=>{const{point:t}=e,i=r(t);if("X"===i||"Y"===i)return o.setSharedStorage(De,i),o.setSharedStorage(Le,t),!1},pointMove:e=>{const{point:i}=e,n=o.getSharedStorage(De);if("X"===n||"Y"===n)return o.setSharedStorage(Ce,i),"X"===n?(e=>{const i=o.getSharedStorage(Le);if(i){const{offsetLeft:n,offsetRight:a}=o.getActiveViewScaleInfo(),{width:r}=o.getActiveViewSizeInfo(),s=-(e.x-i.x)*(r+Math.abs(n)+Math.abs(a))/r;t.scroll({moveX:s}),t.drawFrame()}})(i):"Y"===n&&(e=>{const i=o.getSharedStorage(Le);if(i){const{offsetTop:n,offsetBottom:a}=o.getActiveViewScaleInfo(),{height:r}=o.getActiveViewSizeInfo(),s=-(e.y-i.y)*(r+Math.abs(n)+Math.abs(a))/r;t.scroll({moveY:s}),t.drawFrame()}})(i),o.setSharedStorage(Le,i),!1},pointEnd:e=>{const i=o.getSharedStorage(De);if(a(),"X"===i||"Y"===i)return t.scroll({moveX:0,moveY:0}),t.drawFrame(),!1},beforeDrawFrame({snapshot:e}){const{xThumbRect:t,yThumbRect:i}=Xe(n,{snapshot:e});o.setSharedStorage(je,t),o.setSharedStorage(We,i)}}},e.MiddlewareSelector=e=>{const{viewer:t,sharer:i,viewContent:o,calculator:n,eventHub:a}=e,{helperContext:r}=o;let s=null,l=null;a.on("select",(({uuids:e})=>{const o=i.getSharedStorage(ce),n=i.getActiveStorage("data"),a=function(e,t){const i=[];return function t(o){var n;for(let a=0;a<o.length;a++){const r=o[a];e.includes(r.uuid)?i.push(r):"group"===r.type&&t((null===(n=null==r?void 0:r.detail)||void 0===n?void 0:n.children)||[])}}(t),i}(e,(null==n?void 0:n.elements)||[]);let r=!1;if(o||1!==a.length?"select"===o&&1===a.length&&(r=!0):(i.setSharedStorage(ce,"select"),r=!0),r){const e=function(e,t){const i=[];return function e(t,o){var n;let a=null;for(let r=0;r<o.length;r++){const s=o[r];if(s.uuid===t){a=s;break}if(!a&&"group"===s.type){i.push(s);const o=e(t,(null===(n=null==s?void 0:s.detail)||void 0===n?void 0:n.children)||[]);if((null==o?void 0:o.uuid)===t){a=o;break}i.pop()}}return a}(e,t),i}(a[0].uuid,(null==n?void 0:n.elements)||[]);i.setSharedStorage(me,e),u(a),t.drawFrame()}})),i.setSharedStorage(ce,null);const h=()=>i.getSharedStorage(we),c=e=>{let t=i.getSharedStorage(me);Array.isArray(t)||(t=[]),t.length>0?!function(e,t){var i;if("group"===(null==t?void 0:t.type)&&Array.isArray(null==(i=null==t?void 0:t.detail)?void 0:i.children))for(let i=0;i<t.detail.children.length;i++){const o=t.detail.children[i];if(e.uuid===o.uuid)return!0}return!1}(e,t[t.length-1])?t=[]:t.push(e):0===t.length&&t.push(e);const o=k(t);return i.setSharedStorage(me,t),i.setSharedStorage(ye,o),t.length>0},d=e=>{i.setSharedStorage(fe,e);let t=null;e&&(t=F(e,{groupQueue:i.getSharedStorage(me)})),i.setSharedStorage(ve,t)},u=(e,t)=>{if(i.setSharedStorage(we,e),1===e.length){const t=Z(e[0],{groupQueue:i.getSharedStorage(me),controllerSize:10,viewScaleInfo:i.getActiveViewScaleInfo()});i.setSharedStorage(Se,t)}else i.setSharedStorage(Se,null);!0===(null==t?void 0:t.triggerEvent)&&a.trigger("select",{uuids:e.map((e=>e.uuid))})},g=()=>({ctx:r,calculator:n,data:i.getActiveStorage("data"),selectedElements:h(),viewScaleInfo:i.getActiveViewScaleInfo(),viewSizeInfo:i.getActiveViewSizeInfo(),groupQueue:i.getSharedStorage(me),areaSize:null,selectedElementController:i.getSharedStorage(Se)}),f=()=>{i.setSharedStorage(ce,null),i.setSharedStorage(de,null),i.setSharedStorage(ue,null),i.setSharedStorage(ge,null),i.setSharedStorage(me,[]),i.setSharedStorage(ye,[]),i.setSharedStorage(fe,null),i.setSharedStorage(ve,null),i.setSharedStorage(we,[]),i.setSharedStorage(xe,null),i.setSharedStorage(Se,null)};return f(),{mode:he,hover:e=>{var o,s;const c=i.getSharedStorage(de),u=i.getSharedStorage(ce),f=i.getSharedStorage(me),v=e=>{let t=e.type;null===l&&a.trigger("cursor",{type:t,groupQueue:e.groupQueue,element:e.elements[0]})};if((null==f?void 0:f.length)>0){if(!Pe(e.point,{ctx:r,viewScaleInfo:i.getActiveViewScaleInfo(),viewSizeInfo:i.getActiveViewSizeInfo(),groupQueue:i.getSharedStorage(me)}))return d(null),void t.drawFrame();const n=Te(e.point,g());return v(n),c||["area","drag","drag-list"].includes(u)?(d(null),void t.drawFrame()):1===(null==(o=null==n?void 0:n.elements)?void 0:o.length)?(d(n.elements[0]),void t.drawFrame()):(d(null),void t.drawFrame())}if(c||["area","drag","drag-list"].includes(u))return void d(null);if("drag"===u)return void d(null);const w=h(),x=i.getActiveViewScaleInfo(),S=i.getActiveViewSizeInfo(),m=Te(e.point,{...g(),areaSize:Oe(w,{viewScaleInfo:x,viewSizeInfo:S,calculator:n})});return v(m),"over-element"===m.type&&1===(null==(s=null==m?void 0:m.elements)?void 0:s.length)?(i.setSharedStorage(fe,m.elements[0]),d(m.elements[0]),void t.drawFrame()):i.getSharedStorage(fe)?(d(null),void t.drawFrame()):void 0},pointStart:e=>{var o,a,l,c;s=e.point,d(null);const v=i.getSharedStorage(me);if((null==v?void 0:v.length)>0){if(Pe(e.point,{ctx:r,viewScaleInfo:i.getActiveViewScaleInfo(),viewSizeInfo:i.getActiveViewSizeInfo(),groupQueue:v})){const t=Te(e.point,g());d(null),"over-element"===t.type&&1===(null==(o=null==t?void 0:t.elements)?void 0:o.length)?(u([t.elements[0]],{triggerEvent:!0}),i.setSharedStorage(ce,"drag")):(null==(a=t.type)?void 0:a.startsWith("resize-"))?(i.setSharedStorage(de,t.type),i.setSharedStorage(ce,"resize")):u([],{triggerEvent:!0})}else f();return void t.drawFrame()}const w=Oe(h(),{viewScaleInfo:i.getActiveViewScaleInfo(),viewSizeInfo:i.getActiveViewSizeInfo(),calculator:n}),x=Te(e.point,{...g(),areaSize:w,groupQueue:[]});"list-area"===x.type?i.setSharedStorage(ce,"drag-list"):"over-element"===x.type&&1===(null==(l=null==x?void 0:x.elements)?void 0:l.length)?(u([x.elements[0]],{triggerEvent:!0}),i.setSharedStorage(ce,"drag")):(null==(c=x.type)?void 0:c.startsWith("resize-"))?(i.setSharedStorage(de,x.type),i.setSharedStorage(ce,"resize")):(f(),i.setSharedStorage(ce,"area"),i.setSharedStorage(ue,e.point),u([],{triggerEvent:!0})),t.drawFrame()},pointMove:e=>{const o=i.getActiveStorage("data"),n=h(),a=i.getActiveStorage("scale")||1,r=s,c=e.point,d=i.getSharedStorage(de),g=i.getSharedStorage(ce),f=i.getSharedStorage(me);if("drag"===g){if(l="drag",o&&1===(null==n?void 0:n.length)&&r&&c){const{moveX:e,moveY:t}=function(e,t,i){let o=t.x-e.x,n=t.y-e.y;const a=[];if(i.forEach((e=>{const{x:t,y:i,w:o,h:n,angle:r=0}=e;a.push({x:t,y:i,w:o,h:n,angle:0-r})})),(null==i?void 0:i.length)>0){const i=z(e,a),r=z(t,a);o=r.x-i.x,n=r.y-i.y}return{moveX:o,moveY:n}}(r,c,f);n[0].x+=e/a,n[0].y+=t/a,u([n[0]])}t.drawFrame()}else if("drag-list"===g){if(l="drag-list",o&&r&&c&&(null==n?void 0:n.length)>1){const e=(c.x-r.x)/a,t=(c.y-r.y)/a;n.forEach((i=>{i&&(i.x+=e,i.y+=t)})),i.setActiveStorage("data",o)}t.drawFrame()}else if("resize"===g){if(o&&1===(null==n?void 0:n.length)&&r&&(null==d?void 0:d.startsWith("resize-"))){l="resize";const e=[];f.forEach((t=>{const{x:i,y:o,w:n,h:a,angle:r=0}=t;e.push({x:i,y:o,w:n,h:a,angle:0-r})}));let o=r,s=c;f.length>0&&(o=z(r,e),s=z(c,e));const h=function(e,t){var i,o,n,a,r,s,l,h,c;let{x:d,y:u,w:g,h:f,angle:v=0}=e;const w=M({x:d,y:u,w:g,h:f,angle:v});v=O(v);const x=b(v),S=!!(null==(i=null==e?void 0:e.operations)?void 0:i.limitRatio),{start:m,end:y,resizeType:p,scale:I}=t;let A={...m},z={...y},R={x:A.x,y:w.y},P={x:z.x,y:w.y},T={...R},E={...P},j={x:w.x,y:A.y},W={x:w.x,y:z.y},L={...j},C={...W},D=(E.x-T.x)/I,Y=(E.y-T.y)/I,G=_e(D,Y),k=(C.x-L.x)/I,F=(C.y-L.y)/I,B=_e(k,F);(v>0||v<0)&&(A=_(w,m,0-x),z=_(w,y,0-x),R={x:A.x,y:w.y},P={x:z.x,y:w.y},T=_(w,R,x),E=_(w,P,x),j={x:w.x,y:A.y},W={x:w.x,y:z.y},L=_(w,j,x),C=_(w,W,x),D=(E.x-T.x)/I,Y=(E.y-T.y)/I,G=_e(D,Y),G=ze(G,Y),k=(C.x-L.x)/I,F=(C.y-L.y)/I,B=_e(k,F),B=ze(B,F));let Z=(y.x-m.x)/I,X=(y.y-m.y)/I;if(!0===S)if(["resize-top","resize-bottom","resize-left","resize-right"].includes(p)){const t=Math.max(Math.abs(Z),Math.abs(X));Z=(Z>=0?1:-1)*t,X=(X>=0?1:-1)*t/e.w*e.h;const i=Math.max(Math.abs(k),Math.abs(F));k=(k>=0?1:-1)*i,F=(F>=0?1:-1)*i/e.w*e.h;const o=Math.max(Math.abs(D),Math.abs(Y));D=(D>=0?1:-1)*o,Y=(Y>=0?1:-1)*o/e.w*e.h}else if(["resize-top-left","resize-top-right","resize-bottom-left","resize-bottom-right"].includes(p)){{const t=Math.abs(Z);Z=(Z>=0?1:-1)*t;const i=t/e.w*e.h;"resize-top-left"===p||"resize-bottom-right"===p?X=Z>0?i:-i:"resize-top-right"!==p&&"resize-bottom-left"!==p||(X=Z>0?-i:i)}G=Math.abs(G),B=G/e.w*e.h}switch(p){case"resize-top":if(0===v)f-X>0&&(u+=X,f-=X,!0===(null==(o=e.operations)?void 0:o.limitRatio)&&(d+=X/e.h*e.w/2,g-=X/e.h*e.w));else if(v>0||v<0){let t=w.x,i=w.y;if(v<90){B=0-ze(B,F);const e=Ae(v),o=B/2;t+=o*Math.sin(e),i-=o*Math.cos(e)}else if(v<180){B=ze(B,k);const e=Ae(v-90),o=B/2;t+=o*Math.cos(e),i+=o*Math.sin(e)}else if(v<270){B=ze(B,F);const e=Ae(v-180),o=B/2;t-=o*Math.sin(e),i+=o*Math.cos(e)}else if(v<360){B=0-ze(B,k);const e=Ae(v-270),o=B/2;t-=o*Math.cos(e),i-=o*Math.sin(e)}f+B>0&&(!0===(null==(n=e.operations)?void 0:n.limitRatio)&&(g+=B/e.h*e.w),f+=B,d=t-g/2,u=i-f/2)}break;case"resize-bottom":if(0===v)e.h+X>0&&(f+=X,!0===(null==(a=e.operations)?void 0:a.limitRatio)&&(d-=X/e.h*e.w/2,g+=X/e.h*e.w));else if(v>0||v<0){let t=w.x,i=w.y;if(v<90){B=ze(B,F);const e=Ae(v),o=B/2;t-=o*Math.sin(e),i+=o*Math.cos(e)}else if(v<180){B=0-ze(B,k);const e=Ae(v-90),o=B/2;t-=o*Math.cos(e),i-=o*Math.sin(e)}else if(v<270){B=ze(B,k);const e=Ae(v-180),o=B/2;t+=o*Math.sin(e),i-=o*Math.cos(e)}else if(v<360){B=ze(B,k);const e=Ae(v-270),o=B/2;t+=o*Math.cos(e),i+=o*Math.sin(e)}f+B>0&&(!0===(null==(r=e.operations)?void 0:r.limitRatio)&&(g+=B/e.h*e.w),f+=B,d=t-g/2,u=i-f/2)}break;case"resize-left":if(0===v)e.w-Z>0&&(d+=Z,g-=Z,!0===(null==(s=e.operations)?void 0:s.limitRatio)&&(f-=Z/e.w*e.h,u+=Z/e.w*e.h/2));else if(v>0||v<0){let t=w.x,i=w.y;if(v<90){G=0-ze(G,D);const e=Ae(v),o=G/2;t-=o*Math.cos(e),i-=o*Math.sin(e)}else if(v<180){G=ze(G,D);const e=Ae(v-90),o=G/2;t+=o*Math.sin(e),i-=o*Math.cos(e)}else if(v<270){G=ze(G,Y);const e=Ae(v-180),o=G/2;t+=o*Math.cos(e),i+=o*Math.sin(e)}else if(v<360){G=ze(G,Y);const e=Ae(v-270),o=G/2;t-=o*Math.sin(e),i+=o*Math.cos(e)}g+G>0&&(!0===(null==(l=e.operations)?void 0:l.limitRatio)&&(f+=G/e.w*e.h),g+=G,d=t-g/2,u=i-f/2)}break;case"resize-right":if(0===v)e.w+Z>0&&(g+=Z,!0===(null==(h=e.operations)?void 0:h.limitRatio)&&(u-=Z*e.h/e.w/2,f+=Z*e.h/e.w));else if(v>0||v<0){let t=w.x,i=w.y;if(v<90){G=ze(G,Y);const e=Ae(v),o=G/2;t+=o*Math.cos(e),i+=o*Math.sin(e)}else if(v<180){G=ze(G,X);const e=Ae(v-90),o=G/2;t-=o*Math.sin(e),i+=o*Math.cos(e)}else if(v<270){G=ze(G,X);const e=Ae(v-180),o=G/2;t+=o*Math.cos(e),i+=o*Math.sin(e),G=0-G}else if(v<360){G=ze(G,Z);const e=Ae(v-270),o=G/2;t+=o*Math.sin(e),i-=o*Math.cos(e)}g+G>0&&(!0===(null==(c=e.operations)?void 0:c.limitRatio)&&(f+=G/e.w*e.h),g+=G,d=t-g/2,u=i-f/2)}break;case"resize-top-left":if(0===v)g-Z>0&&(d+=Z,g-=Z),f-X>0&&(u+=X,f-=X);else if(v>0||v<0){let e=w.x,t=w.y;if(v<90){B=0-ze(B,F),G=0-ze(G,S?0-B:D);const i=B/2;e+=i*Math.sin(x),t-=i*Math.cos(x);const o=G/2;e-=o*Math.cos(x),t-=o*Math.sin(x)}else if(v<180){B=ze(B,k),G=ze(G,S?B:D);const i=Ae(v-90),o=B/2;e+=o*Math.cos(i),t+=o*Math.sin(i);const n=G/2;e+=n*Math.sin(i),t-=n*Math.cos(i)}else if(v<270){B=ze(B,F),G=ze(G,S?B:Y);const i=Ae(v-180),o=B/2;e-=o*Math.sin(i),t+=o*Math.cos(i);const n=G/2;e+=n*Math.cos(i),t+=n*Math.sin(i)}else if(v<360){B=0-ze(B,k),G=ze(G,S?B:Y);const i=Ae(v-270),o=B/2;e-=o*Math.cos(i),t-=o*Math.sin(i);const n=G/2;e-=n*Math.sin(i),t+=n*Math.cos(i)}f+B>0&&(f+=B),g+G>0&&(g+=G),d=e-g/2,u=t-f/2}break;case"resize-top-right":if(0===v)g+Z>0&&(g+=Z),f-X>0&&(u+=X,f-=X);else if(v>0||v<0){let e=w.x,t=w.y;if(v<90){B=0-ze(B,F),G=ze(G,S?B:Y);const i=Ae(v),o=B/2;e+=o*Math.sin(i),t-=o*Math.cos(i);const n=G/2;e+=n*Math.cos(i),t+=n*Math.sin(i)}else if(v<180){B=ze(B,k),G=ze(G,S?B:Y);const i=Ae(v-90),o=B/2;e+=o*Math.cos(i),t+=o*Math.sin(i);const n=G/2;e-=n*Math.sin(i),t+=n*Math.cos(i)}else if(v<270){const i=Ae(v-180);B=ze(B,F),G=ze(G,S?B:0-D);const o=B/2;e-=o*Math.sin(i),t+=o*Math.cos(i);const n=G/2;e-=n*Math.cos(i),t-=n*Math.sin(i)}else if(v<360){B=0-ze(B,k),G=ze(G,S?B:D);const i=Ae(v-270),o=B/2;e-=o*Math.cos(i),t-=o*Math.sin(i);const n=G/2;e+=n*Math.sin(i),t-=n*Math.cos(i)}f+B>0&&(f+=B),g+G>0&&(g+=G),d=e-g/2,u=t-f/2}break;case"resize-bottom-left":if(0===v)e.h+X>0&&(f+=X),e.w-Z>0&&(d+=Z,g-=Z);else if(v>0||v<0){let e=w.x,t=w.y;if(v<90){B=ze(B,F),G=0-ze(G,S?0-B:D);const i=Ae(v),o=B/2;e-=o*Math.sin(i),t+=o*Math.cos(i);const n=G/2;e-=n*Math.cos(i),t-=n*Math.sin(i)}else if(v<180){B=0-ze(B,k),G=ze(G,S?B:D);const i=Ae(v-90),o=B/2;e-=o*Math.cos(i),t-=o*Math.sin(i);const n=G/2;e+=n*Math.sin(i),t-=n*Math.cos(i)}else if(v<270){B=ze(B,k),G=ze(G,S?B:Y);const i=Ae(v-180),o=B/2;e+=o*Math.sin(i),t-=o*Math.cos(i);const n=G/2;e+=n*Math.cos(i),t+=n*Math.sin(i)}else if(v<360){B=ze(B,k),G=ze(G,S?B:Y);const i=Ae(v-270),o=B/2;e+=o*Math.cos(i),t+=o*Math.sin(i);const n=G/2;e-=n*Math.sin(i),t+=n*Math.cos(i)}f+B>0&&(f+=B),g+G>0&&(g+=G),d=e-g/2,u=t-f/2}break;case"resize-bottom-right":if(0===v)e.h+X>0&&(f+=X),e.w+Z>0&&(g+=Z);else if(v>0||v<0){let e=w.x,t=w.y;if(v<90){B=ze(B,F),G=ze(G,S?B:Y);const i=Ae(v),o=B/2;e-=o*Math.sin(i),t+=o*Math.cos(i);const n=G/2;e+=n*Math.cos(i),t+=n*Math.sin(i)}else if(v<180){B=0-ze(B,k),G=ze(G,S?B:X);const i=Ae(v-90),o=B/2;e-=o*Math.cos(i),t-=o*Math.sin(i);const n=G/2;e-=n*Math.sin(i),t+=n*Math.cos(i)}else if(v<270){B=ze(B,k),G=ze(G,S?B:0-Y);const i=Ae(v-180),o=B/2;e+=o*Math.sin(i),t-=o*Math.cos(i);const n=G/2;e-=n*Math.cos(i),t-=n*Math.sin(i)}else if(v<360){B=ze(B,k),G=ze(G,S?B:D);const i=Ae(v-270),o=B/2;e+=o*Math.cos(i),t+=o*Math.sin(i);const n=G/2;e+=n*Math.sin(i),t-=n*Math.cos(i)}f+B>0&&(f+=B),g+G>0&&(g+=G),d=e-g/2,u=t-f/2}}return{x:d,y:u,w:g,h:f,angle:e.angle}}(n[0],{scale:a,start:o,end:s,resizeType:d,sharer:i});n[0].x=h.x,n[0].y=h.y,n[0].w=h.w,n[0].h=h.h,u([n[0]]),t.drawFrame()}}else"area"===g&&(l="area",i.setSharedStorage(ge,e.point),t.drawFrame());s=e.point},pointEnd(e){l=null;const o=i.getActiveStorage("data"),r=i.getSharedStorage(de),h=i.getSharedStorage(ce),c=i.getActiveViewSizeInfo();let d=!1;if(s=null,"resize"===h&&r)i.setSharedStorage(de,null),d=!0;else if("area"===h){if(i.setSharedStorage(ce,null),o){const e=i.getSharedStorage(ue),t=i.getSharedStorage(ge);if(e&&t){const{elements:a}=function(e,t){const i=[],o=[],n=[],{calculator:a,viewScaleInfo:r,viewSizeInfo:s,start:l,end:h}=t;if(!(Array.isArray(e.elements)&&l&&h))return{indexes:i,uuids:o,elements:n};const c=Math.min(l.x,h.x),d=Math.max(l.x,h.x),u=Math.min(l.y,h.y),g=Math.max(l.y,h.y);return e.elements.forEach(((e,t)=>{const l=a.elementSize(e,r,s),h=M(l);if(h.x>=c&&h.x<=d&&h.y>=u&&h.y<=g&&(i.push(t),o.push(e.uuid),n.push(e),l.angle&&(l.angle>0||l.angle<0))){const e=P(l);if(4===e.length){const t=[e[0].x,e[1].x,e[2].x,e[3].x],i=[e[0].y,e[1].y,e[2].y,e[3].y];l.x=Math.min(...t),l.y=Math.min(...i),l.w=Math.abs(Math.max(...t)-Math.min(...t)),l.h=Math.abs(Math.max(...i)-Math.min(...i))}}})),{indexes:i,uuids:o,elements:n}}(o,{start:e,end:t,calculator:n,viewScaleInfo:i.getActiveViewScaleInfo(),viewSizeInfo:i.getActiveViewSizeInfo()});a.length>0&&(i.setSharedStorage(ce,"drag-list"),u(a,{triggerEvent:!0}),d=!0)}}}else if("drag-list"===h)i.setSharedStorage(ce,"drag-list-end"),d=!0;else if(o){n.getPointElement(e.point,{data:o,viewScaleInfo:i.getActiveViewScaleInfo(),viewSizeInfo:i.getActiveViewSizeInfo()}).element?(i.setSharedStorage(ce,"select"),d=!0):i.setSharedStorage(ce,null)}null===i.getSharedStorage(ce)&&(f(),d=!0);(()=>{if(d){if(o&&Array.isArray(null==o?void 0:o.elements)&&["drag","drag-list"].includes(h)){const e=function(e,t,i){const o=j(e,{viewWidth:t.width,viewHeight:t.height,extend:null==i?void 0:i.extend});return!0===(null==i?void 0:i.extend)&&(o.contextWidth=Math.max(o.contextWidth,t.contextWidth),o.contextHeight=Math.max(o.contextHeight,t.contextHeight)),{contextSize:o}}(o.elements,c,{extend:!0});i.setActiveStorage("contextHeight",e.contextSize.contextHeight),i.setActiveStorage("contextWidth",e.contextSize.contextWidth)}o&&["drag","drag-list","drag-list-end","resize"].includes(h)&&a.trigger("change",{data:o}),t.drawFrame()}})()},pointLeave(){s=null,f(),t.drawFrame()},doubleClick(e){var o;const n=Te(e.point,g());if(1===n.elements.length&&"group"===(null==(o=n.elements[0])?void 0:o.type)){if(!0===c(n.elements[0]))return i.setSharedStorage(ce,null),void t.drawFrame()}i.setSharedStorage(ce,null)},beforeDrawFrame({snapshot:t}){const{activeStore:i,sharedStore:o}=t,{scale:a,offsetLeft:s,offsetTop:l,offsetRight:c,offsetBottom:d,width:u,height:g,contextHeight:f,contextWidth:v,devicePixelRatio:w}=i,x=e.sharer,S={scale:a,offsetLeft:s,offsetTop:l,offsetRight:c,offsetBottom:d},m={width:u,height:g,contextHeight:f,contextWidth:v,devicePixelRatio:w},y=o[we][0],p=o[fe],b=o[ve],I=o[ce],M=o[ue],A=o[ge],_=o[me],z=o[ye],R={calculator:n,viewScaleInfo:S,viewSizeInfo:m},P=y?Z(y,{groupQueue:_,controllerSize:10,viewScaleInfo:S}):null;if((null==_?void 0:_.length)>0)!function(e,t,i){for(let o=0;o<t.length;o++){const n=t[o],a={borderColor:pe,borderWidth:2,background:"transparent",lineDash:[4,4]};be(e,C(n,i),a)}}(r,z,R),p&&"drag"!==I&&Ie(r,b,R),y&&["select","drag","resize"].includes(I)&&Me(r,P,{...R});else if(p&&"drag"!==I&&Ie(r,b,R),y&&["select","drag","resize"].includes(I))Me(r,P,{...R});else if("area"===I&&M&&A)!function(e,t){const{start:i,end:o}=t;e.setLineDash([]),e.lineWidth=1,e.strokeStyle=pe,e.fillStyle="#1976d24f",e.beginPath(),e.moveTo(i.x,i.y),e.lineTo(o.x,i.y),e.lineTo(o.x,o.y),e.lineTo(i.x,o.y),e.closePath(),e.stroke(),e.fill()}(r,{start:M,end:A});else if(["drag-list","drag-list-end"].includes(I)){const e=Oe(h(),{viewScaleInfo:x.getActiveViewScaleInfo(),viewSizeInfo:x.getActiveViewSizeInfo(),calculator:n});e&&function(e,t){const{areaSize:i}=t,{x:o,y:n,w:a,h:r}=i;e.setLineDash([]),e.lineWidth=1,e.strokeStyle=pe,e.fillStyle="#1976d21c",e.beginPath(),e.moveTo(o,n),e.lineTo(o+a,n),e.lineTo(o+a,n+r),e.lineTo(o,n+r),e.closePath(),e.stroke(),e.fill()}(r,{areaSize:e})}}}},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idraw/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-alpha.2",
|
|
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.
|
|
24
|
+
"@idraw/types": "^0.4.0-alpha.0"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@idraw/board": "^0.
|
|
28
|
-
"@idraw/renderer": "^0.
|
|
29
|
-
"@idraw/util": "^0.
|
|
27
|
+
"@idraw/board": "^0.4.0-alpha.2",
|
|
28
|
+
"@idraw/renderer": "^0.4.0-alpha.2",
|
|
29
|
+
"@idraw/util": "^0.4.0-alpha.2"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
35
|
-
}
|
|
34
|
+
"gitHead": "5cc462b9206ea0e4e70b5183771dfbf694402483"
|
|
35
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021-present idrawjs
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare enum Mode {
|
|
2
|
-
NULL = "null",
|
|
3
|
-
SELECT_ELEMENT = "select-element",
|
|
4
|
-
SELECT_ELEMENT_LIST = "select-element-list",
|
|
5
|
-
SELECT_ELEMENT_WRAPPER_CONTROLLER = "select-element-wrapper-controller",
|
|
6
|
-
SELECT_AREA = "select-area"
|
|
7
|
-
}
|
|
8
|
-
export declare enum CursorStatus {
|
|
9
|
-
DRAGGING = "dragging",
|
|
10
|
-
NULL = "null"
|
|
11
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export var Mode;
|
|
2
|
-
(function (Mode) {
|
|
3
|
-
Mode["NULL"] = "null";
|
|
4
|
-
Mode["SELECT_ELEMENT"] = "select-element";
|
|
5
|
-
Mode["SELECT_ELEMENT_LIST"] = "select-element-list";
|
|
6
|
-
Mode["SELECT_ELEMENT_WRAPPER_CONTROLLER"] = "select-element-wrapper-controller";
|
|
7
|
-
Mode["SELECT_AREA"] = "select-area";
|
|
8
|
-
})(Mode || (Mode = {}));
|
|
9
|
-
export var CursorStatus;
|
|
10
|
-
(function (CursorStatus) {
|
|
11
|
-
CursorStatus["DRAGGING"] = "dragging";
|
|
12
|
-
CursorStatus["NULL"] = "null";
|
|
13
|
-
})(CursorStatus || (CursorStatus = {}));
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { DataElement, DataElemDesc, Point } from '@idraw/types';
|
|
2
|
-
export declare function parseRadianToAngle(radian: number): number;
|
|
3
|
-
export declare function parseAngleToRadian(angle: number): number;
|
|
4
|
-
export declare function calcElementCenter(elem: DataElement<keyof DataElemDesc>): Point;
|
|
5
|
-
export declare function calcRadian(center: Point, start: Point, end: Point): number;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
export function parseRadianToAngle(radian) {
|
|
2
|
-
return (radian / Math.PI) * 180;
|
|
3
|
-
}
|
|
4
|
-
export function parseAngleToRadian(angle) {
|
|
5
|
-
return (angle / 180) * Math.PI;
|
|
6
|
-
}
|
|
7
|
-
export function calcElementCenter(elem) {
|
|
8
|
-
const p = {
|
|
9
|
-
x: elem.x + elem.w / 2,
|
|
10
|
-
y: elem.y + elem.h / 2
|
|
11
|
-
};
|
|
12
|
-
return p;
|
|
13
|
-
}
|
|
14
|
-
export function calcRadian(center, start, end) {
|
|
15
|
-
const startAngle = calcLineAngle(center, start);
|
|
16
|
-
const endAngle = calcLineAngle(center, end);
|
|
17
|
-
if (endAngle !== null && startAngle !== null) {
|
|
18
|
-
if (startAngle > (Math.PI * 3) / 2 && endAngle < Math.PI / 2) {
|
|
19
|
-
return endAngle + (Math.PI * 2 - startAngle);
|
|
20
|
-
}
|
|
21
|
-
else if (endAngle > (Math.PI * 3) / 2 && startAngle < Math.PI / 2) {
|
|
22
|
-
return startAngle + (Math.PI * 2 - endAngle);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
return endAngle - startAngle;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
return 0;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function calcLineAngle(center, p) {
|
|
33
|
-
const x = p.x - center.x;
|
|
34
|
-
const y = center.y - p.y;
|
|
35
|
-
if (x === 0) {
|
|
36
|
-
if (y < 0) {
|
|
37
|
-
return Math.PI / 2;
|
|
38
|
-
}
|
|
39
|
-
else if (y > 0) {
|
|
40
|
-
return Math.PI * (3 / 2);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
else if (y === 0) {
|
|
44
|
-
if (x < 0) {
|
|
45
|
-
return Math.PI;
|
|
46
|
-
}
|
|
47
|
-
else if (x > 0) {
|
|
48
|
-
return 0;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
if (x > 0 && y < 0) {
|
|
52
|
-
return Math.atan(Math.abs(y) / Math.abs(x));
|
|
53
|
-
}
|
|
54
|
-
else if (x < 0 && y < 0) {
|
|
55
|
-
return Math.PI - Math.atan(Math.abs(y) / Math.abs(x));
|
|
56
|
-
}
|
|
57
|
-
else if (x < 0 && y > 0) {
|
|
58
|
-
return Math.PI + Math.atan(Math.abs(y) / Math.abs(x));
|
|
59
|
-
}
|
|
60
|
-
else if (x > 0 && y > 0) {
|
|
61
|
-
return Math.PI * 2 - Math.atan(Math.abs(y) / Math.abs(x));
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
64
|
-
}
|
package/dist/esm/lib/check.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { DataElementAttrs } from '@idraw/types';
|
|
2
|
-
declare function attrs(attrs: DataElementAttrs): boolean;
|
|
3
|
-
declare function rectDesc(desc: any): boolean;
|
|
4
|
-
declare function circleDesc(desc: any): boolean;
|
|
5
|
-
declare function imageDesc(desc: any): boolean;
|
|
6
|
-
declare function svgDesc(desc: any): boolean;
|
|
7
|
-
declare function htmlDesc(desc: any): boolean;
|
|
8
|
-
declare function textDesc(desc: any): boolean;
|
|
9
|
-
declare const check: {
|
|
10
|
-
attrs: typeof attrs;
|
|
11
|
-
textDesc: typeof textDesc;
|
|
12
|
-
rectDesc: typeof rectDesc;
|
|
13
|
-
circleDesc: typeof circleDesc;
|
|
14
|
-
imageDesc: typeof imageDesc;
|
|
15
|
-
svgDesc: typeof svgDesc;
|
|
16
|
-
htmlDesc: typeof htmlDesc;
|
|
17
|
-
};
|
|
18
|
-
type CheckTypeUtil = {
|
|
19
|
-
attrs: (value: any) => boolean;
|
|
20
|
-
rectDesc: (value: any) => boolean;
|
|
21
|
-
circleDesc: (value: any) => boolean;
|
|
22
|
-
imageDesc: (value: any) => boolean;
|
|
23
|
-
svgDesc: (value: any) => boolean;
|
|
24
|
-
htmlDesc: (value: any) => boolean;
|
|
25
|
-
textDesc: (value: any) => boolean;
|
|
26
|
-
};
|
|
27
|
-
export { CheckTypeUtil };
|
|
28
|
-
export default check;
|