@idraw/core 0.4.0-alpha.2 → 0.4.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- 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,"&amp;");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,iVBORw0KGgoAAAANSUhEUgAAACgAAAApCAYAAABHomvIAAAACXBIWXMAAAsTAAALEwEAmpwYAAAF92lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNi4wLWMwMDYgNzkuMTY0NzUzLCAyMDIxLzAyLzE1LTExOjUyOjEzICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cGhvdG9zaG9wPSJodHRwOi8vbnMuYWRvYmUuY29tL3Bob3Rvc2hvcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLm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FhROokSIi8/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/rhtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAF92lUWHR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KgIBoP9IiKrV682hLPZbP8DEpH7vb29N1paWn602WwHFyxYsAX4EKgE3gIsQBFQgOIeT6j3z0wFqEkc60OPx9Odn58/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}({});
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(e,t){if(1===t)return e;let i=1;const o=/^\#[0-9a-f]{6,6}$/i;let n=e;if(o.test(e)?i=parseInt(e.substring(5,7).replace(/^\#/,"0x")):/^\#[0-9a-f]{8,8}$/i.test(e)&&(i=parseInt(e.substring(7,9).replace(/^\#/,"0x")),n=e.substring(0,7)),i*=t,o.test(n)&&i>0&&i<1){const e=Math.max(0,Math.min(255,Math.ceil(256*i)));n=`${n.toUpperCase()}${e.toString(16).toUpperCase()}`}return n}function n(){function e(){return(65536*(1+Math.random())|0).toString(16).substring(1)}return`${e()}${e()}-${e()}-${e()}-${e()}-${e()}${e()}${e()}`}function a(e){let t=0;for(let i=0;i<e.length;i++)t+=e.charCodeAt(i)*e.charCodeAt(i)*i*i;return t.toString(16).substring(0,4)}function s(e){const t=e.length,i=Math.floor(t/2),o=e.substring(0,4).padEnd(4,"0"),n=e.substring(0,4).padEnd(4,"0");return`@assets/${a(t.toString(16).padEnd(4,o))}${a(e.substring(i-4,i).padEnd(4,o)).padEnd(4,"f")}-${a(e.substring(i-8,i-4).padEnd(4,o)).padEnd(4,"f")}-${a(e.substring(i-12,i-8).padEnd(4,o)).padEnd(4,"f")}-${a(e.substring(i-16,i-12).padEnd(4,n)).padEnd(4,"f")}-${a(e.substring(i,i+4).padEnd(4,n)).padEnd(4,"f")}${a(e.substring(i+4,i+8).padEnd(4,n)).padEnd(4,"f")}${a(n.padEnd(4,o).padEnd(4,n))}`}function r(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 l(e){return(Object.prototype.toString.call(e)||"").replace(/(\[object|\])/gi,"").trim()}const h={type(e,t){const i=l(e);return!0===t?i.toLocaleLowerCase():i},array:e=>"Array"===l(e),json:e=>"Object"===l(e),function:e=>"Function"===l(e),asyncFunction:e=>"AsyncFunction"===l(e),string:e=>"String"===l(e),number:e=>"Number"===l(e),undefined:e=>"Undefined"===l(e),null:e=>"Null"===l(e),promise:e=>"Promise"===l(e)};var c=function(e,t,i,o){return new(i||(i=Promise))((function(n,a){function s(e){try{l(o.next(e))}catch(e){a(e)}}function r(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(s,r)}l((o=o.apply(e,t||[])).next())}))};const{Image:d}=window;function u(e){return new Promise(((t,i)=>{const o=new d;o.crossOrigin="anonymous",o.onload=function(){t(o)},o.onabort=i,o.onerror=i,o.src=e}))}function f(e){return c(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 u(t)}))}function g(e,t){return c(this,void 0,void 0,(function*(){e=e.replace(/\&/gi,"&amp;");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"}),s=new FileReader;s.readAsDataURL(a),s.onload=function(e){var i;const o=null===(i=null==e?void 0:e.target)||void 0===i?void 0:i.result;t(o)},s.onerror=function(e){n(e)}}))}(e,t);return yield u(i)}))}function v(e){return"number"==typeof e&&(e>0||e<=0)}function w(e){return"number"==typeof e&&e>=0}function x(e){return"string"==typeof e&&/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${e}`)}function S(e){return"string"==typeof e&&/^(data:image\/)/.test(`${e}`)}const m={x:function(e){return v(e)},y:function(e){return v(e)},w:w,h:function(e){return"number"==typeof e&&e>=0},angle:function(e){return"number"==typeof e&&e>=-360&&e<=360},number:v,numberStr:function(e){return/^(-?\d+(?:\.\d+)?)$/.test(`${e}`)},borderWidth:function(e){return w(e)},borderRadius:function(e){return v(e)&&e>=0},color:function(e){return i(e)},imageSrc:function(e){return S(e)||x(e)},imageURL:x,imageBase64:S,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 v(e)&&e>0},lineHeight:function(e){return v(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 v(e)&&e>0}};class y{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){const t=e.map((e=>this.$doPixelRatio(e)));return this._ctx.setLineDash(t)}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],s=e[e.length-4],r=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(s),this.$doPixelRatio(r),this.$doPixelRatio(l),this.$doPixelRatio(h)):this._ctx.drawImage(t,this.$doPixelRatio(s),this.$doPixelRatio(r),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,s,r){this._ctx.ellipse(this.$doPixelRatio(e),this.$doPixelRatio(t),this.$doPixelRatio(i),this.$doPixelRatio(o),n,a,s,r)}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 p(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 y(a,e)}class b{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 I(e,t){return{x:e.x+(t.x-e.x)/2,y:e.y+(t.y-e.y)/2}}class M{constructor(e){this._backUpDefaultStorage=r(e.defaultStorage),this._temp=this._createTempStorage()}set(e,t){this._temp[e]=t}get(e){return this._temp[e]}getSnapshot(){return r(this._temp)}clear(){this._temp=this._createTempStorage()}_createTempStorage(){return r(this._backUpDefaultStorage)}}function A(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}}function z(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}}function _(e){return e/180*Math.PI}function P(e,t,i,o){const n=_(t||0);i&&(n>0||n<0)&&(e.translate(i.x,i.y),e.rotate(n),e.translate(-i.x,-i.y)),o(e),i&&(n>0||n<0)&&(e.translate(i.x,i.y),e.rotate(-n),e.translate(-i.x,-i.y))}function R(e,t,i){const o=T(t);P(e,t.angle||0,o,(()=>{i(e)}))}function T(e){return{x:e.x+e.w/2,y:e.y+e.h/2}}function E(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 T({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 O(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 s=0,r=0;return 0===n?(s=0,r=0-a):n>0&&n<Math.PI/2?(s=Math.sin(n)*a,r=0-Math.cos(n)*a):n===Math.PI/2?(s=a,r=0):n>Math.PI/2&&n<Math.PI?(s=Math.sin(Math.PI-n)*a,r=Math.cos(Math.PI-n)*a):n===Math.PI?(s=0,r=a):n>Math.PI&&n<1.5*Math.PI?(s=0-Math.sin(n-Math.PI)*a,r=Math.cos(n-Math.PI)*a):n===1.5*Math.PI?(s=0-a,r=0):n>1.5*Math.PI&&n<2*Math.PI?(s=0-Math.sin(2*Math.PI-n)*a,r=0-Math.cos(2*Math.PI-n)*a):n===2*Math.PI&&(s=0,r=0-a),s+=e.x,r+=e.y,{x:s,y:r}}function W(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:s,angle:r=0}=e,l=O(T({x:t,y:n,w:a,h:s,angle:r}),{x:i,y:o},_(r));i=l.x,o=l.y})),{x:i,y:o}}return e}function C(e,t,i){const{x:o,y:n,w:a,h:s}=e;let r={x:o,y:n},l={x:o+a,y:n},h={x:o+a,y:n+s},c={x:o,y:n+s};if(i&&(i>0||i<0)){const e=_(D(i));r=O(t,r,e),l=O(t,l,e),h=O(t,h,e),c=O(t,c,e)}return[r,l,h,c]}function j(e){const{angle:t=0}=e;return C(e,T(e),t)}function L(e,t,i){return[O(e,{x:t[0].x,y:t[0].y},i),O(e,{x:t[1].x,y:t[1].y},i),O(e,{x:t[2].x,y:t[2].y},i),O(e,{x:t[3].x,y:t[3].y},i)]}function D(e){if(!(e>0||e<0)||0===e)return 0;let t=e%360;return t<0&&(t+=360),t}function Y(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=Y(null===(o=null==e?void 0:e.detail)||void 0===o?void 0:o.children))}))}return t}function F(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=j(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),s=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(s-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 k(e,t){const{viewScaleInfo:i}=t,{x:o,y:n,w:a,h:s,angle:r}=e,{scale:l,offsetTop:h,offsetLeft:c}=i;return{x:o*l+c,y:n*l+h,w:a*l,h:s*l,angle:r}}function B(e,t){const{viewScaleInfo:i}=t,{x:o,y:n}=e,{scale:a,offsetTop:s,offsetLeft:r}=i;return{x:o*a+r,y:n*a+s}}function G(e,t){return[B(e[0],t),B(e[1],t),B(e[2],t),B(e[3],t)]}function N(e,t){const{context2d:i,element:o,viewScaleInfo:n,viewSizeInfo:a}=t,{angle:s=0}=o,{x:r,y:l,w:h,h:c}=k(o,{viewScaleInfo:n,viewSizeInfo:a}),d=j({x:r,y:l,w:h,h:c,angle:s});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 X(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 Z(e){const{x:t,y:i,w:o,h:n,angle:a=0}=e;return 0===a?X(e):C(e,T({x:t,y:i,w:o,h:n,angle:a}),a)}function V(e){const t=[];let i=0,o=0;const n=[],a=[...e];for(let e=0;e<a.length;e++){const{x:s,y:r,w:l,h:h,angle:c=0}=a[e];let d;if(i+=s,o+=r,0===e){const e={x:i,y:o,w:l,h:h,angle:c};d=Z({x:s,y:r,w:l,h:h,angle:c}),n.push({center:T(e),angle:c,radian:_(c)})}else{d=X({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=L(t,d,i)}const e=E(d);if(c>0||c<0){d=L(e,d,_(c))}n.push({center:e,angle:c,radian:_(c)})}t.push(d)}return t}function $(e,t){const i=function(e,t){const{groupQueue:i}=t;return i.length>0?V([...i,e]):[Z(e)]}(e,t);return i.pop()||null}function H(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 Q(e,t){const{groupQueue:i,controllerSize:o,viewScaleInfo:a}=t,s=(o&&o>0?o:8)/a.scale,{x:r,y:l,w:h,h:c,angle:d=0}=e,u=[{uuid:n(),x:r,y:l,w:h,h:c,angle:d,type:"group",detail:{children:[]}},...i];let f=0;u.forEach((({angle:e=0})=>{f+=e}));const g=$(e,{groupQueue:i}),v=I(g[0],g[1]),w=I(g[1],g[2]),x=I(g[2],g[3]),S=I(g[3],g[0]),m=g[0],y=g[1],p=g[2],b=g[3],M=H(m,{size:s,angle:f}),A=H(y,{size:s,angle:f}),z=H(b,{size:s,angle:f}),_=H(p,{size:s,angle:f}),P=Z(M),R=Z(A),T=Z(z),E=Z(_),O=[P[1],R[0],R[3],P[2]],W=[R[3],R[2],E[1],E[0]],C=[T[1],E[0],E[3],T[2]];return{elementWrapper:g,left:{type:"left",vertexes:[P[3],P[2],T[1],T[0]],center:S},right:{type:"right",vertexes:W,center:w},top:{type:"top",vertexes:O,center:v},bottom:{type:"bottom",vertexes:C,center:x},topLeft:{type:"top-left",vertexes:P,center:m},topRight:{type:"top-right",vertexes:R,center:y},bottomLeft:{type:"bottom-left",vertexes:T,center:b},bottomRight:{type:"bottom-right",vertexes:E,center:p}}}function U(e){let t="";return e.forEach((e=>{t+=e.type+e.params.join(" ")})),t}function J(e,t){let i=2;return void 0!==(null==t?void 0:t.decimalPlaces)&&(null==t?void 0:t.decimalPlaces)>=0&&(i=t.decimalPlaces),parseFloat(e.toFixed(i))}const K={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,lineHeight:20,fontFamily:"sans-serif",fontWeight:400};function q(e,t){const{viewScaleInfo:i}=t,{scale:o}=i;let{borderRadius:n,boxSizing:a=K.boxSizing,borderWidth:s}=e.detail;"number"!=typeof s&&(n=0);let{x:r,y:l,w:h,h:c}=e,d=[0,0,0,0];if("number"==typeof n){const e=n*o;d=[e,e,e,e]}else Array.isArray(n)&&4===(null==n?void 0:n.length)&&(d=[n[0]*o,n[1]*o,n[2]*o,n[3]*o]);let u=0;return"number"==typeof s&&(u=(s||1)*o),"border-box"===a?(r=e.x+u/2,l=e.y+u/2,h=e.w-u,c=e.h-u):"content-box"===a?(r=e.x-u/2,l=e.y-u/2,h=e.w+u,c=e.h+u):(r=e.x,l=e.y,h=e.w,c=e.h),{x:r,y:l,w:h,h:c,radiusList:d}}function ee(e,t,i){if("string"==typeof t)return t;const{viewElementSize:n,viewScaleInfo:a,opacity:s=1}=i,{x:r,y:l}=n,{scale:h}=a;if("linear-gradient"===(null==t?void 0:t.type)){const{start:i,end:n,stops:a}=t,c={x:r+i.x*h,y:l+i.y*h},d={x:r+n.x*h,y:l+n.y*h},u=e.createLinearGradient(c.x,c.y,d.x,d.y);return a.forEach((e=>{u.addColorStop(e.offset,o(e.color,s))})),u}if("radial-gradient"===(null==t?void 0:t.type)){const{inner:i,outer:n,stops:a}=t,c={x:r+i.x*h,y:l+i.y*h,radius:i.radius*h},d={x:r+n.x*h,y:l+n.y*h,radius:n.radius*h},u=e.createRadialGradient(c.x,c.y,c.radius,d.x,d.y,d.radius);return a.forEach((e=>{u.addColorStop(e.offset,o(e.color,s))})),u}return"#000000"}const te={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,lineHeight:20,fontFamily:"sans-serif",fontWeight:400};function ie(e,t,o){const{pattern:n,renderContent:a,originElem:s,calcElemSize:r,viewScaleInfo:l,viewSizeInfo:c}=o||{};!function(e,t,i){const{renderContent:o,originElem:n,calcElemSize:a,viewScaleInfo:s,viewSizeInfo:r}=i,l=s.scale*r.devicePixelRatio,{clipPath:h}=(null==n?void 0:n.detail)||{};if(h&&a&&h.commands){const{x:i,y:n,w:s,h:r}=a,{originW:c,originH:d,originX:u,originY:f}=h,g=s/c,v=r/d;let w=i-u*g,x=n-f*v;e.save(),e.translate(w,x),e.scale(l*g,l*v);const S=U(h.commands||[]),m=new Path2D(S);e.clip(m),e.translate(0-w,0-x),e.setTransform(1,0,0,1,0,0),R(e,Object.assign({},t),(()=>{null==o||o()})),e.restore()}else null==o||o()}(e,t,{originElem:s,calcElemSize:r,viewScaleInfo:l,viewSizeInfo:c,renderContent:()=>{var o,s;void 0!==(null===(o=null==t?void 0:t.detail)||void 0===o?void 0:o.opacity)&&(null===(s=null==t?void 0:t.detail)||void 0===s?void 0:s.opacity)>=0?e.globalAlpha=t.detail.opacity:e.globalAlpha=1,function(e,t,i){var o,n;const{pattern:a,viewScaleInfo:s,viewSizeInfo:r}=i;let l=[];if(t.detail,t.detail.background||a){const{x:i,y:c,w:d,h:u,radiusList:f}=q(t,{viewScaleInfo:s,viewSizeInfo:r});if(e.beginPath(),e.moveTo(i+f[0],c),e.arcTo(i+d,c,i+d,c+u,f[1]),e.arcTo(i+d,c+u,i,c+u,f[2]),e.arcTo(i,c+u,i,c,f[3]),e.arcTo(i,c,i+d,c,f[0]),e.closePath(),"string"==typeof a)e.fillStyle=a;else if(["CanvasPattern"].includes(h.type(a)))e.fillStyle=a;else if("string"==typeof t.detail.background)e.fillStyle=t.detail.background;else if("linear-gradient"===(null===(o=t.detail.background)||void 0===o?void 0:o.type)){const o=ee(e,t.detail.background,{viewElementSize:{x:i,y:c,w:d,h:u},viewScaleInfo:s,opacity:e.globalAlpha});e.fillStyle=o}else if("radial-gradient"===(null===(n=t.detail.background)||void 0===n?void 0:n.type)){const o=ee(e,t.detail.background,{viewElementSize:{x:i,y:c,w:d,h:u},viewScaleInfo:s,opacity:e.globalAlpha});if(e.fillStyle=o,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]+c):"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:n,viewScaleInfo:l,viewSizeInfo:c}),null==a||a(),function(e,t,o){var n,a;if(0===t.detail.borderWidth)return;if(!i(t.detail.borderColor))return;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{viewScaleInfo:s}=o,{scale:r}=s;let l=te.borderColor;!0===i(t.detail.borderColor)&&(l=t.detail.borderColor);const{borderWidth:h,borderRadius:c,borderDash:d,boxSizing:u=te.boxSizing}=t.detail;let f=0;"number"==typeof h&&(f=h||1);f*=r;let g=[0,0,0,0];if("number"==typeof c){const e=c*r;g=[e,e,e,e]}else Array.isArray(c)&&4===(null==c?void 0:c.length)&&(g=[c[0]*r,c[1]*r,c[2]*r,c[3]*r]);e.strokeStyle=l;let v=[];Array.isArray(d)&&d.length>0&&(v=d.map((e=>Math.ceil(e*r))));let w=0,x=0,S=0,m=0;Array.isArray(h)&&(w=(h[0]||0)*r,x=(h[1]||0)*r,S=(h[2]||0)*r,m=(h[3]||0)*r);if(m||x||w||S){e.lineCap="butt";let{x:i,y:o,w:n,h:a}=t;"border-box"===u?(i+=m/2,o+=w/2,n=n-m/2-x/2,a=a-w/2-S/2):"content-box"===u?(i-=m/2,o-=w/2,n=n+m/2+x/2,a=a+w/2+S/2):(i=t.x,o=t.y,n=t.w,a=t.h),w&&(e.beginPath(),e.lineWidth=w,e.moveTo(i-m/2,o),e.lineTo(i+n+x/2,o),e.closePath(),e.stroke()),x&&(e.beginPath(),e.lineWidth=x,e.moveTo(i+n,o-w/2),e.lineTo(i+n,o+a+S/2),e.closePath(),e.stroke()),S&&(e.beginPath(),e.lineWidth=S,e.moveTo(i-m/2,o+a),e.lineTo(i+n+x/2,o+a),e.closePath(),e.stroke()),m&&(e.beginPath(),e.lineWidth=m,e.moveTo(i,o-w/2),e.lineTo(i,o+a+S/2),e.closePath(),e.stroke())}else{let{x:i,y:o,w:n,h:a}=t;"border-box"===u?(i=t.x+f/2,o=t.y+f/2,n=t.w-f,a=t.h-f):"content-box"===u?(i=t.x-f/2,o=t.y-f/2,n=t.w+f,a=t.h+f):(i=t.x,o=t.y,n=t.w,a=t.h),v.length>0?e.lineCap="butt":e.lineCap="square",e.setLineDash(v),e.lineWidth=f,e.beginPath(),e.moveTo(i+g[0],o),e.arcTo(i+n,o,i+n,o+a,g[1]),e.arcTo(i+n,o+a,i,o+a,g[2]),e.arcTo(i,o+a,i,o,g[3]),e.arcTo(i,o,i+n,o,g[0]),e.closePath(),e.stroke(),e.globalAlpha=1}e.setLineDash([])}(e,t,{viewScaleInfo:l,viewSizeInfo:c}),e.globalAlpha=1}})}function oe(e,t,i){const{detail:o}=t,{viewScaleInfo:n,renderContent:a}=i,{shadowColor:s,shadowOffsetX:r,shadowOffsetY:l,shadowBlur:h}=o;m.number(h)?(e.save(),e.shadowColor=s||te.shadowColor,e.shadowOffsetX=(r||0)*n.scale,e.shadowOffsetY=(l||0)*n.scale,e.shadowBlur=(h||0)*n.scale,a(),e.restore()):a()}const ne={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,lineHeight:20,fontFamily:"sans-serif",fontWeight:400};function ae(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:s,y:r,w:l,h:h,angle:c}=o.elementSize(t,n,a);const d=Object.assign(Object.assign({},t),{x:s,y:r,w:l,h:h,angle:c});R(e,{x:s,y:r,w:l,h:h,angle:c},(()=>{oe(e,d,{viewScaleInfo:n,viewSizeInfo:a,renderContent:()=>{ie(e,d,{originElem:t,calcElemSize:{x:s,y:r,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:s="#000000",borderWidth:r=0}=o,{calculator:l,viewScaleInfo:h,viewSizeInfo:c}=i,{x:d,y:u,w:f,h:g}=l.elementSize({x:t.x,y:t.y,w:t.w,h:t.h},h,c),v=Object.assign(Object.assign({},t),{x:d,y:u,w:f,h:g,angle:n});R(e,{x:d,y:u,w:f,h:g,angle:n},(()=>{oe(e,v,{viewScaleInfo:h,viewSizeInfo:c,renderContent:()=>{var i,o;const n=f/2,l=g/2,c=d+n,v=u+l;if(void 0!==(null===(i=null==t?void 0:t.detail)||void 0===i?void 0:i.opacity)&&(null===(o=null==t?void 0:t.detail)||void 0===o?void 0:o.opacity)>=0?e.globalAlpha=t.detail.opacity:e.globalAlpha=1,"number"==typeof r&&r>0){const t=r/2+n,i=r/2+l;e.beginPath(),e.strokeStyle=s,e.lineWidth=r,e.circle(c,v,t,i,0,0,2*Math.PI),e.closePath(),e.stroke()}e.beginPath();const w=ee(e,a,{viewElementSize:{x:d,y:u,w:f,h:g},viewScaleInfo:h,opacity:e.globalAlpha});e.fillStyle=w,e.circle(c,v,n,l,0,0,2*Math.PI),e.closePath(),e.fill(),e.globalAlpha=1}})}))}(e,t,o);break;case"text":!function(e,t,o){const{calculator:n,viewScaleInfo:a,viewSizeInfo:s}=o,{x:r,y:l,w:h,h:c,angle:d}=n.elementSize(t,a,s),u=Object.assign(Object.assign({},t),{x:r,y:l,w:h,h:c,angle:d});R(e,{x:r,y:l,w:h,h:c,angle:d},(()=>{ie(e,u,{originElem:t,calcElemSize:{x:r,y:l,w:h,h:c,angle:d},viewScaleInfo:a,viewSizeInfo:s,renderContent:()=>{const o=Object.assign(Object.assign({},ne),t.detail),n=(o.fontSize||ne.fontSize)*a.scale,s=o.lineHeight?o.lineHeight*a.scale:n;e.fillStyle=t.detail.color||ne.color,e.textBaseline="top",e.$setFont({fontWeight:o.fontWeight,fontSize:n,fontFamily:o.fontFamily});const d=o.text.replace(/\r\n/gi,"\n"),u=s,f=d.split("\n"),g=[];let v=0;f.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]||"":(g.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){g.push({text:o,width:e.$undoPixelRatio(e.measureText(o).width)}),i<f.length-1&&v++;break}}else g.push({text:"",width:0})}));let w=0;g.length*u<c&&("top"===t.detail.verticalAlign?w=0:"bottom"===t.detail.verticalAlign?w+=c-g.length*u:w+=(c-g.length*u)/2);{const t=l+w;void 0!==o.textShadowColor&&i(o.textShadowColor)&&(e.shadowColor=o.textShadowColor),void 0!==o.textShadowOffsetX&&m.number(o.textShadowOffsetX)&&(e.shadowOffsetX=o.textShadowOffsetX),void 0!==o.textShadowOffsetY&&m.number(o.textShadowOffsetY)&&(e.shadowOffsetY=o.textShadowOffsetY),void 0!==o.textShadowBlur&&m.number(o.textShadowBlur)&&(e.shadowBlur=o.textShadowBlur),g.forEach(((i,n)=>{let a=r;"center"===o.textAlign?a=r+(h-i.width)/2:"right"===o.textAlign&&(a=r+(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),{calculator:n,viewScaleInfo:a,viewSizeInfo:s}=i,{x:r,y:l,w:h,h:c,angle:d}=n.elementSize(t,a,s),u=Object.assign(Object.assign({},t),{x:r,y:l,w:h,h:c,angle:d});R(e,{x:r,y:l,w:h,h:c,angle:d},(()=>{oe(e,u,{viewScaleInfo:a,viewSizeInfo:s,renderContent:()=>{ie(e,u,{originElem:t,calcElemSize:{x:r,y:l,w:h,h:c,angle:d},viewScaleInfo:a,viewSizeInfo:s,renderContent:()=>{if(o||i.loader.load(t,i.elementAssets||{}),"image"===t.type&&o){const{opacity:i}=t.detail;e.globalAlpha=i||1;const{x:n,y:r,w:l,h:h,radiusList:c}=q(u,{viewScaleInfo:a,viewSizeInfo:s});e.save(),e.beginPath(),e.moveTo(n+c[0],r),e.arcTo(n+l,r,n+l,r+h,c[1]),e.arcTo(n+l,r+h,n,r+h,c[2]),e.arcTo(n,r+h,n,r,c[3]),e.arcTo(n,r,n+l,r,c[0]),e.closePath(),e.fill(),e.clip(),e.drawImage(o,n,r,l,h),e.globalAlpha=1,e.restore()}}})}})}))}(e,t,o);break;case"svg":!function(e,t,i){const o=i.loader.getContent(t),{calculator:n,viewScaleInfo:a,viewSizeInfo:s}=i,{x:r,y:l,w:h,h:c,angle:d}=n.elementSize(t,a,s);R(e,{x:r,y:l,w:h,h:c,angle:d},(()=>{if(o||i.loader.load(t,i.elementAssets||{}),"svg"===t.type&&o){const{opacity:i}=t.detail;e.globalAlpha=i||1,e.drawImage(o,r,l,h,c),e.globalAlpha=1}}))}(e,t,o);break;case"html":!function(e,t,i){const o=i.loader.getContent(t),{calculator:n,viewScaleInfo:a,viewSizeInfo:s}=i,{x:r,y:l,w:h,h:c,angle:d}=n.elementSize(t,a,s);R(e,{x:r,y:l,w:h,h:c,angle:d},(()=>{if(o||i.loader.load(t,i.elementAssets||{}),"html"===t.type&&o){const{opacity:i}=t.detail;e.globalAlpha=i||1,e.drawImage(o,r,l,h,c),e.globalAlpha=1}}))}(e,t,o);break;case"path":!function(e,t,i){const{detail:o}=t,{originX:n,originY:a,originW:s,originH:r}=o,{calculator:l,viewScaleInfo:h,viewSizeInfo:c}=i,{x:d,y:u,w:f,h:g,angle:v}=l.elementSize(t,h,c),w=f/s,x=g/r,S=d-n*w,m=u-a*x,y=h.scale*c.devicePixelRatio,p=Object.assign(Object.assign({},t),{x:d,y:u,w:f,h:g,angle:v});R(e,{x:d,y:u,w:f,h:g,angle:v},(()=>{ie(e,p,{originElem:t,calcElemSize:{x:d,y:u,w:f,h:g,angle:v},viewScaleInfo:h,viewSizeInfo:c,renderContent:()=>{oe(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=U(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:s,y:r,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:s,y:r,w:l,h:h,angle:c});R(e,{x:s,y:r,w:l,h:h,angle:c},(()=>{ie(e,d,{originElem:t,calcElemSize:{x:s,y:r,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(s,r),e.lineTo(s+l,r),e.lineTo(s+l,r+h),e.lineTo(s,r+h),e.closePath(),e.clip());for(let o=0;o<t.detail.children.length;o++){let s=t.detail.children[o];if(s=Object.assign(Object.assign({},s),{x:n.x+s.x,y:n.y+s.y}),a.isElementInView(s,i.viewScaleInfo,i.viewSizeInfo))try{ae(e,s,Object.assign({},i))}catch(e){console.error(e)}}e.restore()}}})}))}(e,t,o)}}catch(e){console.error(e)}}const se={boxSizing:"border-box",borderWidth:0,borderColor:"#000000",shadowColor:"#000000",borderRadius:0,borderDash:[],shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,opacity:1,color:"#000000",textAlign:"left",verticalAlign:"top",fontSize:16,lineHeight:20,fontFamily:"sans-serif",fontWeight:400};var re=function(e,t,i,o){return new(i||(i=Promise))((function(n,a){function s(e){try{l(o.next(e))}catch(e){a(e)}}function r(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(s,r)}l((o=o.apply(e,t||[])).next())}))};const le=["image","svg","html"],he=e=>{var t,i,o;let a=null;return"image"===e.type?a=(null===(t=null==e?void 0:e.detail)||void 0===t?void 0:t.src)||null:"svg"===e.type?a=(null===(i=null==e?void 0:e.detail)||void 0===i?void 0:i.svg)||null:"html"===e.type&&(a=(null===(o=null==e?void 0:e.detail)||void 0===o?void 0:o.html)||null),"string"==typeof a&&a?/^@assets\/[0-9a-z]{8,8}\-[0-9a-z]{4,4}\-[0-9a-z]{4,4}\-[0-9a-z]{4,4}\-[0-9a-z]{12,12}$/.test(`${a}`)?a:s(a):s(`${n()}-${e.uuid}-${n()}-${n()}`)};class ce extends b{constructor(){super(),this._loadFuncMap={},this._currentLoadItemMap={},this._storageLoadItemMap={},this._registerLoadFunc("image",((e,t)=>re(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 u(o);return{uuid:e.uuid,lastModified:Date.now(),content:n}})))),this._registerLoadFunc("html",((e,t)=>re(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 g(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)=>re(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 f(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=he(e.element),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=he(e.element),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),o=he(e);this._currentLoadItemMap[o]=i;const n=this._loadFuncMap[e.type];"function"==typeof n&&(i.startTime=Date.now(),n(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=he(e),o=null===(t=this._currentLoadItemMap)||void 0===t?void 0:t[i];return!(!o||"error"!==o.status||!o.source||o.source!==this._getLoadElementSource(e))}load(e,t){this._isExistingErrorStorage(e)||le.includes(e.type)&&this._loadResource(e,t)}getContent(e){var t,i;const o=he(e);return(null===(i=null===(t=this._storageLoadItemMap)||void 0===t?void 0:t[o])||void 0===i?void 0:i.content)||null}}class de extends b{constructor(e){super(),this._loader=new ce,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],a=Object.assign(Object.assign({},n),{detail:Object.assign(Object.assign({},se),null==n?void 0:n.detail)});if(i.calculator.isElementInView(a,i.viewScaleInfo,i.viewSizeInfo))try{ae(e,a,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:s,width:r,height:l,contextHeight:h,contextWidth:c,devicePixelRatio:d}=t.getActiveStoreSnapshot();i&&this.drawData(i,{viewScaleInfo:{scale:e,offsetTop:o,offsetBottom:n,offsetLeft:a,offsetRight:s},viewSizeInfo:{width:r,height:l,contextHeight:h,contextWidth:c,devicePixelRatio:d}})}}class ue{constructor(e){this._opts=e}elementSize(e,t,i){return k(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:s}=e,{x:r,y:l,w:h,h:c}=k(e,{viewScaleInfo:o,viewSizeInfo:i}),d=j({x:r,y:l,w:h,h:c,angle:s}),u={x:0,y:0,w:n,h:a},f=Math.min(d[0].x,d[1].x,d[2].x,d[3].x),g=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,s=t.x,r=t.y,l=t.x+t.w,h=t.y+t.h;return i<=l&&n>=s&&o<=h&&a>=r}(u,{x:f,y:g,w:Math.max(d[0].x,d[1].x,d[2].x,d[3].x)-f,h:Math.max(d[0].y,d[1].y,d[2].y,d[3].y)-g})}(e,{viewScaleInfo:t,viewSizeInfo:i})}isPointInElement(e,t,i,o){return N(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:s,viewScaleInfo:r,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,s=0,d=0;for(let e=0;e<=t;e++)n+=h[e].x,s+=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 f=u.detail.children[i];if(!0!==(null===(o=null==f?void 0:f.operations)||void 0===o?void 0:o.invisible)){if(!f)break;if(N(e,{context2d:a,element:{x:n+f.x,y:s+f.y,w:f.w,h:f.h,angle:d+(f.angle||0)},viewScaleInfo:r,viewSizeInfo:l})){c.element=f,(t<h.length-1||"group"!==f.type)&&(c.groupQueueIndex=t);break}}}if(c.element)break}if(c.element)return c;for(let t=s.elements.length-1;t>=0;t--){const i=s.elements[t];if(!0!==(null===(n=null==i?void 0:i.operations)||void 0===n?void 0:n.invisible)&&N(e,{context2d:a,element:i,viewScaleInfo:r,viewSizeInfo:l})){c.index=t,c.element=i;break}}return c}(e,Object.assign(Object.assign({},t),{context2d:i}))}}function fe(e){return e>0||e<0||0===e}class ge extends b{constructor(e){super();const t=new M({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!!(fe(e.x)&&fe(e.y)&&e.x<=i&&e.y<=o)}}const ve={width:0,height:0,devicePixelRatio:1,contextWidth:0,contextHeight:0,data:null,scale:1,offsetLeft:0,offsetRight:0,offsetTop:0,offsetBottom:0};class we{constructor(){const e=new M({defaultStorage:ve}),t=new M({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:xe}=window;class Se extends b{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:s,offsetBottom:r,offsetLeft:l,offsetRight:h,width:c,height:d,contextHeight:u,contextWidth:f,devicePixelRatio:g}=e.activeStore,{underContext:v,viewContext:w,helperContext:x,boardContext:S}=i;(null==e?void 0:e.activeStore.data)&&t.drawData(e.activeStore.data,{viewScaleInfo:{scale:a,offsetTop:s,offsetBottom:r,offsetLeft:l,offsetRight:h},viewSizeInfo:{width:c,height:d,contextHeight:u,contextWidth:f,devicePixelRatio:g}}),o({snapshot:e}),S.clearRect(0,0,c,d),S.drawImage(v.canvas,0,0,c,d),S.drawImage(w.canvas,0,0,c,d),S.drawImage(x.canvas,0,0,c,d),v.clearRect(0,0,c,d),w.clearRect(0,0,c,d),x.clearRect(0,0,c,d),n({snapshot:e})}0!==this._drawFrameSnapshotQueue.length?(this._drawFrameStatus="DRAWING")&&xe((()=>{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,s=t/o.scale,r=i.x,l=i.y;return{moveX:r-r*s+(n*s-n),moveY:l-l*s+(a*s-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:s,height:r,contextWidth:l,contextHeight:h}=n;let c=o.offsetLeft,d=o.offsetRight,u=o.offsetTop,f=o.offsetBottom;return c+=t,u+=i,d=s-(l*a+c),f=r-(h*a+u),{scale:a,offsetTop:u,offsetLeft:c,offsetRight:d,offsetBottom:f}}({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:s}=o,{underContext:r,boardContext:l,helperContext:h,viewContext:c}=this._opts.viewContent;return l.canvas.width=n*s,l.canvas.height=a*s,l.canvas.style.width=`${n}px`,l.canvas.style.height=`${a}px`,r.canvas.width=n*s,r.canvas.height=a*s,h.canvas.width=n*s,h.canvas.height=a*s,c.canvas.width=n*s,c.canvas.height=a*s,t.setActiveViewSizeInfo(o),o}}const me=["RULER"];class ye{constructor(e){this._middlewares=[],this._middlewareObjs=[],this._activeMiddlewareObjs=[],this._eventHub=new b,this._activeMode="SELECT";const{viewContent:t}=e,i=new we,o=new ue({viewContent:t}),n=new ge({viewContent:t,sharer:i}),a=new de({viewContent:t,sharer:i,calculator:o});this._opts=e,this._sharer=i,this._renderer=a,this._watcher=n,this._calculator=o,this._viewer=new Se({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=[...me,e],i=[];this._middlewareObjs.forEach((e=>{(!0===e.isDefault||t.includes(e.mode))&&i.push(e)})),this._activeMiddlewareObjs=i}getSharer(){return this._sharer}getViewer(){return this._viewer}setData(e){const t=this._sharer;this._sharer.setActiveStorage("data",e);const i=t.getActiveViewSizeInfo(),o=F(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,s=e({viewContent:t,sharer:i,viewer:o,calculator:n,eventHub:a});this._middlewares.push(e),this._activeMiddlewareObjs.push(s)}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 s=a.viewContext.canvas;s.style.width=`${i}px`,s.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,{underContext:t,helperContext:i,viewContext:o,boardContext:n}=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),n.clearRect(0,0,n.canvas.width,n.canvas.height),this._handleClear()}getEventHub(){return this._eventHub}}const pe="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAApCAYAAABHomvIAAAACXBIWXMAAAsTAAALEwEAmpwYAAAF92lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6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TqdQvesJgMDisUVevXh3Xry9fvnxTv66qqprQ/cfHx/vVNj/J/couv0DAv7q6+pMDeYPNSalkwkUikX7s4ukl4FHgAODPN1CXnPsWFxd/dCAjW+GGhoZCwAfYpeczwMPAPjVW3gv3IvXN98disZ8dyBGNCwQC4/r94eHhfuy6+JS6zATUCeJXY+W9cNfIUuDAwsLCr05kIBDYeBQ8Ojr6h8Lpx25BtbWlGpfv62BG5PLy8m+SFpOTk38C76mVe84NVyhgOvLgysrK7xoXjUb/Uqt2XG1rEDiYCbcd0MgwsWtk+J1EI03An0wmw5Zlefx+/2n1eRKIO5r+rWTTpFsZ/gWFrGMmeObuqwAAAABJRU5ErkJggg==";class be{constructor(e,t){this._cursorType=null,this._resizeCursorBaseImage=null,this._cursorImageMap={auto:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAAAsTAAALEwEAmpwYAAAF92lUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNi4wLWMwMDYgNzkuMTY0NzUzLCAyMDIxLzAyLzE1LTExOjUyOjEzICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIgeG1sbnM6cGhvdG9zaG9wPSJodHRwOi8vbnMuYWRvYmUuY29tL3Bob3Rvc2hvcC8xLjAvIiB4bWx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C3gRKURXcOSn9lTRRsvIAZKI4+l/gjQFREZMeOHSIiEggE+tetW/cRitkuRhmERxnnxjxZQFDWnzzURwCv1+vUHxHHjh37lri0C1Am9KGpgDMC1G8SQnxxCHs8Hqf2RldX10+bN28+i+JjwyT62KSaP13oAfWTHO7t7f0dIBQK/b1v375GlEnVjPYuyoQaHlNTDahVMALca29vdwBcvnz5+KlTp26OATft1UuODBS7yEOxj0K/329HOSWWopjxlE1tchhtM7FriPfgXSDDbrfXo0gbJr4QzIi0WiRPYBbKZJrUV23b0dYn7XSYcsBkS9EiO/k6lApq1cwiPjzaAM1Y9cYC1G6uAWrPCtrvMwoHqU02Q5caIEzj1KaS+D+vIjxtLug31gAAAABJRU5ErkJggg==","rotate-0":pe},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(){u(pe).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+=D((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+=D(e.angle||0)})),i=D(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,s={x:n/2,y:a/2};o.width=n,o.height=a;const r=o.getContext("2d"),l=_(e);r.translate(s.x,s.y),r.rotate(l),r.translate(-s.x,-s.y),r.drawImage(i,0,0,n,a),r.translate(s.x,s.y),r.rotate(-l),r.translate(-s.x,-s.y);const h=o.toDataURL("image/png");this._cursorImageMap[t]=h}}return t}}const Ie="SELECT",Me=Symbol(`${Ie}_actionType`),Ae=Symbol(`${Ie}_resizeType`),ze=Symbol(`${Ie}_areaStart`),_e=Symbol(`${Ie}_areaEnd`),Pe=Symbol(`${Ie}_hoverElement`),Re=Symbol(`${Ie}_hoverElementVertexes`),Te=Symbol(`${Ie}_selectedElementList`),Ee=Symbol(`${Ie}_selectedElementListVertexes`),Oe=Symbol(`${Ie}_selectedElementController`),We=Symbol(`${Ie}_groupQueue`),Ce=Symbol(`${Ie}_groupQueueVertexesList`),je="#1973ba";function Le(e,t,i){const{borderColor:o,borderWidth:n,background:a,lineDash:s}=i;e.setLineDash([]),e.lineWidth=n,e.strokeStyle=o,e.fillStyle=a,e.setLineDash(s),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 De(e,t,i){if(!t)return;const o={borderColor:je,borderWidth:1,background:"transparent",lineDash:[]};Le(e,G(t,i),o)}function Ye(e,t,i){if(!t)return;const{elementWrapper:o,left:n,right:a,top:s,bottom:r,topLeft:l,topRight:h,bottomLeft:c,bottomRight:d}=t,u={borderColor:je,borderWidth:1,background:"transparent",lineDash:[]},f={...u,borderWidth:2,background:"#FFFFFF"};Le(e,G(o,i),u),Le(e,G(l.vertexes,i),f),Le(e,G(h.vertexes,i),f),Le(e,G(c.vertexes,i),f),Le(e,G(d.vertexes,i),f)}function Fe(e){return e*Math.PI/180}function ke(e,t){return Math.sqrt(e*e+t*t)}function Be(e,t){return t>0?Math.abs(e):0-Math.abs(e)}function Ge(e,t){const{ctx:i,viewScaleInfo:o,viewSizeInfo:n,vertexes:a}=t,s=B(a[0],{viewScaleInfo:o,viewSizeInfo:n}),r=B(a[1],{viewScaleInfo:o,viewSizeInfo:n}),l=B(a[2],{viewScaleInfo:o,viewSizeInfo:n}),h=B(a[3],{viewScaleInfo:o,viewSizeInfo:n});return i.beginPath(),i.moveTo(s.x,s.y),i.lineTo(r.x,r.y),i.lineTo(l.x,l.y),i.lineTo(h.x,h.y),i.lineTo(s.x,s.y),i.closePath(),!!i.isPointInPath(e.x,e.y)}function Ne(e,t){const{ctx:i,viewScaleInfo:o,viewSizeInfo:n,groupQueue:a}=t;if(!(a&&(null==a?void 0:a.length)>0))return!1;const s=V(a),r=s[s.length-1];return!!r&&Ge(e,{ctx:i,vertexes:r,viewScaleInfo:o,viewSizeInfo:n})}function Xe(e,t){var i,o,n;const a={type:null,elements:[],elementVertexesList:[],groupQueue:[],groupQueueVertexesList:[]},{ctx:s,data:r,calculator:l,selectedElements:h,viewScaleInfo:c,viewSizeInfo:d,areaSize:u,groupQueue:f,selectedElementController:g}=t;if(g){const{left:t,right:i,top:o,bottom:n,topLeft:r,topRight:l,bottomLeft:u,bottomRight:v}=g,w=[t,i,o,n,r,l,u,v];for(let t=0;t<w.length;t++){const i=w[t];if(Ge(e,{ctx:s,vertexes:i.vertexes,viewSizeInfo:d,viewScaleInfo:c})){a.type=`resize-${i.type}`,h&&(null==h?void 0:h.length)>0&&(a.groupQueue=f||[],a.elements=[h[0]]);break}}}if(f&&Array.isArray(f)&&f.length>0){const t=f[f.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=$(o,{groupQueue:f});if(n&&Ge(e,{ctx:s,vertexes:n,viewScaleInfo:c,viewSizeInfo:d}))return a.type||(a.type="over-element"),a.groupQueue=f,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(r){const{index:t,element:i}=l.getPointElement(e,{data:r,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 Ze(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:s}=t;let r=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,s);if(h.angle&&(h.angle>0||h.angle<0)){const e=j(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(r){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;r=h}return o}const Ve="@middleware/select",$e="SCROLL",He=Symbol(`${$e}_xThumbRect`),Qe=Symbol(`${$e}_yThumbRect`),Ue=Symbol(`${$e}_prevPoint`),Je=Symbol(`${$e}_activePoint`),Ke=Symbol(`${$e}_activeThumbType`),qe=16,et=.36,tt={width:12,thumbColor:"#000000AA",scrollBarColor:"#FFFFFF60",showScrollBar:!1};function it(e,t,i){const o=e,{x:n,y:a,w:s,h:r}=i;return o.beginPath(),o.rect(n,a,s,r),o.closePath(),!!o.isPointInPath(t.x,t.y)}function ot(e,t){let{x:i,y:o,h:n,w:a}=t;e.save(),e.shadowColor="#FFFFFF",e.shadowOffsetX=0,e.shadowOffsetY=0,e.shadowBlur=1;{const{color:s,axis:r}=t;"X"===r?(o=o+n/4+0,n/=2):"Y"===r&&(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=et,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=s,e.fill(),e.globalAlpha=1,e.beginPath(),e.lineWidth=1,e.strokeStyle=s,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()}e.restore()}function nt(e,t){const i=e,{viewScaleInfo:o,viewSizeInfo:n,scrollInfo:a}=t,{activeThumbType:s,prevPoint:r,activePoint:l}=a,h=function(e,t){const{width:i,height:o}=t,{offsetTop:n,offsetBottom:a,offsetLeft:s,offsetRight:r}=e,l=2.5*qe,h=qe;let c=0,d=0;c=Math.max(l,i-(Math.abs(s)+Math.abs(r))),c>=i&&(c=i),d=Math.max(l,o-(Math.abs(n)+Math.abs(a))),d>=o&&(d=o);const u=h;let f=u;s>0?f=u:r>0?f=i-c-h:s<=0&&c>0&&(0!==s||0!==r)&&(f=u+(i-c)*Math.abs(s)/(Math.abs(s)+Math.abs(r)),f=Math.min(Math.max(0,f-u),i-c));const g=h;let v=g;n>0?v=g:a>0?v=o-d-h:n<=0&&d>0&&(0!==n||0!==a)&&(v=g+(o-d)*Math.abs(n)/(Math.abs(n)+Math.abs(a)),v=Math.min(Math.max(0,v-g),o-d));const w={x:f,y:o-h,w:c,h:h},x={x:i-h,y:v,w:h,h:d};return{lineSize:h,xSize:c,ySize:d,translateY:v,translateX:f,thumbColor:tt.thumbColor,scrollBarColor:tt.scrollBarColor,xThumbRect:w,yThumbRect:x}}(o,n);let c={...h.xThumbRect},d={...h.yThumbRect};return s&&r&&l&&("X"===s&&a.xThumbRect?(c={...a.xThumbRect},c.x=c.x+(l.x-r.x)):"Y"===s&&a.yThumbRect&&(d={...a.yThumbRect},d.y=d.y+(l.y-r.y))),ot(i,{axis:"X",...c,r:h.lineSize/2,color:h.thumbColor}),ot(i,{axis:"Y",...d,r:h.lineSize/2,color:h.thumbColor}),i.globalAlpha=1,{xThumbRect:c,yThumbRect:d}}function at(e,t){const{snapshot:i}=t,o=z(i),n=A(i),a=function(e){const{sharedStore:t}=e;return{activePoint:t[Je]||null,prevPoint:t[Ue]||null,activeThumbType:t[Ke]||null,xThumbRect:t[He]||null,yThumbRect:t[Qe]||null}}(i),{xThumbRect:s,yThumbRect:r}=nt(e,{viewSizeInfo:o,viewScaleInfo:n,scrollInfo:a});return{xThumbRect:s,yThumbRect:r}}const st="@middleware/scale",rt=16,lt="#000000",ht="#00000080",ct="monospace",dt="#AAAAAA30",ut="#AAAAAA70";function ft(e){const{scale:t,viewLength:i,viewOffset:o}=e,n=[];let a=10;a=J(a/t,{decimalPlaces:0}),a=Math.max(1,Math.min(a,1e3));const s=10*a,r=5*a;let l=0;const h=a*t,c=0-o,d=c%h,u=(c-d+h)/t,f=h-d+0;for(;f+l*h<i;){const e=J(u+l*a,{decimalPlaces:0}),t={num:e,position:J(f+l*h,{decimalPlaces:0}),showNum:e%s==0,isKeyNum:e%s==0,isSubKeyNum:e%r==0};n.push(t),l++}return n}const gt="@middleware/show-ruler";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 s=function(e,t){const i={width:e.canvas.width,height:e.canvas.height,devicePixelRatio:(null==t?void 0:t.devicePixelRatio)||1},o=p(i),n=p(i);return{underContext:p(i),viewContext:o,helperContext:n,boardContext:p(Object.assign({ctx:e},i))}}(a.getContext("2d"),{devicePixelRatio:i}),r=new ye({viewContent:s}),l=r.getSharer();l.setActiveViewSizeInfo({width:o,height:n,devicePixelRatio:i,contextWidth:o,contextHeight:n}),this._board=r,this.resize(l.getActiveViewSizeInfo());const h=r.getEventHub();new be(e,{eventHub:h})}use(e){this._board.use(e)}setData(e){Y((null==e?void 0:e.elements)||[]),this._board.setData(e)}getData(){return this._board.getData()}scale(e){this._board.scale(e);this._board.getViewer().drawFrame()}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.MiddlewareRuler=e=>{const{viewContent:t,viewer:i,eventHub:o}=e,{helperContext:n,underContext:a}=t;let s=!0;return o.on(gt,(e=>{"boolean"==typeof(null==e?void 0:e.show)&&(s=e.show,i.drawFrame())})),{mode:"RULE",isDefault:!0,beforeDrawFrame:({snapshot:e})=>{if(!0===s){const t=A(e),i=z(e);!function(e,t){const{viewSizeInfo:i}=t,{width:o,height:n}=i;e.beginPath(),e.moveTo(0,0),e.lineTo(o+1,0),e.lineTo(o+1,rt),e.lineTo(rt,rt),e.lineTo(rt,n+1),e.lineTo(0,n+1),e.lineTo(0,0),e.closePath(),e.fillStyle="#FFFFFFA8",e.fill(),e.strokeStyle="#00000080",e.stroke()}(n,{viewScaleInfo:t,viewSizeInfo:i});const o=function(e){const{viewScaleInfo:t,viewSizeInfo:i}=e,{scale:o,offsetLeft:n}=t,{width:a}=i;return ft({axis:"X",scale:o,viewLength:a,viewOffset:n})}({viewScaleInfo:t,viewSizeInfo:i});!function(e,t){const{scaleList:i}=t;for(let t=0;t<i.length;t++){const o=i[t];o.position<rt||(e.beginPath(),e.moveTo(o.position,16),e.lineTo(o.position,o.isKeyNum?3.2:o.isSubKeyNum?6.4:12.8),e.closePath(),e.fillStyle=lt,e.stroke(),o.isKeyNum&&(e.fillStyle=ht,e.textBaseline="top",e.$setFont({fontWeight:100,fontSize:10,fontFamily:ct}),e.fillText(`${o.num}`,o.position+3.2,3.2)))}}(n,{scaleList:o});const s=function(e){const{viewScaleInfo:t,viewSizeInfo:i}=e,{scale:o,offsetTop:n}=t,{height:a}=i;return ft({axis:"Y",scale:o,viewLength:a,viewOffset:n})}({viewScaleInfo:t,viewSizeInfo:i});!function(e,t){const{scaleList:i}=t,o=3.2;for(let t=0;t<i.length;t++){const n=i[t];if(!(n.position<rt)&&(e.beginPath(),e.moveTo(16,n.position),e.lineTo(n.isKeyNum?3.2:n.isSubKeyNum?6.4:12.8,n.position),e.closePath(),e.fillStyle=lt,e.stroke(),!0===n.showNum)){const t=o,i=n.position+o,a=`${n.num}`;P(e,-90,{x:t,y:i},(()=>{e.fillStyle=ht,e.textBaseline="top",e.$setFont({fontWeight:100,fontSize:10,fontFamily:ct}),e.fillText(a,13.2,n.position+o)}))}}}(n,{scaleList:s}),function(e,t){const{xList:i,yList:o,viewSizeInfo:n}=t,{width:a,height:s}=n;for(let t=0;t<i.length;t++){const o=i[t];e.beginPath(),e.moveTo(o.position,0),e.lineTo(o.position,s),!0===o.isKeyNum||!0===o.isSubKeyNum?e.strokeStyle=ut:e.strokeStyle=dt,e.lineWidth=1,e.closePath(),e.stroke()}for(let t=0;t<o.length;t++){const i=o[t];e.beginPath(),e.moveTo(0,i.position),e.lineTo(a,i.position),!0===i.isKeyNum||!0===i.isSubKeyNum?e.strokeStyle=ut:e.strokeStyle=dt,e.lineWidth=1,e.closePath(),e.stroke()}}(a,{xList:o,yList:s,viewScaleInfo:t,viewSizeInfo:i})}}}},e.MiddlewareScaler=e=>{const{viewer:t,sharer:i,eventHub:o}=e;return{mode:"SCALE",isDefault:!0,wheelScale(e){const{deltaY:n,point:a}=e,{scale:s}=i.getActiveViewScaleInfo();let r=s;n<0?r=1.1*s:n>0&&(r=.9*s);const{moveX:l,moveY:h}=t.scale({scale:r,point:a});t.scroll({moveX:l,moveY:h}),t.drawFrame();const c=J(s);o.trigger(st,{scale:c})}}},e.MiddlewareScroller=e=>{const{viewer:t,viewContent:i,sharer:o}=e,{helperContext:n}=i;o.setSharedStorage(He,null),o.setSharedStorage(Qe,null);const a=()=>{o.setSharedStorage(Ue,null),o.setSharedStorage(Je,null),o.setSharedStorage(Ke,null)};a();const s=e=>function(e,t,i){let o=null;const{xThumbRect:n,yThumbRect:a}=i;return n&&it(e,t,n)?o="X":a&&it(e,t,a)&&(o="Y"),o}(n,e,{xThumbRect:o.getSharedStorage(He),yThumbRect:o.getSharedStorage(Qe)});return{mode:$e,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=s(t);if("X"===i||"Y"===i)return o.setSharedStorage(Ke,i),o.setSharedStorage(Ue,t),!1},pointMove:e=>{const{point:i}=e,n=o.getSharedStorage(Ke);if("X"===n||"Y"===n)return o.setSharedStorage(Je,i),"X"===n?(e=>{const i=o.getSharedStorage(Ue);if(i){const{offsetLeft:n,offsetRight:a}=o.getActiveViewScaleInfo(),{width:s}=o.getActiveViewSizeInfo(),r=-(e.x-i.x)*(s+Math.abs(n)+Math.abs(a))/s;t.scroll({moveX:r}),t.drawFrame()}})(i):"Y"===n&&(e=>{const i=o.getSharedStorage(Ue);if(i){const{offsetTop:n,offsetBottom:a}=o.getActiveViewScaleInfo(),{height:s}=o.getActiveViewSizeInfo(),r=-(e.y-i.y)*(s+Math.abs(n)+Math.abs(a))/s;t.scroll({moveY:r}),t.drawFrame()}})(i),o.setSharedStorage(Ue,i),!1},pointEnd:e=>{const i=o.getSharedStorage(Ke);if(a(),"X"===i||"Y"===i)return t.scroll({moveX:0,moveY:0}),t.drawFrame(),!1},beforeDrawFrame({snapshot:e}){const{xThumbRect:t,yThumbRect:i}=at(n,{snapshot:e});o.setSharedStorage(He,t),o.setSharedStorage(Qe,i)}}},e.MiddlewareSelector=e=>{const{viewer:t,sharer:i,viewContent:o,calculator:n,eventHub:a}=e,{helperContext:s}=o;let r=null,l=null;a.on(Ve,(({uuids:e})=>{const o=i.getSharedStorage(Me),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 s=o[a];e.includes(s.uuid)?i.push(s):"group"===s.type&&t((null===(n=null==s?void 0:s.detail)||void 0===n?void 0:n.children)||[])}}(t),i}(e,(null==n?void 0:n.elements)||[]);let s=!1;if(o||1!==a.length?"select"===o&&1===a.length&&(s=!0):(i.setSharedStorage(Me,"select"),s=!0),s){const e=function(e,t){const i=[];return function e(t,o){var n;let a=null;for(let s=0;s<o.length;s++){const r=o[s];if(r.uuid===t){a=r;break}if(!a&&"group"===r.type){i.push(r);const o=e(t,(null===(n=null==r?void 0:r.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(We,e),u(a),t.drawFrame()}})),i.setSharedStorage(Me,null);const h=()=>i.getSharedStorage(Te),c=e=>{let t=i.getSharedStorage(We);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=V(t);return i.setSharedStorage(We,t),i.setSharedStorage(Ce,o),t.length>0},d=e=>{i.setSharedStorage(Pe,e);let t=null;e&&(t=$(e,{groupQueue:i.getSharedStorage(We)})),i.setSharedStorage(Re,t)},u=(e,t)=>{if(i.setSharedStorage(Te,e),1===e.length){const t=Q(e[0],{groupQueue:i.getSharedStorage(We),controllerSize:10,viewScaleInfo:i.getActiveViewScaleInfo()});i.setSharedStorage(Oe,t)}else i.setSharedStorage(Oe,null);!0===(null==t?void 0:t.triggerEvent)&&a.trigger(Ve,{uuids:e.map((e=>e.uuid))})},f=()=>({ctx:s,calculator:n,data:i.getActiveStorage("data"),selectedElements:h(),viewScaleInfo:i.getActiveViewScaleInfo(),viewSizeInfo:i.getActiveViewSizeInfo(),groupQueue:i.getSharedStorage(We),areaSize:null,selectedElementController:i.getSharedStorage(Oe)}),g=()=>{i.setSharedStorage(Me,null),i.setSharedStorage(Ae,null),i.setSharedStorage(ze,null),i.setSharedStorage(_e,null),i.setSharedStorage(We,[]),i.setSharedStorage(Ce,[]),i.setSharedStorage(Pe,null),i.setSharedStorage(Re,null),i.setSharedStorage(Te,[]),i.setSharedStorage(Ee,null),i.setSharedStorage(Oe,null)};return g(),{mode:Ie,hover:e=>{var o,r;const c=i.getSharedStorage(Ae),u=i.getSharedStorage(Me),g=i.getSharedStorage(We),v=e=>{let t=e.type;null===l&&a.trigger("cursor",{type:t,groupQueue:e.groupQueue,element:e.elements[0]})};if((null==g?void 0:g.length)>0){if(!Ne(e.point,{ctx:s,viewScaleInfo:i.getActiveViewScaleInfo(),viewSizeInfo:i.getActiveViewSizeInfo(),groupQueue:i.getSharedStorage(We)}))return d(null),void t.drawFrame();const n=Xe(e.point,f());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=Xe(e.point,{...f(),areaSize:Ze(w,{viewScaleInfo:x,viewSizeInfo:S,calculator:n})});return v(m),"over-element"===m.type&&1===(null==(r=null==m?void 0:m.elements)?void 0:r.length)?(i.setSharedStorage(Pe,m.elements[0]),d(m.elements[0]),void t.drawFrame()):i.getSharedStorage(Pe)?(d(null),void t.drawFrame()):void 0},pointStart:e=>{var o,a,l,c;r=e.point,d(null);const v=i.getSharedStorage(We);if((null==v?void 0:v.length)>0){if(Ne(e.point,{ctx:s,viewScaleInfo:i.getActiveViewScaleInfo(),viewSizeInfo:i.getActiveViewSizeInfo(),groupQueue:v})){const t=Xe(e.point,f());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(Me,"drag")):(null==(a=t.type)?void 0:a.startsWith("resize-"))?(i.setSharedStorage(Ae,t.type),i.setSharedStorage(Me,"resize")):u([],{triggerEvent:!0})}else g();return void t.drawFrame()}const w=Ze(h(),{viewScaleInfo:i.getActiveViewScaleInfo(),viewSizeInfo:i.getActiveViewSizeInfo(),calculator:n}),x=Xe(e.point,{...f(),areaSize:w,groupQueue:[]});"list-area"===x.type?i.setSharedStorage(Me,"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(Me,"drag")):(null==(c=x.type)?void 0:c.startsWith("resize-"))?(i.setSharedStorage(Ae,x.type),i.setSharedStorage(Me,"resize")):(g(),i.setSharedStorage(Me,"area"),i.setSharedStorage(ze,e.point),u([],{triggerEvent:!0})),t.drawFrame()},pointMove:e=>{const o=i.getActiveStorage("data"),n=h(),a=i.getActiveStorage("scale")||1,s=r,c=e.point,d=i.getSharedStorage(Ae),f=i.getSharedStorage(Me),g=i.getSharedStorage(We);if("drag"===f){if(l="drag",o&&1===(null==n?void 0:n.length)&&s&&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:s=0}=e;a.push({x:t,y:i,w:o,h:n,angle:0-s})})),(null==i?void 0:i.length)>0){const i=W(e,a),s=W(t,a);o=s.x-i.x,n=s.y-i.y}return{moveX:o,moveY:n}}(s,c,g);n[0].x+=e/a,n[0].y+=t/a,u([n[0]])}t.drawFrame()}else if("drag-list"===f){if(l="drag-list",o&&s&&c&&(null==n?void 0:n.length)>1){const e=(c.x-s.x)/a,t=(c.y-s.y)/a;n.forEach((i=>{i&&(i.x+=e,i.y+=t)})),i.setActiveStorage("data",o)}t.drawFrame()}else if("resize"===f){if(o&&1===(null==n?void 0:n.length)&&s&&(null==d?void 0:d.startsWith("resize-"))){l="resize";const e=[];g.forEach((t=>{const{x:i,y:o,w:n,h:a,angle:s=0}=t;e.push({x:i,y:o,w:n,h:a,angle:0-s})}));let o=s,r=c;g.length>0&&(o=W(s,e),r=W(c,e));const h=function(e,t){var i,o,n,a,s,r,l,h,c;let{x:d,y:u,w:f,h:g,angle:v=0}=e;const w=T({x:d,y:u,w:f,h:g,angle:v});v=D(v);const x=_(v),S=!!(null==(i=null==e?void 0:e.operations)?void 0:i.limitRatio),{start:m,end:y,resizeType:p,scale:b}=t;let I={...m},M={...y},A={x:I.x,y:w.y},z={x:M.x,y:w.y},P={...A},R={...z},E={x:w.x,y:I.y},W={x:w.x,y:M.y},C={...E},j={...W},L=(R.x-P.x)/b,Y=(R.y-P.y)/b,F=ke(L,Y),k=(j.x-C.x)/b,B=(j.y-C.y)/b,G=ke(k,B);(v>0||v<0)&&(I=O(w,m,0-x),M=O(w,y,0-x),A={x:I.x,y:w.y},z={x:M.x,y:w.y},P=O(w,A,x),R=O(w,z,x),E={x:w.x,y:I.y},W={x:w.x,y:M.y},C=O(w,E,x),j=O(w,W,x),L=(R.x-P.x)/b,Y=(R.y-P.y)/b,F=ke(L,Y),F=Be(F,Y),k=(j.x-C.x)/b,B=(j.y-C.y)/b,G=ke(k,B),G=Be(G,B));let N=(y.x-m.x)/b,X=(y.y-m.y)/b;if(!0===S)if(["resize-top","resize-bottom","resize-left","resize-right"].includes(p)){const t=Math.max(Math.abs(N),Math.abs(X));N=(N>=0?1:-1)*t,X=(X>=0?1:-1)*t/e.w*e.h;const i=Math.max(Math.abs(k),Math.abs(B));k=(k>=0?1:-1)*i,B=(B>=0?1:-1)*i/e.w*e.h;const o=Math.max(Math.abs(L),Math.abs(Y));L=(L>=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(N);N=(N>=0?1:-1)*t;const i=t/e.w*e.h;"resize-top-left"===p||"resize-bottom-right"===p?X=N>0?i:-i:"resize-top-right"!==p&&"resize-bottom-left"!==p||(X=N>0?-i:i)}F=Math.abs(F),G=F/e.w*e.h}switch(p){case"resize-top":if(0===v)g-X>0&&(u+=X,g-=X,!0===(null==(o=e.operations)?void 0:o.limitRatio)&&(d+=X/e.h*e.w/2,f-=X/e.h*e.w));else if(v>0||v<0){let t=w.x,i=w.y;if(v<90){G=0-Be(G,B);const e=Fe(v),o=G/2;t+=o*Math.sin(e),i-=o*Math.cos(e)}else if(v<180){G=Be(G,k);const e=Fe(v-90),o=G/2;t+=o*Math.cos(e),i+=o*Math.sin(e)}else if(v<270){G=Be(G,B);const e=Fe(v-180),o=G/2;t-=o*Math.sin(e),i+=o*Math.cos(e)}else if(v<360){G=0-Be(G,k);const e=Fe(v-270),o=G/2;t-=o*Math.cos(e),i-=o*Math.sin(e)}g+G>0&&(!0===(null==(n=e.operations)?void 0:n.limitRatio)&&(f+=G/e.h*e.w),g+=G,d=t-f/2,u=i-g/2)}break;case"resize-bottom":if(0===v)e.h+X>0&&(g+=X,!0===(null==(a=e.operations)?void 0:a.limitRatio)&&(d-=X/e.h*e.w/2,f+=X/e.h*e.w));else if(v>0||v<0){let t=w.x,i=w.y;if(v<90){G=Be(G,B);const e=Fe(v),o=G/2;t-=o*Math.sin(e),i+=o*Math.cos(e)}else if(v<180){G=0-Be(G,k);const e=Fe(v-90),o=G/2;t-=o*Math.cos(e),i-=o*Math.sin(e)}else if(v<270){G=Be(G,k);const e=Fe(v-180),o=G/2;t+=o*Math.sin(e),i-=o*Math.cos(e)}else if(v<360){G=Be(G,k);const e=Fe(v-270),o=G/2;t+=o*Math.cos(e),i+=o*Math.sin(e)}g+G>0&&(!0===(null==(s=e.operations)?void 0:s.limitRatio)&&(f+=G/e.h*e.w),g+=G,d=t-f/2,u=i-g/2)}break;case"resize-left":if(0===v)e.w-N>0&&(d+=N,f-=N,!0===(null==(r=e.operations)?void 0:r.limitRatio)&&(g-=N/e.w*e.h,u+=N/e.w*e.h/2));else if(v>0||v<0){let t=w.x,i=w.y;if(v<90){F=0-Be(F,L);const e=Fe(v),o=F/2;t-=o*Math.cos(e),i-=o*Math.sin(e)}else if(v<180){F=Be(F,L);const e=Fe(v-90),o=F/2;t+=o*Math.sin(e),i-=o*Math.cos(e)}else if(v<270){F=Be(F,Y);const e=Fe(v-180),o=F/2;t+=o*Math.cos(e),i+=o*Math.sin(e)}else if(v<360){F=Be(F,Y);const e=Fe(v-270),o=F/2;t-=o*Math.sin(e),i+=o*Math.cos(e)}f+F>0&&(!0===(null==(l=e.operations)?void 0:l.limitRatio)&&(g+=F/e.w*e.h),f+=F,d=t-f/2,u=i-g/2)}break;case"resize-right":if(0===v)e.w+N>0&&(f+=N,!0===(null==(h=e.operations)?void 0:h.limitRatio)&&(u-=N*e.h/e.w/2,g+=N*e.h/e.w));else if(v>0||v<0){let t=w.x,i=w.y;if(v<90){F=Be(F,Y);const e=Fe(v),o=F/2;t+=o*Math.cos(e),i+=o*Math.sin(e)}else if(v<180){F=Be(F,X);const e=Fe(v-90),o=F/2;t-=o*Math.sin(e),i+=o*Math.cos(e)}else if(v<270){F=Be(F,X);const e=Fe(v-180),o=F/2;t+=o*Math.cos(e),i+=o*Math.sin(e),F=0-F}else if(v<360){F=Be(F,N);const e=Fe(v-270),o=F/2;t+=o*Math.sin(e),i-=o*Math.cos(e)}f+F>0&&(!0===(null==(c=e.operations)?void 0:c.limitRatio)&&(g+=F/e.w*e.h),f+=F,d=t-f/2,u=i-g/2)}break;case"resize-top-left":if(0===v)f-N>0&&(d+=N,f-=N),g-X>0&&(u+=X,g-=X);else if(v>0||v<0){let e=w.x,t=w.y;if(v<90){G=0-Be(G,B),F=0-Be(F,S?0-G:L);const i=G/2;e+=i*Math.sin(x),t-=i*Math.cos(x);const o=F/2;e-=o*Math.cos(x),t-=o*Math.sin(x)}else if(v<180){G=Be(G,k),F=Be(F,S?G:L);const i=Fe(v-90),o=G/2;e+=o*Math.cos(i),t+=o*Math.sin(i);const n=F/2;e+=n*Math.sin(i),t-=n*Math.cos(i)}else if(v<270){G=Be(G,B),F=Be(F,S?G:Y);const i=Fe(v-180),o=G/2;e-=o*Math.sin(i),t+=o*Math.cos(i);const n=F/2;e+=n*Math.cos(i),t+=n*Math.sin(i)}else if(v<360){G=0-Be(G,k),F=Be(F,S?G:Y);const i=Fe(v-270),o=G/2;e-=o*Math.cos(i),t-=o*Math.sin(i);const n=F/2;e-=n*Math.sin(i),t+=n*Math.cos(i)}g+G>0&&(g+=G),f+F>0&&(f+=F),d=e-f/2,u=t-g/2}break;case"resize-top-right":if(0===v)f+N>0&&(f+=N),g-X>0&&(u+=X,g-=X);else if(v>0||v<0){let e=w.x,t=w.y;if(v<90){G=0-Be(G,B),F=Be(F,S?G:Y);const i=Fe(v),o=G/2;e+=o*Math.sin(i),t-=o*Math.cos(i);const n=F/2;e+=n*Math.cos(i),t+=n*Math.sin(i)}else if(v<180){G=Be(G,k),F=Be(F,S?G:Y);const i=Fe(v-90),o=G/2;e+=o*Math.cos(i),t+=o*Math.sin(i);const n=F/2;e-=n*Math.sin(i),t+=n*Math.cos(i)}else if(v<270){const i=Fe(v-180);G=Be(G,B),F=Be(F,S?G:0-L);const o=G/2;e-=o*Math.sin(i),t+=o*Math.cos(i);const n=F/2;e-=n*Math.cos(i),t-=n*Math.sin(i)}else if(v<360){G=0-Be(G,k),F=Be(F,S?G:L);const i=Fe(v-270),o=G/2;e-=o*Math.cos(i),t-=o*Math.sin(i);const n=F/2;e+=n*Math.sin(i),t-=n*Math.cos(i)}g+G>0&&(g+=G),f+F>0&&(f+=F),d=e-f/2,u=t-g/2}break;case"resize-bottom-left":if(0===v)e.h+X>0&&(g+=X),e.w-N>0&&(d+=N,f-=N);else if(v>0||v<0){let e=w.x,t=w.y;if(v<90){G=Be(G,B),F=0-Be(F,S?0-G:L);const i=Fe(v),o=G/2;e-=o*Math.sin(i),t+=o*Math.cos(i);const n=F/2;e-=n*Math.cos(i),t-=n*Math.sin(i)}else if(v<180){G=0-Be(G,k),F=Be(F,S?G:L);const i=Fe(v-90),o=G/2;e-=o*Math.cos(i),t-=o*Math.sin(i);const n=F/2;e+=n*Math.sin(i),t-=n*Math.cos(i)}else if(v<270){G=Be(G,k),F=Be(F,S?G:Y);const i=Fe(v-180),o=G/2;e+=o*Math.sin(i),t-=o*Math.cos(i);const n=F/2;e+=n*Math.cos(i),t+=n*Math.sin(i)}else if(v<360){G=Be(G,k),F=Be(F,S?G:Y);const i=Fe(v-270),o=G/2;e+=o*Math.cos(i),t+=o*Math.sin(i);const n=F/2;e-=n*Math.sin(i),t+=n*Math.cos(i)}g+G>0&&(g+=G),f+F>0&&(f+=F),d=e-f/2,u=t-g/2}break;case"resize-bottom-right":if(0===v)e.h+X>0&&(g+=X),e.w+N>0&&(f+=N);else if(v>0||v<0){let e=w.x,t=w.y;if(v<90){G=Be(G,B),F=Be(F,S?G:Y);const i=Fe(v),o=G/2;e-=o*Math.sin(i),t+=o*Math.cos(i);const n=F/2;e+=n*Math.cos(i),t+=n*Math.sin(i)}else if(v<180){G=0-Be(G,k),F=Be(F,S?G:X);const i=Fe(v-90),o=G/2;e-=o*Math.cos(i),t-=o*Math.sin(i);const n=F/2;e-=n*Math.sin(i),t+=n*Math.cos(i)}else if(v<270){G=Be(G,k),F=Be(F,S?G:0-Y);const i=Fe(v-180),o=G/2;e+=o*Math.sin(i),t-=o*Math.cos(i);const n=F/2;e-=n*Math.cos(i),t-=n*Math.sin(i)}else if(v<360){G=Be(G,k),F=Be(F,S?G:L);const i=Fe(v-270),o=G/2;e+=o*Math.cos(i),t+=o*Math.sin(i);const n=F/2;e+=n*Math.sin(i),t-=n*Math.cos(i)}g+G>0&&(g+=G),f+F>0&&(f+=F),d=e-f/2,u=t-g/2}}return{x:d,y:u,w:f,h:g,angle:e.angle}}(n[0],{scale:a,start:o,end:r,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"===f&&(l="area",i.setSharedStorage(_e,e.point),t.drawFrame());r=e.point},pointEnd(e){l=null;const o=i.getActiveStorage("data"),s=i.getSharedStorage(Ae),h=i.getSharedStorage(Me),c=i.getActiveViewSizeInfo();let d=!1;if(r=null,"resize"===h&&s)i.setSharedStorage(Ae,null),d=!0;else if("area"===h){if(i.setSharedStorage(Me,null),o){const e=i.getSharedStorage(ze),t=i.getSharedStorage(_e);if(e&&t){const{elements:a}=function(e,t){const i=[],o=[],n=[],{calculator:a,viewScaleInfo:s,viewSizeInfo:r,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),f=Math.max(l.y,h.y);return e.elements.forEach(((e,t)=>{const l=a.elementSize(e,s,r),h=T(l);if(h.x>=c&&h.x<=d&&h.y>=u&&h.y<=f&&(i.push(t),o.push(e.uuid),n.push(e),l.angle&&(l.angle>0||l.angle<0))){const e=j(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(Me,"drag-list"),u(a,{triggerEvent:!0}),d=!0)}}}else if("drag-list"===h)i.setSharedStorage(Me,"drag-list-end"),d=!0;else if(o){n.getPointElement(e.point,{data:o,viewScaleInfo:i.getActiveViewScaleInfo(),viewSizeInfo:i.getActiveViewSizeInfo()}).element?(i.setSharedStorage(Me,"select"),d=!0):i.setSharedStorage(Me,null)}null===i.getSharedStorage(Me)&&(g(),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=F(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(){r=null,g(),t.drawFrame()},doubleClick(e){var o;const n=Xe(e.point,f());if(1===n.elements.length&&"group"===(null==(o=n.elements[0])?void 0:o.type)){if(!0===c(n.elements[0]))return i.setSharedStorage(Me,null),void t.drawFrame()}i.setSharedStorage(Me,null)},beforeDrawFrame({snapshot:t}){const{activeStore:i,sharedStore:o}=t,{scale:a,offsetLeft:r,offsetTop:l,offsetRight:c,offsetBottom:d,width:u,height:f,contextHeight:g,contextWidth:v,devicePixelRatio:w}=i,x=e.sharer,S={scale:a,offsetLeft:r,offsetTop:l,offsetRight:c,offsetBottom:d},m={width:u,height:f,contextHeight:g,contextWidth:v,devicePixelRatio:w},y=o[Te][0],p=o[Pe],b=o[Re],I=o[Me],M=o[ze],A=o[_e],z=o[We],_=o[Ce],P={calculator:n,viewScaleInfo:S,viewSizeInfo:m},R=y?Q(y,{groupQueue:z,controllerSize:10,viewScaleInfo:S}):null;if((null==z?void 0:z.length)>0)!function(e,t,i){for(let o=0;o<t.length;o++){const n=t[o],a={borderColor:je,borderWidth:2,background:"transparent",lineDash:[4,4]};Le(e,G(n,i),a)}}(s,_,P),p&&"drag"!==I&&De(s,b,P),y&&["select","drag","resize"].includes(I)&&Ye(s,R,{...P});else if(p&&"drag"!==I&&De(s,b,P),y&&["select","drag","resize"].includes(I))Ye(s,R,{...P});else if("area"===I&&M&&A)!function(e,t){const{start:i,end:o}=t;e.setLineDash([]),e.lineWidth=1,e.strokeStyle=je,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()}(s,{start:M,end:A});else if(["drag-list","drag-list-end"].includes(I)){const e=Ze(h(),{viewScaleInfo:x.getActiveViewScaleInfo(),viewSizeInfo:x.getActiveViewSizeInfo(),calculator:n});e&&function(e,t){const{areaSize:i}=t,{x:o,y:n,w:a,h:s}=i;e.setLineDash([]),e.lineWidth=1,e.strokeStyle=je,e.fillStyle="#1976d21c",e.beginPath(),e.moveTo(o,n),e.lineTo(o+a,n),e.lineTo(o+a,n+s),e.lineTo(o,n+s),e.closePath(),e.stroke(),e.fill()}(s,{areaSize:e})}}}},e.middlewareEventRuler=gt,e.middlewareEventScale=st,e.middlewareEventSelect=Ve,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.4.0-alpha.2",
3
+ "version": "0.4.0-alpha.4",
4
4
  "description": "",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -21,15 +21,16 @@
21
21
  "author": "chenshenhai",
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "@idraw/types": "^0.4.0-alpha.0"
24
+ "@idraw/types": "^0.4.0-alpha.4"
25
25
  },
26
- "dependencies": {
27
- "@idraw/board": "^0.4.0-alpha.2",
28
- "@idraw/renderer": "^0.4.0-alpha.2",
29
- "@idraw/util": "^0.4.0-alpha.2"
26
+ "dependencies": {},
27
+ "peerDependencies": {
28
+ "@idraw/board": "^0.4.0-alpha.4",
29
+ "@idraw/renderer": "^0.4.0-alpha.4",
30
+ "@idraw/util": "^0.4.0-alpha.4"
30
31
  },
31
32
  "publishConfig": {
32
- "access": "public"
33
- },
34
- "gitHead": "5cc462b9206ea0e4e70b5183771dfbf694402483"
33
+ "access": "public",
34
+ "provenance": true
35
+ }
35
36
  }