diff --git a/index.html b/index.html index a4963ed..d1f2e49 100644 --- a/index.html +++ b/index.html @@ -181,6 +181,6 @@ - + \ No newline at end of file diff --git a/index.js b/index.js index 6e8ac86..a5cd024 100644 --- a/index.js +++ b/index.js @@ -1 +1 @@ -const t=(t,n)=>t.querySelector(`[data-key="${n}"]`),n=(t,n)=>t.querySelector(`[${n}]`),e=t=>document.getElementById(t);function o(t,n){t.style.transform=`translate(${n.x}px, ${n.y}px)`}const i=(t,...n)=>t?.classList.add(...n),a=(t,...n)=>t?.classList.remove(...n),s=(t,n)=>t?.classList.contains(n),c=(t,n,e,o)=>(t.addEventListener(n,e,{passive:!0,once:o}),e),r=(t,n,e,o)=>t?.removeEventListener(n,e,{capture:o}),l=(t,n,e)=>t.querySelectorAll(n).forEach((t=>c(t,"click",e))),d=(t,n)=>t.currentTarget.getAttribute(n),u=t=>"TEXTAREA"===t.target.tagName.toUpperCase()||"INPUT"===t.target.tagName.toUpperCase(),h=t=>"mouse"===t.pointerType,p=t=>({x:t.clientX,y:t.clientY});function f(t,n){const e=document.createElementNS("http://www.w3.org/2000/svg",t);return n&&(e.innerHTML=n),e}const m=(t,n)=>{const e=document.createElement("div");return t&&(e.innerHTML=t),e.style.cssText=n,e},v=(...t)=>document.body.append(...t);function g(t){let n,e=0;for(const o of t.getElementsByTagName("tspan"))for(const t of w(o.getBBox())){const o=Math.abs(t.x)+Math.abs(t.y);e[{x:t.x,y:t.y},{x:t.right,y:t.y},{x:t.x,y:t.bottom},{x:t.right,y:t.bottom}];function y(t){const n={x:1/0,y:1/0},e={x:-1/0,y:-1/0};for(const o of t){const t=o.getBoundingClientRect();n.x>t.x&&(n.x=t.x),n.y>t.y&&(n.y=t.y),e.x{let e;(n=n||{}).credentials="include";try{e=await fetch(t,n)}catch(t){throw console.log(t),t}if(!e.ok)throw 401===e.status&&alert("You have to relogin."),new Error;return e},b=(t,n)=>x(t,{method:"POST",body:n}),$=(t,n)=>x(t,{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:n?X(n):null}),k=(t,n)=>{const e=new URL(window.location.href);return e.searchParams.set(t,n),e.toString()},M=(...t)=>{const n=new URL(window.location.href);t?.forEach((t=>n.searchParams.delete(t))),history.replaceState(null,null,n.toString())};function C(t,n,e,o){function i(n){r(t,"pointercancel",i),r(t,"pointerup",i),r(t,"wheel",i),r(document,"pointerdown",i),r(t,"pointermove",e),o(n)}c(t,"pointercancel",i,!0),c(t,"pointerup",i,!0),c(t,"wheel",i,!0),c(document,"pointerdown",i,!0),c(t,"pointermove",e),t.setPointerCapture(n.pointerId)}const H=(t,n)=>L(t.ownerSVGElement,t,n);function L(t,n,e,o){const i=()=>{r(t,"pointercancel",a),r(t,"wheel",a),r(t,"pointerdown",a)},a=t=>{o&&o(t),n.contains(t.target)||(i(),e(t))};return c(t,"pointercancel",a),c(t,"wheel",a),c(t,"pointerdown",a),i}const V=t=>{const n=n=>{"Escape"===n.key&&t()};return c(document,"keydown",n),()=>r(document,"keydown",n)},z=(t,n,e)=>new CustomEvent(t,{detail:n,cancelable:e}),S=(t,n)=>t.dispatchEvent(n),Z=(t,n)=>{let e,o,i=!1;return function a(){if(i)return e=arguments,void(o=this);t.apply(this,arguments),i=!0,setTimeout((function(){i=!1,e&&(a.apply(o,e),e=o=null)}),n)}};function D(t,n,e){return t??=0,e<=t?t:t+Math.ceil((e-t)/n)*n}const B=t=>Math.round(100*(t+Number.EPSILON))/100,T=(t,n,e)=>{let o=!1;return n>e?n>t&&(o=!0,e*=t/n,n=t):e>t&&(o=!0,n*=t/e,e=t),{w:n,h:e,c:o}};function E(t,n){const e=t.indexOf(n);e>-1&&t.splice(e,1)}function A(t,n){for(let e=t.length-1;e>=0;--e)n(t[e])}const R=t=>t?[...t]:t,P=t=>t.values().next().value;function U(t,n,e){const o=e??1;return t.x+=o*n.x,t.y+=o*n.y,t}const I=(t,n)=>({x:t.x+n,y:t.y+n}),N=(t,n)=>O(t,n.x,n.y),O=(t,n,e)=>(t.x=n,t.y=e,t),j=t=>({x:t.x,y:t.y}),F=(t,n)=>t?.x===n?.x&&t?.y===n?.y;function K(){const t=new Uint8Array(4);return window.crypto.getRandomValues(t),Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("")}const Y=t=>t?.substring(0,t.lastIndexOf("."))||t,_=t=>G(X(t)),X=t=>JSON.stringify(t),G=t=>JSON.parse(t),q=(t,n,e,o)=>{let i,a;const s=()=>{a=setTimeout((async t=>{await e(),i||s()}),t)};s();const c=setTimeout((t=>{r(),o&&o()}),n),r=()=>{i=!0,clearTimeout(a),clearTimeout(c)};return r},J=(t,n)=>t?n:"",W=t=>J(t,"disabled");function Q(t,n,e){t.x+=e[tt]/n,t.y+=e[nt]/n}const tt=Symbol("movementX"),nt=Symbol("movementY"),et=Symbol("Canvas"),ot=(t,n,e)=>({x:(n-t.position.x)/t.scale,y:(e-t.position.y)/t.scale}),it=(t,n)=>ot(t,n.clientX,n.clientY);function at(t,n){const e=n/2;function o(t){const o=Math.round(t/n)*n;return t-o>=0?o+e:o-e}return t.x=o(t.x),t.y=o(t.y),t}function st(t,n){return{id:t.pointerId,pos:p(t),shift:{x:n.position.x-t.clientX,y:n.position.y-t.clientY}}}let ct;function rt(t){t&&!ct?(ct=m("","z-index: 2; position: fixed; left: 0; top: 0; width:100%; height:100%; background: #fff; opacity: 0"),ct.classList.add("blnk"),v(ct)):t||(ct?.remove(),ct=null)}const lt=async t=>{try{return rt(!0),await t()}catch(t){console.log(t),alert("Error")}finally{rt(!1)}};function dt(t,n,e,o,i){const a=m(null,"position: fixed; left: 50%; top: 30%; box-shadow: 0 4px 24px rgba(0,0,0,.12); border-radius: 8px; background-color: rgb(255,255,255);");function s(t,n){a&&(o?(a.style.right="0",a.style.left="unset",a.style.marginRight=`${t}px`):a.style.left=`${t}px`,a.style.top=i?`${window.scrollY+n}px`:window.scrollY+n-a.getBoundingClientRect().height+"px")}return a.setAttribute("ap-modal",""),a.append(t),v(a),null!=n?s(n,e):a.style.transform="translate(-50%, -30%)",a[wt]={position:s,del:()=>{a?.remove()}},a}const ut=t=>((t,n)=>{const e=t=>t&&t!==document&&t!==window?t.closest(n)||e(t.getRootNode().host):null;return e(t)})(t,"[ap-modal]"),ht=()=>{for(;;){const t=document.querySelector("[ap-modal]");if(!t)return;t[wt]?.del()}};function pt(t,n,e,o,i,a){const s=m(null,"z-index: 2; position: fixed; left: 0; top: 0; width:100%; height:100%; "+(o?"background-color: rgba(52,71,103,.05);":""));v(s);const r=dt(t,n,e,i,a);s.append(r);const l=mt(s,r,(t=>{"pointerdown"===t?.type?c(s,"click",(t=>{t.stopImmediatePropagation(),u()}),!0):u()}),(t=>t.stopImmediatePropagation())),d=r[wt].del,u=()=>{d(),l(),s.remove()};return r[wt].del=u,r}function ft(t,n,e){const o=dt(t,n,e),i=o[wt].del,a=mt(document,o,(t=>s())),s=()=>{i(),a()};return o[wt].del=s,o}function mt(t,n,e,o){const i=((t,n,e,o)=>L(t,n,e,o))(t,n,e,o),a=V((()=>{((t,n)=>{const e=t.querySelectorAll(n);return e?.length?e[e?.length-1]:null})(document,"[ap-modal]")===n&&(e(),s())})),s=()=>{i(),a()};return s}function vt(t,n,e,o){const i=m(""+(o?"":''),"display: flex; flex-flow: column; padding: 15px;");i.className=n??"mds",o?i.append(o):l(i,"[ap-close]",(t=>a[wt].del())),i.append(t);const a=e?pt(i,null,null,!0):ft(i);return a}function gt(t,n,e){const o=vt(m(`${t}`,"display: flex; flex-flow: column; height: 100%; overflow-y: overlay;"),"mdh",e,n);return i(ut(o),"mdhc"),o}const wt=Symbol(0);function yt(t,n){const e=t.getBoundingClientRect(),o=window.innerHeight-e.bottom<40*n.length;!function(t,n,e,o){const i=pt(m(`
${t.map((t=>t[0])).join(" ")}
`),n,e,!1,!0,!o);l(i,"a",(n=>{i[wt].del(),t[a(n.currentTarget)][1]()}));const a=t=>Array.prototype.indexOf.call(t.parentNode.children,t)}(n,window.innerWidth-e.right-5,o?e.top:e.bottom,o)}const xt=(t,n)=>[`${t}`,n],bt=(t,n)=>[`${t}`,()=>{confirm("Delete?")&&n()}],$t=t=>bt("Delete",t);function kt(t){const n=m(`${t}`,"min-width: 150px;\n\t\tbackground-color: rgb(52,71,103);\n\t\tcolor: #fff;\n\t\ttext-align: center;\n\t\tborder-radius: 8px;\n\t\tpadding: 10px;\n\t\tposition: fixed;\n\t\tz-index: 1;\n\t\tleft: 50%;\n\t\ttop: 30px;\n\t\ttransform: translate(-50%, -30%)");n.className="toast",v(n),setTimeout((t=>n.remove()),2800)}const Mt=()=>kt("Link copied to clipboard"),Ct="https://api.dgrm.net/api/",Ht=`${Ct}s/`,Lt=`${Ct}r/d/`,Vt=`${Ct}r/f/`,zt=async t=>{const n=await x(`${Ht}${t}`),e=n.headers.get("X-Dgrm-loc");return{e:n.headers.has("X-Dgrm-edit"),m:n.headers.has("X-Dgrm-manage"),n:decodeURIComponent(n.headers.get("X-Dgrm-name")),l:e?decodeURIComponent(e):null,d:await n.json()}},St=async t=>{const n=await x(`${Ht}a/l/${t??""}`);let e;try{const t=await n.json();e={f:new Map(t.f.map((t=>[t.i,t]))),d:new Map(t.d.map((t=>[t.i,t])))}}catch{}return e};async function Zt(t,n,e,o){const i=new URL(`${Ht}a/c`);return Bt(i,"k",t),n&&Bt(i,"f",n.toString()),Bt(i,"n",e),(await $(i.toString(),o)).text()}function Dt(){const t=new Date;return`${t.getUTCFullYear()}${(t.getUTCMonth()+1).toString().padStart(2,"0")}${K()}`}const Bt=(t,n,e)=>t.searchParams.set(n,e),Tt=new Map,Et=(t,n)=>Tt.set(t,n);function At(t){return Pt(t).find((t=>!t.hasAttribute("data-evt-no")))}function Rt(t){return Pt(t)[0]}function Pt(t){return document.elementsFromPoint(t.clientX,t.clientY).sort(((t,n)=>{const e=t.getAttribute("data-evt-index"),o=n.getAttribute("data-evt-index");return e===o?0:e>o?-1:1}))}const Ut=Symbol("path"),It=Symbol("shape"),Nt="1.2",Ot=()=>({v:Nt,s:{}}),jt=t=>{return!((n=t.s)&&Object.keys(n).length);var n},Ft=t=>Kt([...t.children],!1);function Kt(t,n,e){const o=Ot();if(!t?.length)return o;const i=new Map,a=t=>{let e=i.get(t);if(!e){const a=_(t[It].data);n&&(a.id=K(),e=a.id),i.set(t,e),o.s[a.id]=a}return e},s=i=>{if(o.s[i[Ut].data.id])return;const s=o=>{return n?(i=o.shape?.shapeEl,-1!==t.indexOf(i)?{s:a(o.shape.shapeEl),k:o.shape.connectorKey}:{p:_(o.data)}):o.shape?(e&&a(o.shape.shapeEl),{s:o.shape.shapeEl[It].data.id,k:o.shape.connectorKey}):{p:_(o.data)};var i},c=i[Ut].data,r={id:n?K():c.id,type:0,s:s(c.s),e:s(c.e)};c.styles&&(r.c=_(c.styles)),o.s[r.id]=r};for(const n of t)n[It]?(a(n),e&&n[It].paths?.forEach(s)):s(n);return o}function Yt(t){return{v:Nt,s:{[t.id]:0!==t.type?t:(n=t,{id:n.id,type:0,s:{p:n.s.data},e:{p:n.e.data},c:n.styles})}};var n}const _t=(t,n)=>Xt(t,"1.1"===n.v?function(t){const n={v:Nt,s:{}};return t.s.forEach(((t,e)=>{switch(t.type){case 0:{const o=t,i={id:e.toString(),type:0,c:o.c?.map((t=>"d-"+t)),s:{s:o.s.s?.toString(),k:o.s.k,p:o.s.p},e:{s:o.e.s?.toString(),k:o.e.k,p:o.e.p}};n.s[i.id]=i;break}default:{const o=t;o.id=e.toString(),o.styles=o.styles?.map((t=>"d-"+t)),n.s[o.id]=o;break}}})),n}(n):n);function Xt(t,n){if(n.v!==Nt)return alert("Wrong format"),null;const o=new Map;function i(n){let e=o.get(n);return e||(e=qt(t,n),o.set(n,e)),e}const a=t=>n.s[t]?i(n.s[t]):e(t),s=[];for(const e in n.s)switch(n.s[e].type){case 0:{const o=Jt(t,n.s[e],a);o&&s.push(o);break}default:i(n.s[e])}return[...o.values(),...s]}function Gt(t,n){const o=e(n.id);return o?((o[It]||o[Ut]).patch(n),o):t[et].shapeMap[n.type].create(n)}const qt=(t,n)=>Gt(t,_(n)),Jt=(t,n,e)=>{const o=function(t,n){const e=t=>{const e=n(t.s);return e?{shape:{shapeEl:e,connectorKey:t.k}}:null},o=t=>t.p?{data:{dir:t.p.dir,position:j(t.p.position)}}:e(t),i={type:0,id:t.id,styles:t.c,s:o(t.s),e:o(t.e)};return i.e&&i.s?i:null}(n,e);return o?Gt(t,o):null};function Wt(t){for(const n in t.s)Qt(t.s[n]);return t}function Qt(t){switch(t.type){case 6:delete t.d,delete t.r;break;case 7:delete t.d}}const tn=(t,n,e)=>S(t,nn(n,e)),nn=(t,n)=>z("dgrmc",{newIds:t,shapesToCreateData:n}),en=(t,n)=>z("dgrmd",{delIds:t,shapesToDelData:n}),on=(t,n,e)=>S(t,an(Wt(n),Wt(e))),an=(t,n)=>z("dgrmu",{shapesBeforeUpdData:t,shapesToUpdData:n}),sn=(t,n,e,o)=>z("dgrmdc",{delIds:t,shapesToDelData:n,newIds:e,shapesToCreateData:o});function cn(t,n,e,o){const i=U(((t,n,e)=>{const o=ot(t,n,e);return at(o,t.cell),o})(t[et].data,e,o),function(t){const n=function(t){const n={x:1/0,y:1/0},e={x:-1/0,y:-1/0};return rn(t,(t=>{t&&(n.x>t.x&&(n.x=t.x),n.y>t.y&&(n.y=t.y),e.x{n&&at(U(n,i),t[et].data.cell)}))}function rn(t,n){for(const e in t.s)0===t.s[e].type?(n(t.s[e].s.p?.position),n(t.s[e].e.p?.position)):n(t.s[e].position)}const ln=(t,n)=>t[et].select(dn(t,Kt(n,!0),!0));function dn(t,n,e,o,i){return cn(t,n,null==o?window.innerWidth/2:o,null==i?window.innerHeight/2:i),un(t,n,e)}function un(t,n,e){return e&&tn(t,vn(n),_(n)),hn(t,n)}function hn(t,n){return t[et].select(null),Xt(t,n)}function pn(t,n){((t,n,e)=>{S(t,en(n,e))})(t,mn(n),Kt(n,!1,!0)),gn(n)}function fn(t,n,e){((t,n,e,o,i)=>{S(t,sn(n,e,o,i))})(t,mn(n),Kt(n,!1,!0),vn(e),_(e)),gn(n),hn(t,e)}const mn=t=>t.map((t=>(t[It]||t[Ut]).data.id)),vn=t=>Object.keys(t.s),gn=t=>t.forEach((t=>(t[It]||t[Ut]).del())),wn='',yn='',xn='',bn='',$n=(t,n)=>({id:K(),type:t,position:{x:0,y:0},title:"Title",styles:n});function kn(n){for(const e in n.cons)o(t(n.el,e),n.cons[e].position)}function Mn(t,n){const e=t.getBoundingClientRect(),o=dt(n,e.left+10,e.top+10);return{del:o[wt].del,updPos:()=>{const n=t.getBoundingClientRect();o[wt].position(n.left+10,n.top+10)}}}const Cn=(t,n)=>({del:dt(t,n.clientX-66,n.clientY-10)[wt].del}),Hn=(t,n,e)=>{const o=Kt([n],!1,!1);(n[It]??n[Ut]).patch(e),on(t,o,Kt([n],!1,!1))};function Ln(t,n){return function(t,n){const e=t.el[It].data;null!=n.title&&e.title!==n.title&&(e.title=n.title,t.drawTxt());n.styles&&(e.styles=n.styles,Sn(t.el))}(t,n),Vn(t,n)}function Vn(t,n){const e=n.position&&!F(t.el[It].data.position,n.position);return e&&N(t.el[It].data.position,n.position),e}const zn=t=>t.forEach((t=>{const n=e(t);n&&(n[It]||n[Ut]).del()}));function Sn(t){const n=(t[It]??t[Ut]).data;n.styles||(n.styles=[]),A(t.classList,(n=>{n?.startsWith("d-")&&t.classList.remove(n)})),i(t,...n.styles)}const Zn=(t,n,e)=>{const o=(n[It]??n[Ut]).data;o.styles||(o.styles=[]);const i={styles:_(o.styles)};Hn(t,n,function(t,n){const e=t.styles.findIndex((t=>t.startsWith("d-cl-")));e>-1&&t.styles.splice(e,1);n&&t.styles.push(n);return t}(i,e))};function Dn(t,n,e){return n.setAttribute("bg",e.toString()),Bn(t,n),n}function Bn(t,n){const e=Number(n.getAttribute("bg"));if(3===e)return void t.append(n);const o=t.querySelector(Tn(e+1,3).map((t=>`[bg="${t}"]`)).join());o?o.before(n):t.append(n)}const Tn=(t,n)=>[...Array(n-t+1).keys()].map((n=>n+t));class En extends HTMLElement{constructor(t,n){super(),this.o=n,this.g=t}connectedCallback(){const t=t=>this.o[Ut].data.styles?.includes(t)?'class="actv"':"",n=this.attachShadow({mode:"closed"});n.innerHTML=`
`,c(n.getElementById("edit"),"cmd",(t=>{switch(t.detail.cmd){case"style":Zn(this.g,this.o,t.detail.arg);break;case"del":pn(this.g,[this.o]);break;case"copy":ln(this.g,[this.o])}})),l(n,"[data-cmd]",(t=>{const n=d(t,"data-cmd-arg"),e={styles:this.o[Ut].data.styles?_(this.o[Ut].data.styles):[]},o=e.styles.indexOf(n);o>-1?(e.styles.splice(o,1),a(t.currentTarget,"actv")):(e.styles.push(n),i(t.currentTarget,"actv")),Hn(this.g,this.o,e)}))}}function An(t,n,e,o){const i=On(t,n);i.shape={shapeEl:e,connectorKey:o},Un(t,i)}function Rn(t,n,e){const o=On(t,n);o.shape.shapeEl!==jn(t,o)&&In(t,o),o.shape=null,o.data={dir:o.data.dir,position:e}}function Pn(t,n){const e=t[Ut].data,o=o=>{const i=e[o],a=n[o];i.shape?null==a.shape||i.shape.shapeEl===a.shape.shapeEl&&i.shape.connectorKey===a.shape.connectorKey?a.data&&Rn(t,o,a.data.position):function(t,n,e,o){const i=On(t,n);if(i.shape.shapeEl===e&&i.shape.connectorKey===o)return;i.shape.shapeEl!==e&&i.shape.shapeEl!==jn(t,i)&&In(t,i);i.shape={shapeEl:e,connectorKey:o},Un(t,i)}(t,o,a.shape.shapeEl,a.shape.connectorKey):null!=a.shape?An(t,o,a.shape.shapeEl,a.shape.connectorKey):N(i.data.position,a.data.position)};o("s"),o("e")}function Un(t,n){n.data=Nn(n.shape).pathAdd(n.shape.connectorKey,t)}customElements.define("ap-path-settings",En);const In=(t,n)=>Nn(n.shape)?.pathDel(t),Nn=t=>t?.shapeEl[It],On=(t,n)=>t[Ut].data[n],jn=(t,n)=>(t[Ut].data.e===n?t[Ut].data.s:t[Ut].data.e).shape?.shapeEl;let Fn;const Kn=(t,n)=>({id:K(),type:0,s:t,e:n,styles:R(Fn)});Et(0,(()=>Kn({data:{dir:"right",position:{x:-24,y:0}}},{data:{dir:"right",position:{x:24,y:0}}})));function Yn(n,e){const o=f("g",'');o.id=e.id,i(o,"shpath"),e.s.el=t(o,"start"),e.e.el=t(o,"end"),e.styles=e.styles??["d-arw-e"];const s=Qn(o,"path","outer","selected");function c(){if(!e.s.shape||!e.e.shape){const t=function(t,n){const e=Math.atan2(n.y-t.y,n.x-t.x);return te(e,-.8,.8)?"left":te(e,.8,2.4)?"top":te(e,2.4,3.2)||te(e,-3.2,-2.4)?"right":"bottom"}(e.s.data.position,e.e.data.position);e.e.shape||(e.e.data.dir=t),e.s.shape||(e.s.data.dir=Wn(t))}const t=function(t){let n=.5*Math.hypot(t.s.data.position.x-t.e.data.position.x,t.s.data.position.y-t.e.data.position.y);function e(t){return"right"===t.dir||"left"===t.dir?"right"===t.dir?t.position.x+n:t.position.x-n:t.position.x}function o(t){return"right"===t.dir||"left"===t.dir?t.position.y:"bottom"===t.dir?t.position.y+n:t.position.y-n}n=n>70?70:n<15?15:n;const i=(n,e,o,i)=>t.styles.includes(o)?n.position[e]+(i[n.dir]??0):n.position[e],a=(t,n)=>i(t,"x",n,{left:-6,right:6}),s=(t,n)=>i(t,"y",n,{top:-6,bottom:6});return`M ${a(t.s.data,"d-arw-s")} ${s(t.s.data,"d-arw-s")} C ${e(t.s.data)} ${o(t.s.data)}, ${e(t.e.data)} ${o(t.e.data)}, ${a(t.e.data,"d-arw-e")} ${s(t.e.data,"d-arw-e")}`}(e);s.forEach((n=>n.setAttribute("d",t))),Gn(e.s),Gn(e.e)}let r,l;let d,u,p=0;const m=()=>{u&&(u(),u=null)},v=t=>{m(),u=V(t)};function g(t){switch(p){case 0:y();break;case 1:p=2,d=H(o,(t=>w(!0))),v((()=>{w(!0),y()})),function(t){r||(r=Cn(new En(n,o),t))}(t)}}function w(t){t||(l=null),p=0,a(o,"select","highlight-s","highlight-e"),qn(e.s,1),qn(e.e,1),r?.del(),r=null,d&&(d(),d=null),m()}function y(){p=1,i(o,"s"===l?"highlight-s":"e"===l?"highlight-e":"select"),qn(e.s,2),qn(e.e,2),Bn(n,o),v((()=>{w(!0)}))}return o[Ut]={data:e,drawPosition:c,click:(t,n)=>{if(0===p||l){const o=n||t?ne(e,n??At(t)):null;ee(l,o)||w(),l=o}g(t)},patch:t=>{var n,i,a;e.styles&&(e.styles=t.styles,Sn(o),n=[...t.styles],Fn=n,E(Fn,"d-arw-s"),a="d-arw-e",-1===(i=Fn).indexOf(a)&&i.push(a)),t.s&&Pn(o,t),c()},moveCapture:(t,i,a)=>{w(!0);const s=a?null:Kt([o],!1,!0),r=t=>{w(!0),s?on(n,s,Kt([o],!1,!0)):tn(n,[e.id],Kt([o],!1,!0)),h(t)||g()},l=ne(e,i);l?Xn(n,o,c,t,l,r):function(t,n,e,o,i){C(n,o,(o=>{!function(t,n,e,o){const i=n=>Q(n,t.scale,o);_n(n.s,i),n.s.shape?.shapeEl&&n.s.shape?.shapeEl===n.e.shape?.shapeEl||_n(n.e,i);n.s.shape||n.e.shape||e()}(t[et].data,n[Ut].data,e,o)}),(o=>{!function(t,n,e){const o=n=>at(n,t.cell);_n(n.s,o),_n(n.e,o),n.s.shape&&n.e.shape||e()}(t[et].data,n[Ut].data,e),i(o)}))}(n,o,c,t,r)},unselect:w,del:function(){w(),In(o,e.s),In(o,e.e),o.remove()}},e.styles&&i(o,...e.styles),e.s.shape&&Un(o,e.s),e.e.shape&&Un(o,e.e),c(),o}function _n(t,n){t.shape?(n(Nn(t.shape).data.position),Nn(t.shape).drawPosition()):n(t.data.position)}const Xn=(t,n,e,o,l,d)=>{n[Ut].data[l].shape&&Rn(n,l,it(t[et].data,o)),n.style.pointerEvents="none";const u=function(t){let n=null;function e(t){const e=Rt(t);if(n!==e){s(e,"hovertrack")&&i(e,"hover");let t=!1;s(e?.parentElement,"hovertrack")&&(i(e.parentElement,"hover"),t=!0),a(n,"hover"),n?.parentElement===e?.parentElement&&t||a(n?.parentElement,"hover"),n=e}}return c(t,"pointermove",e),function(){r(t,"pointermove",e),a(n,"hover"),a(n?.parentElement,"hover"),n=null}}(n.parentElement);C(n[Ut].data[l].el,o,(o=>{Q(n[Ut].data[l].data.position,t[et].data.scale,o),e()}),(o=>{const i=Rt(o),a=i?.getAttribute("data-connect");a?An(n,l,i.parentElement,a):at(n[Ut].data[l].data.position,t[et].data.cell),e(),u(),n.style.pointerEvents="unset",d(o)}))};function Gn(t){t.el.style.transform=`translate(${t.data.position.x}px, ${t.data.position.y}px) rotate(${Jn(t.data.dir)}deg)`}function qn(t,n){t.el.firstElementChild.setAttribute("data-evt-index",n.toString())}const Jn=t=>"right"===t?180:"left"===t?0:"bottom"===t?270:90,Wn=t=>"left"===t?"right":"right"===t?"left":"top"===t?"bottom":"top";const Qn=(n,...e)=>e.map((e=>t(n,e))),te=(t,n,e)=>n<=t&&t<=e,ne=(t,n)=>t.e.el.contains(n)?"e":t.s.el.contains(n)?"s":null,ee=(t,n)=>!t||t===n,oe=(t,n,e)=>ae(t,n,e,(t=>function(t){return t.split(" ")?.forEach((n=>{(n.startsWith("http://")||n.startsWith("https://"))&&(t=t.replace(n,`${new URL(n).hostname}`))})),t}(se(t)))),ie=(t,n,e)=>ae(t,n,e,se);function ae(t,n,e,o){const i=function(t,n,e){let o=0;return{s:t.split("\n").map(((t,i)=>(o=i,`${0===t.length?".":e(t)}`))).join(""),c:o}}(e||"",t.x?.baseVal[0]?.value??0,o);t.innerHTML=i.s,null!=n&&t.y.baseVal[0].newValueSpecifiedUnits(t.y.baseVal[0].SVG_LENGTHTYPE_EMS,i.c>0?n-i.c/2:n)}function se(t){return t.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'").replaceAll(" "," ")}const ce=(t,n)=>Mn(n,le(t,n)),re=(t,n,e)=>Cn(le(t,n),e);function le(t,n){const e=new de;return c(e,"cmd",(e=>{switch(e.detail.cmd){case"style":Zn(t,n,e.detail.arg);break;case"del":pn(t,[n]);break;case"copy":ln(t,[n])}})),e}class de extends HTMLElement{connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML=`
${yn} ${wn}
`;{const n=t.getElementById("pnl");let e;l(t,"[data-toggle]",(o=>{const i=t=>{const e=ut(this);e.style.top=`${e.getBoundingClientRect().top+window.scrollY+t*n.getBoundingClientRect().height}px`};e&&(i(1),ue(e,!1));const a=t.getElementById(d(o,"data-toggle"));e!==a?(ue(a,!0),i(-1),e=a):e=null}))}l(t,"[data-cmd]",(t=>{this.dispatchEvent(new CustomEvent("cmd",{detail:{cmd:d(t,"data-cmd"),arg:d(t,"data-cmd-arg")}}))}))}}function ue(t,n){t.style.display=n?"unset":"none"}function he(n,e,o,i,a,s,c,r,l=0,d){const u=fe(e.id,o,i),h={el:t(u,"text"),vMid:l};d??=oe;const p=()=>d(h.el,h.vMid,e.title);p();return{el:u,cons:i,draw:me(n,u,e,i,h,r??ce,(t=>c(h.el,t)),a,s,null).draw,drawTxt:p}}function pe(t,n,e,o,i,a,s,c,r){const l=fe(n.id,e,o);return{el:l,cons:o,draw:me(t,l,n,o,null,c??re,null,i,a,s,r).draw}}customElements.define("ap-shape-edit",de);const fe=(t,n,e)=>{const o=f("g",`${n}\n\t${Object.entries(e).map((t=>``)).join()}`);return o.id=t,o};function me(t,n,e,s,c,r,l,d,u,p,m){let v,g,w,y;e.styles??=[];const x=()=>Kt([n],!1,!1);function b(t){e.title=t,l()}const $=function(t,n,e,s,c,r,l,d,u,p){i(n,"hovertrack");const m=_(s),v=new Set;let g,w,y,x=0;function b(){g?.remove(),g=null}const $=()=>{y&&(y(),y=null)},k=t=>{$(),y=V(t)};function M(){n.style.transform=`translate(${e.position.x}px, ${e.position.y}px)`;for(const t in s)m[t].position={x:s[t].position.x+e.position.x,y:s[t].position.y+e.position.y};for(const t of v)t[Ut].drawPosition()}function L(){x=1,i(n,"select"),l&&(g=function(t,n){const e=f("circle");return e.setAttribute("data-evt-index","2"),i(e,"resizer"),o(e,n),t.append(e),e}(n,l())),k((()=>z()))}function z(t){r(),x=0,a(n,"select","highlight"),t||b(),w&&(w(),w=null),$()}const S=t=>{switch(x){case 0:L();break;case 1:x=2,a(n,"select"),i(n,"highlight"),b(),w=H(n,(t=>z())),k((()=>{z(),L()}))}c(t,x)},Z=(e,o,i)=>{if(o===g){z(!0);const o=Kt([n],!1,!1);return void C(g,e,d,(e=>{u&&u(),b(),L(),on(t,o,Kt([n],!1,!1))}))}z();const a=o.getAttribute("data-connect");if(a){const o=((t,n,e)=>Dn(t,Yn(t,Kn(n,e)),3))(t,{shape:{shapeEl:n,connectorKey:a}},{data:{dir:Wn(m[a].dir),position:it(t[et].data,e)}});return t[et].select(h(e)?null:[o]),o[Ut].moveCapture(e,o[Ut].data.e.el,!0),void v.add(o)}D(e,i)};p??=()=>at(e.position,t[et].data.cell);const D=(o,i)=>{const a=i?null:Kt([n],!1,!1);C(n,o,(n=>{Q(e.position,t[et].data.scale,n),M()}),(o=>{p(),M(),a?on(t,a,Kt([n],!1,!1)):tn(t,[e.id],Kt([n],!1)),h(o)||L()}))};return n[It]={data:e,drawPosition:M,click:S,moveCapture:Z,unselect:z,del:function(){z();for(const t of v)t[Ut].del();n.remove()},paths:v,pathAdd:function(t,n){return v.add(n),m[t]},pathDel:function(t){v.delete(t)}},M}(t,n,e,s,((o,i)=>{1===i&&Bn(t,n),2===i&&(c&&!v&&(w=e.title,g=x(),ie(c.el,c.vMid,e.title),l(),v=function(t,n,e,o,i){let a=f("foreignObject");const s=document.createElement("textarea"),c=()=>function(t,n,e,o,i){const a=t.getBBox(),s=a.width+20;n.width.baseVal.value=s+2*o+2,n.x.baseVal.value=a.x-o-("center"===i?10:"right"===i?20:0),n.height.baseVal.value=a.height+2*o+3,n.y.baseVal.value=a.y-o,e.style.width=`${s}px`,e.style.height=`${a.height}px`}(t,a,s,l,r.textAlign);s.value=e||"",s.oninput=function(){ie(t,n,s.value),o(s.value),c()},i&&(s.onblur=function(){i(s.value)}),s.onpointerdown=function(t){t.stopImmediatePropagation()},a.appendChild(s),t.parentElement.appendChild(a);const r=getComputedStyle(s),l=parseInt(r.paddingLeft)+parseInt(r.borderWidth);return c(),s.focus(),{dispose:()=>{a.remove(),a=null},draw:c}}(c.el,c.vMid,e.title,b)),y||(y=r(t,n,o)))}),(function(){v&&(oe(c.el,c.vMid,e.title),l(!0),v?.dispose(),v=null),y?.del(),y=null,g&&w!==e.title&&on(t,g,x()),g=null,w=null}),d,u,p,m);return e.styles&&i(n,...e.styles),{draw:()=>{$(),y?.updPos&&y?.updPos(),v?.draw()}}}let ve;function ge(n,e,o){t(n,e).r.baseVal.value=o}Et(1,(()=>$n(1,R(ve))));const we=(t,n)=>function(t,n,e){const o=g(t);return D(n,e,Math.sqrt(o.x**2+o.y**2))}(t,n,24);let ye;function xe(n,e){e.w??=96,e.h??=48;const a={w:e.w,h:e.h};let s;const c=he(n,e,'\n\t\t \n\t\t  ',{right:{dir:"right",position:{x:48,y:0}},left:{dir:"left",position:{x:-48,y:0}},bottom:{dir:"bottom",position:{x:0,y:24}},top:{dir:"top",position:{x:0,y:-24}}},(()=>{const t=function(t){const n=t.w/2,e=t.h/2;return{t:{x:t.position.x-n,y:t.position.y-e},b:{x:n,y:e}}}(e);return s=t.t,t.b}),(i=>{let l;(function(t,n,e,i,a){const s=U(it(t[et].data,i),n,-1),c={};let r=!1;function l(t){s[t]<48&&(s[t]=48);const o=48*Math.round(s[t]/48),i="x"===t?"w":"h";e[i]!==o&&(!a||a()[i]<=o)&&(e[i]=o,e.position[t]=n[t]+o/2,r=!0),c[t]=s[t]-e[i]/2}return l("x"),l("y"),o(i.target,c),r})(n,s,e,i,(()=>(l??=ke(t(c.el,"text")),l)))&&($e(a,e),r())}),(t=>{const n=ke(t,a);be(e,n)||($e(e,n),r())}));function r(){!function(t,n){const e=n.w/-2,o=n.h/-2;t.cons.right.position.x=-e,t.cons.left.position.x=e,t.cons.bottom.position.y=-o,t.cons.top.position.y=o,kn(t),Me(t.el,"main",n.w,n.h,e,o),Me(t.el,"outer",n.w+48,n.h+48,e-24,o-24)}(c,e),c.draw()}return i(c.el,"shrect"),96!==e.w||48!==e.h?r():c.draw(),c.el[It].patch=t=>{const n=Ln(c,t),o=(null!=t.w||null!=t.h)&&!be(e,t);o&&($e(e,t),a.h=e.h,a.w=e.w),o?r():n&&c.draw(),t.styles&&(ye=[...t.styles])},c.el}Et(2,(()=>$n(2,R(ye))));const be=(t,n)=>t.w===n.w&&t.h===n.h,$e=(t,n)=>{t.h=n.h,t.w=n.w};function ke(t,n){const e=t.getBBox();return{w:D(n?.w,48,e.width),h:D(n?.h,48,e.height)}}const Me=(n,e,o,i,a,s)=>{const c=t(n,e);c.width.baseVal.value=o,c.height.baseVal.value=i,c.x.baseVal.value=a,c.y.baseVal.value=s};let Ce;function He(t,n){let e;n.w??=96,n.h??=96;const a=pe(t,n,'\n\t\t \n\t\t ',{right:{dir:"right",position:{x:48,y:0}},left:{dir:"left",position:{x:-48,y:0}},bottom:{dir:"bottom",position:{x:0,y:48}},top:{dir:"top",position:{x:0,y:-48}}},(()=>{const t=Le(n);return e=t.tCanvas,t.bInner}),(i=>s(function(t,n,e,i){const a=U(it(t[et].data,i),n,-1);e.w=a.x<48?48:a.x;const s=e.w/2;e.position.x=n.x+s,e.h=a.y<48?48:a.y;const c=e.h/2;return e.position.y=n.y+c,o(i.target,{x:s,y:c}),{x:-s,y:-c}}(t,e,n,i))),(t=>s(function(t,n){const e=t=>24*Math.round(t/24);t.w=e(t.w),t.h=e(t.h);const o=Le(t);return t.position.x=n.x-o.tInner.x,t.position.y=n.y-o.tInner.y,o.tInner}(n,e))));i(a.el,"shbox");const s=t=>{a.cons.right.position.x=n.w+t.x,a.cons.left.position.x=t.x,a.cons.bottom.position.y=n.h+t.y,a.cons.top.position.y=t.y,kn(a),Me(a.el,"main",n.w,n.h,t.x,t.y),Me(a.el,"selected",n.w,n.h,t.x,t.y),Me(a.el,"outer",n.w+48,n.h+48,t.x-24,t.y-24),a.draw()};return 96!==n.w||96!==n.h?s(Le(n).tInner):a.draw(),a.el[It].patch=t=>{const e=Ln(a,t),o=(null!=t.w||null!=t.h)&&!be(n,t);o&&$e(n,t),o?s(Le(n).tInner):e&&a.draw(),t.styles&&(Ce=[...t.styles])},a.el}function Le(t){const n=Ve(t.w),e=Ve(t.h);return{tCanvas:{x:t.position.x-n,y:t.position.y-e},tInner:{x:-n,y:-e},bInner:{x:t.w-n,y:t.h-e}}}Et(5,(()=>({id:K(),type:5,position:{x:0,y:0},styles:R(Ce)})));const Ve=t=>24*Math.floor(t/2/24);function ze(t,n){return De?async function(t,n){try{const e=await window.showSaveFilePicker({suggestedName:n,types:[Be]}),o=await e.createWritable();return await o.write(t),await o.close(),e}catch(t){"AbortError"!==t.name&&alert("File not saved")}}(t,n):function(t,n){const e=document.createElement("a");e.download=n,e.href=URL.createObjectURL(t),e.click(),URL.revokeObjectURL(e.href),e.remove()}(t,n)}async function Se(t){const n="AbortError";try{return Ze?await async function(t){const[n]=await window.showOpenFilePicker({types:[t]});return{h:n,f:await n.getFile()}}(t):await new Promise(((e,o)=>{!function(t,n,e){const o=document.createElement("input");o.type="file",o.multiple=!1,o.accept=t,c(o,"cancel",(t=>e(t)),!0),c(o,"change",(async()=>n(o.files?.length?o.files[0]:null)),!0),o.click(),o.remove()}(t.inputAccept,(t=>{e({f:t})}),(t=>o(Error(n))))}))}catch(t){if(t.name===n||t.message===n)return null;throw t}}const Ze="showOpenFilePicker"in window,De="showSaveFilePicker"in window,Be={accept:{"image/png":[".png"]},inputAccept:"image/png"},Te={accept:{"image/*":[".png",".gif",".jpeg",".jpg"]},inputAccept:"image/*"};function Ee(t,n,e){const o=m(`
${yn} ${wn}
`);return l(o,"[data-cmd]",(e=>{switch(d(e,"data-cmd")){case"del":pn(t,[n]);break;case"copy":ln(t,[n])}})),Cn(o,e)}function Ae(t,n,e,o){Re(n,(n=>t[et].select(dn(t,Yt(n),!0,e,o))))}function Re(t,n){!function(t,n,e){const o=new Image;o.onload=function(){const i=T(n,o.width,o.height);if(!i.c){URL.revokeObjectURL(o.src);const n=new FileReader;return n.onloadend=function(){e(n.result,i.w,i.h)},void n.readAsDataURL(t)}const a=document.createElement("canvas");a.width=i.w,a.height=i.h;const s=a.getContext("2d");s.imageSmoothingEnabled=!1,s.imageSmoothingQuality="high",s.drawImage(o,0,0,i.w,i.h),URL.revokeObjectURL(o.src),e(a.toDataURL(),i.w,i.h)},o.src=URL.createObjectURL(t)}(t,4096,((t,e,o)=>{const i=T(Math.min(document.body.clientHeight/2,264),e,o),a={id:K(),type:6,position:{x:0,y:0},w:i.w,h:i.h,r:B(o/e),d:t};Ue(a),n(a)}))}function Pe(t,n){let e;const a=pe(t,n,`\n\t\t \n\t\t `,{right:{dir:"right",position:{x:48,y:0}},left:{dir:"left",position:{x:-48,y:0}},bottom:{dir:"bottom",position:{x:0,y:48}},top:{dir:"top",position:{x:0,y:-24}}},(()=>{const t=Le(n);return e=t.tCanvas,t.bInner}),(i=>s(function(t,n,e,i){const a=U(it(t[et].data,i),n,-1);e.w=a.x<48?48:a.x;const s=e.w/2;e.position.x=n.x+s,e.h=e.r*e.w;const c=e.h/2;return e.position.y=n.y+c,o(i.target,{x:s,y:c}),{x:-s,y:-c}}(t,e,n,i))),(t=>s(function(t,n){Ue(t);const e=Le(t);return t.position.x=n.x-e.tInner.x,t.position.y=n.y-e.tInner.y,e.tInner}(n,e))),Ee);i(a.el,"shimg");const s=t=>{a.cons.right.position.x=n.w+t.x,a.cons.left.position.x=t.x,a.cons.bottom.position.y=n.h+t.y,a.cons.top.position.y=t.y,kn(a),Me(a.el,"main",n.w,n.h,t.x,t.y),Me(a.el,"selected",n.w,n.h,t.x,t.y),Me(a.el,"outer",n.w+48,n.h+48,t.x-24,t.y-24),a.draw()};return s(Le(n).tInner),a.el[It].patch=t=>{const e=Vn(a,t),o=(null!=t.w||null!=t.h)&&!be(n,t);o&&$e(n,t),o?s(Le(n).tInner):e&&a.draw()},a.el}function Ue(t){t.w=24*Math.round(t.w/24),t.h=B(t.r*t.w)}const Ie=(t,n)=>Mn(n,new Ne(t,n));class Ne extends HTMLElement{constructor(t,n){super(),this.$=n,this.g=t}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML='
';const n=this.$[It].data,e=t.getElementById("edit");c(e,"cmd",(t=>{switch(t.detail.cmd){case"style":Zn(this.g,this.$,t.detail.arg);break;case"del":pn(this.g,[this.$]);break;case"copy":ln(this.g,[this.$])}}));const o=t=>Hn(this.g,this.$,t);i(e,`ta-${n.a}`),l(t,'[data-cmd="a"]',(t=>{const s=Number.parseInt(d(t,"data-cmd-arg"));s!==n.a&&(a(e,`ta-${n.a}`),i(e,`ta-${s}`),o({a:s}))})),["d-h","d-b"].forEach((t=>{n.styles?.includes(t)&&i(e,t)})),l(t,'[data-cmd="s"]',(t=>{const s=d(t,"data-cmd-arg"),c={styles:n.styles?_(n.styles):[]};c.styles?.includes(s)?(E(c.styles,s),a(e,s)):(c.styles??=[],c.styles.push(s),i(e,s)),o(c)}))}}let Oe;function je(n,e){e.w??=48,e.h??=48,e.a??=1;const o=he(n,e,`\n\t\t \n\t\t  `,{right:{dir:"right",position:{x:24,y:0}},left:{dir:"left",position:{x:-24,y:0}},bottom:{dir:"bottom",position:{x:0,y:24}},top:{dir:"top",position:{x:0,y:-24}}},null,null,((t,n)=>s(t,n)),Ie,null,qe);i(o.el,"shtxt"),i(o.el,`ta-${e.a}`);const a=()=>t(o.el,"text"),s=(t,n)=>{n&&Xe(t)&&t.append(Ge());const o=Fe(t);be(e,o)||($e(e,o),u())};let c,r,l;function d(){r=e.w,c=e.h,l=e.a}function u(t){if(function(t,n){const e=n.w/-2,o=-Ve(n.h);t.cons.left.position.y=o+24,t.cons.left.position.x=e,t.cons.top.position.y=o,t.cons.bottom.position.y=n.h+o,t.cons.right.position.y=o+24,t.cons.right.position.x=-e,kn(t),Me(t.el,"main",n.w,n.h,e,o),Me(t.el,"outer",n.w+48,n.h+48,e-24,o-24)}(o,e),t||l!==e.a||r!==e.w){const t=e.w/-2;let n,i;switch(e.a){case 1:n=t+8,i=(e.w-r)/2;break;case 2:n=0,i=0;break;case 3:n=-t-8,i=(e.w-r)/-2}const s=a();s.x.baseVal[0].value=n,s.querySelectorAll("tspan[x]").forEach((t=>{t.x.baseVal[0].value=n})),e.position.x+=i,l!==e.a&&(_e(o.el,l,e.a),l=e.a),r=e.w}c!==e.h&&(a().y.baseVal[0].value=Ye(e.h),e.position.y+=Ve(e.h)-Ve(c),c=e.h),o.draw()}return d(),48!==e.w||48!==e.h?u(!0):o.draw(),o.el[It].patch=t=>{const n=t.position&&!F(e.position,t.position);n&&N(e.position,t.position);let i=!1;t.styles&&(e.styles=t.styles,Sn(o.el),i=!0),null!=t.title&&e.title!==t.title&&(e.title=t.title,o.drawTxt(),i=!0);let s=!1;if(null==t.w&&i){const t=Fe(a());be(e,t)||($e(e,t),s=!0)}null==t.w||be(e,t)||($e(e,t),d(),s=!0),null!=t.a&&e.a!==t.a&&(_e(o.el,e.a,t.a),e.a=t.a,l=e.a,s=!0),s?(a().y.baseVal[0].value=Ye(e.h),u(!0)):n&&o.draw(),t.styles&&(Oe=[...t.styles])},o.el}function Fe(t){const n=t.getBBox();return{w:D(0,48,n.width+12),h:D(0,24,n.height+14)}}customElements.define("ap-rect-txt-settings",Ne),Et(3,(()=>$n(3,R(Oe))));const Ke=t=>1===t.a?-16:2===t.a?0:16,Ye=t=>24-Ve(t);function _e(t,n,e){a(t,`ta-${n}`),i(t,`ta-${e}`)}const Xe=t=>[...t.childNodes].every((t=>![...t.childNodes].some((t=>t.nodeType===Node.TEXT_NODE&&t.textContent?.trim())))),Ge=()=>{const t=f("tspan"," ➜");return t.setAttribute("fill","rgb(13, 110, 253)"),t},qe=(t,n,e)=>{oe(t,n,e),Xe(t)&&t.append(Ge())};let Je;function We(n,e,o){t(n,e).setAttribute("d",`M${o.l.x} ${o.l.y} L${o.t.x} ${o.t.y} L${o.r.x} ${o.r.y} L${o.b.x} ${o.b.y} Z`)}function Qe(t,n){const e=t/2,o=n-e,i=e-n;return{l:{x:o,y:0},t:{x:0,y:o},r:{x:i,y:0},b:{x:0,y:i}}}Et(4,(()=>$n(4,R(Je))));const to=(t,n)=>D(n,48,function(t){const n=g(t);return 2*(Math.abs(n.x)+Math.abs(n.y))}(t)-20);async function no(t,n,e){return function(t,n,e){let o,i;const a=eo(t,n);if(a)o=new DataView(t,0,a.byteOffset-8),i=new DataView(t,a.byteOffset+a.byteLength+4);else{const n=t.byteLength-12;o=new DataView(t,0,n),i=new DataView(t,n)}const s=new DataView(new ArrayBuffer(8));return s.setUint32(0,e.length),s.setUint32(4,n),new Blob([o,s,e,new Uint32Array([0]),i],{type:"image/png"})}(await t.arrayBuffer(),oo(n),e)}function eo(t,n){const e=new DataView(t,8);let o,i=0,a=e.getUint32(4);for(;1229278788!==a;){if(o=e.getUint32(i),a===n)return new DataView(t,i+16,o);i=i+12+o,a=e.getUint32(i+4)}return null}function oo(t){return new DataView((new TextEncoder).encode(t).buffer).getUint32(0)}const io=()=>"undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent||"")||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1),ao=(t,n,e)=>so(t,X(n),null,e);function so(t,n,e,o){const i=t.ownerSVGElement.cloneNode(!0),a=i.querySelector("#canvas");let c;i.style.backgroundImage=null,e?(c=y(uo(t,co)),A(a.children,(t=>((t,n)=>n.some((n=>s(t,n))))(t,co)?(lo(t),!0):(t.remove(),!1)))):(c=t.getBoundingClientRect(),uo(a,ro).forEach((t=>lo(t))));const r=i.getElementsByTagName("foreignObject");for(;r[0];)r[0].parentNode.removeChild(r[0]);const l=t[et].data,d=1/l.scale;a.style.transform=`matrix(1, 0, 0, 1, ${d*(l.position.x+15*l.scale-c.x)}, ${d*(l.position.y+15*l.scale-c.y)})`,function(t,n,e,o){const i=T(io()?4096:10836,n.width*e*window.devicePixelRatio,n.height*e*window.devicePixelRatio),a=new Image;a.width=n.width,a.height=n.height,a.onload=function(){const t=document.createElement("canvas");t.width=i.w,t.height=i.h,t.style.width=`${i.w}px`,t.style.height=`${i.h}px`;const e=t.getContext("2d");e.imageSmoothingEnabled=!1,e.drawImage(a,n.x,n.y,n.width,n.height,0,0,i.w,i.h),URL.revokeObjectURL(a.src),t.toBlob(o,"image/png")},t.width.baseVal.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX,a.width),t.height.baseVal.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX,a.height),a.src=URL.createObjectURL(new Blob([(new XMLSerializer).serializeToString(t)],{type:"image/svg+xml;charset=utf-8"}))}(i,{x:0,y:0,height:c.height/l.scale+30,width:c.width/l.scale+30},3,(async t=>o(n?await no(t,"dgRm",(new TextEncoder).encode(n)):t)))}const co=["select","highlight"],ro=["select","highlight","highlight-e","highlight-s"],lo=t=>{a(t,...ro),t.querySelector(".resizer")?.remove()},uo=(t,n)=>t.querySelectorAll(`.${n.join(", .")}`);async function ho(t){const n=await async function(t,n){return eo(await t.arrayBuffer(),oo(n))}(t,"dgRm");return n?(new TextDecoder).decode(n):null}const po=navigator.clipboard.readText;async function fo(t,n){const e=`web text/dgrm${X(Kt(n,!0))}`;await async function(t){try{await navigator.clipboard.writeText(t)}catch(t){alert(t)}}(e),window.ClipboardItem&&so(t,null,!0,(async t=>{try{await navigator.clipboard.write([new window.ClipboardItem({[t.type]:Promise.resolve(t),"text/plain":Promise.resolve(new Blob([e],{type:"text/plain"}))})])}catch{}}))}const mo=t=>{if(!t?.startsWith("web text/dgrm"))return null;try{return G(t.slice("web text/dgrm".length))}catch{return null}};function vo(t,n,e){const o=function(t,n){async function e(e){if(document.activeElement===t.ownerSVGElement){const o=n();if(o?.length)return e.preventDefault(),fo(t,o),o}return null}async function o(n){const o=await e(n);o&&go(t,o)}return document.addEventListener("copy",e),document.addEventListener("cut",o),function(){r(document,"copy",e),r(document,"cut",o)}}(t,n);function i(o){if(u(o)||"Delete"!==o.key&&"Backspace"!==o.key)"Escape"===o.key&&e();else{const e=n();e?.length&&go(t,e)}}return c(document,"keydown",i),function(){o(),r(document,"keydown",i)}}function go(t,n){t[et].select(null),pn(t,n)}const wo=()=>{if(!document.cookie.includes("dgrma=1"))return null;const t=G(localStorage.getItem("dgrm"));return t&&new Date(t.e)>new Date?t:null},yo=(t,n,e,o,i)=>{n&&$o(xo(),e,o,n.n,0===e?n.i:n.n,n.i,new Date,i)},xo=()=>`dgrm${wo()?.l}`,bo=(t,n)=>Lo(t,(t=>ko(t.transaction("r","readonly").objectStore("r"),n))),$o=(t,n,e,o,i,a,s,c)=>Lo(t,(t=>{const r=t.transaction("r","readwrite").objectStore("r");ko(r,(l=>{const d=l.find((t=>t.k===i));l.length>=5&&!d&&Mo(t,r,l[l.length-1]);const u=d?.i??a??Dt();r.put({t:n,i:u,k:i,n:o,l:e,d:s}),c&&t.transaction("d","readwrite").objectStore("d").put({i:u,d:c})}))})),ko=(t,n)=>{t.getAll().onsuccess=t=>{n((t.target.result??[]).sort(((t,n)=>n.d.getTime()-t.d.getTime())))}},Mo=(t,n,e,o)=>{let i=0;const a=()=>{1!==i?i++:o&&o()};n.delete(e.i).onsuccess=a,1===e.t?t.transaction("d","readwrite").objectStore("d").delete(e.i).onsuccess=a:a()},Co=(t,n,e)=>Lo(t,(t=>{let o=null,i=null;const a=(t,n)=>{t&&(o=t),n&&(i=n),o&&i&&(o.s=i.d,e(o))};t.transaction("r","readonly").objectStore("r").get(n).onsuccess=t=>{a(t.target.result,null)},t.transaction("d","readonly").objectStore("d").get(n).onsuccess=t=>{a(null,t.target.result)}})),Ho=(t,n,e)=>Lo(t,(t=>{const o=t.transaction("r","readwrite").objectStore("r");ko(o,(i=>{const a=i.find((t=>t.k===n));a?Mo(t,o,a,e):e()}))})),Lo=(t,n)=>{const e=indexedDB.open(t);e.onerror=t=>console.error(e.error),e.onupgradeneeded=t=>{const n=e.result;n.createObjectStore("d",{keyPath:"i"}),n.createObjectStore("r",{keyPath:"i"})},e.onsuccess=t=>{e.result.onerror=t=>console.error("indexedDB error",t),n(e.result)}},Vo=(t,n,e,o,i,a)=>{t[Ao]={i:n,n:e,e:o,m:i},Bo(t,0,a,null)},zo=(t,n,e)=>{const o=Y(n.name);t[Ao]={f:n,n:o},Bo(t,1,null,e)},So=(t,n,e)=>{t[Ao]={n:n},Bo(t,1,null,e)},Zo=t=>{t[Ao]=void 0,Bo(t,null,null,null)},Do=t=>t[Ao],Bo=(t,n,e,o)=>{const i=t[Ao];To(i?.n),yo(0,i,n,e,o)},To=t=>{document.title=t??"DGRM - Flowchart editor"},Eo=t=>t?.replace(/[/\\?%*:|"<>]/g,"-"),Ao=Symbol(0),Ro=async(t,n)=>{const e=`${Do(t)?.n??"dgrm"}.png`;if(Po())return void await ze(n,e);const o={files:[new File([n],e,{type:n.type})]};navigator.canShare&&navigator.canShare(o)?await navigator.share(o):await ze(n,e)},Po=()=>screen.width>768;class Uo extends HTMLElement{constructor(t,n){super(),this.g=t,this.M=n}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML=`
${yn}Create copy
Copy to clipboard
${Po()?xn+"Download":bn+"Send"} image
${wn}Delete
`;const n=()=>ut(this)[wt].del();function e(e,o){c(t.getElementById(e),"click",(t=>{n(),o()}))}e("clone",(()=>ln(this.g,this.M()))),e("copy",(async()=>await fo(this.g,this.M()))),e("save",(()=>so(this.g,X(Kt(this.M(),!1)),!0,(async t=>Ro(this.g,t))))),e("del",(()=>pn(this.g,this.M())))}}customElements.define("ap-grp-settings",Uo);const Io=Symbol("p"),No=Symbol(0);const Oo=(t,n,e)=>{if(e[Io])return null;if("a"===e?.target?.tagName)return null;const o=At(e),i=ci(o);if(!i)return Wo(n),null;const a=ei(n,o),s=ai(n);if(s&&a)return ri(i,e),null;if(e.shiftKey||e.ctrlKey){if(s){const t=ii(n);li(t),Go(n,t)}return a?qo(n,i):Go(n,i),ti(n,e),null}return a?ft(new Uo(t,(()=>Qo(n))),e.clientX-10,e.clientY-10):(Wo(n),Go(n,i),ti(n,e),null)},jo=(t,n,e,o)=>{if(e[Io])return;if(t[No]?.size)for(const n of t[No])if(n(e,o))return;if(o===t.ownerSVGElement)return void t[et].moveCapture();const i=ei(n,o);if(!i&&!h(e))return void t[et].moveCapture();if(!i&&h(e))return Wo(n),void di(ci(o),e,o);const a=ai(n);i&&a?di(ci(o),e,o):i&&!a&&Fo(t,n,e)},Fo=(t,n,e)=>{const o=()=>Ko(n),i=t=>Yo(n,t),a=o();C(t.ownerSVGElement,e,(n=>i((e=>Q(e,t[et].data.scale,n)))),(n=>{i((n=>at(n,t[et].data.cell))),on(t,a,o())}))},Ko=t=>Kt([...t.shapesToMove,...ui(t.pathEndsToMove)],!1,!0),Yo=(t,n)=>{t.shapesToMove?.forEach((t=>{n(t[It].data.position),t[It].drawPosition()})),t.pathEndsToMove?.forEach((t=>{n(t.data.position),hi(t)[Ut].drawPosition()}))},_o=t=>{t[et].select(null),t[et].select(t.children)},Xo=()=>({shapes:new Set,paths:new Set,pathEnds:new Set,shapesToMove:new Set,pathEndsToMove:new Set}),Go=(t,n)=>{if(n.shape)t.shapes.add(n.shape),i(n.shape,"highlight");else if(n.path)t.paths.add(n.path),i(n.path,"highlight"),a(n.path,"highlight-s","highlight-e"),t.pathEnds.delete(n.path[Ut].data.s),t.pathEnds.delete(n.path[Ut].data.e);else if(n.pathEnd){const e=hi(n.pathEnd);if(t.paths.has(e))return;t.pathEnds.add(n.pathEnd),i(e,mi(n.pathEnd))}},qo=(t,n)=>{if(n.shape)t.shapes.delete(n.shape),a(n.shape,"highlight");else if(n.path)t.paths.delete(n.path),t.pathEnds.delete(n.path[Ut].data.s),t.pathEnds.delete(n.path[Ut].data.e),a(n.path,"highlight","highlight-s","highlight-e");else if(n.pathEnd){const e=hi(n.pathEnd);if(t.paths.delete(e)){a(e,"highlight","highlight-s","highlight-e");const o=fi(n.pathEnd);t.pathEnds.add(o),i(e,mi(o))}else t.pathEnds.delete(n.pathEnd),a(e,mi(n.pathEnd))}},Jo=t=>{const n=t=>a(t,"highlight","highlight-s","highlight-e");t.shapes.forEach((t=>n(t))),t.paths.forEach((t=>n(t))),t.pathEnds.forEach((t=>n(hi(t))))},Wo=t=>{Jo(t);const n=ii(t);n&&li(n),t.pathEnds.clear(),t.pathEndsToMove.clear(),t.paths.clear(),t.shapes.clear(),t.shapesToMove.clear()},Qo=t=>[...t.shapes,...t.paths,...ui(t.pathEnds)],ti=(t,n)=>{ni(t);const e=oi(t);e&&(Jo(t),ri(e,n))},ni=t=>{t.shapesToMove=new Set(t.shapes),t.pathEndsToMove=new Set;const n=n=>{n.shape?t.shapesToMove.add(n.shape.shapeEl):t.pathEndsToMove.add(n)};t.paths?.forEach((t=>{n(t[Ut].data.s),n(t[Ut].data.e)})),t.pathEnds?.forEach(n)},ei=(t,n)=>[...t.shapes,...[...t.pathEnds].map((t=>t.el)),...t.paths].some((t=>t.contains(n))),oi=t=>si(t)?ii(t):{},ii=t=>1!==t.shapes.size||t.paths.size||t.pathEnds.size?t.shapes.size||1!==t.paths.size||t.pathEnds.size?t.shapes.size||t.paths.size||1!==t.pathEnds.size?null:{pathEnd:P(t.pathEnds)}:{path:P(t.paths)}:{shape:P(t.shapes)},ai=t=>!!ii(t),si=t=>t.shapes.size||t.pathEnds.size||t.paths.size,ci=t=>{const n=t[It]?{shape:t}:t.parentElement[It]?{shape:t.parentElement}:t.parentElement.parentElement[It]?{shape:t.parentElement.parentElement}:null;if(n)return n;const e=t[Ut]?{path:t}:t.parentElement[Ut]?{path:t.parentElement}:null;if(e)return e;const o=pi(t);return o?{pathEnd:o}:null},ri=(t,n)=>{t.shape?t.shape[It].click(n):t.path?t.path[Ut].click(n):t.pathEnd&&hi(t.pathEnd)[Ut].click(n,t.pathEnd.el)},li=t=>{t.shape?t.shape[It].unselect():t.path?t.path[Ut].unselect():t.pathEnd&&hi(t.pathEnd)[Ut].unselect()},di=(t,n,e)=>{t.shape?t.shape[It].moveCapture(n,e):t.path?t.path[Ut].moveCapture(n,e):t.pathEnd&&hi(t.pathEnd)[Ut].moveCapture(n,e)},ui=t=>[...t].map(hi),hi=t=>t.el.parentNode,pi=t=>{const n=t.hasAttribute("data-key")?t:t.parentElement.hasAttribute("data-key")?t.parentElement:null;if(!n)return null;const e=n.parentNode[Ut].data;return e.s.el===n?e.s:e.e},fi=t=>{const n=hi(t)[Ut].data;return n.s===t?n.e:n.s},mi=t=>hi(t)[Ut].data.s===t?"highlight-s":"highlight-e";function vi(t){const n=(n,e)=>(function(t,n,e){const o=f("path");o.style.pointerEvents="none",i(o,"mrkp"),t.append(o);const a=[],c=n=>a.push(ot(t[et].data,n.clientX,n.clientY)),r=new Set,l=t=>{s(t,"mrkt")&&r.add(t)};l(e),c(n),C(o,n,(t=>{c(t),o.setAttribute("d",$i(a)),l(document.elementFromPoint(t.clientX,t.clientY))}),(n=>{let e=ki(y([o,...r]));o.remove(),e=Mi(ot(t[et].data,e.x,e.y));const i={id:K(),type:7,position:e,d:""},s=[{position:{x:0,y:0},d:$i(a)}],c=[];r.forEach((t=>{const n=t.parentNode;c.push(n),s.push(n[It].data)}));for(const t of s)wi(i,t);c.length?fn(t,c,Yt(i)):un(t,Yt(i),!0)}))}(t,n,e),!0);return((t,n)=>{t[No]??=new Set,t[No].add(n)})(t,n),()=>{((t,n)=>{t[No]?.delete(n)})(t,n)}}const gi=t=>``;function wi(t,n){const e=yi(n.d),o=j(n.position);U(o,t.position,-1);let i=n.d;for(const t of e){const n=j(t);Mi(U(t,o)),i=bi(i,n,t)}t.d+=i}const yi=t=>t.match(/M(.*?)l/g).map((t=>{const n=t.split(" ");return{x:Number.parseFloat(n[0].substring(1)),y:Number.parseFloat(n[1].substring(0,n[1].length-1))}})),xi=t=>`M${t.x} ${t.y}l`,bi=(t,n,e)=>t.replaceAll(xi(n),xi(e));function $i(t,n=5,e=2){const o=t.length,i=o-n-1==0;let a="M",s=[t[0].x,t[0].y];const[c,r]=s.map((t=>+t.toFixed(e)));let l=`${a}${c} ${r}`,d=c,u=r;const[h,p]=[t[1].x,t[1].y],[f,m]=[(c+h)/2,(r+p)/2],[v,g]=[f-d,m-u].map((t=>+t.toFixed(e)));l+=`l${v} ${g}`,d+=v,u+=g;for(let i=1;i1&&(a="t",s=[w,y]),l+=`${a}${s.map((t=>+t.toFixed(e))).join(" ")} `,d+=w,u+=y}return i||(s=[t[o-1].x-d,t[o-1].y-u],l+=`l${s.map((t=>+t.toFixed(e))).join(" ")}`),l}const ki=t=>({x:Math.round(t.x+t.width/2),y:Math.round(t.y+t.height/2)}),Mi=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t);const Ci=()=>{const t=wo()?.n;if(t)return t;const n=`User${Math.floor(100*Math.random())}`,e=prompt("Your name",n);return null==e?null:e?.substring(0,25)??n},Hi=t=>document.getElementById("menu").bage(t),Li=t=>{const n=Vi(t),e=document.createElement("div");return e.innerHTML=` ${t}`,e.style.cssText=`position: fixed; top:0; color:${n}; pointer-events: none;`,e.style.transform="translate(-9999px, 0px)",v(e),e},Vi=t=>`hsl(${[...t].reduce(((t,n)=>n.charCodeAt(0)+((t<<5)-t)),0)%360}, 97%, 47%)`,zi=(t,n,e,o)=>{const i=((t,n,e)=>({x:t.position.x+n*t.scale,y:t.position.y+e*t.scale}))(t[et].data,e,o);n.style.transform=`translate(${i.x}px, ${i.y}px)`},Si=(t,n,e)=>{const o=t=>e(X(t)),i=c(t,"dgrmc",(t=>o([4,t.detail.shapesToCreateData]))),a=c(t,"dgrmu",(t=>o([4,t.detail.shapesToUpdData]))),s=c(t,"dgrmd",(t=>o([5,t.detail.delIds]))),l=c(t,"dgrmdc",(t=>{o([5,t.detail.delIds]),o([4,t.detail.shapesToCreateData])}));let d=!0;const u=c(t.ownerSVGElement,"pointermove",Z((e=>{if(d){const i=ot(t[et].data,e.clientX,e.clientY);o([6,n,i.x,i.y])}}),60));return()=>{d=!1,r(t,"dgrmc",i),r(t,"dgrmu",a),r(t,"dgrmd",s),r(t,"dgrmdc",l),r(t.ownerSVGElement,"pointermove",u)}},Zi=(t,n)=>{Xt(t,n),S(t,new CustomEvent(Bi,{detail:n,cancelable:!1}))},Di=(t,n)=>{zn(n),S(t,new CustomEvent(Ti,{detail:n,cancelable:!1}))},Bi="dgrmcu",Ti="dgrmcd",Ei=t=>k("k",t);function Ai(t,n){_t(t,n),function(t){const n=t.getBoundingClientRect(),e=window.innerWidth/2,o=window.innerHeight/2;t[et].move(e-n.width/2-n.x,o-n.height/2-n.y,1);const i=t=>t>1?1:Math.max(t,.25),a=Math.min(i(window.innerWidth/n.width),i(window.innerHeight/n.height));a<1&&t[et].scale(a,{x:e,y:o})}(t)}function Ri(t){return!!Ii(t)&&(t.c[t.i].u(),t.i-=1,!0)}function Pi(t){const n=Ui(t);return null!==n&&(t.i=n,t.c[n].r(),!0)}const Ui=t=>{if(!t)return null;const n=t.i+1;return n<=t.c.length-1?n:null},Ii=t=>t&&t.i>=0,Ni=(t,n,e)=>_i(t,(()=>{Ki(t,en(n,e)),Xt(t,e),zn(n)}),(()=>{Ki(t,nn(n,e)),Xt(t,e)})),Oi=(t,n,e)=>_i(t,(()=>{Ki(t,nn(n,e)),Xt(t,e)}),(()=>{Ki(t,en(n,e)),zn(n)})),ji=(t,n,e)=>_i(t,(()=>{Ki(t,an(e,n)),Xt(t,n)}),(()=>{Ki(t,an(n,e)),Xt(t,e)})),Fi=(t,n,e,o,i)=>_i(t,(()=>{Ki(t,nn(n,e)),Xt(t,e),Ki(t,en(o,i)),Xt(t,i),zn(o)}),(()=>{Ki(t,en(n,e)),zn(n),Ki(t,nn(o,i)),Xt(t,i)})),Ki=(t,n)=>{n[Yi]=!0,S(t,n)},Yi=Symbol(0);function _i(t,n,e){t[Qi]??={c:[],i:-1},function(t,n,e){15===t.c.length&&(t.c.splice(0,1),t.i--),t.c.splice(t.i+1),t.i=t.c.push({u:n,r:e})-1}(t[Qi],n,e),Ji(t)}function Xi(t,n){n(t[Qi])&&(t[et].select(null),Ji(t))}const Gi=t=>Xi(t,Ri),qi=t=>Xi(t,Pi);const Ji=t=>{return S(t,z(Wi,(n=t[Qi],{u:Ii(n),r:null!==Ui(n)})));var n},Wi="dgrmh",Qi=Symbol("h");function ta(t){S(t,z("dgrmn",null,!0))&&(!function(t){for(t[et].select(null);t.firstChild;)(t.firstChild[It]||t.firstChild[Ut]).del();t[et].move(0,0,1)}(t),function(t){var n;(n=t[Qi])&&(n.c=[],n.i=-1),Ji(t)}(t),Zo(t))}async function na(t,n){if(!t?.i)return void oa({a:0,u:[]},!0,!0,n);const e=await lt((()=>(async t=>(await x(`${Lt}${t}`)).json())(t.i))),o=oa(e,!1,!t.m,n);t.m&&(la(o,"[anon]",[da[0],da[1],da[2]],(n=>lt((async()=>{var o,i;e.a!==n[1]&&(e.a=n[1],await(o=t.i,i=n[1],b(`${Lt}a/${o}`,i.toString())))})))),ea(o,e.u,((n,e)=>{return o=t.i,$(`${Lt}${o}`,{i:n,r:e});var o})),l(o,"[inv]",(n=>aa((n=>lt((async()=>{const e=Dt();var o,i,a;await navigator.clipboard.writeText(`${Ct}invite/${e}`),await(o=t.i,i=e,a=n,$(`${Lt}i/${o}`,{i:i,r:a})),Mt()}))))))),l(o,"[cop]",(async n=>{await navigator.clipboard.writeText(Ei(t.i)),Mt(),o[wt].del()}))}const ea=(t,n,e)=>l(t,"[uu]",(o=>{const i=o.currentTarget,a=Number(o.currentTarget.getAttribute("uu")),s=t=>lt((async()=>{const o=n.find((t=>t.i===a));o.r!==t[1]&&(i.textContent=t[0],await e(a,t[1]),o.r=t[1])}));ra(o,[xt(da[1][0],(()=>s(da[1]))),xt(da[2][0],(()=>s(da[2]))),$t((()=>lt((async()=>{await e(a,da[0][1]),t.querySelector(`[uitm="${a}"]`).remove()}))))])})),oa=(t,n,e,o)=>gt(`
${ia({i:0,n:"Anyone with the link",r:t.a})} ${t?.u?.map(ia).join(" ")}
${J(n,'To share, save diagram to the cloud.')} ${J(e&&!n,'You do not have access to manage permissions.')}
`,null,o),ia=t=>``,aa=t=>{const n=vt(m('
Send a link to the person you want to invite.

Person must have a DGRM subscription.

Permissions: Viewer
The invitation link is one-time only and is active for 24 hours.'),null,!0);let e=1;la(n,"[prm]",[da[1],da[2]],(t=>{e=t[1]})),l(n,"[crt]",(o=>{n[wt].del(),t(e)}))};async function sa(t){const n=await lt((()=>(async t=>(await x(`${Vt}${t}`)).json())(t))),e=ca(n);ea(e,n,((n,e)=>((t,n,e)=>$(`${Vt}${t}`,{i:n,r:e}))(t,n,e))),l(e,"[inv]",(n=>aa((n=>lt((async()=>{const e=Dt();await navigator.clipboard.writeText(`${Ct}invite-folder/${e}`),await((t,n,e)=>$(`${Vt}i/${t}`,{i:n,r:e}))(t,e,n),Mt()}))))))}const ca=t=>gt(`
${t.map(ia).join(" ")}
`,null,!0),ra=(t,n)=>yt(t.currentTarget,n),la=(t,n,e,o)=>l(t,n,(t=>{const n=t.currentTarget;ra(t,e.map((t=>xt(t[0],(()=>(async t=>{n.textContent=t[0],o(t)})(t))))))})),da=[["No access",0],["Viewer",1],["Editor",2]],ua=async t=>{const e=ha(`
${wo()?'':'
Log in to access cloud storage.
'}
`);e.s();const o=t=>{n(e.m,"ftr").style.display=t?"unset":"none"},i=async()=>{await pa(e.h,e.b,(()=>e.m[wt].del())),o(!0)};await i(),l(e.m,"[cld]",(()=>lt((async()=>{o(!1),await fa(t,e.h,e.b,!0,(async t=>await i()))})))),l(e.m,"[dvc]",(async()=>{e.m[wt].del(),await async function(t){try{const n=await Se(Be);if(!n)return;const e=await $a(t,n.f);if(!e)return void ka();n.h?zo(t,n.h,e):So(t,Y(n.f.name),e)}catch(t){console.log(t),ka()}}(t)}))};const ha=t=>{const e=gt(`
${t}`,m('
')),o=t=>n(e,t);return{m:e,h:o("hdr"),b:o("cnt"),s:()=>{ut(e).style.display="flex"}}},pa=async(t,n,e)=>{t.innerHTML='CloseRecent',l(t,"[c]",e);const o=await new Promise(((t,n)=>bo(xo(),t)));n.innerHTML=o?.length?o.map((t=>``)).join(" "):La},fa=async(t,n,e,o,i)=>{let a=await St(),s={i:null,n:"Cloud",m:!0,r:!1};const c=[],r=n=>{a.d.delete(n),n===Do(t)?.i&&Zo(t),d()},l=(n,e)=>{e&&Zo(t),a.f.delete(n),d()},d=()=>va(e,s,a,((n,e)=>lt((async()=>{a.d.get(n).n=await(async(t,n)=>(await b(`${Ht}a/n/${t}`,n)).text())(n,e),n===Do(t)?.i&&((t,n,e)=>{t[Ao].n=n,Bo(t,0,e,null)})(t,a.d.get(n).n,s?.n),d()}))),(t=>lt((async()=>{var n;await(n=t,$(`${Ht}a/d/${n}`)),r(t)}))),(t=>lt((async()=>{var n;await(n=t,$(`${Lt}r/${n}`)),r(t)}))),(t=>lt((async()=>{c.push(s),s=a.f.get(t),u(),a=await St(t),d()}))),((t,n)=>lt((async()=>{a.f.get(t).n=await(async(t,n)=>(await b(`${Ht}f/n/${t}`,n)).text())(t,n),d()}))),(n=>lt((async()=>l(n,await(async(t,n)=>{const e=new URL(`${Ht}f/d/${t}`);return Bt(e,"k",n),(await $(e.toString())).json()})(n,Do(t)?.i))))),(n=>lt((async()=>l(n,await(async(t,n)=>(await b(`${Vt}r/${t}`,n)).json())(n,Do(t)?.i)))))),u=()=>ma(n,s,o,i,(()=>lt((async()=>{const t=c.pop();s=t,u(),a=await St(t.i),d()}))),(t=>lt((async()=>{const n=await(async t=>(await b(`${Ht}f/a`,t)).json())(t);n.m=!0,a.f.set(n.i,n),d()}))),((t,n)=>lt((async()=>{const e=Dt();a.d.set(e,{i:e,n:await Zt(e,t,n,Ot()),d:Date.now(),m:!0,r:!1}),d()}))));return d(),u(),()=>({f:s,d:a})},ma=(t,n,e,o,i,a,s)=>{t.innerHTML=`\n\t\t${n.i||e?`${Ca}`:"Close"}\n\t\t${n.n??""}\n\t\t${n.m?`${Ma}`:''}`,l(t,"[c]",(t=>n.i?i():o()));const c=xt("Add diagram",(()=>xa("New diagram",(t=>s(n.i,t)))));l(t,"[af]",(t=>ga(t,n.i?[c,ya(n.i)]:[c,xt("Add folder",(()=>xa("New folder",a)))])))},va=(t,n,e,o,i,a,s,c,r,d)=>{t.innerHTML=`${[...e.f].map((t=>``)).join(" ")}\n\t\t${[...e.d].map((t=>``)).join(" ")}\n\t${e.f.size||e.d.size?"":La}`,l(t,"[fld]",(t=>s(Number(t.currentTarget.getAttribute("fld"))))),l(t,"[fedt]",(t=>{const n=e.f.get(Number(t.currentTarget.getAttribute("fedt"))),o=n.m?[wa(n.n,(t=>c(n.i,t))),ya(n.i),$t((()=>r(n.i)))]:[];n.r&&o.push(bt("Remove from my cloud",(()=>d(n.i)))),ga(t,o)})),l(t,"[edt]",(t=>{const n=e.d.get(t.currentTarget.getAttribute("edt")),s=n.m?[wa(n.n,(t=>o(n.i,t))),xt("Share",(t=>na(n,!0))),$t((()=>i(n.i)))]:[];n.r&&s.push(bt("Remove from my cloud",(()=>a(n.i)))),ga(t,s)}))},ga=(t,e)=>yt(n(t.currentTarget,"dts"),e),wa=(t,n)=>xt("Rename",(()=>xa(t,(e=>{t!==e&&n(e)})))),ya=t=>xt("Share",(()=>sa(t)));function xa(t,e){const o=vt(m(`
`),"mdm",!0);l(o,"[sv]",(t=>{o[wt].del(),e(Eo(n(o,"nm").value))}))}async function ba(t,n,e){const o=await $a(t,n);return o||(Ae(t,n,e.clientX,e.clientY),null)}async function $a(t,n){if("image/png"!==n.type)return null;const e=await ho(n);if(e){ta(t);const n=G(e);return Ai(t,n),n}return null}const ka=()=>alert("File cannot be read. Use the exact image file you got from the application."),Ma='',Ca='',Ha='',La='
No items
',Va=async t=>{const n=Do(t);if(n?.f){const e=Ft(t);ao(t,e,(async o=>{const i=await n.f.createWritable();await i.write(o),await i.close(),yo(0,n,1,null,e),Ra(t)}))}else n?.i?n.e?lt((async()=>await Ba(t,n.i))):alert('You do not have access to edit this diagram. Use "Save As" to make your own copy.'):za(t)},za=async t=>wo()?Sa(t):Za(t),Sa=async t=>{const e=await lt((()=>(async(t,n)=>{const e=ha(n),o=await fa(t,e.h,e.b,!1,(()=>e.m[wt].del()));return e.s(),{m:e.m,d:()=>o()}})(t,`
`))),o=()=>e.m[wt].del(),i=()=>Eo(n(e.m,"snm").value);l(e.m,"[dvc]",(n=>{o(),Da(t,i())})),l(e.m,"[cld]",(async()=>{const n=e.d();if(n.d.d.size>29&&(alert("Maximum number of diagrams in folder exceeded"),1))return;const a=async t=>{lt(t),o()},s=(e,o)=>{Vo(t,e,o,!0,!0,n?.f?.n),Ra(t)},c=i(),r=Object.entries(n.d.d).find((t=>t[1].n===c));if(r){const n=Do(t);return r[0]===n?.i&&n.m?void a((async()=>await Ba(t,n.i))):void(confirm("Overwrite existing file?")&&a((async()=>s(r[0],await(async(t,n)=>(await $(`${Ht}a/o/${t}`,n)).text())(r[0],Ft(t))))))}a((async()=>{const e=Dt();s(e,await Zt(e,n.f.i,c,Ft(t)))}))}))},Za=t=>{const e=vt(m(`
Log in to access cloud storage.
`),"mdm");l(e,"[dvc]",(o=>{Da(t,Eo(n(e,"nm").value)),e[wt].del()}))},Da=(t,n)=>{const e=Ft(t);ao(t,e,(async o=>{const i=ze(o,n?.length?n:Pa());if(i){const n=await i;n&&(zo(t,n,e),Ra(t))}else So(t,n,e),Ra(t)}))},Ba=async(t,n)=>{let e;if(Ta(t)){const o=[...t[Aa].c,...t[Aa].u],i=function(t,n){for(const e in t.s)n.has(e)&&Qt(t.s[e]);return t}(Kt(o.length?[...document.querySelectorAll(o.map((t=>`[id="${t}"]`)).join(","))]:null,!1),t[Aa].u);t[Aa].d.forEach((t=>{i.s[t]=null})),e=await(async(t,n)=>(await $(`${Ht}u/${t}`,n)).json())(n,i)}else e=(await zt(n)).d;Xt(t,e),Ra(t)},Ta=t=>t[Aa].c.size||t[Aa].u.size||t[Aa].d.size,Ea=t=>{t[Aa].c.clear(),t[Aa].u.clear(),t[Aa].d.clear()},Aa=Symbol(0),Ra=t=>{Ea(t),kt("Saved")},Pa=()=>{const t=t=>t<10?`0${t}`:t.toString(),n=new Date;return`${n.getFullYear()}-${t(n.getMonth()+1)}-${t(n.getDate())}.${t(n.getHours())}${t(n.getMinutes())}${t(n.getSeconds())}.png`};function Ua(t,n,e,o){const i=n=>t[et].select(dn(t,n,!0,e,o));if(n?.data)i(function(t){if(!t)return null;const n=new Map,e=t=>{const e=K();return n.set(t,e),e},o=[];for(const n in t.s){const i=e(t.s[n].id);t.s[i]=t.s[n],t.s[i].id=i,delete t.s[n],0===t.s[i].type&&o.push(t.s[i])}return o.forEach((t=>{t.s.s=n.get(t.s.s),t.e.s=n.get(t.e.s)})),t}(n.data));else if(n?.img)Re(n.img,(t=>i(Yt(t))));else if(n?.txt){const e=function(t,n){const e=f("text");qe(e,null,n),e.style.visibility="hidden",t.append(e);const o=Fe(e);return e.remove(),o}(t,n.txt);i(Yt({id:K(),type:3,position:{x:0,y:0},title:n.txt,w:e.w,h:e.h}))}else kt("Clipboard is empty")}class Ia extends HTMLElement{constructor(t){super(),this.g=t}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML='';const n=t.getElementById("u"),e=t.getElementById("r");c(this.g,Wi,(t=>{const o=(t,n)=>n?i(t,"actv"):a(t,"actv");o(n,t.detail.u),o(e,t.detail.r)})),c(n,"click",(t=>Gi(this.g))),c(e,"click",(t=>qi(this.g)))}}customElements.define("ap-history",Ia);const Na=-1!==window.navigator.userAgent.indexOf(" OPR"),Oa=t=>Na&&0!==t.button,ja=(t,n,e,o,i)=>t.x<=o&&o<=t.x+n&&t.y<=i&&i<=t.y+e,Fa={iceServers:[{urls:"stun:stun3.l.google.com:19302"}]},Ka=`${Ct}m/`;async function Ya(t,n,e,o){const i=Ci();if(null==i)return e(),null;rt(!0);const a=K(),s=new Map,c=await async function(t,n,e,o,i){const a=await async function(t,n,e){const o=new RTCPeerConnection(Fa),i=o.createDataChannel("dgrm");return i.onopen=n=>t(i,n),i.onmessage=t=>n(i,t),i.onerror=t=>{o.close(),e()},await o.setLocalDescription(),new Promise(((t,n)=>{o.onicecandidate=n=>{n.candidate||t(o)}}))}(e,o,i);await((t,n,e)=>$(`${Ka}o`,{m:t,c:n,s:e}))(n,t,a.localDescription.sdp);const s=q(3e3,15e3,(async()=>{try{const e=await(async(t,n)=>(await x(`${Ka}a?m=${t}&c=${n}`)).text())(n,t);e&&(s(),a.setRemoteDescription({sdp:e,type:"answer"}))}catch{c(),i()}}),i),c=()=>{s(),a.close(),rt(!1)};return c}(a,n,((t,n)=>t.send(X([0,a,i]))),((n,e)=>{const o=G(e.data);switch(o[0]){case 6:zi(t,s.get(o[1]),o[2],o[3]);break;case 4:Zi(t,o[1]);break;case 5:Di(t,o[1]);break;case 0:s.set(o[1],Li(o[2]));break;case 7:s.get(o[1]).remove(),s.delete(o[1]);break;case 2:Ai(t,o[1]),l(n);break;case 3:t[et].move(o[1],o[2],1),l(n)}}),(()=>{d(),o()}));let r;const l=n=>{r=Si(t,a,(t=>n.send(t))),rt(!1)},d=()=>{s.forEach((t=>t.remove())),r&&r(),c(),rt(!1)};return d}async function _a(t,n,e){const o=Ci();if(null==o)return n(),null;const i=K(),a=K(),s=new Map,c=(t,n)=>s.forEach(((e,o)=>o!==n?o.send(t):null)),r=await async function(t,n,e,o,i){const a=K();await((t,n)=>$(`${Ka}c`,{m:t,k:n}))(t,a);const s=new Set,c=q(5e3,72e5,(async()=>{try{const i=await(async(t,n)=>{const e=await(await x(`${Ka}o?m=${t}&k=${n}`)).json();return e?Object.entries(e):void 0})(t,a);if(!i?.length)return;i.forEach((async i=>{const c=await async function(t,n,e,o){const i=new RTCPeerConnection(Fa);return i.ondatachannel=t=>{const a=t.channel;a.onopen=t=>n(a,t),a.onmessage=t=>e(a,t),a.onerror=t=>{i.close(),o(i,a,t)}},await i.setRemoteDescription({sdp:t,type:"offer"}),await i.setLocalDescription(),new Promise(((t,n)=>{i.onicecandidate=n=>{n.candidate||t(i)}}))}(i[1],((t,e)=>n(i[0],t,e)),e,((t,n,e)=>{s.delete(t),o(n,e)}));s.add(c),await((t,n,e,o)=>$(`${Ka}a`,{m:t,k:n,c:e,s:o}))(t,a,i[0],c.localDescription.sdp)}))}catch{r(),i()}})),r=()=>{c(),s?.forEach((t=>t.close()))};return r}(i,((n,e,i)=>{e.send(X([0,a,o]));const c=Ft(t);e.send(X(jt(c)?[3,t[et].data.position.x,t[et].data.position.y]:[2,c])),s.forEach((t=>e.send(X([0,t.i,t.n]))))}),((n,e)=>{const o=G(e.data);switch(o[0]){case 6:zi(t,s.get(n).c,o[2],o[3]),c(e.data,n);break;case 4:Zi(t,o[1]),c(e.data,n);break;case 5:Di(t,o[1]),c(e.data,n);break;case 0:s.set(n,{i:o[1],n:o[2],c:Li(o[2])}),c(e.data,n)}}),((t,n)=>{const e=s.get(t);c(X([7,e.i]),t),e.c.remove(),s.delete(t)}),(()=>{d(),e()})),l=Si(t,a,c),d=()=>{l(),s.forEach((t=>t.c.remove())),r()};return{dispose:d,id:i}}function Xa(t,n,e){const o=m(`
Live collaboration in progress
`),i=vt(o),a=(t,n)=>l(o,t,(t=>{i[wt].del(),n()}));a("[mstop]",n),a("[mshare]",(async n=>{await navigator.clipboard.writeText(k("m",t)),Mt()}))}const Ga=t=>{t[Ja]?.dispose(),t[Ja]=void 0,Hi(!1)},qa=t=>{Ga(t),alert("Live collaboration disabled")},Ja=Symbol(0);class Wa extends HTMLElement{constructor(t){super(),this.g=t}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML='',this.C=!1;const e=e=>n(t,e);this.H=e;const o=t=>{this.contains(t.target)||s()};let i;let a=null;const s=()=>{a.remove(),a=null,r(document,"pointerdown",o),i&&i()},d=()=>{c(document,"pointerdown",o,!0),i=V(s),a=function(t,n,e){const o=wo(),i=o||Ze,a=Do(t)?.i?"Save and sync with cloud":"Save",s=m(`
New
Open
${i?'
'+a+"
":""}
Save${De||i?" as":""}
${Po()?xn+"Download":bn+"Send"} image
Share
Live collaboration
${o?o.n:"Log in"}
`);s.setAttribute("options","");const d=(t,n)=>l(s,t,(async t=>{e(),await n(t)}));l(s,"[menu2]",(t=>e())),d("[new]",(()=>{ta(t)})),i&&d("[save]",(async()=>await Va(t)));return d("[saveas]",(()=>za(t))),d("[open]",(async()=>await ua(t))),d("[collab]",(async n=>await async function(t){const n=()=>Ga(t),e=()=>qa(t);try{switch(t[Ja]?.clientType){case 1:Xa(t[Ja].id,n);break;case 2:Xa(t[Ja].id,n,!0);break;default:{const o=await _a(t,n,e);if(!o)return;c(t,"dgrmn",e,!0),t[Ja]={clientType:1,id:o.id,dispose:()=>{r(t,"dgrmn",e),o.dispose()}},Hi(!0),Xa(t[Ja].id,n);break}}}catch{e()}}(t))),d("[login]",(t=>function(){const t=wo();vt(m(t?`
${t.n}
${t.l}
Log out Delete account Delete account and all data. Disable auto payment for subscription.
`:'
Log in to access
cloud storage
'))}())),d("[link]",(n=>(t=>na(Do(t),!1))(t))),d("[down]",(n=>(t=>ao(t,Ft(t),(async n=>await Ro(t,n))))(t))),s}(this.g,this.C,(()=>s())),t.append(a)};c(e("menu"),"click",(t=>d()))}bage(t){(t?i:a)(this.H("menu"),"bage"),this.C=t}}customElements.define("ap-menu",Wa);class Qa extends HTMLElement{constructor(t){super(),this.g=t}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML='';const n=t.getElementById("smenu");n.querySelectorAll('[data-cmd="shapeAdd"]').forEach((t=>{c(t,"pointerdown",this),c(t,"click",this)})),c(n,"pointerleave",this),c(n,"pointerup",this),c(n,"pointermove",this);const e=t.getElementById("m");let o;c(e,"click",(t=>{o?(o(),o=null,e.style.opacity="0.4"):(o=vi(this.g),e.style.opacity="1")}))}handleEvent(t){switch(t.type){case"pointermove":if(!this.L){const n=document.elementFromPoint(t.clientX,t.clientY);if(n===this.V)return;this.S===this.V&&this.g.ownerSVGElement.setPointerCapture(t.pointerId),this.V=n}break;case"pointerleave":if(this.L=!0,null!=this.Z){const n=ts(this.g,this.Z,!1,t.clientX,t.clientY)[0];h(t)||this.g[et].select([n]),n[It]?n[It]?.moveCapture(t,n,!0):n[Ut]?.moveCapture(t,n,!0)}this.D();break;case"pointerdown":this.Z=parseInt(d(t,"data-cmd-arg")),this.S=document.elementFromPoint(t.clientX,t.clientY),this.V=this.S,this.L=null;break;case"pointerup":this.D();break;case"click":this.g.ownerSVGElement.focus(),this.g[et].select(ts(this.g,parseInt(d(t,"data-cmd-arg")),!0))}}D(){this.Z=null,this.S=null,this.V=null}}customElements.define("ap-menu-shape",Qa);const ts=(t,n,e,o,i)=>{return dn(t,Yt((a=n,Tt.get(a)())),e,o,i);var a};const ns=document.getElementById("canvas");var es,os,is,as,ss;ns[et]={data:{position:{x:0,y:0},scale:1,cell:24},shapeMap:function(n){const e=(t,e)=>Dn(n,t,e);return{0:{create:t=>e(Yn(n,t),3)},1:{create:i=>e(function(n,e){e.r??=48;let i,a=e.r;const s=he(n,e,' ',{right:{dir:"right",position:{x:48,y:0}},left:{dir:"left",position:{x:-48,y:0}},bottom:{dir:"bottom",position:{x:0,y:48}},top:{dir:"top",position:{x:0,y:-48}}},(()=>(i=I(e.position,-e.r),{x:e.r,y:e.r})),(r=>{let l=it(n[et].data,r).x-i.x;l<48&&(l=48);const d=48*Math.round(l/48)/2;e.r!==d&&we(t(s.el,"text"))<=d&&(e.r=d,e.position.x=i.x+d,e.position.y=i.y+d,c(),a=d);const u=l-e.r;o(r.target,{x:u,y:u})}),(t=>{const n=we(t,a);n!==e.r&&(e.r=n,c())}));function c(){s.cons.right.position.x=e.r,s.cons.left.position.x=-e.r,s.cons.bottom.position.y=e.r,s.cons.top.position.y=-e.r,kn(s),ge(s.el,"outer",e.r+24),ge(s.el,"main",e.r),s.draw()}return 48!==e.r?c():s.draw(),s.el[It].patch=t=>{const n=Ln(s,t),o=null!=t.r&&e.r!==t.r;o&&(e.r=t.r,a=e.r),o?c():n&&s.draw(),t.styles&&(ve=[...t.styles])},s.el}(n,i),2)},2:{create:t=>e(xe(n,t),2)},3:{create:t=>e(je(n,t),2)},4:{create:a=>e(function(n,e){e.w??=96;let a,s=e.w;const c=he(n,e,' ',{right:{dir:"right",position:{x:48,y:0}},left:{dir:"left",position:{x:-48,y:0}},bottom:{dir:"bottom",position:{x:0,y:48}},top:{dir:"top",position:{x:0,y:-48}}},(()=>{const t=e.w/2;return a=I(e.position,-t),{x:t,y:t}}),(i=>{let l=it(n[et].data,i).x-a.x;l<48&&(l=48);const d=48*Math.round(l/48);if(e.w!==d&&to(t(c.el,"text"))<=d){e.w=d;const t=d/2;e.position.x=a.x+t,e.position.y=a.y+t,r(),s=d}const u=l-e.w/2;o(i.target,{x:u,y:u})}),(t=>{const n=to(t,s);n!==e.w&&(e.w=n,r())}));function r(){const t=Qe(e.w,0);c.cons.right.position.x=t.r.x,c.cons.left.position.x=t.l.x,c.cons.bottom.position.y=t.b.y,c.cons.top.position.y=t.t.y,kn(c);const n=Qe(e.w,9);We(c.el,"main",n),We(c.el,"border",n),We(c.el,"outer",Qe(e.w,-24)),c.draw()}return i(c.el,"shrhomb"),96!==e.w?r():c.draw(),c.el[It].patch=t=>{const n=Ln(c,t),o=null!=t.w&&e.w!==t.w;o&&(e.w=t.w,s=e.w),o?r():n&&c.draw(),t.styles&&(Je=[...t.styles])},c.el}(n,a),2)},5:{create:t=>e(He(n,t),1)},6:{create:t=>e(Pe(n,t),0)},7:{create:t=>e(function(t,n){const e=pe(t,n,gi(n),{},null,null,null,Ee,(()=>{Mi(n.position)}));return i(e.el,"shmrk"),e.draw(),e.el[It].patch=t=>{Vn(e,t)&&e.draw()},e.el}(n,t),4)}}}(ns)},ns.ownerSVGElement.addEventListener("contextmenu",(async t=>{u(t)||t.preventDefault()})),function(t){let n,e,o;function i(t){t.isPrimary&&t.isTrusted&&(n&&Math.abs(n.x-t.clientX)<3&&Math.abs(n.y-t.clientY)<3?t.stopImmediatePropagation():(n=null,void 0===t.movementX?(t[tt]=e?t.clientX-e:0,t[nt]=o?t.clientY-o:0,e=t.clientX,o=t.clientY):(t[tt]=t.movementX,t[nt]=t.movementY)))}t.addEventListener("pointerdown",(a=>{n={x:a.clientX,y:a.clientY},e=null,o=null,t.addEventListener("pointermove",i,{capture:!0,passive:!0}),t.addEventListener("pointerup",(n=>{r(t,"pointermove",i,!0)}),{capture:!0,once:!0,passive:!0})}),{capture:!0,passive:!0})}(document),function(t){c(document,"paste",(async n=>{u(n)||Ua(t,(t=>{const n=t.getData("text/plain"),e=mo(n);return e?{data:e}:t.files?.length&&t.files.item(0).type?.startsWith("image/")?{img:t.files.item(0)}:n?{txt:n}:null})(n.clipboardData))}));const n=Z((async()=>await Va(t)),500);document.addEventListener("keydown",(async e=>{if((e.ctrlKey||e.metaKey)&&"KeyS"===e.code&&e.preventDefault(),(e.ctrlKey||e.metaKey)&&!e.repeat&&!u(e))switch(e.code){case"KeyZ":ht(),Gi(t);break;case"KeyY":ht(),qi(t);break;case"KeyS":ht(),e.shiftKey?za(t):n();break;case"KeyA":ht(),_o(t)}}))}(ns),function(t){const n=t.ownerSVGElement;let e,a,s,l,d;const u=()=>{d?.remove(),d=null};let h=!1;function p(t){if(t[Io]||!s)return void v();t[Io]=!0,h&&(u(),h=!1);const n=t.clientX-a.x,e=t.clientY-a.y;s.width.baseVal.value=Math.abs(n),s.height.baseVal.value=Math.abs(e),n<0&&(l.x=t.clientX),e<0&&(l.y=t.clientY),s.style.transform=`translate(${l.x}px, ${l.y}px)`}function m(n){if(s&&!h){n[Io]=!0;const e=n=>ja(ot(t[et].data,l.x,l.y),s.width.baseVal.value/t[et].data.scale,s.height.baseVal.value/t[et].data.scale,n.x,n.y);!function(t,n,e,o){const i=Xo(),a=t=>Go(i,t),s=t=>t.shape&&e(t.shape.shapeEl)||o(t);for(const t of n)if(t[It])e(t)&&a({shape:t});else if(t[Ut]){const n=s(t[Ut].data.s),e=s(t[Ut].data.e);n&&e?a({path:t}):n?a({pathEnd:t[Ut].data.s}):e&&a({pathEnd:t[Ut].data.e})}t[et].selectedSet(i)}(t,t.children,(t=>e(t[It].data.position)),(t=>e(t.data.position)))}v()}function v(){clearTimeout(e),e=null,s?.remove(),s=null,u(),h=!1,r(n,"pointermove",p),r(n,"wheel",v),r(n,"pointercancel",v),r(n,"pointerup",m)}c(n,"pointerdown",(r=>{if(!r.isPrimary||At(r)!==n||Oa(r))return void v();c(n,"pointermove",p),c(n,"wheel",v,!0),c(n,"pointercancel",v,!0),c(n,"pointerup",m,!0);const u=()=>{t[et].selectedSet(null),h=!0,n.setPointerCapture(r.pointerId),a={x:r.clientX,y:r.clientY},l={x:r.clientX,y:r.clientY},s=f("rect"),s.style.cssText="rx:8px; fill: rgb(108 187 247 / 51%)",o(s,l),n.append(s)};2!==r.button?e=setTimeout((t=>{u(),d=f("circle"),i(d,"ative-elem"),d.style.cssText="r:10px; fill: rgb(108 187 247 / 51%)",o(d,{x:r.clientX,y:r.clientY}),n.append(d)}),500):u()}))}(ns),function(t){const n=t.ownerSVGElement;let e,o=Xo();const i=()=>{e&&(e[wt]?.del(),e=null)};let a,s;c(n,"pointerdown",(l=>{if(i(),!l.isPrimary)return r(n,"pointermove",a),r(n,"pointerup",s),void t[et].moveCapture();s=s=>{var c;r(n,"pointermove",a),c=Oo(t,o,s),i(),e=c},c(n,"pointerup",s,!0),a=e=>{r(n,"pointerup",s),jo(t,o,e,At(l))},0===l.button&&c(n,"pointermove",a,!0)})),vo(t,(()=>Qo(o)),(()=>{e?i():si(o)&&!ii(o)&&t[et].select(null)}));const l=t=>{Wo(o),o=t??Xo(),ti(o,null)};t[et].selectedSet=l,t[et].select=t=>{i();const n=Xo();if(t?.length)for(const e of t)Go(n,ci(e));l(n)}}(ns),function(t){const n=t[et].data,e=function(t,n){let e;function o(n){e!==n&&(e=n,t.style.backgroundImage=`radial-gradient(rgb(73 80 87 / ${n}) 1px, transparent 0)`)}return o(.6),t.style.backgroundSize=`${n.cell}px ${n.cell}px`,function(){const e=n.cell*n.scale;n.scale<.5?o(0):n.scale<=.9?o(.2):o(.6),t.style.backgroundSize=`${e}px ${e}px`,t.style.backgroundPosition=`${n.position.x}px ${n.position.y}px`}}(t.ownerSVGElement,n);function o(){t.style.transform=`matrix(${n.scale}, 0, 0, ${n.scale}, ${n.position.x}, ${n.position.y})`,e()}function i(t,e){if(t<.25||t>4)return;const i=t/n.scale;n.scale=t,n.position.x=i*(n.position.x-e.x)+e.x,n.position.y=i*(n.position.y-e.y)+e.y,o()}!function(t,n,e,o){let i,a,s,l,d=!1;function u(t){s=null,l=null,i?.id===t.pointerId&&(i=null),a?.id===t.pointerId&&(a=null),i||a||(r(document,"pointermove",h),r(document,"pointercancel",u),r(document,"pointerup",u),d=!1)}function h(t){if(d){if(i&&!a||!i&&a)return n.position.x=t.clientX+(i||a).shift.x,n.position.y=t.clientY+(i||a).shift.y,void o();if(!a||!i||a?.id!==t.pointerId&&i?.id!==t.pointerId)return;const c=Math.hypot(i.pos.x-a.pos.x,i.pos.y-a.pos.y),r={x:(i.pos.x+a.pos.x)/2,y:(i.pos.y+a.pos.y)/2};s&&(n.position.x=n.position.x+r.x-l.x,n.position.y=n.position.y+r.y-l.y,e(n.scale/s*c,r)),s=c,l=r}i?.id===t.pointerId&&(i=st(t,n)),a?.id===t.pointerId&&(a=st(t,n))}c(t.ownerSVGElement,"pointerdown",(t=>{!i&&!t.isPrimary||i&&a||(i||(c(document,"pointermove",h),c(document,"pointercancel",u),c(document,"pointerup",u),i=st(t,n)),a||i?.id===t.pointerId||(a=st(t,n)))})),t[et].moveCapture=()=>{d=!0}}(t,n,i,o),t.ownerSVGElement.addEventListener("wheel",(t=>{t.preventDefault();const e=()=>{n.position.x-=t.deltaX,n.position.y-=t.deltaY,o()},a=e=>i(n.scale+e,p(t));Math.abs(t.deltaY)>50?t.ctrlKey?e():a(t.deltaY<0?.25:-.25):t.ctrlKey?a(-.01*t.deltaY):e()})),t[et].move=function(t,e,i){n.position.x=t,n.position.y=e,n.scale=i,o()},t[et].scale=i}(ns),function(t){const n=t.ownerSVGElement,e=t.ownerDocument;let o,i,a,s;function d(n){r(e,"pointermove",p),r(e,"pointerup",u),a||(a=function(t,n,e,o){const i=m(`${po?'
Paste
':""}
Select all
Add image
`),a=(t,n)=>l(i,t,(async t=>{await n(),o()}));po&&a("[p]",(async()=>Ua(e,await(async()=>{let t;try{t=await(navigator.clipboard?.read())}catch{}if(!t?.length)return null;const n=t[0],e=n.types.includes("text/plain")?await(await n.getType("text/plain")).text():null,o=mo(e);if(o)return{data:o};const i=n.types.find((t=>t.startsWith("image/")));return i?{img:await n.getType(i)}:e?{txt:e}:null})(),t,n)));a("[s]",(async()=>_o(e))),a("[i]",(async()=>async function(t,n,e){const o=await Se(Te);o&&Ae(t,o.f,n,e)}(e,t,n)));return{del:ft(i,t-10,n-10)[wt].del,el:i}}(n.clientX,n.clientY,t,u),c(e,"pointerdown",h))}function u(){clearTimeout(o),o=null,a?.del(),a=null,r(e,"pointerdown",h),r(e,"pointerup",u),r(e,"wheel",u),r(e,"keydown",u),r(e,"pointerup",v),r(e,"pointercancel",v),r(e,"pointermove",f),i=!1,s=!1}function h(t){a.el.contains(t.target)||u()}function p(){u(),i=!0}function f(){s||u(),i=!0}function v(){s=!0}c(n,"pointerdown",(async function(t){t.isPrimary&&At(t)===n?(u(),c(e,"pointermove",p,!0),c(e,"pointerup",u,!0),c(e,"wheel",u,!0),c(e,"keydown",u,!0),2!==t.button&&(o=setTimeout((n=>{d(t),c(e,"pointerup",v,!0),c(e,"pointercancel",v,!0),c(e,"pointermove",f,!0)}),500))):u()})),n.addEventListener("contextmenu",(async t=>{n===At(t)&&(t.preventDefault(),i||d(t))}))}(ns),(t=>{const n=(n,e)=>c(t,n,(t=>{t[Yi]||e(t)}));n("dgrmc",(n=>Ni(t,n.detail.newIds,n.detail.shapesToCreateData))),n("dgrmd",(n=>Oi(t,n.detail.delIds,n.detail.shapesToDelData))),n("dgrmu",(n=>ji(t,n.detail.shapesBeforeUpdData,n.detail.shapesToUpdData))),n("dgrmdc",(n=>Fi(t,n.detail.delIds,n.detail.shapesToDelData,n.detail.newIds,n.detail.shapesToCreateData)))})(ns),function(t){document.body.addEventListener("dragover",(t=>{t.preventDefault()})),document.body.addEventListener("drop",(async n=>{if(n.preventDefault(),1===n.dataTransfer?.items?.length&&"file"===n.dataTransfer.items[0].kind&&n.dataTransfer.items[0].type.startsWith("image/"))if("getAsFileSystemHandle"in n.dataTransfer.items[0]){const e=await n.dataTransfer.items[0].getAsFileSystemHandle(),o=await ba(t,await e.getFile(),n);o&&zo(t,e,o)}else{const e=n.dataTransfer.items[0].getAsFile(),o=await ba(t,e,n);o&&So(t,Y(e.name),o)}else ka()}))}(ns),(t=>{t[Aa]={c:new Set,u:new Set,d:new Set};const n=n=>{t[Aa].c.add(n),t[Aa].u.delete(n),t[Aa].d.delete(n)},e=n=>{t[Aa].c.has(n)||t[Aa].u.add(n),t[Aa].d.delete(n)},o=n=>n?.forEach((n=>{t[Aa].d.add(n),t[Aa].c.delete(n),t[Aa].u.delete(n)})),i=t=>Object.keys(t.s).forEach(e);c(t,"dgrmc",(t=>{t.detail.newIds?.forEach(n)})),c(t,"dgrmu",(t=>i(t.detail.shapesToUpdData))),c(t,"dgrmd",(t=>o(t.detail.delIds))),c(t,"dgrmdc",(t=>{o(t.detail.delIds),t.detail.newIds?.forEach(n)})),c(t,Bi,(t=>i(t.detail))),c(t,Ti,(t=>o(t.detail))),t.addEventListener("dgrmn",(n=>{!Ta(t)||window.confirm("Changes you made may not be saved. Continue?")?Ea(t):n.preventDefault()})),window.addEventListener("beforeunload",(n=>{Ta(t)&&n.preventDefault()}))})(ns);{const t=new URL(window.location.href),n=n=>t.searchParams.get(n);n("usr")&&(es=n("usr"),os=n("usrn"),is=parseInt(n("expr")),localStorage.setItem("dgrm",X({l:es,n:os,e:is})),M("usr","usrn","expr"))}(t=>{const n=new Wa(t);n.id="menu",v(n)})(ns),v(new Ia(ns)),v(new Qa(ns));{const t=new URL(window.location.href),e=n=>t.searchParams.get(n);if(e("k")){rt(!0);const t=e("k");try{const n=await zt(t);Ai(ns,n.d),Vo(ns,t,n.n,n.e,n.m,n.l)}catch{alert("The link is broken or you do not have permission. Try to relogin."),await(ss=t,new Promise(((t,n)=>Ho(xo(),ss,(()=>t())))))}M("k"),rt(!1)}else if(e("l")){try{const t=e("l"),n=await(as=t,new Promise(((t,n)=>Co(xo(),as,t))));n&&(Ai(ns,n.s),So(ns,n.n,n.s))}catch{alert("The link is broken.")}M("l")}else if(e("m")){const t=e("m");M("m"),await async function(t,n){const e=()=>qa(t);try{const o=await Ya(t,n,(()=>Ga(t)),e);if(!o)return;c(t,"dgrmn",e,!0),t[Ja]={clientType:2,id:n,dispose:()=>{r(t,"dgrmn",e),o()}},Hi(!0)}catch{e()}}(ns,t)}else wo()||function(){const t=m('');function e(){t.remove(),r(document,"pointerdown",o),r(document,"wheel",e),r(document,"keydown",e),r(document,"dragover",e)}function o(n){t.contains(n.target)||e()}t.style.display="unset",c(document,"pointerdown",o),c(document,"wheel",e,!0),c(document,"keydown",e,!0),c(document,"dragover",e,!0),c(n(t,"cl"),"click",(t=>e()),!0),v(t)}()} +const t=(t,n)=>t.querySelector(`[data-key="${n}"]`),n=(t,n)=>t.querySelector(`[${n}]`),e=t=>document.getElementById(t);function o(t,n){t.style.transform=`translate(${n.x}px, ${n.y}px)`}const i=(t,...n)=>t?.classList.add(...n),a=(t,...n)=>t?.classList.remove(...n),s=(t,n)=>t?.classList.contains(n),c=(t,n,e,o)=>(t.addEventListener(n,e,{passive:!0,once:o}),e),r=(t,n,e,o)=>t?.removeEventListener(n,e,{capture:o}),l=(t,n,e)=>t.querySelectorAll(n).forEach((t=>c(t,"click",e))),d=(t,n)=>t.currentTarget.getAttribute(n),u=t=>"TEXTAREA"===t.target.tagName.toUpperCase()||"INPUT"===t.target.tagName.toUpperCase(),h=t=>"mouse"===t.pointerType,p=t=>({x:t.clientX,y:t.clientY});function f(t,n){const e=document.createElementNS("http://www.w3.org/2000/svg",t);return n&&(e.innerHTML=n),e}const m=(t,n)=>{const e=document.createElement("div");return t&&(e.innerHTML=t),e.style.cssText=n,e},v=(...t)=>document.body.append(...t);function g(t){let n,e=0;for(const o of t.getElementsByTagName("tspan"))for(const t of w(o.getBBox())){const o=Math.abs(t.x)+Math.abs(t.y);e[{x:t.x,y:t.y},{x:t.right,y:t.y},{x:t.x,y:t.bottom},{x:t.right,y:t.bottom}];function y(t){const n={x:1/0,y:1/0},e={x:-1/0,y:-1/0};for(const o of t){const t=o.getBoundingClientRect();n.x>t.x&&(n.x=t.x),n.y>t.y&&(n.y=t.y),e.x{let e;(n=n||{}).credentials="include";try{e=await fetch(t,n)}catch(t){throw console.log(t),t}if(!e.ok)throw 401===e.status&&alert("You have to relogin."),new Error;return e},b=(t,n)=>x(t,{method:"POST",body:n}),$=(t,n)=>x(t,{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:n?X(n):null}),k=(t,n)=>{const e=new URL(window.location.href);return e.searchParams.set(t,n),e.toString()},M=(...t)=>{const n=new URL(window.location.href);t?.forEach((t=>n.searchParams.delete(t))),history.replaceState(null,null,n.toString())};function C(t,n,e,o){function i(n){r(t,"pointercancel",i),r(t,"pointerup",i),r(t,"wheel",i),r(document,"pointerdown",i),r(t,"pointermove",e),o(n)}c(t,"pointercancel",i,!0),c(t,"pointerup",i,!0),c(t,"wheel",i,!0),c(document,"pointerdown",i,!0),c(t,"pointermove",e),t.setPointerCapture(n.pointerId)}const H=(t,n)=>L(t.ownerSVGElement,t,n);function L(t,n,e,o){const i=()=>{r(t,"pointercancel",a),r(t,"wheel",a),r(t,"pointerdown",a)},a=t=>{o&&o(t),n.contains(t.target)||(i(),e(t))};return c(t,"pointercancel",a),c(t,"wheel",a),c(t,"pointerdown",a),i}const V=t=>{const n=n=>{"Escape"===n.key&&t()};return c(document,"keydown",n),()=>r(document,"keydown",n)},z=(t,n,e)=>new CustomEvent(t,{detail:n,cancelable:e}),S=(t,n)=>t.dispatchEvent(n),Z=(t,n)=>{let e,o,i=!1;return function a(){if(i)return e=arguments,void(o=this);t.apply(this,arguments),i=!0,setTimeout((function(){i=!1,e&&(a.apply(o,e),e=o=null)}),n)}};function D(t,n,e){return t??=0,e<=t?t:t+Math.ceil((e-t)/n)*n}const B=t=>Math.round(100*(t+Number.EPSILON))/100,T=(t,n,e)=>{let o=!1;return n>e?n>t&&(o=!0,e*=t/n,n=t):e>t&&(o=!0,n*=t/e,e=t),{w:n,h:e,c:o}};function E(t,n){const e=t.indexOf(n);e>-1&&t.splice(e,1)}function A(t,n){for(let e=t.length-1;e>=0;--e)n(t[e])}const R=t=>t?[...t]:t,P=t=>t.values().next().value;function U(t,n,e){const o=e??1;return t.x+=o*n.x,t.y+=o*n.y,t}const I=(t,n)=>({x:t.x+n,y:t.y+n}),N=(t,n)=>O(t,n.x,n.y),O=(t,n,e)=>(t.x=n,t.y=e,t),j=t=>({x:t.x,y:t.y}),F=(t,n)=>t?.x===n?.x&&t?.y===n?.y;function K(){const t=new Uint8Array(4);return window.crypto.getRandomValues(t),Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("")}const Y=t=>t?.substring(0,t.lastIndexOf("."))||t,_=t=>G(X(t)),X=t=>JSON.stringify(t),G=t=>JSON.parse(t),q=(t,n,e,o)=>{let i,a;const s=()=>{a=setTimeout((async t=>{await e(),i||s()}),t)};s();const c=setTimeout((t=>{r(),o&&o()}),n),r=()=>{i=!0,clearTimeout(a),clearTimeout(c)};return r},J=(t,n)=>t?n:"",W=t=>J(t,"disabled");function Q(t,n,e){t.x+=e[tt]/n,t.y+=e[nt]/n}const tt=Symbol("movementX"),nt=Symbol("movementY"),et=Symbol("Canvas"),ot=(t,n,e)=>({x:(n-t.position.x)/t.scale,y:(e-t.position.y)/t.scale}),it=(t,n)=>ot(t,n.clientX,n.clientY);function at(t,n){const e=n/2;function o(t){const o=Math.round(t/n)*n;return t-o>=0?o+e:o-e}return t.x=o(t.x),t.y=o(t.y),t}function st(t,n){return{id:t.pointerId,pos:p(t),shift:{x:n.position.x-t.clientX,y:n.position.y-t.clientY}}}let ct;function rt(t){t&&!ct?(ct=m("","z-index: 2; position: fixed; left: 0; top: 0; width:100%; height:100%; background: #fff; opacity: 0"),ct.classList.add("blnk"),v(ct)):t||(ct?.remove(),ct=null)}const lt=async t=>{try{return rt(!0),await t()}catch(t){console.log(t),alert("Error")}finally{rt(!1)}};function dt(t,n,e,o,i){const a=m(null,"position: fixed; left: 50%; top: 30%; box-shadow: 0 4px 24px rgba(0,0,0,.12); border-radius: 8px; background-color: rgb(255,255,255);");function s(t,n){a&&(o?(a.style.right="0",a.style.left="unset",a.style.marginRight=`${t}px`):a.style.left=`${t}px`,a.style.top=i?`${window.scrollY+n}px`:window.scrollY+n-a.getBoundingClientRect().height+"px")}return a.setAttribute("ap-modal",""),a.append(t),v(a),null!=n?s(n,e):a.style.transform="translate(-50%, -30%)",a[wt]={position:s,del:()=>{a?.remove()}},a}const ut=t=>((t,n)=>{const e=t=>t&&t!==document&&t!==window?t.closest(n)||e(t.getRootNode().host):null;return e(t)})(t,"[ap-modal]"),ht=()=>{for(;;){const t=document.querySelector("[ap-modal]");if(!t)return;t[wt]?.del()}};function pt(t,n,e,o,i,a){const s=m(null,"z-index: 2; position: fixed; left: 0; top: 0; width:100%; height:100%; "+(o?"background-color: rgba(52,71,103,.05);":""));v(s);const r=dt(t,n,e,i,a);s.append(r);const l=mt(s,r,(t=>{"pointerdown"===t?.type?c(s,"click",(t=>{t.stopImmediatePropagation(),u()}),!0):u()}),(t=>t.stopImmediatePropagation())),d=r[wt].del,u=()=>{d(),l(),s.remove()};return r[wt].del=u,r}function ft(t,n,e){const o=dt(t,n,e),i=o[wt].del,a=mt(document,o,(t=>s())),s=()=>{i(),a()};return o[wt].del=s,o}function mt(t,n,e,o){const i=((t,n,e,o)=>L(t,n,e,o))(t,n,e,o),a=V((()=>{((t,n)=>{const e=t.querySelectorAll(n);return e?.length?e[e?.length-1]:null})(document,"[ap-modal]")===n&&(e(),s())})),s=()=>{i(),a()};return s}function vt(t,n,e,o){const i=m(""+(o?"":''),"display: flex; flex-flow: column; padding: 15px;");i.className=n??"mds",o?i.append(o):l(i,"[ap-close]",(t=>a[wt].del())),i.append(t);const a=e?pt(i,null,null,!0):ft(i);return a}function gt(t,n,e){const o=vt(m(`${t}`,"display: flex; flex-flow: column; height: 100%; overflow-y: overlay;"),"mdh",e,n);return i(ut(o),"mdhc"),o}const wt=Symbol(0);function yt(t,n){const e=t.getBoundingClientRect(),o=window.innerHeight-e.bottom<40*n.length;!function(t,n,e,o){const i=pt(m(`
${t.map((t=>t[0])).join(" ")}
`),n,e,!1,!0,!o);l(i,"a",(n=>{i[wt].del(),t[a(n.currentTarget)][1]()}));const a=t=>Array.prototype.indexOf.call(t.parentNode.children,t)}(n,window.innerWidth-e.right-5,o?e.top:e.bottom,o)}const xt=(t,n)=>[`${t}`,n],bt=(t,n)=>[`${t}`,()=>{confirm("Delete?")&&n()}],$t=t=>bt("Delete",t);function kt(t){const n=m(`${t}`,"min-width: 150px;\n\t\tbackground-color: rgb(52,71,103);\n\t\tcolor: #fff;\n\t\ttext-align: center;\n\t\tborder-radius: 8px;\n\t\tpadding: 10px;\n\t\tposition: fixed;\n\t\tz-index: 1;\n\t\tleft: 50%;\n\t\ttop: 30px;\n\t\ttransform: translate(-50%, -30%)");n.className="toast",v(n),setTimeout((t=>n.remove()),2800)}const Mt=()=>kt("Link copied to clipboard"),Ct="https://api.dgrm.net/api/",Ht=`${Ct}s/`,Lt=`${Ct}r/d/`,Vt=`${Ct}r/f/`,zt=async t=>{const n=await x(`${Ht}${t}`),e=n.headers.get("X-Dgrm-loc");return{e:n.headers.has("X-Dgrm-edit"),m:n.headers.has("X-Dgrm-manage"),n:decodeURIComponent(n.headers.get("X-Dgrm-name")),l:e?decodeURIComponent(e):null,d:await n.json()}},St=async t=>{const n=await x(`${Ht}a/l/${t??""}`);let e;try{const t=await n.json();e={f:new Map(t.f.map((t=>[t.i,t]))),d:new Map(t.d.map((t=>[t.i,t])))}}catch{}return e};async function Zt(t,n,e,o){const i=new URL(`${Ht}a/c`);return Bt(i,"k",t),n&&Bt(i,"f",n.toString()),Bt(i,"n",e),(await $(i.toString(),o)).text()}function Dt(){const t=new Date;return`${t.getUTCFullYear()}${(t.getUTCMonth()+1).toString().padStart(2,"0")}${K()}`}const Bt=(t,n,e)=>t.searchParams.set(n,e),Tt=new Map,Et=(t,n)=>Tt.set(t,n);function At(t){return Pt(t).find((t=>!t.hasAttribute("data-evt-no")))}function Rt(t){return Pt(t)[0]}function Pt(t){return document.elementsFromPoint(t.clientX,t.clientY).sort(((t,n)=>{const e=t.getAttribute("data-evt-index"),o=n.getAttribute("data-evt-index");return e===o?0:e>o?-1:1}))}const Ut=Symbol("path"),It=Symbol("shape"),Nt="1.2",Ot=()=>({v:Nt,s:{}}),jt=t=>{return!((n=t.s)&&Object.keys(n).length);var n},Ft=t=>Kt([...t.children],!1);function Kt(t,n,e){const o=Ot();if(!t?.length)return o;const i=new Map,a=t=>{let e=i.get(t);if(!e){const a=_(t[It].data);n&&(a.id=K(),e=a.id),i.set(t,e),o.s[a.id]=a}return e},s=i=>{if(o.s[i[Ut].data.id])return;const s=o=>{return n?(i=o.shape?.shapeEl,-1!==t.indexOf(i)?{s:a(o.shape.shapeEl),k:o.shape.connectorKey}:{p:_(o.data)}):o.shape?(e&&a(o.shape.shapeEl),{s:o.shape.shapeEl[It].data.id,k:o.shape.connectorKey}):{p:_(o.data)};var i},c=i[Ut].data,r={id:n?K():c.id,type:0,s:s(c.s),e:s(c.e)};c.styles&&(r.c=_(c.styles)),o.s[r.id]=r};for(const n of t)n[It]?(a(n),e&&n[It].paths?.forEach(s)):s(n);return o}function Yt(t){return{v:Nt,s:{[t.id]:0!==t.type?t:(n=t,{id:n.id,type:0,s:{p:n.s.data},e:{p:n.e.data},c:n.styles})}};var n}const _t=(t,n)=>Xt(t,"1.1"===n.v?function(t){const n={v:Nt,s:{}};return t.s.forEach(((t,e)=>{switch(t.type){case 0:{const o=t,i={id:e.toString(),type:0,c:o.c?.map((t=>"d-"+t)),s:{s:o.s.s?.toString(),k:o.s.k,p:o.s.p},e:{s:o.e.s?.toString(),k:o.e.k,p:o.e.p}};n.s[i.id]=i;break}default:{const o=t;o.id=e.toString(),o.styles=o.styles?.map((t=>"d-"+t)),n.s[o.id]=o;break}}})),n}(n):n);function Xt(t,n){if(n.v!==Nt)return alert("Wrong format"),null;const o=new Map;function i(n){let e=o.get(n);return e||(e=qt(t,n),o.set(n,e)),e}const a=t=>n.s[t]?i(n.s[t]):e(t),s=[];for(const e in n.s)switch(n.s[e].type){case 0:{const o=Jt(t,n.s[e],a);o&&s.push(o);break}default:i(n.s[e])}return[...o.values(),...s]}function Gt(t,n){const o=e(n.id);return o?((o[It]||o[Ut]).patch(n),o):t[et].shapeMap[n.type].create(n)}const qt=(t,n)=>Gt(t,_(n)),Jt=(t,n,e)=>{const o=function(t,n){const e=t=>{const e=n(t.s);return e?{shape:{shapeEl:e,connectorKey:t.k}}:null},o=t=>t.p?{data:{dir:t.p.dir,position:j(t.p.position)}}:e(t),i={type:0,id:t.id,styles:t.c,s:o(t.s),e:o(t.e)};return i.e&&i.s?i:null}(n,e);return o?Gt(t,o):null};function Wt(t){for(const n in t.s)Qt(t.s[n]);return t}function Qt(t){switch(t.type){case 6:delete t.d,delete t.r;break;case 7:delete t.d}}const tn=(t,n,e)=>S(t,nn(n,e)),nn=(t,n)=>z("dgrmc",{newIds:t,shapesToCreateData:n}),en=(t,n)=>z("dgrmd",{delIds:t,shapesToDelData:n}),on=(t,n,e)=>S(t,an(Wt(n),Wt(e))),an=(t,n)=>z("dgrmu",{shapesBeforeUpdData:t,shapesToUpdData:n}),sn=(t,n,e,o)=>z("dgrmdc",{delIds:t,shapesToDelData:n,newIds:e,shapesToCreateData:o});function cn(t,n,e,o){const i=U(((t,n,e)=>{const o=ot(t,n,e);return at(o,t.cell),o})(t[et].data,e,o),function(t){const n=function(t){const n={x:1/0,y:1/0},e={x:-1/0,y:-1/0};return rn(t,(t=>{t&&(n.x>t.x&&(n.x=t.x),n.y>t.y&&(n.y=t.y),e.x{n&&at(U(n,i),t[et].data.cell)}))}function rn(t,n){for(const e in t.s)0===t.s[e].type?(n(t.s[e].s.p?.position),n(t.s[e].e.p?.position)):n(t.s[e].position)}const ln=(t,n)=>t[et].select(dn(t,Kt(n,!0),!0));function dn(t,n,e,o,i){return cn(t,n,null==o?window.innerWidth/2:o,null==i?window.innerHeight/2:i),un(t,n,e)}function un(t,n,e){return e&&tn(t,vn(n),_(n)),hn(t,n)}function hn(t,n){return t[et].select(null),Xt(t,n)}function pn(t,n){((t,n,e)=>{S(t,en(n,e))})(t,mn(n),Kt(n,!1,!0)),gn(n)}function fn(t,n,e){((t,n,e,o,i)=>{S(t,sn(n,e,o,i))})(t,mn(n),Kt(n,!1,!0),vn(e),_(e)),gn(n),hn(t,e)}const mn=t=>t.map((t=>(t[It]||t[Ut]).data.id)),vn=t=>Object.keys(t.s),gn=t=>t.forEach((t=>(t[It]||t[Ut]).del())),wn='',yn='',xn='',bn='',$n=(t,n)=>({id:K(),type:t,position:{x:0,y:0},title:"Title",styles:n});function kn(n){for(const e in n.cons)o(t(n.el,e),n.cons[e].position)}function Mn(t,n){const e=t.getBoundingClientRect(),o=dt(n,e.left+10,e.top+10);return{del:o[wt].del,updPos:()=>{const n=t.getBoundingClientRect();o[wt].position(n.left+10,n.top+10)}}}const Cn=(t,n)=>({del:dt(t,n.clientX-66,n.clientY-10)[wt].del}),Hn=(t,n,e)=>{const o=Kt([n],!1,!1);(n[It]??n[Ut]).patch(e),on(t,o,Kt([n],!1,!1))};function Ln(t,n){return function(t,n){const e=t.el[It].data;null!=n.title&&e.title!==n.title&&(e.title=n.title,t.drawTxt());n.styles&&(e.styles=n.styles,Sn(t.el))}(t,n),Vn(t,n)}function Vn(t,n){const e=n.position&&!F(t.el[It].data.position,n.position);return e&&N(t.el[It].data.position,n.position),e}const zn=t=>t.forEach((t=>{const n=e(t);n&&(n[It]||n[Ut]).del()}));function Sn(t){const n=(t[It]??t[Ut]).data;n.styles||(n.styles=[]),A(t.classList,(n=>{n?.startsWith("d-")&&t.classList.remove(n)})),i(t,...n.styles)}const Zn=(t,n,e)=>{const o=(n[It]??n[Ut]).data;o.styles||(o.styles=[]);const i={styles:_(o.styles)};Hn(t,n,function(t,n){const e=t.styles.findIndex((t=>t.startsWith("d-cl-")));e>-1&&t.styles.splice(e,1);n&&t.styles.push(n);return t}(i,e))};function Dn(t,n,e){return n.setAttribute("bg",e.toString()),Bn(t,n),n}function Bn(t,n){const e=Number(n.getAttribute("bg"));if(4===e)return void t.append(n);const o=t.querySelector(Tn(e+1,4).map((t=>`[bg="${t}"]`)).join());o?o.before(n):t.append(n)}const Tn=(t,n)=>[...Array(n-t+1).keys()].map((n=>n+t));class En extends HTMLElement{constructor(t,n){super(),this.o=n,this.g=t}connectedCallback(){const t=t=>this.o[Ut].data.styles?.includes(t)?'class="actv"':"",n=this.attachShadow({mode:"closed"});n.innerHTML=`
`,c(n.getElementById("edit"),"cmd",(t=>{switch(t.detail.cmd){case"style":Zn(this.g,this.o,t.detail.arg);break;case"del":pn(this.g,[this.o]);break;case"copy":ln(this.g,[this.o])}})),l(n,"[data-cmd]",(t=>{const n=d(t,"data-cmd-arg"),e={styles:this.o[Ut].data.styles?_(this.o[Ut].data.styles):[]},o=e.styles.indexOf(n);o>-1?(e.styles.splice(o,1),a(t.currentTarget,"actv")):(e.styles.push(n),i(t.currentTarget,"actv")),Hn(this.g,this.o,e)}))}}function An(t,n,e,o){const i=On(t,n);i.shape={shapeEl:e,connectorKey:o},Un(t,i)}function Rn(t,n,e){const o=On(t,n);o.shape.shapeEl!==jn(t,o)&&In(t,o),o.shape=null,o.data={dir:o.data.dir,position:e}}function Pn(t,n){const e=t[Ut].data,o=o=>{const i=e[o],a=n[o];i.shape?null==a.shape||i.shape.shapeEl===a.shape.shapeEl&&i.shape.connectorKey===a.shape.connectorKey?a.data&&Rn(t,o,a.data.position):function(t,n,e,o){const i=On(t,n);if(i.shape.shapeEl===e&&i.shape.connectorKey===o)return;i.shape.shapeEl!==e&&i.shape.shapeEl!==jn(t,i)&&In(t,i);i.shape={shapeEl:e,connectorKey:o},Un(t,i)}(t,o,a.shape.shapeEl,a.shape.connectorKey):null!=a.shape?An(t,o,a.shape.shapeEl,a.shape.connectorKey):N(i.data.position,a.data.position)};o("s"),o("e")}function Un(t,n){n.data=Nn(n.shape).pathAdd(n.shape.connectorKey,t)}customElements.define("ap-path-settings",En);const In=(t,n)=>Nn(n.shape)?.pathDel(t),Nn=t=>t?.shapeEl[It],On=(t,n)=>t[Ut].data[n],jn=(t,n)=>(t[Ut].data.e===n?t[Ut].data.s:t[Ut].data.e).shape?.shapeEl;let Fn;const Kn=(t,n)=>({id:K(),type:0,s:t,e:n,styles:R(Fn)});Et(0,(()=>Kn({data:{dir:"right",position:{x:-24,y:0}}},{data:{dir:"right",position:{x:24,y:0}}})));function Yn(n,e){const o=f("g",'');o.id=e.id,i(o,"shpath"),e.s.el=t(o,"start"),e.e.el=t(o,"end"),e.styles=e.styles??["d-arw-e"];const s=Qn(o,"path","outer","selected");function c(){if(!e.s.shape||!e.e.shape){const t=function(t,n){const e=Math.atan2(n.y-t.y,n.x-t.x);return te(e,-.8,.8)?"left":te(e,.8,2.4)?"top":te(e,2.4,3.2)||te(e,-3.2,-2.4)?"right":"bottom"}(e.s.data.position,e.e.data.position);e.e.shape||(e.e.data.dir=t),e.s.shape||(e.s.data.dir=Wn(t))}const t=function(t){let n=.5*Math.hypot(t.s.data.position.x-t.e.data.position.x,t.s.data.position.y-t.e.data.position.y);function e(t){return"right"===t.dir||"left"===t.dir?"right"===t.dir?t.position.x+n:t.position.x-n:t.position.x}function o(t){return"right"===t.dir||"left"===t.dir?t.position.y:"bottom"===t.dir?t.position.y+n:t.position.y-n}n=n>70?70:n<15?15:n;const i=(n,e,o,i)=>t.styles.includes(o)?n.position[e]+(i[n.dir]??0):n.position[e],a=(t,n)=>i(t,"x",n,{left:-6,right:6}),s=(t,n)=>i(t,"y",n,{top:-6,bottom:6});return`M ${a(t.s.data,"d-arw-s")} ${s(t.s.data,"d-arw-s")} C ${e(t.s.data)} ${o(t.s.data)}, ${e(t.e.data)} ${o(t.e.data)}, ${a(t.e.data,"d-arw-e")} ${s(t.e.data,"d-arw-e")}`}(e);s.forEach((n=>n.setAttribute("d",t))),Gn(e.s),Gn(e.e)}let r,l;let d,u,p=0;const m=()=>{u&&(u(),u=null)},v=t=>{m(),u=V(t)};function g(t){switch(p){case 0:y();break;case 1:p=2,d=H(o,(t=>w(!0))),v((()=>{w(!0),y()})),function(t){r||(r=Cn(new En(n,o),t))}(t)}}function w(t){t||(l=null),p=0,a(o,"select","highlight-s","highlight-e"),qn(e.s,1),qn(e.e,1),r?.del(),r=null,d&&(d(),d=null),m()}function y(){p=1,i(o,"s"===l?"highlight-s":"e"===l?"highlight-e":"select"),qn(e.s,2),qn(e.e,2),Bn(n,o),v((()=>{w(!0)}))}return o[Ut]={data:e,drawPosition:c,click:(t,n)=>{if(0===p||l){const o=n||t?ne(e,n??At(t)):null;ee(l,o)||w(),l=o}g(t)},patch:t=>{var n,i,a;e.styles&&(e.styles=t.styles,Sn(o),n=[...t.styles],Fn=n,E(Fn,"d-arw-s"),a="d-arw-e",-1===(i=Fn).indexOf(a)&&i.push(a)),t.s&&Pn(o,t),c()},moveCapture:(t,i,a)=>{w(!0);const s=a?null:Kt([o],!1,!0),r=t=>{w(!0),s?on(n,s,Kt([o],!1,!0)):tn(n,[e.id],Kt([o],!1,!0)),h(t)||g()},l=ne(e,i);l?Xn(n,o,c,t,l,r):function(t,n,e,o,i){C(n,o,(o=>{!function(t,n,e,o){const i=n=>Q(n,t.scale,o);_n(n.s,i),n.s.shape?.shapeEl&&n.s.shape?.shapeEl===n.e.shape?.shapeEl||_n(n.e,i);n.s.shape||n.e.shape||e()}(t[et].data,n[Ut].data,e,o)}),(o=>{!function(t,n,e){const o=n=>at(n,t.cell);_n(n.s,o),_n(n.e,o),n.s.shape&&n.e.shape||e()}(t[et].data,n[Ut].data,e),i(o)}))}(n,o,c,t,r)},unselect:w,del:function(){w(),In(o,e.s),In(o,e.e),o.remove()}},e.styles&&i(o,...e.styles),e.s.shape&&Un(o,e.s),e.e.shape&&Un(o,e.e),c(),o}function _n(t,n){t.shape?(n(Nn(t.shape).data.position),Nn(t.shape).drawPosition()):n(t.data.position)}const Xn=(t,n,e,o,l,d)=>{n[Ut].data[l].shape&&Rn(n,l,it(t[et].data,o)),n.style.pointerEvents="none";const u=function(t){let n=null;function e(t){const e=Rt(t);if(n!==e){s(e,"hovertrack")&&i(e,"hover");let t=!1;s(e?.parentElement,"hovertrack")&&(i(e.parentElement,"hover"),t=!0),a(n,"hover"),n?.parentElement===e?.parentElement&&t||a(n?.parentElement,"hover"),n=e}}return c(t,"pointermove",e),function(){r(t,"pointermove",e),a(n,"hover"),a(n?.parentElement,"hover"),n=null}}(n.parentElement);C(n[Ut].data[l].el,o,(o=>{Q(n[Ut].data[l].data.position,t[et].data.scale,o),e()}),(o=>{const i=Rt(o),a=i?.getAttribute("data-connect");a?An(n,l,i.parentElement,a):at(n[Ut].data[l].data.position,t[et].data.cell),e(),u(),n.style.pointerEvents="unset",d(o)}))};function Gn(t){t.el.style.transform=`translate(${t.data.position.x}px, ${t.data.position.y}px) rotate(${Jn(t.data.dir)}deg)`}function qn(t,n){t.el.firstElementChild.setAttribute("data-evt-index",n.toString())}const Jn=t=>"right"===t?180:"left"===t?0:"bottom"===t?270:90,Wn=t=>"left"===t?"right":"right"===t?"left":"top"===t?"bottom":"top";const Qn=(n,...e)=>e.map((e=>t(n,e))),te=(t,n,e)=>n<=t&&t<=e,ne=(t,n)=>t.e.el.contains(n)?"e":t.s.el.contains(n)?"s":null,ee=(t,n)=>!t||t===n,oe=(t,n,e)=>ae(t,n,e,(t=>function(t){return t.split(" ")?.forEach((n=>{(n.startsWith("http://")||n.startsWith("https://"))&&(t=t.replace(n,`${new URL(n).hostname}`))})),t}(se(t)))),ie=(t,n,e)=>ae(t,n,e,se);function ae(t,n,e,o){const i=function(t,n,e){let o=0;return{s:t.split("\n").map(((t,i)=>(o=i,`${0===t.length?".":e(t)}`))).join(""),c:o}}(e||"",t.x?.baseVal[0]?.value??0,o);t.innerHTML=i.s,null!=n&&t.y.baseVal[0].newValueSpecifiedUnits(t.y.baseVal[0].SVG_LENGTHTYPE_EMS,i.c>0?n-i.c/2:n)}function se(t){return t.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'").replaceAll(" "," ")}const ce=(t,n)=>Mn(n,le(t,n)),re=(t,n,e)=>Cn(le(t,n),e);function le(t,n){const e=new de;return c(e,"cmd",(e=>{switch(e.detail.cmd){case"style":Zn(t,n,e.detail.arg);break;case"del":pn(t,[n]);break;case"copy":ln(t,[n])}})),e}class de extends HTMLElement{connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML=`
${yn} ${wn}
`;{const n=t.getElementById("pnl");let e;l(t,"[data-toggle]",(o=>{const i=t=>{const e=ut(this);e.style.top=`${e.getBoundingClientRect().top+window.scrollY+t*n.getBoundingClientRect().height}px`};e&&(i(1),ue(e,!1));const a=t.getElementById(d(o,"data-toggle"));e!==a?(ue(a,!0),i(-1),e=a):e=null}))}l(t,"[data-cmd]",(t=>{this.dispatchEvent(new CustomEvent("cmd",{detail:{cmd:d(t,"data-cmd"),arg:d(t,"data-cmd-arg")}}))}))}}function ue(t,n){t.style.display=n?"unset":"none"}function he(n,e,o,i,a,s,c,r,l=0,d){const u=fe(e.id,o,i),h={el:t(u,"text"),vMid:l};d??=oe;const p=()=>d(h.el,h.vMid,e.title);p();return{el:u,cons:i,draw:me(n,u,e,i,h,r??ce,(t=>c(h.el,t)),a,s,null).draw,drawTxt:p}}function pe(t,n,e,o,i,a,s,c,r){const l=fe(n.id,e,o);return{el:l,cons:o,draw:me(t,l,n,o,null,c??re,null,i,a,s,r).draw}}customElements.define("ap-shape-edit",de);const fe=(t,n,e)=>{const o=f("g",`${n}\n\t${Object.entries(e).map((t=>``)).join()}`);return o.id=t,o};function me(t,n,e,s,c,r,l,d,u,p,m){let v,g,w,y;e.styles??=[];const x=()=>Kt([n],!1,!1);function b(t){e.title=t,l()}const $=function(t,n,e,s,c,r,l,d,u,p){i(n,"hovertrack");const m=_(s),v=new Set;let g,w,y,x=0;function b(){g?.remove(),g=null}const $=()=>{y&&(y(),y=null)},k=t=>{$(),y=V(t)};function M(){n.style.transform=`translate(${e.position.x}px, ${e.position.y}px)`;for(const t in s)m[t].position={x:s[t].position.x+e.position.x,y:s[t].position.y+e.position.y};for(const t of v)t[Ut].drawPosition()}function L(){x=1,i(n,"select"),l&&(g=function(t,n){const e=f("circle");return e.setAttribute("data-evt-index","2"),i(e,"resizer"),o(e,n),t.append(e),e}(n,l())),k((()=>z()))}function z(t){r(),x=0,a(n,"select","highlight"),t||b(),w&&(w(),w=null),$()}const S=t=>{switch(x){case 0:L();break;case 1:x=2,a(n,"select"),i(n,"highlight"),b(),w=H(n,(t=>z())),k((()=>{z(),L()}))}c(t,x)},Z=(e,o,i)=>{if(o===g){z(!0);const o=Kt([n],!1,!1);return void C(g,e,d,(e=>{u&&u(),b(),L(),on(t,o,Kt([n],!1,!1))}))}z();const a=o.getAttribute("data-connect");if(a){const o=((t,n,e)=>Dn(t,Yn(t,Kn(n,e)),3))(t,{shape:{shapeEl:n,connectorKey:a}},{data:{dir:Wn(m[a].dir),position:it(t[et].data,e)}});return t[et].select(h(e)?null:[o]),o[Ut].moveCapture(e,o[Ut].data.e.el,!0),void v.add(o)}D(e,i)};p??=()=>at(e.position,t[et].data.cell);const D=(o,i)=>{const a=i?null:Kt([n],!1,!1);C(n,o,(n=>{Q(e.position,t[et].data.scale,n),M()}),(o=>{p(),M(),a?on(t,a,Kt([n],!1,!1)):tn(t,[e.id],Kt([n],!1)),h(o)||L()}))};return n[It]={data:e,drawPosition:M,click:S,moveCapture:Z,unselect:z,del:function(){z();for(const t of v)t[Ut].del();n.remove()},paths:v,pathAdd:function(t,n){return v.add(n),m[t]},pathDel:function(t){v.delete(t)}},M}(t,n,e,s,((o,i)=>{1===i&&Bn(t,n),2===i&&(c&&!v&&(w=e.title,g=x(),ie(c.el,c.vMid,e.title),l(),v=function(t,n,e,o,i){let a=f("foreignObject");const s=document.createElement("textarea"),c=()=>function(t,n,e,o,i){const a=t.getBBox(),s=a.width+20;n.width.baseVal.value=s+2*o+2,n.x.baseVal.value=a.x-o-("center"===i?10:"right"===i?20:0),n.height.baseVal.value=a.height+2*o+3,n.y.baseVal.value=a.y-o,e.style.width=`${s}px`,e.style.height=`${a.height}px`}(t,a,s,l,r.textAlign);s.value=e||"",s.oninput=function(){ie(t,n,s.value),o(s.value),c()},i&&(s.onblur=function(){i(s.value)}),s.onpointerdown=function(t){t.stopImmediatePropagation()},a.appendChild(s),t.parentElement.appendChild(a);const r=getComputedStyle(s),l=parseInt(r.paddingLeft)+parseInt(r.borderWidth);return c(),s.focus(),{dispose:()=>{a.remove(),a=null},draw:c}}(c.el,c.vMid,e.title,b)),y||(y=r(t,n,o)))}),(function(){v&&(oe(c.el,c.vMid,e.title),l(!0),v?.dispose(),v=null),y?.del(),y=null,g&&w!==e.title&&on(t,g,x()),g=null,w=null}),d,u,p,m);return e.styles&&i(n,...e.styles),{draw:()=>{$(),y?.updPos&&y?.updPos(),v?.draw()}}}let ve;function ge(n,e,o){t(n,e).r.baseVal.value=o}Et(1,(()=>$n(1,R(ve))));const we=(t,n)=>function(t,n,e){const o=g(t);return D(n,e,Math.sqrt(o.x**2+o.y**2))}(t,n,24);let ye;function xe(n,e){e.w??=96,e.h??=48;const a={w:e.w,h:e.h};let s;const c=he(n,e,'\n\t\t \n\t\t  ',{right:{dir:"right",position:{x:48,y:0}},left:{dir:"left",position:{x:-48,y:0}},bottom:{dir:"bottom",position:{x:0,y:24}},top:{dir:"top",position:{x:0,y:-24}}},(()=>{const t=function(t){const n=t.w/2,e=t.h/2;return{t:{x:t.position.x-n,y:t.position.y-e},b:{x:n,y:e}}}(e);return s=t.t,t.b}),(i=>{let l;(function(t,n,e,i,a){const s=U(it(t[et].data,i),n,-1),c={};let r=!1;function l(t){s[t]<48&&(s[t]=48);const o=48*Math.round(s[t]/48),i="x"===t?"w":"h";e[i]!==o&&(!a||a()[i]<=o)&&(e[i]=o,e.position[t]=n[t]+o/2,r=!0),c[t]=s[t]-e[i]/2}return l("x"),l("y"),o(i.target,c),r})(n,s,e,i,(()=>(l??=ke(t(c.el,"text")),l)))&&($e(a,e),r())}),(t=>{const n=ke(t,a);be(e,n)||($e(e,n),r())}));function r(){!function(t,n){const e=n.w/-2,o=n.h/-2;t.cons.right.position.x=-e,t.cons.left.position.x=e,t.cons.bottom.position.y=-o,t.cons.top.position.y=o,kn(t),Me(t.el,"main",n.w,n.h,e,o),Me(t.el,"outer",n.w+48,n.h+48,e-24,o-24)}(c,e),c.draw()}return i(c.el,"shrect"),96!==e.w||48!==e.h?r():c.draw(),c.el[It].patch=t=>{const n=Ln(c,t),o=(null!=t.w||null!=t.h)&&!be(e,t);o&&($e(e,t),a.h=e.h,a.w=e.w),o?r():n&&c.draw(),t.styles&&(ye=[...t.styles])},c.el}Et(2,(()=>$n(2,R(ye))));const be=(t,n)=>t.w===n.w&&t.h===n.h,$e=(t,n)=>{t.h=n.h,t.w=n.w};function ke(t,n){const e=t.getBBox();return{w:D(n?.w,48,e.width),h:D(n?.h,48,e.height)}}const Me=(n,e,o,i,a,s)=>{const c=t(n,e);c.width.baseVal.value=o,c.height.baseVal.value=i,c.x.baseVal.value=a,c.y.baseVal.value=s};let Ce;function He(t,n){let e;n.w??=96,n.h??=96;const a=pe(t,n,'\n\t\t \n\t\t ',{right:{dir:"right",position:{x:48,y:0}},left:{dir:"left",position:{x:-48,y:0}},bottom:{dir:"bottom",position:{x:0,y:48}},top:{dir:"top",position:{x:0,y:-48}}},(()=>{const t=Le(n);return e=t.tCanvas,t.bInner}),(i=>s(function(t,n,e,i){const a=U(it(t[et].data,i),n,-1);e.w=a.x<48?48:a.x;const s=e.w/2;e.position.x=n.x+s,e.h=a.y<48?48:a.y;const c=e.h/2;return e.position.y=n.y+c,o(i.target,{x:s,y:c}),{x:-s,y:-c}}(t,e,n,i))),(t=>s(function(t,n){const e=t=>24*Math.round(t/24);t.w=e(t.w),t.h=e(t.h);const o=Le(t);return t.position.x=n.x-o.tInner.x,t.position.y=n.y-o.tInner.y,o.tInner}(n,e))));i(a.el,"shbox");const s=t=>{a.cons.right.position.x=n.w+t.x,a.cons.left.position.x=t.x,a.cons.bottom.position.y=n.h+t.y,a.cons.top.position.y=t.y,kn(a),Me(a.el,"main",n.w,n.h,t.x,t.y),Me(a.el,"selected",n.w,n.h,t.x,t.y),Me(a.el,"outer",n.w+48,n.h+48,t.x-24,t.y-24),a.draw()};return 96!==n.w||96!==n.h?s(Le(n).tInner):a.draw(),a.el[It].patch=t=>{const e=Ln(a,t),o=(null!=t.w||null!=t.h)&&!be(n,t);o&&$e(n,t),o?s(Le(n).tInner):e&&a.draw(),t.styles&&(Ce=[...t.styles])},a.el}function Le(t){const n=Ve(t.w),e=Ve(t.h);return{tCanvas:{x:t.position.x-n,y:t.position.y-e},tInner:{x:-n,y:-e},bInner:{x:t.w-n,y:t.h-e}}}Et(5,(()=>({id:K(),type:5,position:{x:0,y:0},styles:R(Ce)})));const Ve=t=>24*Math.floor(t/2/24);function ze(t,n){return De?async function(t,n){try{const e=await window.showSaveFilePicker({suggestedName:n,types:[Be]}),o=await e.createWritable();return await o.write(t),await o.close(),e}catch(t){"AbortError"!==t.name&&alert("File not saved")}}(t,n):function(t,n){const e=document.createElement("a");e.download=n,e.href=URL.createObjectURL(t),e.click(),URL.revokeObjectURL(e.href),e.remove()}(t,n)}async function Se(t){const n="AbortError";try{return Ze?await async function(t){const[n]=await window.showOpenFilePicker({types:[t]});return{h:n,f:await n.getFile()}}(t):await new Promise(((e,o)=>{!function(t,n,e){const o=document.createElement("input");o.type="file",o.multiple=!1,o.accept=t,c(o,"cancel",(t=>e(t)),!0),c(o,"change",(async()=>n(o.files?.length?o.files[0]:null)),!0),o.click(),o.remove()}(t.inputAccept,(t=>{e({f:t})}),(t=>o(Error(n))))}))}catch(t){if(t.name===n||t.message===n)return null;throw t}}const Ze="showOpenFilePicker"in window,De="showSaveFilePicker"in window,Be={accept:{"image/png":[".png"]},inputAccept:"image/png"},Te={accept:{"image/*":[".png",".gif",".jpeg",".jpg"]},inputAccept:"image/*"};function Ee(t,n,e){const o=m(`
${yn} ${wn}
`);return l(o,"[data-cmd]",(e=>{switch(d(e,"data-cmd")){case"del":pn(t,[n]);break;case"copy":ln(t,[n])}})),Cn(o,e)}function Ae(t,n,e,o){Re(n,(n=>t[et].select(dn(t,Yt(n),!0,e,o))))}function Re(t,n){!function(t,n,e){const o=new Image;o.onload=function(){const i=T(n,o.width,o.height);if(!i.c){URL.revokeObjectURL(o.src);const n=new FileReader;return n.onloadend=function(){e(n.result,i.w,i.h)},void n.readAsDataURL(t)}const a=document.createElement("canvas");a.width=i.w,a.height=i.h;const s=a.getContext("2d");s.imageSmoothingEnabled=!1,s.imageSmoothingQuality="high",s.drawImage(o,0,0,i.w,i.h),URL.revokeObjectURL(o.src),e(a.toDataURL(),i.w,i.h)},o.src=URL.createObjectURL(t)}(t,4096,((t,e,o)=>{const i=T(Math.min(document.body.clientHeight/2,264),e,o),a={id:K(),type:6,position:{x:0,y:0},w:i.w,h:i.h,r:B(o/e),d:t};Ue(a),n(a)}))}function Pe(t,n){let e;const a=pe(t,n,`\n\t\t \n\t\t `,{right:{dir:"right",position:{x:48,y:0}},left:{dir:"left",position:{x:-48,y:0}},bottom:{dir:"bottom",position:{x:0,y:48}},top:{dir:"top",position:{x:0,y:-24}}},(()=>{const t=Le(n);return e=t.tCanvas,t.bInner}),(i=>s(function(t,n,e,i){const a=U(it(t[et].data,i),n,-1);e.w=a.x<48?48:a.x;const s=e.w/2;e.position.x=n.x+s,e.h=e.r*e.w;const c=e.h/2;return e.position.y=n.y+c,o(i.target,{x:s,y:c}),{x:-s,y:-c}}(t,e,n,i))),(t=>s(function(t,n){Ue(t);const e=Le(t);return t.position.x=n.x-e.tInner.x,t.position.y=n.y-e.tInner.y,e.tInner}(n,e))),Ee);i(a.el,"shimg");const s=t=>{a.cons.right.position.x=n.w+t.x,a.cons.left.position.x=t.x,a.cons.bottom.position.y=n.h+t.y,a.cons.top.position.y=t.y,kn(a),Me(a.el,"main",n.w,n.h,t.x,t.y),Me(a.el,"selected",n.w,n.h,t.x,t.y),Me(a.el,"outer",n.w+48,n.h+48,t.x-24,t.y-24),a.draw()};return s(Le(n).tInner),a.el[It].patch=t=>{const e=Vn(a,t),o=(null!=t.w||null!=t.h)&&!be(n,t);o&&$e(n,t),o?s(Le(n).tInner):e&&a.draw()},a.el}function Ue(t){t.w=24*Math.round(t.w/24),t.h=B(t.r*t.w)}const Ie=(t,n)=>Mn(n,new Ne(t,n));class Ne extends HTMLElement{constructor(t,n){super(),this.$=n,this.g=t}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML='
';const n=this.$[It].data,e=t.getElementById("edit");c(e,"cmd",(t=>{switch(t.detail.cmd){case"style":Zn(this.g,this.$,t.detail.arg);break;case"del":pn(this.g,[this.$]);break;case"copy":ln(this.g,[this.$])}}));const o=t=>Hn(this.g,this.$,t);i(e,`ta-${n.a}`),l(t,'[data-cmd="a"]',(t=>{const s=Number.parseInt(d(t,"data-cmd-arg"));s!==n.a&&(a(e,`ta-${n.a}`),i(e,`ta-${s}`),o({a:s}))})),["d-h","d-b"].forEach((t=>{n.styles?.includes(t)&&i(e,t)})),l(t,'[data-cmd="s"]',(t=>{const s=d(t,"data-cmd-arg"),c={styles:n.styles?_(n.styles):[]};c.styles?.includes(s)?(E(c.styles,s),a(e,s)):(c.styles??=[],c.styles.push(s),i(e,s)),o(c)}))}}let Oe;function je(n,e){e.w??=48,e.h??=48,e.a??=1;const o=he(n,e,`\n\t\t \n\t\t  `,{right:{dir:"right",position:{x:24,y:0}},left:{dir:"left",position:{x:-24,y:0}},bottom:{dir:"bottom",position:{x:0,y:24}},top:{dir:"top",position:{x:0,y:-24}}},null,null,((t,n)=>s(t,n)),Ie,null,qe);i(o.el,"shtxt"),i(o.el,`ta-${e.a}`);const a=()=>t(o.el,"text"),s=(t,n)=>{n&&Xe(t)&&t.append(Ge());const o=Fe(t);be(e,o)||($e(e,o),u())};let c,r,l;function d(){r=e.w,c=e.h,l=e.a}function u(t){if(function(t,n){const e=n.w/-2,o=-Ve(n.h);t.cons.left.position.y=o+24,t.cons.left.position.x=e,t.cons.top.position.y=o,t.cons.bottom.position.y=n.h+o,t.cons.right.position.y=o+24,t.cons.right.position.x=-e,kn(t),Me(t.el,"main",n.w,n.h,e,o),Me(t.el,"outer",n.w+48,n.h+48,e-24,o-24)}(o,e),t||l!==e.a||r!==e.w){const t=e.w/-2;let n,i;switch(e.a){case 1:n=t+8,i=(e.w-r)/2;break;case 2:n=0,i=0;break;case 3:n=-t-8,i=(e.w-r)/-2}const s=a();s.x.baseVal[0].value=n,s.querySelectorAll("tspan[x]").forEach((t=>{t.x.baseVal[0].value=n})),e.position.x+=i,l!==e.a&&(_e(o.el,l,e.a),l=e.a),r=e.w}c!==e.h&&(a().y.baseVal[0].value=Ye(e.h),e.position.y+=Ve(e.h)-Ve(c),c=e.h),o.draw()}return d(),48!==e.w||48!==e.h?u(!0):o.draw(),o.el[It].patch=t=>{const n=t.position&&!F(e.position,t.position);n&&N(e.position,t.position);let i=!1;t.styles&&(e.styles=t.styles,Sn(o.el),i=!0),null!=t.title&&e.title!==t.title&&(e.title=t.title,o.drawTxt(),i=!0);let s=!1;if(null==t.w&&i){const t=Fe(a());be(e,t)||($e(e,t),s=!0)}null==t.w||be(e,t)||($e(e,t),d(),s=!0),null!=t.a&&e.a!==t.a&&(_e(o.el,e.a,t.a),e.a=t.a,l=e.a,s=!0),s?(a().y.baseVal[0].value=Ye(e.h),u(!0)):n&&o.draw(),t.styles&&(Oe=[...t.styles])},o.el}function Fe(t){const n=t.getBBox();return{w:D(0,48,n.width+12),h:D(0,24,n.height+14)}}customElements.define("ap-rect-txt-settings",Ne),Et(3,(()=>$n(3,R(Oe))));const Ke=t=>1===t.a?-16:2===t.a?0:16,Ye=t=>24-Ve(t);function _e(t,n,e){a(t,`ta-${n}`),i(t,`ta-${e}`)}const Xe=t=>[...t.childNodes].every((t=>![...t.childNodes].some((t=>t.nodeType===Node.TEXT_NODE&&t.textContent?.trim())))),Ge=()=>{const t=f("tspan"," ➜");return t.setAttribute("fill","rgb(13, 110, 253)"),t},qe=(t,n,e)=>{oe(t,n,e),Xe(t)&&t.append(Ge())};let Je;function We(n,e,o){t(n,e).setAttribute("d",`M${o.l.x} ${o.l.y} L${o.t.x} ${o.t.y} L${o.r.x} ${o.r.y} L${o.b.x} ${o.b.y} Z`)}function Qe(t,n){const e=t/2,o=n-e,i=e-n;return{l:{x:o,y:0},t:{x:0,y:o},r:{x:i,y:0},b:{x:0,y:i}}}Et(4,(()=>$n(4,R(Je))));const to=(t,n)=>D(n,48,function(t){const n=g(t);return 2*(Math.abs(n.x)+Math.abs(n.y))}(t)-20);async function no(t,n,e){return function(t,n,e){let o,i;const a=eo(t,n);if(a)o=new DataView(t,0,a.byteOffset-8),i=new DataView(t,a.byteOffset+a.byteLength+4);else{const n=t.byteLength-12;o=new DataView(t,0,n),i=new DataView(t,n)}const s=new DataView(new ArrayBuffer(8));return s.setUint32(0,e.length),s.setUint32(4,n),new Blob([o,s,e,new Uint32Array([0]),i],{type:"image/png"})}(await t.arrayBuffer(),oo(n),e)}function eo(t,n){const e=new DataView(t,8);let o,i=0,a=e.getUint32(4);for(;1229278788!==a;){if(o=e.getUint32(i),a===n)return new DataView(t,i+16,o);i=i+12+o,a=e.getUint32(i+4)}return null}function oo(t){return new DataView((new TextEncoder).encode(t).buffer).getUint32(0)}const io=()=>"undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent||"")||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1),ao=(t,n,e)=>so(t,X(n),null,e);function so(t,n,e,o){const i=t.ownerSVGElement.cloneNode(!0),a=i.querySelector("#canvas");let c;i.style.backgroundImage=null,e?(c=y(uo(t,co)),A(a.children,(t=>((t,n)=>n.some((n=>s(t,n))))(t,co)?(lo(t),!0):(t.remove(),!1)))):(c=t.getBoundingClientRect(),uo(a,ro).forEach((t=>lo(t))));const r=i.getElementsByTagName("foreignObject");for(;r[0];)r[0].parentNode.removeChild(r[0]);const l=t[et].data,d=1/l.scale;a.style.transform=`matrix(1, 0, 0, 1, ${d*(l.position.x+15*l.scale-c.x)}, ${d*(l.position.y+15*l.scale-c.y)})`,function(t,n,e,o){const i=T(io()?4096:10836,n.width*e*window.devicePixelRatio,n.height*e*window.devicePixelRatio),a=new Image;a.width=n.width,a.height=n.height,a.onload=function(){const t=document.createElement("canvas");t.width=i.w,t.height=i.h,t.style.width=`${i.w}px`,t.style.height=`${i.h}px`;const e=t.getContext("2d");e.imageSmoothingEnabled=!1,e.drawImage(a,n.x,n.y,n.width,n.height,0,0,i.w,i.h),URL.revokeObjectURL(a.src),t.toBlob(o,"image/png")},t.width.baseVal.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX,a.width),t.height.baseVal.newValueSpecifiedUnits(SVGLength.SVG_LENGTHTYPE_PX,a.height),a.src=URL.createObjectURL(new Blob([(new XMLSerializer).serializeToString(t)],{type:"image/svg+xml;charset=utf-8"}))}(i,{x:0,y:0,height:c.height/l.scale+30,width:c.width/l.scale+30},3,(async t=>o(n?await no(t,"dgRm",(new TextEncoder).encode(n)):t)))}const co=["select","highlight"],ro=["select","highlight","highlight-e","highlight-s"],lo=t=>{a(t,...ro),t.querySelector(".resizer")?.remove()},uo=(t,n)=>t.querySelectorAll(`.${n.join(", .")}`);async function ho(t){const n=await async function(t,n){return eo(await t.arrayBuffer(),oo(n))}(t,"dgRm");return n?(new TextDecoder).decode(n):null}const po=navigator.clipboard.readText;async function fo(t,n){const e=`web text/dgrm${X(Kt(n,!0))}`;await async function(t){try{await navigator.clipboard.writeText(t)}catch(t){alert(t)}}(e),window.ClipboardItem&&so(t,null,!0,(async t=>{try{await navigator.clipboard.write([new window.ClipboardItem({[t.type]:Promise.resolve(t),"text/plain":Promise.resolve(new Blob([e],{type:"text/plain"}))})])}catch{}}))}const mo=t=>{if(!t?.startsWith("web text/dgrm"))return null;try{return G(t.slice("web text/dgrm".length))}catch{return null}};function vo(t,n,e){const o=function(t,n){async function e(e){if(document.activeElement===t.ownerSVGElement){const o=n();if(o?.length)return e.preventDefault(),fo(t,o),o}return null}async function o(n){const o=await e(n);o&&go(t,o)}return document.addEventListener("copy",e),document.addEventListener("cut",o),function(){r(document,"copy",e),r(document,"cut",o)}}(t,n);function i(o){if(u(o)||"Delete"!==o.key&&"Backspace"!==o.key)"Escape"===o.key&&e();else{const e=n();e?.length&&go(t,e)}}return c(document,"keydown",i),function(){o(),r(document,"keydown",i)}}function go(t,n){t[et].select(null),pn(t,n)}const wo=()=>{if(!document.cookie.includes("dgrma=1"))return null;const t=G(localStorage.getItem("dgrm"));return t&&new Date(t.e)>new Date?t:null},yo=(t,n,e,o,i)=>{n&&$o(xo(),e,o,n.n,0===e?n.i:n.n,n.i,new Date,i)},xo=()=>`dgrm${wo()?.l}`,bo=(t,n)=>Lo(t,(t=>ko(t.transaction("r","readonly").objectStore("r"),n))),$o=(t,n,e,o,i,a,s,c)=>Lo(t,(t=>{const r=t.transaction("r","readwrite").objectStore("r");ko(r,(l=>{const d=l.find((t=>t.k===i));l.length>=5&&!d&&Mo(t,r,l[l.length-1]);const u=d?.i??a??Dt();r.put({t:n,i:u,k:i,n:o,l:e,d:s}),c&&t.transaction("d","readwrite").objectStore("d").put({i:u,d:c})}))})),ko=(t,n)=>{t.getAll().onsuccess=t=>{n((t.target.result??[]).sort(((t,n)=>n.d.getTime()-t.d.getTime())))}},Mo=(t,n,e,o)=>{let i=0;const a=()=>{1!==i?i++:o&&o()};n.delete(e.i).onsuccess=a,1===e.t?t.transaction("d","readwrite").objectStore("d").delete(e.i).onsuccess=a:a()},Co=(t,n,e)=>Lo(t,(t=>{let o=null,i=null;const a=(t,n)=>{t&&(o=t),n&&(i=n),o&&i&&(o.s=i.d,e(o))};t.transaction("r","readonly").objectStore("r").get(n).onsuccess=t=>{a(t.target.result,null)},t.transaction("d","readonly").objectStore("d").get(n).onsuccess=t=>{a(null,t.target.result)}})),Ho=(t,n,e)=>Lo(t,(t=>{const o=t.transaction("r","readwrite").objectStore("r");ko(o,(i=>{const a=i.find((t=>t.k===n));a?Mo(t,o,a,e):e()}))})),Lo=(t,n)=>{const e=indexedDB.open(t);e.onerror=t=>console.error(e.error),e.onupgradeneeded=t=>{const n=e.result;n.createObjectStore("d",{keyPath:"i"}),n.createObjectStore("r",{keyPath:"i"})},e.onsuccess=t=>{e.result.onerror=t=>console.error("indexedDB error",t),n(e.result)}},Vo=(t,n,e,o,i,a)=>{t[Ao]={i:n,n:e,e:o,m:i},Bo(t,0,a,null)},zo=(t,n,e)=>{const o=Y(n.name);t[Ao]={f:n,n:o},Bo(t,1,null,e)},So=(t,n,e)=>{t[Ao]={n:n},Bo(t,1,null,e)},Zo=t=>{t[Ao]=void 0,Bo(t,null,null,null)},Do=t=>t[Ao],Bo=(t,n,e,o)=>{const i=t[Ao];To(i?.n),yo(0,i,n,e,o)},To=t=>{document.title=t??"DGRM - Flowchart editor"},Eo=t=>t?.replace(/[/\\?%*:|"<>]/g,"-"),Ao=Symbol(0),Ro=async(t,n)=>{const e=`${Do(t)?.n??"dgrm"}.png`;if(Po())return void await ze(n,e);const o={files:[new File([n],e,{type:n.type})]};navigator.canShare&&navigator.canShare(o)?await navigator.share(o):await ze(n,e)},Po=()=>screen.width>768;class Uo extends HTMLElement{constructor(t,n){super(),this.g=t,this.M=n}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML=`
${yn}Create copy
Copy to clipboard
${Po()?xn+"Download":bn+"Send"} image
${wn}Delete
`;const n=()=>ut(this)[wt].del();function e(e,o){c(t.getElementById(e),"click",(t=>{n(),o()}))}e("clone",(()=>ln(this.g,this.M()))),e("copy",(async()=>await fo(this.g,this.M()))),e("save",(()=>so(this.g,X(Kt(this.M(),!1)),!0,(async t=>Ro(this.g,t))))),e("del",(()=>pn(this.g,this.M())))}}customElements.define("ap-grp-settings",Uo);const Io=Symbol("p"),No=Symbol(0);const Oo=(t,n,e)=>{if(e[Io])return null;if("a"===e?.target?.tagName)return null;const o=At(e),i=ci(o);if(!i)return Wo(n),null;const a=ei(n,o),s=ai(n);if(s&&a)return ri(i,e),null;if(e.shiftKey||e.ctrlKey){if(s){const t=ii(n);li(t),Go(n,t)}return a?qo(n,i):Go(n,i),ti(n,e),null}return a?ft(new Uo(t,(()=>Qo(n))),e.clientX-10,e.clientY-10):(Wo(n),Go(n,i),ti(n,e),null)},jo=(t,n,e,o)=>{if(e[Io])return;if(t[No]?.size)for(const n of t[No])if(n(e,o))return;if(o===t.ownerSVGElement)return void t[et].moveCapture();const i=ei(n,o);if(!i&&!h(e))return void t[et].moveCapture();if(!i&&h(e))return Wo(n),void di(ci(o),e,o);const a=ai(n);i&&a?di(ci(o),e,o):i&&!a&&Fo(t,n,e)},Fo=(t,n,e)=>{const o=()=>Ko(n),i=t=>Yo(n,t),a=o();C(t.ownerSVGElement,e,(n=>i((e=>Q(e,t[et].data.scale,n)))),(n=>{i((n=>at(n,t[et].data.cell))),on(t,a,o())}))},Ko=t=>Kt([...t.shapesToMove,...ui(t.pathEndsToMove)],!1,!0),Yo=(t,n)=>{t.shapesToMove?.forEach((t=>{n(t[It].data.position),t[It].drawPosition()})),t.pathEndsToMove?.forEach((t=>{n(t.data.position),hi(t)[Ut].drawPosition()}))},_o=t=>{t[et].select(null),t[et].select(t.children)},Xo=()=>({shapes:new Set,paths:new Set,pathEnds:new Set,shapesToMove:new Set,pathEndsToMove:new Set}),Go=(t,n)=>{if(n.shape)t.shapes.add(n.shape),i(n.shape,"highlight");else if(n.path)t.paths.add(n.path),i(n.path,"highlight"),a(n.path,"highlight-s","highlight-e"),t.pathEnds.delete(n.path[Ut].data.s),t.pathEnds.delete(n.path[Ut].data.e);else if(n.pathEnd){const e=hi(n.pathEnd);if(t.paths.has(e))return;t.pathEnds.add(n.pathEnd),i(e,mi(n.pathEnd))}},qo=(t,n)=>{if(n.shape)t.shapes.delete(n.shape),a(n.shape,"highlight");else if(n.path)t.paths.delete(n.path),t.pathEnds.delete(n.path[Ut].data.s),t.pathEnds.delete(n.path[Ut].data.e),a(n.path,"highlight","highlight-s","highlight-e");else if(n.pathEnd){const e=hi(n.pathEnd);if(t.paths.delete(e)){a(e,"highlight","highlight-s","highlight-e");const o=fi(n.pathEnd);t.pathEnds.add(o),i(e,mi(o))}else t.pathEnds.delete(n.pathEnd),a(e,mi(n.pathEnd))}},Jo=t=>{const n=t=>a(t,"highlight","highlight-s","highlight-e");t.shapes.forEach((t=>n(t))),t.paths.forEach((t=>n(t))),t.pathEnds.forEach((t=>n(hi(t))))},Wo=t=>{Jo(t);const n=ii(t);n&&li(n),t.pathEnds.clear(),t.pathEndsToMove.clear(),t.paths.clear(),t.shapes.clear(),t.shapesToMove.clear()},Qo=t=>[...t.shapes,...t.paths,...ui(t.pathEnds)],ti=(t,n)=>{ni(t);const e=oi(t);e&&(Jo(t),ri(e,n))},ni=t=>{t.shapesToMove=new Set(t.shapes),t.pathEndsToMove=new Set;const n=n=>{n.shape?t.shapesToMove.add(n.shape.shapeEl):t.pathEndsToMove.add(n)};t.paths?.forEach((t=>{n(t[Ut].data.s),n(t[Ut].data.e)})),t.pathEnds?.forEach(n)},ei=(t,n)=>[...t.shapes,...[...t.pathEnds].map((t=>t.el)),...t.paths].some((t=>t.contains(n))),oi=t=>si(t)?ii(t):{},ii=t=>1!==t.shapes.size||t.paths.size||t.pathEnds.size?t.shapes.size||1!==t.paths.size||t.pathEnds.size?t.shapes.size||t.paths.size||1!==t.pathEnds.size?null:{pathEnd:P(t.pathEnds)}:{path:P(t.paths)}:{shape:P(t.shapes)},ai=t=>!!ii(t),si=t=>t.shapes.size||t.pathEnds.size||t.paths.size,ci=t=>{const n=t[It]?{shape:t}:t.parentElement[It]?{shape:t.parentElement}:t.parentElement.parentElement[It]?{shape:t.parentElement.parentElement}:null;if(n)return n;const e=t[Ut]?{path:t}:t.parentElement[Ut]?{path:t.parentElement}:null;if(e)return e;const o=pi(t);return o?{pathEnd:o}:null},ri=(t,n)=>{t.shape?t.shape[It].click(n):t.path?t.path[Ut].click(n):t.pathEnd&&hi(t.pathEnd)[Ut].click(n,t.pathEnd.el)},li=t=>{t.shape?t.shape[It].unselect():t.path?t.path[Ut].unselect():t.pathEnd&&hi(t.pathEnd)[Ut].unselect()},di=(t,n,e)=>{t.shape?t.shape[It].moveCapture(n,e):t.path?t.path[Ut].moveCapture(n,e):t.pathEnd&&hi(t.pathEnd)[Ut].moveCapture(n,e)},ui=t=>[...t].map(hi),hi=t=>t.el.parentNode,pi=t=>{const n=t.hasAttribute("data-key")?t:t.parentElement.hasAttribute("data-key")?t.parentElement:null;if(!n)return null;const e=n.parentNode[Ut].data;return e.s.el===n?e.s:e.e},fi=t=>{const n=hi(t)[Ut].data;return n.s===t?n.e:n.s},mi=t=>hi(t)[Ut].data.s===t?"highlight-s":"highlight-e";function vi(t){const n=(n,e)=>(function(t,n,e){const o=f("path");o.style.pointerEvents="none",i(o,"mrkp"),t.append(o);const a=[],c=n=>a.push(ot(t[et].data,n.clientX,n.clientY)),r=new Set,l=t=>{s(t,"mrkt")&&r.add(t)};l(e),c(n),C(o,n,(t=>{c(t),o.setAttribute("d",$i(a)),l(document.elementFromPoint(t.clientX,t.clientY))}),(n=>{let e=ki(y([o,...r]));o.remove(),e=Mi(ot(t[et].data,e.x,e.y));const i={id:K(),type:7,position:e,d:""},s=[{position:{x:0,y:0},d:$i(a)}],c=[];r.forEach((t=>{const n=t.parentNode;c.push(n),s.push(n[It].data)}));for(const t of s)wi(i,t);c.length?fn(t,c,Yt(i)):un(t,Yt(i),!0)}))}(t,n,e),!0);return((t,n)=>{t[No]??=new Set,t[No].add(n)})(t,n),()=>{((t,n)=>{t[No]?.delete(n)})(t,n)}}const gi=t=>``;function wi(t,n){const e=yi(n.d),o=j(n.position);U(o,t.position,-1);let i=n.d;for(const t of e){const n=j(t);Mi(U(t,o)),i=bi(i,n,t)}t.d+=i}const yi=t=>t.match(/M(.*?)l/g).map((t=>{const n=t.split(" ");return{x:Number.parseFloat(n[0].substring(1)),y:Number.parseFloat(n[1].substring(0,n[1].length-1))}})),xi=t=>`M${t.x} ${t.y}l`,bi=(t,n,e)=>t.replaceAll(xi(n),xi(e));function $i(t,n=5,e=2){const o=t.length,i=o-n-1==0;let a="M",s=[t[0].x,t[0].y];const[c,r]=s.map((t=>+t.toFixed(e)));let l=`${a}${c} ${r}`,d=c,u=r;const[h,p]=[t[1].x,t[1].y],[f,m]=[(c+h)/2,(r+p)/2],[v,g]=[f-d,m-u].map((t=>+t.toFixed(e)));l+=`l${v} ${g}`,d+=v,u+=g;for(let i=1;i1&&(a="t",s=[w,y]),l+=`${a}${s.map((t=>+t.toFixed(e))).join(" ")} `,d+=w,u+=y}return i||(s=[t[o-1].x-d,t[o-1].y-u],l+=`l${s.map((t=>+t.toFixed(e))).join(" ")}`),l}const ki=t=>({x:Math.round(t.x+t.width/2),y:Math.round(t.y+t.height/2)}),Mi=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t);const Ci=()=>{const t=wo()?.n;if(t)return t;const n=`User${Math.floor(100*Math.random())}`,e=prompt("Your name",n);return null==e?null:e?.substring(0,25)??n},Hi=t=>document.getElementById("menu").bage(t),Li=t=>{const n=Vi(t),e=document.createElement("div");return e.innerHTML=` ${t}`,e.style.cssText=`position: fixed; top:0; color:${n}; pointer-events: none;`,e.style.transform="translate(-9999px, 0px)",v(e),e},Vi=t=>`hsl(${[...t].reduce(((t,n)=>n.charCodeAt(0)+((t<<5)-t)),0)%360}, 97%, 47%)`,zi=(t,n,e,o)=>{const i=((t,n,e)=>({x:t.position.x+n*t.scale,y:t.position.y+e*t.scale}))(t[et].data,e,o);n.style.transform=`translate(${i.x}px, ${i.y}px)`},Si=(t,n,e)=>{const o=t=>e(X(t)),i=c(t,"dgrmc",(t=>o([4,t.detail.shapesToCreateData]))),a=c(t,"dgrmu",(t=>o([4,t.detail.shapesToUpdData]))),s=c(t,"dgrmd",(t=>o([5,t.detail.delIds]))),l=c(t,"dgrmdc",(t=>{o([5,t.detail.delIds]),o([4,t.detail.shapesToCreateData])}));let d=!0;const u=c(t.ownerSVGElement,"pointermove",Z((e=>{if(d){const i=ot(t[et].data,e.clientX,e.clientY);o([6,n,i.x,i.y])}}),60));return()=>{d=!1,r(t,"dgrmc",i),r(t,"dgrmu",a),r(t,"dgrmd",s),r(t,"dgrmdc",l),r(t.ownerSVGElement,"pointermove",u)}},Zi=(t,n)=>{Xt(t,n),S(t,new CustomEvent(Bi,{detail:n,cancelable:!1}))},Di=(t,n)=>{zn(n),S(t,new CustomEvent(Ti,{detail:n,cancelable:!1}))},Bi="dgrmcu",Ti="dgrmcd",Ei=t=>k("k",t);function Ai(t,n){_t(t,n),function(t){const n=t.getBoundingClientRect(),e=window.innerWidth/2,o=window.innerHeight/2;t[et].move(e-n.width/2-n.x,o-n.height/2-n.y,1);const i=t=>t>1?1:Math.max(t,.25),a=Math.min(i(window.innerWidth/n.width),i(window.innerHeight/n.height));a<1&&t[et].scale(a,{x:e,y:o})}(t)}function Ri(t){return!!Ii(t)&&(t.c[t.i].u(),t.i-=1,!0)}function Pi(t){const n=Ui(t);return null!==n&&(t.i=n,t.c[n].r(),!0)}const Ui=t=>{if(!t)return null;const n=t.i+1;return n<=t.c.length-1?n:null},Ii=t=>t&&t.i>=0,Ni=(t,n,e)=>_i(t,(()=>{Ki(t,en(n,e)),Xt(t,e),zn(n)}),(()=>{Ki(t,nn(n,e)),Xt(t,e)})),Oi=(t,n,e)=>_i(t,(()=>{Ki(t,nn(n,e)),Xt(t,e)}),(()=>{Ki(t,en(n,e)),zn(n)})),ji=(t,n,e)=>_i(t,(()=>{Ki(t,an(e,n)),Xt(t,n)}),(()=>{Ki(t,an(n,e)),Xt(t,e)})),Fi=(t,n,e,o,i)=>_i(t,(()=>{Ki(t,nn(n,e)),Xt(t,e),Ki(t,en(o,i)),Xt(t,i),zn(o)}),(()=>{Ki(t,en(n,e)),zn(n),Ki(t,nn(o,i)),Xt(t,i)})),Ki=(t,n)=>{n[Yi]=!0,S(t,n)},Yi=Symbol(0);function _i(t,n,e){t[Qi]??={c:[],i:-1},function(t,n,e){15===t.c.length&&(t.c.splice(0,1),t.i--),t.c.splice(t.i+1),t.i=t.c.push({u:n,r:e})-1}(t[Qi],n,e),Ji(t)}function Xi(t,n){n(t[Qi])&&(t[et].select(null),Ji(t))}const Gi=t=>Xi(t,Ri),qi=t=>Xi(t,Pi);const Ji=t=>{return S(t,z(Wi,(n=t[Qi],{u:Ii(n),r:null!==Ui(n)})));var n},Wi="dgrmh",Qi=Symbol("h");function ta(t){S(t,z("dgrmn",null,!0))&&(!function(t){for(t[et].select(null);t.firstChild;)(t.firstChild[It]||t.firstChild[Ut]).del();t[et].move(0,0,1)}(t),function(t){var n;(n=t[Qi])&&(n.c=[],n.i=-1),Ji(t)}(t),Zo(t))}async function na(t,n){if(!t?.i)return void oa({a:0,u:[]},!0,!0,n);const e=await lt((()=>(async t=>(await x(`${Lt}${t}`)).json())(t.i))),o=oa(e,!1,!t.m,n);t.m&&(la(o,"[anon]",[da[0],da[1],da[2]],(n=>lt((async()=>{var o,i;e.a!==n[1]&&(e.a=n[1],await(o=t.i,i=n[1],b(`${Lt}a/${o}`,i.toString())))})))),ea(o,e.u,((n,e)=>{return o=t.i,$(`${Lt}${o}`,{i:n,r:e});var o})),l(o,"[inv]",(n=>aa((n=>lt((async()=>{const e=Dt();var o,i,a;await navigator.clipboard.writeText(`${Ct}invite/${e}`),await(o=t.i,i=e,a=n,$(`${Lt}i/${o}`,{i:i,r:a})),Mt()}))))))),l(o,"[cop]",(async n=>{await navigator.clipboard.writeText(Ei(t.i)),Mt(),o[wt].del()}))}const ea=(t,n,e)=>l(t,"[uu]",(o=>{const i=o.currentTarget,a=Number(o.currentTarget.getAttribute("uu")),s=t=>lt((async()=>{const o=n.find((t=>t.i===a));o.r!==t[1]&&(i.textContent=t[0],await e(a,t[1]),o.r=t[1])}));ra(o,[xt(da[1][0],(()=>s(da[1]))),xt(da[2][0],(()=>s(da[2]))),$t((()=>lt((async()=>{await e(a,da[0][1]),t.querySelector(`[uitm="${a}"]`).remove()}))))])})),oa=(t,n,e,o)=>gt(`
${ia({i:0,n:"Anyone with the link",r:t.a})} ${t?.u?.map(ia).join(" ")}
${J(n,'To share, save diagram to the cloud.')} ${J(e&&!n,'You do not have access to manage permissions.')}
`,null,o),ia=t=>``,aa=t=>{const n=vt(m('
Send a link to the person you want to invite.

Person must have a DGRM subscription.

Permissions: Viewer
The invitation link is one-time only and is active for 24 hours.'),null,!0);let e=1;la(n,"[prm]",[da[1],da[2]],(t=>{e=t[1]})),l(n,"[crt]",(o=>{n[wt].del(),t(e)}))};async function sa(t){const n=await lt((()=>(async t=>(await x(`${Vt}${t}`)).json())(t))),e=ca(n);ea(e,n,((n,e)=>((t,n,e)=>$(`${Vt}${t}`,{i:n,r:e}))(t,n,e))),l(e,"[inv]",(n=>aa((n=>lt((async()=>{const e=Dt();await navigator.clipboard.writeText(`${Ct}invite-folder/${e}`),await((t,n,e)=>$(`${Vt}i/${t}`,{i:n,r:e}))(t,e,n),Mt()}))))))}const ca=t=>gt(`
${t.map(ia).join(" ")}
`,null,!0),ra=(t,n)=>yt(t.currentTarget,n),la=(t,n,e,o)=>l(t,n,(t=>{const n=t.currentTarget;ra(t,e.map((t=>xt(t[0],(()=>(async t=>{n.textContent=t[0],o(t)})(t))))))})),da=[["No access",0],["Viewer",1],["Editor",2]],ua=async t=>{const e=ha(`
${wo()?'':'
Log in to access cloud storage.
'}
`);e.s();const o=t=>{n(e.m,"ftr").style.display=t?"unset":"none"},i=async()=>{await pa(e.h,e.b,(()=>e.m[wt].del())),o(!0)};await i(),l(e.m,"[cld]",(()=>lt((async()=>{o(!1),await fa(t,e.h,e.b,!0,(async t=>await i()))})))),l(e.m,"[dvc]",(async()=>{e.m[wt].del(),await async function(t){try{const n=await Se(Be);if(!n)return;const e=await $a(t,n.f);if(!e)return void ka();n.h?zo(t,n.h,e):So(t,Y(n.f.name),e)}catch(t){console.log(t),ka()}}(t)}))};const ha=t=>{const e=gt(`
${t}`,m('
')),o=t=>n(e,t);return{m:e,h:o("hdr"),b:o("cnt"),s:()=>{ut(e).style.display="flex"}}},pa=async(t,n,e)=>{t.innerHTML='CloseRecent',l(t,"[c]",e);const o=await new Promise(((t,n)=>bo(xo(),t)));n.innerHTML=o?.length?o.map((t=>``)).join(" "):La},fa=async(t,n,e,o,i)=>{let a=await St(),s={i:null,n:"Cloud",m:!0,r:!1};const c=[],r=n=>{a.d.delete(n),n===Do(t)?.i&&Zo(t),d()},l=(n,e)=>{e&&Zo(t),a.f.delete(n),d()},d=()=>va(e,s,a,((n,e)=>lt((async()=>{a.d.get(n).n=await(async(t,n)=>(await b(`${Ht}a/n/${t}`,n)).text())(n,e),n===Do(t)?.i&&((t,n,e)=>{t[Ao].n=n,Bo(t,0,e,null)})(t,a.d.get(n).n,s?.n),d()}))),(t=>lt((async()=>{var n;await(n=t,$(`${Ht}a/d/${n}`)),r(t)}))),(t=>lt((async()=>{var n;await(n=t,$(`${Lt}r/${n}`)),r(t)}))),(t=>lt((async()=>{c.push(s),s=a.f.get(t),u(),a=await St(t),d()}))),((t,n)=>lt((async()=>{a.f.get(t).n=await(async(t,n)=>(await b(`${Ht}f/n/${t}`,n)).text())(t,n),d()}))),(n=>lt((async()=>l(n,await(async(t,n)=>{const e=new URL(`${Ht}f/d/${t}`);return Bt(e,"k",n),(await $(e.toString())).json()})(n,Do(t)?.i))))),(n=>lt((async()=>l(n,await(async(t,n)=>(await b(`${Vt}r/${t}`,n)).json())(n,Do(t)?.i)))))),u=()=>ma(n,s,o,i,(()=>lt((async()=>{const t=c.pop();s=t,u(),a=await St(t.i),d()}))),(t=>lt((async()=>{const n=await(async t=>(await b(`${Ht}f/a`,t)).json())(t);n.m=!0,a.f.set(n.i,n),d()}))),((t,n)=>lt((async()=>{const e=Dt();a.d.set(e,{i:e,n:await Zt(e,t,n,Ot()),d:Date.now(),m:!0,r:!1}),d()}))));return d(),u(),()=>({f:s,d:a})},ma=(t,n,e,o,i,a,s)=>{t.innerHTML=`\n\t\t${n.i||e?`${Ca}`:"Close"}\n\t\t${n.n??""}\n\t\t${n.m?`${Ma}`:''}`,l(t,"[c]",(t=>n.i?i():o()));const c=xt("Add diagram",(()=>xa("New diagram",(t=>s(n.i,t)))));l(t,"[af]",(t=>ga(t,n.i?[c,ya(n.i)]:[c,xt("Add folder",(()=>xa("New folder",a)))])))},va=(t,n,e,o,i,a,s,c,r,d)=>{t.innerHTML=`${[...e.f].map((t=>``)).join(" ")}\n\t\t${[...e.d].map((t=>``)).join(" ")}\n\t${e.f.size||e.d.size?"":La}`,l(t,"[fld]",(t=>s(Number(t.currentTarget.getAttribute("fld"))))),l(t,"[fedt]",(t=>{const n=e.f.get(Number(t.currentTarget.getAttribute("fedt"))),o=n.m?[wa(n.n,(t=>c(n.i,t))),ya(n.i),$t((()=>r(n.i)))]:[];n.r&&o.push(bt("Remove from my cloud",(()=>d(n.i)))),ga(t,o)})),l(t,"[edt]",(t=>{const n=e.d.get(t.currentTarget.getAttribute("edt")),s=n.m?[wa(n.n,(t=>o(n.i,t))),xt("Share",(t=>na(n,!0))),$t((()=>i(n.i)))]:[];n.r&&s.push(bt("Remove from my cloud",(()=>a(n.i)))),ga(t,s)}))},ga=(t,e)=>yt(n(t.currentTarget,"dts"),e),wa=(t,n)=>xt("Rename",(()=>xa(t,(e=>{t!==e&&n(e)})))),ya=t=>xt("Share",(()=>sa(t)));function xa(t,e){const o=vt(m(`
`),"mdm",!0);l(o,"[sv]",(t=>{o[wt].del(),e(Eo(n(o,"nm").value))}))}async function ba(t,n,e){const o=await $a(t,n);return o||(Ae(t,n,e.clientX,e.clientY),null)}async function $a(t,n){if("image/png"!==n.type)return null;const e=await ho(n);if(e){ta(t);const n=G(e);return Ai(t,n),n}return null}const ka=()=>alert("File cannot be read. Use the exact image file you got from the application."),Ma='',Ca='',Ha='',La='
No items
',Va=async t=>{const n=Do(t);if(n?.f){const e=Ft(t);ao(t,e,(async o=>{const i=await n.f.createWritable();await i.write(o),await i.close(),yo(0,n,1,null,e),Ra(t)}))}else n?.i?n.e?lt((async()=>await Ba(t,n.i))):alert('You do not have access to edit this diagram. Use "Save As" to make your own copy.'):za(t)},za=async t=>wo()?Sa(t):Za(t),Sa=async t=>{const e=await lt((()=>(async(t,n)=>{const e=ha(n),o=await fa(t,e.h,e.b,!1,(()=>e.m[wt].del()));return e.s(),{m:e.m,d:()=>o()}})(t,`
`))),o=()=>e.m[wt].del(),i=()=>Eo(n(e.m,"snm").value);l(e.m,"[dvc]",(n=>{o(),Da(t,i())})),l(e.m,"[cld]",(async()=>{const n=e.d();if(n.d.d.size>29&&(alert("Maximum number of diagrams in folder exceeded"),1))return;const a=async t=>{lt(t),o()},s=(e,o)=>{Vo(t,e,o,!0,!0,n?.f?.n),Ra(t)},c=i(),r=Object.entries(n.d.d).find((t=>t[1].n===c));if(r){const n=Do(t);return r[0]===n?.i&&n.m?void a((async()=>await Ba(t,n.i))):void(confirm("Overwrite existing file?")&&a((async()=>s(r[0],await(async(t,n)=>(await $(`${Ht}a/o/${t}`,n)).text())(r[0],Ft(t))))))}a((async()=>{const e=Dt();s(e,await Zt(e,n.f.i,c,Ft(t)))}))}))},Za=t=>{const e=vt(m(`
Log in to access cloud storage.
`),"mdm");l(e,"[dvc]",(o=>{Da(t,Eo(n(e,"nm").value)),e[wt].del()}))},Da=(t,n)=>{const e=Ft(t);ao(t,e,(async o=>{const i=ze(o,n?.length?n:Pa());if(i){const n=await i;n&&(zo(t,n,e),Ra(t))}else So(t,n,e),Ra(t)}))},Ba=async(t,n)=>{let e;if(Ta(t)){const o=[...t[Aa].c,...t[Aa].u],i=function(t,n){for(const e in t.s)n.has(e)&&Qt(t.s[e]);return t}(Kt(o.length?[...document.querySelectorAll(o.map((t=>`[id="${t}"]`)).join(","))]:null,!1),t[Aa].u);t[Aa].d.forEach((t=>{i.s[t]=null})),e=await(async(t,n)=>(await $(`${Ht}u/${t}`,n)).json())(n,i)}else e=(await zt(n)).d;Xt(t,e),Ra(t)},Ta=t=>t[Aa].c.size||t[Aa].u.size||t[Aa].d.size,Ea=t=>{t[Aa].c.clear(),t[Aa].u.clear(),t[Aa].d.clear()},Aa=Symbol(0),Ra=t=>{Ea(t),kt("Saved")},Pa=()=>{const t=t=>t<10?`0${t}`:t.toString(),n=new Date;return`${n.getFullYear()}-${t(n.getMonth()+1)}-${t(n.getDate())}.${t(n.getHours())}${t(n.getMinutes())}${t(n.getSeconds())}.png`};function Ua(t,n,e,o){const i=n=>t[et].select(dn(t,n,!0,e,o));if(n?.data)i(function(t){if(!t)return null;const n=new Map,e=t=>{const e=K();return n.set(t,e),e},o=[];for(const n in t.s){const i=e(t.s[n].id);t.s[i]=t.s[n],t.s[i].id=i,delete t.s[n],0===t.s[i].type&&o.push(t.s[i])}return o.forEach((t=>{t.s.s=n.get(t.s.s),t.e.s=n.get(t.e.s)})),t}(n.data));else if(n?.img)Re(n.img,(t=>i(Yt(t))));else if(n?.txt){const e=function(t,n){const e=f("text");qe(e,null,n),e.style.visibility="hidden",t.append(e);const o=Fe(e);return e.remove(),o}(t,n.txt);i(Yt({id:K(),type:3,position:{x:0,y:0},title:n.txt,w:e.w,h:e.h}))}else kt("Clipboard is empty")}class Ia extends HTMLElement{constructor(t){super(),this.g=t}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML='';const n=t.getElementById("u"),e=t.getElementById("r");c(this.g,Wi,(t=>{const o=(t,n)=>n?i(t,"actv"):a(t,"actv");o(n,t.detail.u),o(e,t.detail.r)})),c(n,"click",(t=>Gi(this.g))),c(e,"click",(t=>qi(this.g)))}}customElements.define("ap-history",Ia);const Na=-1!==window.navigator.userAgent.indexOf(" OPR"),Oa=t=>Na&&0!==t.button,ja=(t,n,e,o,i)=>t.x<=o&&o<=t.x+n&&t.y<=i&&i<=t.y+e,Fa={iceServers:[{urls:"stun:stun3.l.google.com:19302"}]},Ka=`${Ct}m/`;async function Ya(t,n,e,o){const i=Ci();if(null==i)return e(),null;rt(!0);const a=K(),s=new Map,c=await async function(t,n,e,o,i){const a=await async function(t,n,e){const o=new RTCPeerConnection(Fa),i=o.createDataChannel("dgrm");return i.onopen=n=>t(i,n),i.onmessage=t=>n(i,t),i.onerror=t=>{o.close(),e()},await o.setLocalDescription(),new Promise(((t,n)=>{o.onicecandidate=n=>{n.candidate||t(o)}}))}(e,o,i);await((t,n,e)=>$(`${Ka}o`,{m:t,c:n,s:e}))(n,t,a.localDescription.sdp);const s=q(3e3,15e3,(async()=>{try{const e=await(async(t,n)=>(await x(`${Ka}a?m=${t}&c=${n}`)).text())(n,t);e&&(s(),a.setRemoteDescription({sdp:e,type:"answer"}))}catch{c(),i()}}),i),c=()=>{s(),a.close(),rt(!1)};return c}(a,n,((t,n)=>t.send(X([0,a,i]))),((n,e)=>{const o=G(e.data);switch(o[0]){case 6:zi(t,s.get(o[1]),o[2],o[3]);break;case 4:Zi(t,o[1]);break;case 5:Di(t,o[1]);break;case 0:s.set(o[1],Li(o[2]));break;case 7:s.get(o[1]).remove(),s.delete(o[1]);break;case 2:Ai(t,o[1]),l(n);break;case 3:t[et].move(o[1],o[2],1),l(n)}}),(()=>{d(),o()}));let r;const l=n=>{r=Si(t,a,(t=>n.send(t))),rt(!1)},d=()=>{s.forEach((t=>t.remove())),r&&r(),c(),rt(!1)};return d}async function _a(t,n,e){const o=Ci();if(null==o)return n(),null;const i=K(),a=K(),s=new Map,c=(t,n)=>s.forEach(((e,o)=>o!==n?o.send(t):null)),r=await async function(t,n,e,o,i){const a=K();await((t,n)=>$(`${Ka}c`,{m:t,k:n}))(t,a);const s=new Set,c=q(5e3,72e5,(async()=>{try{const i=await(async(t,n)=>{const e=await(await x(`${Ka}o?m=${t}&k=${n}`)).json();return e?Object.entries(e):void 0})(t,a);if(!i?.length)return;i.forEach((async i=>{const c=await async function(t,n,e,o){const i=new RTCPeerConnection(Fa);return i.ondatachannel=t=>{const a=t.channel;a.onopen=t=>n(a,t),a.onmessage=t=>e(a,t),a.onerror=t=>{i.close(),o(i,a,t)}},await i.setRemoteDescription({sdp:t,type:"offer"}),await i.setLocalDescription(),new Promise(((t,n)=>{i.onicecandidate=n=>{n.candidate||t(i)}}))}(i[1],((t,e)=>n(i[0],t,e)),e,((t,n,e)=>{s.delete(t),o(n,e)}));s.add(c),await((t,n,e,o)=>$(`${Ka}a`,{m:t,k:n,c:e,s:o}))(t,a,i[0],c.localDescription.sdp)}))}catch{r(),i()}})),r=()=>{c(),s?.forEach((t=>t.close()))};return r}(i,((n,e,i)=>{e.send(X([0,a,o]));const c=Ft(t);e.send(X(jt(c)?[3,t[et].data.position.x,t[et].data.position.y]:[2,c])),s.forEach((t=>e.send(X([0,t.i,t.n]))))}),((n,e)=>{const o=G(e.data);switch(o[0]){case 6:zi(t,s.get(n).c,o[2],o[3]),c(e.data,n);break;case 4:Zi(t,o[1]),c(e.data,n);break;case 5:Di(t,o[1]),c(e.data,n);break;case 0:s.set(n,{i:o[1],n:o[2],c:Li(o[2])}),c(e.data,n)}}),((t,n)=>{const e=s.get(t);c(X([7,e.i]),t),e.c.remove(),s.delete(t)}),(()=>{d(),e()})),l=Si(t,a,c),d=()=>{l(),s.forEach((t=>t.c.remove())),r()};return{dispose:d,id:i}}function Xa(t,n,e){const o=m(`
Live collaboration in progress
`),i=vt(o),a=(t,n)=>l(o,t,(t=>{i[wt].del(),n()}));a("[mstop]",n),a("[mshare]",(async n=>{await navigator.clipboard.writeText(k("m",t)),Mt()}))}const Ga=t=>{t[Ja]?.dispose(),t[Ja]=void 0,Hi(!1)},qa=t=>{Ga(t),alert("Live collaboration disabled")},Ja=Symbol(0);class Wa extends HTMLElement{constructor(t){super(),this.g=t}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML='',this.C=!1;const e=e=>n(t,e);this.H=e;const o=t=>{this.contains(t.target)||s()};let i;let a=null;const s=()=>{a.remove(),a=null,r(document,"pointerdown",o),i&&i()},d=()=>{c(document,"pointerdown",o,!0),i=V(s),a=function(t,n,e){const o=wo(),i=o||Ze,a=Do(t)?.i?"Save and sync with cloud":"Save",s=m(`
New
Open
${i?'
'+a+"
":""}
Save${De||i?" as":""}
${Po()?xn+"Download":bn+"Send"} image
Share
Live collaboration
${o?o.n:"Log in"}
`);s.setAttribute("options","");const d=(t,n)=>l(s,t,(async t=>{e(),await n(t)}));l(s,"[menu2]",(t=>e())),d("[new]",(()=>{ta(t)})),i&&d("[save]",(async()=>await Va(t)));return d("[saveas]",(()=>za(t))),d("[open]",(async()=>await ua(t))),d("[collab]",(async n=>await async function(t){const n=()=>Ga(t),e=()=>qa(t);try{switch(t[Ja]?.clientType){case 1:Xa(t[Ja].id,n);break;case 2:Xa(t[Ja].id,n,!0);break;default:{const o=await _a(t,n,e);if(!o)return;c(t,"dgrmn",e,!0),t[Ja]={clientType:1,id:o.id,dispose:()=>{r(t,"dgrmn",e),o.dispose()}},Hi(!0),Xa(t[Ja].id,n);break}}}catch{e()}}(t))),d("[login]",(t=>function(){const t=wo();vt(m(t?`
${t.n}
${t.l}
Log out Delete account Delete account and all data. Disable auto payment for subscription.
`:'
Log in to access
cloud storage
'))}())),d("[link]",(n=>(t=>na(Do(t),!1))(t))),d("[down]",(n=>(t=>ao(t,Ft(t),(async n=>await Ro(t,n))))(t))),s}(this.g,this.C,(()=>s())),t.append(a)};c(e("menu"),"click",(t=>d()))}bage(t){(t?i:a)(this.H("menu"),"bage"),this.C=t}}customElements.define("ap-menu",Wa);class Qa extends HTMLElement{constructor(t){super(),this.g=t}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML='';const n=t.getElementById("smenu");n.querySelectorAll('[data-cmd="shapeAdd"]').forEach((t=>{c(t,"pointerdown",this),c(t,"click",this)})),c(n,"pointerleave",this),c(n,"pointerup",this),c(n,"pointermove",this);const e=t.getElementById("m");let o;c(e,"click",(t=>{o?(o(),o=null,e.style.opacity="0.4"):(o=vi(this.g),e.style.opacity="1")}))}handleEvent(t){switch(t.type){case"pointermove":if(!this.L){const n=document.elementFromPoint(t.clientX,t.clientY);if(n===this.V)return;this.S===this.V&&this.g.ownerSVGElement.setPointerCapture(t.pointerId),this.V=n}break;case"pointerleave":if(this.L=!0,null!=this.Z){const n=ts(this.g,this.Z,!1,t.clientX,t.clientY)[0];h(t)||this.g[et].select([n]),n[It]?n[It]?.moveCapture(t,n,!0):n[Ut]?.moveCapture(t,n,!0)}this.D();break;case"pointerdown":this.Z=parseInt(d(t,"data-cmd-arg")),this.S=document.elementFromPoint(t.clientX,t.clientY),this.V=this.S,this.L=null;break;case"pointerup":this.D();break;case"click":this.g.ownerSVGElement.focus(),this.g[et].select(ts(this.g,parseInt(d(t,"data-cmd-arg")),!0))}}D(){this.Z=null,this.S=null,this.V=null}}customElements.define("ap-menu-shape",Qa);const ts=(t,n,e,o,i)=>{return dn(t,Yt((a=n,Tt.get(a)())),e,o,i);var a};const ns=document.getElementById("canvas");var es,os,is,as,ss;ns[et]={data:{position:{x:0,y:0},scale:1,cell:24},shapeMap:function(n){const e=(t,e)=>Dn(n,t,e);return{0:{create:t=>e(Yn(n,t),3)},1:{create:i=>e(function(n,e){e.r??=48;let i,a=e.r;const s=he(n,e,' ',{right:{dir:"right",position:{x:48,y:0}},left:{dir:"left",position:{x:-48,y:0}},bottom:{dir:"bottom",position:{x:0,y:48}},top:{dir:"top",position:{x:0,y:-48}}},(()=>(i=I(e.position,-e.r),{x:e.r,y:e.r})),(r=>{let l=it(n[et].data,r).x-i.x;l<48&&(l=48);const d=48*Math.round(l/48)/2;e.r!==d&&we(t(s.el,"text"))<=d&&(e.r=d,e.position.x=i.x+d,e.position.y=i.y+d,c(),a=d);const u=l-e.r;o(r.target,{x:u,y:u})}),(t=>{const n=we(t,a);n!==e.r&&(e.r=n,c())}));function c(){s.cons.right.position.x=e.r,s.cons.left.position.x=-e.r,s.cons.bottom.position.y=e.r,s.cons.top.position.y=-e.r,kn(s),ge(s.el,"outer",e.r+24),ge(s.el,"main",e.r),s.draw()}return 48!==e.r?c():s.draw(),s.el[It].patch=t=>{const n=Ln(s,t),o=null!=t.r&&e.r!==t.r;o&&(e.r=t.r,a=e.r),o?c():n&&s.draw(),t.styles&&(ve=[...t.styles])},s.el}(n,i),2)},2:{create:t=>e(xe(n,t),2)},3:{create:t=>e(je(n,t),2)},4:{create:a=>e(function(n,e){e.w??=96;let a,s=e.w;const c=he(n,e,' ',{right:{dir:"right",position:{x:48,y:0}},left:{dir:"left",position:{x:-48,y:0}},bottom:{dir:"bottom",position:{x:0,y:48}},top:{dir:"top",position:{x:0,y:-48}}},(()=>{const t=e.w/2;return a=I(e.position,-t),{x:t,y:t}}),(i=>{let l=it(n[et].data,i).x-a.x;l<48&&(l=48);const d=48*Math.round(l/48);if(e.w!==d&&to(t(c.el,"text"))<=d){e.w=d;const t=d/2;e.position.x=a.x+t,e.position.y=a.y+t,r(),s=d}const u=l-e.w/2;o(i.target,{x:u,y:u})}),(t=>{const n=to(t,s);n!==e.w&&(e.w=n,r())}));function r(){const t=Qe(e.w,0);c.cons.right.position.x=t.r.x,c.cons.left.position.x=t.l.x,c.cons.bottom.position.y=t.b.y,c.cons.top.position.y=t.t.y,kn(c);const n=Qe(e.w,9);We(c.el,"main",n),We(c.el,"border",n),We(c.el,"outer",Qe(e.w,-24)),c.draw()}return i(c.el,"shrhomb"),96!==e.w?r():c.draw(),c.el[It].patch=t=>{const n=Ln(c,t),o=null!=t.w&&e.w!==t.w;o&&(e.w=t.w,s=e.w),o?r():n&&c.draw(),t.styles&&(Je=[...t.styles])},c.el}(n,a),2)},5:{create:t=>e(He(n,t),1)},6:{create:t=>e(Pe(n,t),0)},7:{create:t=>e(function(t,n){const e=pe(t,n,gi(n),{},null,null,null,Ee,(()=>{Mi(n.position)}));return i(e.el,"shmrk"),e.draw(),e.el[It].patch=t=>{Vn(e,t)&&e.draw()},e.el}(n,t),4)}}}(ns)},ns.ownerSVGElement.addEventListener("contextmenu",(async t=>{u(t)||t.preventDefault()})),function(t){let n,e,o;function i(t){t.isPrimary&&t.isTrusted&&(n&&Math.abs(n.x-t.clientX)<3&&Math.abs(n.y-t.clientY)<3?t.stopImmediatePropagation():(n=null,void 0===t.movementX?(t[tt]=e?t.clientX-e:0,t[nt]=o?t.clientY-o:0,e=t.clientX,o=t.clientY):(t[tt]=t.movementX,t[nt]=t.movementY)))}t.addEventListener("pointerdown",(a=>{n={x:a.clientX,y:a.clientY},e=null,o=null,t.addEventListener("pointermove",i,{capture:!0,passive:!0}),t.addEventListener("pointerup",(n=>{r(t,"pointermove",i,!0)}),{capture:!0,once:!0,passive:!0})}),{capture:!0,passive:!0})}(document),function(t){c(document,"paste",(async n=>{u(n)||Ua(t,(t=>{const n=t.getData("text/plain"),e=mo(n);return e?{data:e}:t.files?.length&&t.files.item(0).type?.startsWith("image/")?{img:t.files.item(0)}:n?{txt:n}:null})(n.clipboardData))}));const n=Z((async()=>await Va(t)),500);document.addEventListener("keydown",(async e=>{if((e.ctrlKey||e.metaKey)&&"KeyS"===e.code&&e.preventDefault(),(e.ctrlKey||e.metaKey)&&!e.repeat&&!u(e))switch(e.code){case"KeyZ":ht(),Gi(t);break;case"KeyY":ht(),qi(t);break;case"KeyS":ht(),e.shiftKey?za(t):n();break;case"KeyA":ht(),_o(t)}}))}(ns),function(t){const n=t.ownerSVGElement;let e,a,s,l,d;const u=()=>{d?.remove(),d=null};let h=!1;function p(t){if(t[Io]||!s)return void v();t[Io]=!0,h&&(u(),h=!1);const n=t.clientX-a.x,e=t.clientY-a.y;s.width.baseVal.value=Math.abs(n),s.height.baseVal.value=Math.abs(e),n<0&&(l.x=t.clientX),e<0&&(l.y=t.clientY),s.style.transform=`translate(${l.x}px, ${l.y}px)`}function m(n){if(s&&!h){n[Io]=!0;const e=n=>ja(ot(t[et].data,l.x,l.y),s.width.baseVal.value/t[et].data.scale,s.height.baseVal.value/t[et].data.scale,n.x,n.y);!function(t,n,e,o){const i=Xo(),a=t=>Go(i,t),s=t=>t.shape&&e(t.shape.shapeEl)||o(t);for(const t of n)if(t[It])e(t)&&a({shape:t});else if(t[Ut]){const n=s(t[Ut].data.s),e=s(t[Ut].data.e);n&&e?a({path:t}):n?a({pathEnd:t[Ut].data.s}):e&&a({pathEnd:t[Ut].data.e})}t[et].selectedSet(i)}(t,t.children,(t=>e(t[It].data.position)),(t=>e(t.data.position)))}v()}function v(){clearTimeout(e),e=null,s?.remove(),s=null,u(),h=!1,r(n,"pointermove",p),r(n,"wheel",v),r(n,"pointercancel",v),r(n,"pointerup",m)}c(n,"pointerdown",(r=>{if(!r.isPrimary||At(r)!==n||Oa(r))return void v();c(n,"pointermove",p),c(n,"wheel",v,!0),c(n,"pointercancel",v,!0),c(n,"pointerup",m,!0);const u=()=>{t[et].selectedSet(null),h=!0,n.setPointerCapture(r.pointerId),a={x:r.clientX,y:r.clientY},l={x:r.clientX,y:r.clientY},s=f("rect"),s.style.cssText="rx:8px; fill: rgb(108 187 247 / 51%)",o(s,l),n.append(s)};2!==r.button?e=setTimeout((t=>{u(),d=f("circle"),i(d,"ative-elem"),d.style.cssText="r:10px; fill: rgb(108 187 247 / 51%)",o(d,{x:r.clientX,y:r.clientY}),n.append(d)}),500):u()}))}(ns),function(t){const n=t.ownerSVGElement;let e,o=Xo();const i=()=>{e&&(e[wt]?.del(),e=null)};let a,s;c(n,"pointerdown",(l=>{if(i(),!l.isPrimary)return r(n,"pointermove",a),r(n,"pointerup",s),void t[et].moveCapture();s=s=>{var c;r(n,"pointermove",a),c=Oo(t,o,s),i(),e=c},c(n,"pointerup",s,!0),a=e=>{r(n,"pointerup",s),jo(t,o,e,At(l))},0===l.button&&c(n,"pointermove",a,!0)})),vo(t,(()=>Qo(o)),(()=>{e?i():si(o)&&!ii(o)&&t[et].select(null)}));const l=t=>{Wo(o),o=t??Xo(),ti(o,null)};t[et].selectedSet=l,t[et].select=t=>{i();const n=Xo();if(t?.length)for(const e of t)Go(n,ci(e));l(n)}}(ns),function(t){const n=t[et].data,e=function(t,n){let e;function o(n){e!==n&&(e=n,t.style.backgroundImage=`radial-gradient(rgb(73 80 87 / ${n}) 1px, transparent 0)`)}return o(.6),t.style.backgroundSize=`${n.cell}px ${n.cell}px`,function(){const e=n.cell*n.scale;n.scale<.5?o(0):n.scale<=.9?o(.2):o(.6),t.style.backgroundSize=`${e}px ${e}px`,t.style.backgroundPosition=`${n.position.x}px ${n.position.y}px`}}(t.ownerSVGElement,n);function o(){t.style.transform=`matrix(${n.scale}, 0, 0, ${n.scale}, ${n.position.x}, ${n.position.y})`,e()}function i(t,e){if(t<.25||t>4)return;const i=t/n.scale;n.scale=t,n.position.x=i*(n.position.x-e.x)+e.x,n.position.y=i*(n.position.y-e.y)+e.y,o()}!function(t,n,e,o){let i,a,s,l,d=!1;function u(t){s=null,l=null,i?.id===t.pointerId&&(i=null),a?.id===t.pointerId&&(a=null),i||a||(r(document,"pointermove",h),r(document,"pointercancel",u),r(document,"pointerup",u),d=!1)}function h(t){if(d){if(i&&!a||!i&&a)return n.position.x=t.clientX+(i||a).shift.x,n.position.y=t.clientY+(i||a).shift.y,void o();if(!a||!i||a?.id!==t.pointerId&&i?.id!==t.pointerId)return;const c=Math.hypot(i.pos.x-a.pos.x,i.pos.y-a.pos.y),r={x:(i.pos.x+a.pos.x)/2,y:(i.pos.y+a.pos.y)/2};s&&(n.position.x=n.position.x+r.x-l.x,n.position.y=n.position.y+r.y-l.y,e(n.scale/s*c,r)),s=c,l=r}i?.id===t.pointerId&&(i=st(t,n)),a?.id===t.pointerId&&(a=st(t,n))}c(t.ownerSVGElement,"pointerdown",(t=>{!i&&!t.isPrimary||i&&a||(i||(c(document,"pointermove",h),c(document,"pointercancel",u),c(document,"pointerup",u),i=st(t,n)),a||i?.id===t.pointerId||(a=st(t,n)))})),t[et].moveCapture=()=>{d=!0}}(t,n,i,o),t.ownerSVGElement.addEventListener("wheel",(t=>{t.preventDefault();const e=()=>{n.position.x-=t.deltaX,n.position.y-=t.deltaY,o()},a=e=>i(n.scale+e,p(t));Math.abs(t.deltaY)>50?t.ctrlKey?e():a(t.deltaY<0?.25:-.25):t.ctrlKey?a(-.01*t.deltaY):e()})),t[et].move=function(t,e,i){n.position.x=t,n.position.y=e,n.scale=i,o()},t[et].scale=i}(ns),function(t){const n=t.ownerSVGElement,e=t.ownerDocument;let o,i,a,s;function d(n){r(e,"pointermove",p),r(e,"pointerup",u),a||(a=function(t,n,e,o){const i=m(`${po?'
Paste
':""}
Select all
Add image
`),a=(t,n)=>l(i,t,(async t=>{await n(),o()}));po&&a("[p]",(async()=>Ua(e,await(async()=>{let t;try{t=await(navigator.clipboard?.read())}catch{}if(!t?.length)return null;const n=t[0],e=n.types.includes("text/plain")?await(await n.getType("text/plain")).text():null,o=mo(e);if(o)return{data:o};const i=n.types.find((t=>t.startsWith("image/")));return i?{img:await n.getType(i)}:e?{txt:e}:null})(),t,n)));a("[s]",(async()=>_o(e))),a("[i]",(async()=>async function(t,n,e){const o=await Se(Te);o&&Ae(t,o.f,n,e)}(e,t,n)));return{del:ft(i,t-10,n-10)[wt].del,el:i}}(n.clientX,n.clientY,t,u),c(e,"pointerdown",h))}function u(){clearTimeout(o),o=null,a?.del(),a=null,r(e,"pointerdown",h),r(e,"pointerup",u),r(e,"wheel",u),r(e,"keydown",u),r(e,"pointerup",v),r(e,"pointercancel",v),r(e,"pointermove",f),i=!1,s=!1}function h(t){a.el.contains(t.target)||u()}function p(){u(),i=!0}function f(){s||u(),i=!0}function v(){s=!0}c(n,"pointerdown",(async function(t){t.isPrimary&&At(t)===n?(u(),c(e,"pointermove",p,!0),c(e,"pointerup",u,!0),c(e,"wheel",u,!0),c(e,"keydown",u,!0),2!==t.button&&(o=setTimeout((n=>{d(t),c(e,"pointerup",v,!0),c(e,"pointercancel",v,!0),c(e,"pointermove",f,!0)}),500))):u()})),n.addEventListener("contextmenu",(async t=>{n===At(t)&&(t.preventDefault(),i||d(t))}))}(ns),(t=>{const n=(n,e)=>c(t,n,(t=>{t[Yi]||e(t)}));n("dgrmc",(n=>Ni(t,n.detail.newIds,n.detail.shapesToCreateData))),n("dgrmd",(n=>Oi(t,n.detail.delIds,n.detail.shapesToDelData))),n("dgrmu",(n=>ji(t,n.detail.shapesBeforeUpdData,n.detail.shapesToUpdData))),n("dgrmdc",(n=>Fi(t,n.detail.delIds,n.detail.shapesToDelData,n.detail.newIds,n.detail.shapesToCreateData)))})(ns),function(t){document.body.addEventListener("dragover",(t=>{t.preventDefault()})),document.body.addEventListener("drop",(async n=>{if(n.preventDefault(),1===n.dataTransfer?.items?.length&&"file"===n.dataTransfer.items[0].kind&&n.dataTransfer.items[0].type.startsWith("image/"))if("getAsFileSystemHandle"in n.dataTransfer.items[0]){const e=await n.dataTransfer.items[0].getAsFileSystemHandle(),o=await ba(t,await e.getFile(),n);o&&zo(t,e,o)}else{const e=n.dataTransfer.items[0].getAsFile(),o=await ba(t,e,n);o&&So(t,Y(e.name),o)}else ka()}))}(ns),(t=>{t[Aa]={c:new Set,u:new Set,d:new Set};const n=n=>{t[Aa].c.add(n),t[Aa].u.delete(n),t[Aa].d.delete(n)},e=n=>{t[Aa].c.has(n)||t[Aa].u.add(n),t[Aa].d.delete(n)},o=n=>n?.forEach((n=>{t[Aa].d.add(n),t[Aa].c.delete(n),t[Aa].u.delete(n)})),i=t=>Object.keys(t.s).forEach(e);c(t,"dgrmc",(t=>{t.detail.newIds?.forEach(n)})),c(t,"dgrmu",(t=>i(t.detail.shapesToUpdData))),c(t,"dgrmd",(t=>o(t.detail.delIds))),c(t,"dgrmdc",(t=>{o(t.detail.delIds),t.detail.newIds?.forEach(n)})),c(t,Bi,(t=>i(t.detail))),c(t,Ti,(t=>o(t.detail))),t.addEventListener("dgrmn",(n=>{!Ta(t)||window.confirm("Changes you made may not be saved. Continue?")?Ea(t):n.preventDefault()})),window.addEventListener("beforeunload",(n=>{Ta(t)&&n.preventDefault()}))})(ns);{const t=new URL(window.location.href),n=n=>t.searchParams.get(n);n("usr")&&(es=n("usr"),os=n("usrn"),is=parseInt(n("expr")),localStorage.setItem("dgrm",X({l:es,n:os,e:is})),M("usr","usrn","expr"))}(t=>{const n=new Wa(t);n.id="menu",v(n)})(ns),v(new Ia(ns)),v(new Qa(ns));{const t=new URL(window.location.href),e=n=>t.searchParams.get(n);if(e("k")){rt(!0);const t=e("k");try{const n=await zt(t);Ai(ns,n.d),Vo(ns,t,n.n,n.e,n.m,n.l)}catch(n){console.log(n),alert("The link is broken or you do not have permission. Try to relogin."),await(ss=t,new Promise(((t,n)=>Ho(xo(),ss,(()=>t())))))}M("k"),rt(!1)}else if(e("l")){try{const t=e("l"),n=await(as=t,new Promise(((t,n)=>Co(xo(),as,t))));n&&(Ai(ns,n.s),So(ns,n.n,n.s))}catch{alert("The link is broken.")}M("l")}else if(e("m")){const t=e("m");M("m"),await async function(t,n){const e=()=>qa(t);try{const o=await Ya(t,n,(()=>Ga(t)),e);if(!o)return;c(t,"dgrmn",e,!0),t[Ja]={clientType:2,id:n,dispose:()=>{r(t,"dgrmn",e),o()}},Hi(!0)}catch{e()}}(ns,t)}else wo()||function(){const t=m('');function e(){t.remove(),r(document,"pointerdown",o),r(document,"wheel",e),r(document,"keydown",e),r(document,"dragover",e)}function o(n){t.contains(n.target)||e()}t.style.display="unset",c(document,"pointerdown",o),c(document,"wheel",e,!0),c(document,"keydown",e,!0),c(document,"dragover",e,!0),c(n(t,"cl"),"click",(t=>e()),!0),v(t)}()}