diff --git a/index.html b/index.html index a820318..5040ad9 100644 --- a/index.html +++ b/index.html @@ -47,7 +47,7 @@ color: rgb(73, 80, 87); } - svg a { fill:#fff; text-decoration: underline; pointer-events: all !important; } + svg a { fill:#fff; text-decoration: underline; pointer-events: all; } svg .select a { pointer-events: none; } svg .shtxt a { fill: rgb(13, 110, 253); } @@ -181,6 +181,6 @@ - + \ No newline at end of file diff --git a/index.js b/index.js index 6e2358b..4cee453 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)=>{t.style.pointerEvents=n?"unset":"none"},r=(t,n,e,o,i)=>(t.addEventListener(n,e,{passive:!0,once:o,signal:i}),e),l=(t,n,e,o)=>r(n,e,o,void 0,t),d=(t,n,e,o)=>t?.removeEventListener(n,e,{capture:o}),u=(t,n,e)=>t.querySelectorAll(n).forEach((t=>r(t,"click",e))),p=(t,n)=>t.currentTarget.getAttribute(n),h=t=>"TEXTAREA"===t.target.tagName.toUpperCase()||"INPUT"===t.target.tagName.toUpperCase(),f=t=>"mouse"===t.pointerType,m=t=>({x:t.clientX,y:t.clientY});function v(t,n){const e=document.createElementNS("http://www.w3.org/2000/svg",t);return n&&(e.innerHTML=n),e}const g=(t,n)=>{const e=document.createElement("div");return t&&(e.innerHTML=t),e.style.cssText=n,e},w=(...t)=>document.body.append(...t);function y(t){let n,e=0;for(const o of t.getElementsByTagName("tspan"))for(const t of x(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 b(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},k=(t,n)=>$(t,{method:"POST",body:n}),M=(t,n)=>$(t,{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:n?W(n):null}),C=(t,n)=>{const e=new URL(window.location.href);return e.searchParams.set(t,n),e.toString()},H=(...t)=>{const n=new URL(window.location.href);t?.forEach((t=>n.searchParams.delete(t))),history.replaceState(null,null,n.toString())};function L(t,n,e,o){function i(n){d(t,"pointercancel",i),d(t,"pointerup",i),d(t,"wheel",i),d(document,"pointerdown",i),d(t,"pointermove",e),o(n)}r(t,"pointercancel",i,!0),r(t,"pointerup",i,!0),r(t,"wheel",i,!0),r(document,"pointerdown",i,!0),r(t,"pointermove",e),t.setPointerCapture(n.pointerId)}const V=(t,n)=>z(t.ownerSVGElement,t,n);function z(t,n,e,o){const i=()=>{d(t,"pointercancel",a),d(t,"wheel",a),d(t,"pointerdown",a)},a=t=>{o&&o(t),n.contains(t.target)||(i(),e(t))};return r(t,"pointercancel",a),r(t,"wheel",a),r(t,"pointerdown",a),i}const S=t=>{const n=n=>{"Escape"===n.key&&t()};return r(document,"keydown",n),()=>d(document,"keydown",n)},D=(t,n,e)=>new CustomEvent(t,{detail:n,cancelable:e}),B=(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 E(t,n,e){return t??=0,e<=t?t:t+Math.ceil((e-t)/n)*n}const T=t=>Math.round(100*(t+Number.EPSILON))/100,A=(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 R(t,n){const e=t.indexOf(n);e>-1&&t.splice(e,1)}function P(t,n){for(let e=t.length-1;e>=0;--e)n(t[e])}const U=t=>t?[...t]:t,I=t=>t.values().next().value;function N(t,n,e){const o=e??1;return t.x+=o*n.x,t.y+=o*n.y,t}const O=(t,n)=>({x:t.x+n,y:t.y+n}),j=(t,n)=>F(t,n.x,n.y),F=(t,n,e)=>(t.x=n,t.y=e,t),Y=t=>({x:t.x,y:t.y}),K=(t,n)=>t?.x===n?.x&&t?.y===n?.y;function _(){const t=new Uint8Array(4);return window.crypto.getRandomValues(t),Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("")}const X=t=>t?.substring(0,t.lastIndexOf("."))||t,G=t=>q(W(t)),W=t=>JSON.stringify(t),q=t=>JSON.parse(t),J=(t,n)=>{Object.hasOwn(t,n)&&(t[n](),delete t[n])},Q=(t,n,e)=>{Object.hasOwn(t,n)||(t[n]=e())},tt=(t,n)=>t?n:"",nt=t=>tt(t,"disabled"),et=(t,n,e)=>t?.length?t.map(n).join(" "):e??"",ot=()=>screen.width>768;function it(t,n,e){t.x+=e[at]/n,t.y+=e[st]/n}const at=Symbol("movementX"),st=Symbol("movementY"),ct=Symbol("Canvas");let rt;function lt(t){t&&!rt?(rt=g("","z-index: 2; position: fixed; left: 0; top: 0; width:100%; height:100%; background: #fff; opacity: 0"),rt.classList.add("blnk"),w(rt)):t||(rt?.remove(),rt=null)}const dt=async t=>{try{return lt(!0),await t()}catch(t){console.log(t),alert("Error")}finally{lt(!1)}};function ut(t,n,e,o,i){const a=g(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),w(a),null!=n?s(n,e):a.style.transform="translate(-50%, -30%)",a[yt]={position:s,del:()=>{a?.remove()}},a}const pt=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[yt]?.del()}};function ft(t,n,e,o,i,a){const s=g(null,"z-index: 2; position: fixed; left: 0; top: 0; width:100%; height:100%; "+(o?"background-color: rgba(52,71,103,.05);":""));w(s);const c=ut(t,n,e,i,a);s.append(c);const l=vt(s,c,(t=>{"pointerdown"===t?.type?r(s,"click",(t=>{t.stopImmediatePropagation(),u()}),!0):u()}),(t=>t.stopImmediatePropagation())),d=c[yt].del,u=()=>{d(),l(),s.remove()};return c[yt].del=u,c}function mt(t,n,e){const o=ut(t,n,e),i=o[yt].del,a=vt(document,o,(t=>s())),s=()=>{i(),a()};return o[yt].del=s,o}function vt(t,n,e,o){const i=((t,n,e,o)=>z(t,n,e,o))(t,n,e,o),a=S((()=>{((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 gt(t,n,e,o,i){const a=g(""+(o?"":`
Close ${i??""}
`),"display: flex; flex-flow: column; padding: 15px;");a.className=n??"mds",o?a.append(o):u(a,"[ap-close]",(t=>s[yt].del())),a.append(t);const s=e?ft(a,null,null,!0):mt(a);return s}function wt(t,n,e,o){const a=gt(g(`${t}`,"display: flex; flex-flow: column; height: 100%; overflow-y: overlay;"),"mdh",o,n,e);return i(pt(a),"mdhc"),a}const yt=Symbol(0);function xt(t,n){const e=t.getBoundingClientRect(),o=window.innerHeight-e.bottom<40*n.length;!function(t,n,e,o){const i=ft(g(`
${et(t,(t=>t[0]))}
`),n,e,!1,!0,!o);u(i,"a",(n=>{i[yt].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 bt=(t,n)=>[`${t}`,n],$t=(t,n)=>[`${t}`,()=>{confirm("Delete?")&&n()}],kt=t=>$t("Delete",t);function Mt(t){const n=g(`${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",w(n),setTimeout((t=>n.remove()),2800)}const Ct=()=>Mt("Link copied to clipboard"),Ht="https://api.dgrm.net/api/",Lt=`${Ht}s/`,Vt=`${Ht}r/d/`,zt=`${Ht}r/f/`,St=`${Ht}sb/`,Dt=async t=>{const n=await $(`${Lt}${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()}},Bt=async t=>{const n=await $(`${Lt}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(`${Lt}a/c`);return Pt(i,"k",t),n&&Pt(i,"f",n.toString()),Pt(i,"n",e),(await M(i.toString(),o)).text()}const Et=async(t,n)=>parseInt(await(await k(`${St}${t}`,n.toString())).text()),Tt=t=>Et("d",t),At=t=>Et("dp",t);function Rt(){const t=new Date;return`${t.getUTCFullYear()}${(t.getUTCMonth()+1).toString().padStart(2,"0")}${_()}`}const Pt=(t,n,e)=>t.searchParams.set(n,e),Ut=(t,n,e)=>({x:(n-t.position.x)/t.scale,y:(e-t.position.y)/t.scale}),It=(t,n)=>Ut(t,n.clientX,n.clientY);function Nt(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}const Ot=Symbol(0),jt=t=>Q(t,Ot,(()=>function(t){const n=t[ct].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()}const a=function(t,n,e,o){let i,a,s,c,l=!1;function u(t){s=null,c=null,i?.id===t.pointerId&&(i=null),a?.id===t.pointerId&&(a=null),i||a||(d(document,"pointermove",p),d(document,"pointercancel",u),d(document,"pointerup",u),l=!1)}function p(t){if(l){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 r=Math.hypot(i.pos.x-a.pos.x,i.pos.y-a.pos.y),l={x:(i.pos.x+a.pos.x)/2,y:(i.pos.y+a.pos.y)/2};s&&(n.position.x=n.position.x+l.x-c.x,n.position.y=n.position.y+l.y-c.y,e(n.scale/s*r,l)),s=r,c=l}i?.id===t.pointerId&&(i=Yt(t,n)),a?.id===t.pointerId&&(a=Yt(t,n))}const h=t=>{!i&&!t.isPrimary||i&&a||(i||(r(document,"pointermove",p),r(document,"pointercancel",u),r(document,"pointerup",u),i=Yt(t,n)),a||i?.id===t.pointerId||(a=Yt(t,n)))};return r(t.ownerSVGElement,"pointerdown",h),t[ct].moveCapture=()=>{l=!0},()=>{d(t.ownerSVGElement,"pointerdown",h),t[ct].moveCapture=void 0}}(t,n,i,o),s=t=>{t.preventDefault();const e=()=>{n.position.x-=t.deltaX,n.position.y-=t.deltaY,o()},a=e=>i(n.scale+e,m(t));Math.abs(t.deltaY)>50?t.ctrlKey?e():a(t.deltaY<0?.25:-.25):t.ctrlKey?a(-.01*t.deltaY):e()};return t.ownerSVGElement.addEventListener("wheel",s),t[ct].move=function(t,e,i){n.position.x=t,n.position.y=e,n.scale=i,o()},t[ct].scale=i,()=>{a(),t.ownerSVGElement.removeEventListener("wheel",s),t[ct].move=void 0,t[ct].scale=void 0}}(t))),Ft=t=>J(t,Ot);function Yt(t,n){return{id:t.pointerId,pos:m(t),shift:{x:n.position.x-t.clientX,y:n.position.y-t.clientY}}}const Kt=new Map,_t=(t,n)=>Kt.set(t,n);function Xt(t){return Wt(t).find((t=>!t.hasAttribute("data-evt-no")))}function Gt(t){return Wt(t)[0]}function Wt(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 qt=Symbol("path"),Jt=Symbol("shape"),Qt="1.2",tn=()=>({v:Qt,s:{}}),nn=t=>en([...t.children],!1);function en(t,n,e){const o=tn();if(!t?.length)return o;const i=new Map,a=t=>{let e=i.get(t);if(!e){const a=G(t[Jt].data);n&&(a.id=_(),e=a.id),i.set(t,e),o.s[a.id]=a}return e},s=i=>{if(o.s[i[qt].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:G(o.data)}):o.shape?(e&&a(o.shape.shapeEl),{s:o.shape.shapeEl[Jt].data.id,k:o.shape.connectorKey}):{p:G(o.data)};var i},c=i[qt].data,r={id:n?_():c.id,type:0,s:s(c.s),e:s(c.e)};c.styles&&(r.c=G(c.styles)),o.s[r.id]=r};for(const n of t)n[Jt]?(a(n),e&&n[Jt].paths?.forEach(s)):s(n);return o}function on(t){return{v:Qt,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 an=(t,n)=>sn(t,"1.1"===n.v?function(t){const n={v:Qt,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 sn(t,n){if(n.v!==Qt)return alert("Wrong format"),null;const o=new Map;function i(n){let e=o.get(n);return e||(e=rn(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=ln(t,n.s[e],a);o&&s.push(o);break}default:i(n.s[e])}return[...o.values(),...s]}function cn(t,n){const o=e(n.id);return o?((o[Jt]||o[qt]).patch(n),o):t[ct].shapeMap[n.type].create(n)}const rn=(t,n)=>cn(t,G(n)),ln=(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:Y(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?cn(t,o):null};function dn(t){for(const n in t.s)un(t.s[n]);return t}function un(t){switch(t.type){case 0:pn(t.s),pn(t.e);break;case 6:delete t.d,delete t.r;break;case 7:delete t.d}}function pn(t){t.p?(t.k=null,t.s=null):t.p=null}const hn=(t,n,e)=>B(t,fn(n,e)),fn=(t,n)=>D("dgrmc",{newIds:t,shapesToCreateData:n}),mn=(t,n)=>D("dgrmd",{delIds:t,shapesToDelData:n}),vn=(t,n,e)=>B(t,gn(dn(n),dn(e))),gn=(t,n)=>D("dgrmu",{shapesBeforeUpdData:t,shapesToUpdData:n}),wn=(t,n,e,o)=>D("dgrmdc",{delIds:t,shapesToDelData:n,newIds:e,shapesToCreateData:o});function yn(t,n,e,o){const i=N(((t,n,e)=>{const o=Ut(t,n,e);return Nt(o,t.cell),o})(t[ct].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 xn(t,(t=>{t&&(n.x>t.x&&(n.x=t.x),n.y>t.y&&(n.y=t.y),e.x{n&&Nt(N(n,i),t[ct].data.cell)}))}function xn(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 bn=(t,n)=>t[ct].select($n(t,en(n,!0),!0));function $n(t,n,e,o,i){return yn(t,n,null==o?window.innerWidth/2:o,null==i?window.innerHeight/2:i),kn(t,n,e)}function kn(t,n,e){return e&&hn(t,Vn(n),G(n)),Mn(t,n)}function Mn(t,n){return t[ct].select(null),sn(t,n)}function Cn(t,n){((t,n,e)=>{B(t,mn(n,e))})(t,Ln(n),en(n,!1,!0)),zn(n)}function Hn(t,n,e){((t,n,e,o,i)=>{B(t,wn(n,e,o,i))})(t,Ln(n),en(n,!1,!0),Vn(e),G(e)),zn(n),Mn(t,e)}const Ln=t=>t.map((t=>(t[Jt]||t[qt]).data.id)),Vn=t=>Object.keys(t.s),zn=t=>t.forEach((t=>(t[Jt]||t[qt]).del())),Sn='',Dn='',Bn='',Zn='',En=(t,n)=>({id:_(),type:t,position:{x:0,y:0},title:"Title",styles:n});function Tn(n){for(const e in n.cons)o(t(n.el,e),n.cons[e].position)}function An(t,n){const e=t.getBoundingClientRect(),o=ut(n,e.left+10,e.top+10);return{del:o[yt].del,updPos:()=>{const n=t.getBoundingClientRect();o[yt].position(n.left+10,n.top+10)}}}const Rn=(t,n)=>({del:ut(t,n.clientX-66,n.clientY-10)[yt].del}),Pn=(t,n,e)=>{const o=en([n],!1,!1);(n[Jt]??n[qt]).patch(e),vn(t,o,en([n],!1,!1))};function Un(t,n){return function(t,n){const e=t.el[Jt].data;null!=n.title&&e.title!==n.title&&(e.title=n.title,t.drawTxt());n.styles&&(e.styles=n.styles,jn(t.el))}(t,n),In(t,n)}function In(t,n){const e=n.position&&!K(t.el[Jt].data.position,n.position);return e&&j(t.el[Jt].data.position,n.position),e}const Nn=t=>t.forEach((t=>{const n=e(t);n&&On(n)})),On=t=>(t[Jt]||t[qt]).del();function jn(t){const n=(t[Jt]??t[qt]).data;n.styles||(n.styles=[]),P(t.classList,(n=>{n?.startsWith("d-")&&t.classList.remove(n)})),i(t,...n.styles)}const Fn=(t,n,e)=>{const o=(n[Jt]??n[qt]).data;o.styles||(o.styles=[]);const i={styles:G(o.styles)};Pn(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 Yn(t,n,e){return n.setAttribute("bg",e.toString()),Kn(t,n),n}function Kn(t,n){const e=Number(n.getAttribute("bg"));if(4===e)return void t.append(n);const o=t.querySelector(_n(e+1,4).map((t=>`[bg="${t}"]`)).join());o?o.before(n):t.append(n)}const _n=(t,n)=>[...Array(n-t+1).keys()].map((n=>n+t));class Xn extends HTMLElement{constructor(t,n){super(),this.o=n,this.g=t}connectedCallback(){const t=t=>this.o[qt].data.styles?.includes(t)?'class="actv"':"",n=this.attachShadow({mode:"closed"});n.innerHTML=`
`,r(n.getElementById("edit"),"cmd",(t=>{switch(t.detail.cmd){case"style":Fn(this.g,this.o,t.detail.arg);break;case"del":Cn(this.g,[this.o]);break;case"copy":bn(this.g,[this.o])}})),u(n,"[data-cmd]",(t=>{const n=p(t,"data-cmd-arg"),e={styles:this.o[qt].data.styles?G(this.o[qt].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")),Pn(this.g,this.o,e)}))}}function Gn(t,n,e,o){const i=ne(t,n);i.shape={shapeEl:e,connectorKey:o},Jn(t,i)}function Wn(t,n,e){const o=ne(t,n);o.shape.shapeEl!==ee(t,o)&&Qn(t,o),o.shape=null,o.data={dir:o.data.dir,position:e}}function qn(t,n){const e=t[qt].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&&Wn(t,o,a.data.position):function(t,n,e,o){const i=ne(t,n);if(i.shape.shapeEl===e&&i.shape.connectorKey===o)return;i.shape.shapeEl!==e&&i.shape.shapeEl!==ee(t,i)&&Qn(t,i);i.shape={shapeEl:e,connectorKey:o},Jn(t,i)}(t,o,a.shape.shapeEl,a.shape.connectorKey):null!=a.shape?Gn(t,o,a.shape.shapeEl,a.shape.connectorKey):j(i.data.position,a.data.position)};o("s"),o("e")}function Jn(t,n){n.data=te(n.shape).pathAdd(n.shape.connectorKey,t)}customElements.define("ap-path-settings",Xn);const Qn=(t,n)=>te(n.shape)?.pathDel(t),te=t=>t?.shapeEl[Jt],ne=(t,n)=>t[qt].data[n],ee=(t,n)=>(t[qt].data.e===n?t[qt].data.s:t[qt].data.e).shape?.shapeEl;let oe;const ie=(t,n)=>({id:_(),type:0,s:t,e:n,styles:U(oe)});_t(0,(()=>ie({data:{dir:"right",position:{x:-24,y:0}}},{data:{dir:"right",position:{x:24,y:0}}})));function ae(n,e){const o=v("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=pe(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 he(e,-.8,.8)?"left":he(e,.8,2.4)?"top":he(e,2.4,3.2)||he(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=ue(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))),re(e.s),re(e.e)}let r,l;let d,u,p=0;const h=()=>{u&&(u(),u=null)},m=t=>{h(),u=S(t)};function g(t){switch(p){case 0:y();break;case 1:p=2,d=V(o,(t=>w(!0))),m((()=>{w(!0),y()})),function(t){r||(r=Rn(new Xn(n,o),t))}(t)}}function w(t){t||(l=null),p=0,a(o,"select","highlight-s","highlight-e"),le(e.s,1),le(e.e,1),r?.del(),r=null,d&&(d(),d=null),h()}function y(){p=1,i(o,"s"===l?"highlight-s":"e"===l?"highlight-e":"select"),le(e.s,2),le(e.e,2),Kn(n,o),m((()=>{w(!0)}))}return o[qt]={data:e,drawPosition:c,click:(t,n)=>{if(0===p||l){const o=n||t?fe(e,n??Xt(t)):null;me(l,o)||w(),l=o}g(t)},patch:t=>{var n,i,a;e.styles&&(e.styles=t.styles,jn(o),n=[...t.styles],oe=n,R(oe,"d-arw-s"),a="d-arw-e",-1===(i=oe).indexOf(a)&&i.push(a)),t.s&&qn(o,t),c()},moveCapture:(t,i,a)=>{w(!0);const s=a?null:en([o],!1,!0),r=t=>{w(!0),s?vn(n,s,en([o],!1,!0)):hn(n,[e.id],en([o],!1,!0)),f(t)||g()},l=fe(e,i);l?ce(n,o,c,t,l,r):function(t,n,e,o,i){L(n,o,(o=>{!function(t,n,e,o){const i=n=>it(n,t.scale,o);se(n.s,i),n.s.shape?.shapeEl&&n.s.shape?.shapeEl===n.e.shape?.shapeEl||se(n.e,i);n.s.shape||n.e.shape||e()}(t[ct].data,n[qt].data,e,o)}),(o=>{!function(t,n,e){const o=n=>Nt(n,t.cell);se(n.s,o),se(n.e,o),n.s.shape&&n.e.shape||e()}(t[ct].data,n[qt].data,e),i(o)}))}(n,o,c,t,r)},unselect:w,del:function(){w(),Qn(o,e.s),Qn(o,e.e),o.remove()}},e.styles&&i(o,...e.styles),e.s.shape&&Jn(o,e.s),e.e.shape&&Jn(o,e.e),c(),o}function se(t,n){t.shape?(n(te(t.shape).data.position),te(t.shape).drawPosition()):n(t.data.position)}const ce=(t,n,e,o,l,u)=>{n[qt].data[l].shape&&Wn(n,l,It(t[ct].data,o)),c(n);const p=function(t){let n=null;function e(t){const e=Gt(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 r(t,"pointermove",e),function(){d(t,"pointermove",e),a(n,"hover"),a(n?.parentElement,"hover"),n=null}}(n.parentElement);L(n[qt].data[l].el,o,(o=>{it(n[qt].data[l].data.position,t[ct].data.scale,o),e()}),(o=>{const i=Gt(o),a=i?.getAttribute("data-connect");a?Gn(n,l,i.parentElement,a):Nt(n[qt].data[l].data.position,t[ct].data.cell),e(),p(),c(n,!0),u(o)}))};function re(t){t.el.style.transform=`translate(${t.data.position.x}px, ${t.data.position.y}px) rotate(${de(t.data.dir)}deg)`}function le(t,n){t.el.firstElementChild.setAttribute("data-evt-index",n.toString())}const de=t=>"right"===t?180:"left"===t?0:"bottom"===t?270:90,ue=t=>"left"===t?"right":"right"===t?"left":"top"===t?"bottom":"top";const pe=(n,...e)=>e.map((e=>t(n,e))),he=(t,n,e)=>n<=t&&t<=e,fe=(t,n)=>t.e.el.contains(n)?"e":t.s.el.contains(n)?"s":null,me=(t,n)=>!t||t===n,ve=(t,n,e)=>we(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}(ye(t)))),ge=(t,n,e)=>we(t,n,e,ye);function we(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 ye(t){return t.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'").replaceAll(" "," ")}const xe=(t,n)=>An(n,$e(t,n)),be=(t,n,e)=>Rn($e(t,n),e);function $e(t,n){const e=new ke;return r(e,"cmd",(e=>{switch(e.detail.cmd){case"style":Fn(t,n,e.detail.arg);break;case"del":Cn(t,[n]);break;case"copy":bn(t,[n])}})),e}class ke extends HTMLElement{connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML=`
${Dn} ${Sn}
`;{const n=t.getElementById("pnl");let e;u(t,"[data-toggle]",(o=>{const i=t=>{const e=pt(this),o=e.getBoundingClientRect().top,i=n.getBoundingClientRect().height;e.style.top=`${o+window.scrollY+t*i}px`};e&&(i(1),Me(e,!1));const a=t.getElementById(p(o,"data-toggle"));e!==a?(Me(a,!0),i(-1),e=a):e=null}))}u(t,"[data-cmd]",(t=>{this.dispatchEvent(new CustomEvent("cmd",{detail:{cmd:p(t,"data-cmd"),arg:p(t,"data-cmd-arg")}}))}))}}function Me(t,n){t.style.display=n?"unset":"none"}function Ce(n,e,o,i,a,s,c,r,l=0,d){const u=Le(e.id,o,i),p={el:t(u,"text"),vMid:l};d??=ve;const h=()=>d(p.el,p.vMid,e.title);h();return{el:u,cons:i,draw:Ve(n,u,e,i,p,r??xe,(t=>c(p.el,t)),a,s,null).draw,drawTxt:h}}function He(t,n,e,o,i,a,s,c,r){const l=Le(n.id,e,o);return{el:l,cons:o,draw:Ve(t,l,n,o,null,c??be,null,i,a,s,r).draw}}customElements.define("ap-shape-edit",ke);const Le=(t,n,e)=>{const o=v("g",`${n}\n\t${Object.entries(e).map((t=>``)).join()}`);return o.id=t,o};function Ve(t,n,e,s,c,r,l,d,u,p,h){let m,g,w,y;e.styles??=[];const x=()=>en([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 h=G(s),m=new Set;let g,w,y,x=0;function b(){g?.remove(),g=null}const $=()=>{y&&(y(),y=null)},k=t=>{$(),y=S(t)};function M(){n.style.transform=`translate(${e.position.x}px, ${e.position.y}px)`;for(const t in s)h[t].position={x:s[t].position.x+e.position.x,y:s[t].position.y+e.position.y};for(const t of m)t[qt].drawPosition()}function C(){x=1,i(n,"select"),l&&(g=function(t,n){const e=v("circle");return e.setAttribute("data-evt-index","2"),i(e,"resizer"),o(e,n),t.append(e),e}(n,l())),k((()=>H()))}function H(t){r(),x=0,a(n,"select","highlight"),t||b(),w&&(w(),w=null),$()}const z=t=>{switch(x){case 0:C();break;case 1:x=2,a(n,"select"),i(n,"highlight"),b(),w=V(n,(t=>H())),k((()=>{H(),C()}))}c(t,x)},D=(e,o,i)=>{if(o===g){H(!0);const o=en([n],!1,!1);return void L(g,e,d,(e=>{u&&u(),b(),C(),vn(t,o,en([n],!1,!1))}))}H();const a=o.getAttribute("data-connect");if(a){const o=((t,n,e)=>Yn(t,ae(t,ie(n,e)),3))(t,{shape:{shapeEl:n,connectorKey:a}},{data:{dir:ue(h[a].dir),position:It(t[ct].data,e)}});return t[ct].select(f(e)?null:[o]),o[qt].moveCapture(e,o[qt].data.e.el,!0),void m.add(o)}B(e,i)};p??=()=>Nt(e.position,t[ct].data.cell);const B=(o,i)=>{const a=i?null:en([n],!1,!1);L(n,o,(n=>{it(e.position,t[ct].data.scale,n),M()}),(o=>{p(),M(),a?vn(t,a,en([n],!1,!1)):hn(t,[e.id],en([n],!1)),f(o)||C()}))};return n[Jt]={data:e,drawPosition:M,click:z,moveCapture:D,unselect:H,del:function(){H();for(const t of m)t[qt].del();n.remove()},paths:m,pathAdd:function(t,n){return m.add(n),h[t]},pathDel:function(t){m.delete(t)}},M}(t,n,e,s,((o,i)=>{1===i&&Kn(t,n),2===i&&(c&&!m&&(w=e.title,g=x(),ge(c.el,c.vMid,e.title),l(),m=function(t,n,e,o,i){let a=v("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(){ge(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(){m&&(ve(c.el,c.vMid,e.title),l(!0),m?.dispose(),m=null),y?.del(),y=null,g&&w!==e.title&&vn(t,g,x()),g=null,w=null}),d,u,p,h);return e.styles&&i(n,...e.styles),{draw:()=>{$(),y?.updPos&&y?.updPos(),m?.draw()}}}let ze;function Se(n,e,o){t(n,e).r.baseVal.value=o}_t(1,(()=>En(1,U(ze))));const De=(t,n)=>function(t,n,e){const o=y(t);return E(n,e,Math.sqrt(o.x**2+o.y**2))}(t,n,24);let Be;function Ze(n,e){e.w??=96,e.h??=48;const a={w:e.w,h:e.h};let s;const c=Ce(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=N(It(t[ct].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??=Ae(t(c.el,"text")),l)))&&(Te(a,e),r())}),(t=>{const n=Ae(t,a);Ee(e,n)||(Te(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,Tn(t),Re(t.el,"main",n.w,n.h,e,o),Re(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[Jt].patch=t=>{const n=Un(c,t),o=(null!=t.w||null!=t.h)&&!Ee(e,t);o&&(Te(e,t),a.h=e.h,a.w=e.w),o?r():n&&c.draw(),t.styles&&(Be=[...t.styles])},c.el}_t(2,(()=>En(2,U(Be))));const Ee=(t,n)=>t.w===n.w&&t.h===n.h,Te=(t,n)=>{t.h=n.h,t.w=n.w};function Ae(t,n){const e=t.getBBox();return{w:E(n?.w,48,e.width),h:E(n?.h,48,e.height)}}const Re=(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 Pe;function Ue(t,n){let e;n.w??=96,n.h??=96;const a=He(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=Ie(n);return e=t.tCanvas,t.bInner}),(i=>s(function(t,n,e,i){const a=N(It(t[ct].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=Ie(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,Tn(a),Re(a.el,"main",n.w,n.h,t.x,t.y),Re(a.el,"selected",n.w,n.h,t.x,t.y),Re(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(Ie(n).tInner):a.draw(),a.el[Jt].patch=t=>{const e=Un(a,t),o=(null!=t.w||null!=t.h)&&!Ee(n,t);o&&Te(n,t),o?s(Ie(n).tInner):e&&a.draw(),t.styles&&(Pe=[...t.styles])},a.el}function Ie(t){const n=Ne(t.w),e=Ne(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}}}_t(5,(()=>({id:_(),type:5,position:{x:0,y:0},styles:U(Pe)})));const Ne=t=>24*Math.floor(t/2/24);function Oe(t,n){return Ye?async function(t,n){try{const e=await window.showSaveFilePicker({suggestedName:n,types:[Ke]}),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 je(t){const n="AbortError";try{return Fe?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,r(o,"cancel",(t=>e(t)),!0),r(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 Fe="showOpenFilePicker"in window,Ye="showSaveFilePicker"in window,Ke={accept:{"image/png":[".png"]},inputAccept:"image/png"},_e={accept:{"image/*":[".png",".gif",".jpeg",".jpg"]},inputAccept:"image/*"};function Xe(t,n,e){const o=g(`
${Dn} ${Sn}
`);return u(o,"[data-cmd]",(e=>{switch(p(e,"data-cmd")){case"del":Cn(t,[n]);break;case"copy":bn(t,[n])}})),Rn(o,e)}function Ge(t,n,e,o){We(n,(n=>t[ct].select($n(t,on(n),!0,e,o))))}function We(t,n){!function(t,n,e){const o=new Image;o.onload=function(){const i=A(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=A(Math.min(document.body.clientHeight/2,264),e,o),a={id:_(),type:6,position:{x:0,y:0},w:i.w,h:i.h,r:T(o/e),d:t};Je(a),n(a)}))}function qe(t,n){let e;const a=He(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=Ie(n);return e=t.tCanvas,t.bInner}),(i=>s(function(t,n,e,i){const a=N(It(t[ct].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){Je(t);const e=Ie(t);return t.position.x=n.x-e.tInner.x,t.position.y=n.y-e.tInner.y,e.tInner}(n,e))),Xe);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,Tn(a),Re(a.el,"main",n.w,n.h,t.x,t.y),Re(a.el,"selected",n.w,n.h,t.x,t.y),Re(a.el,"outer",n.w+48,n.h+48,t.x-24,t.y-24),a.draw()};return s(Ie(n).tInner),a.el[Jt].patch=t=>{const e=In(a,t),o=(null!=t.w||null!=t.h)&&!Ee(n,t);o&&Te(n,t),o?s(Ie(n).tInner):e&&a.draw()},a.el}function Je(t){t.w=24*Math.round(t.w/24),t.h=T(t.r*t.w)}const Qe=(t,n)=>An(n,new to(t,n));class to extends HTMLElement{constructor(t,n){super(),this.$=n,this.g=t}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML='
';const n=this.$[Jt].data,e=t.getElementById("edit");r(e,"cmd",(t=>{switch(t.detail.cmd){case"style":Fn(this.g,this.$,t.detail.arg);break;case"del":Cn(this.g,[this.$]);break;case"copy":bn(this.g,[this.$])}}));const o=t=>Pn(this.g,this.$,t);i(e,`ta-${n.a}`),u(t,'[data-cmd="a"]',(t=>{const s=Number.parseInt(p(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)})),u(t,'[data-cmd="s"]',(t=>{const s=p(t,"data-cmd-arg"),c={styles:n.styles?G(n.styles):[]};c.styles?.includes(s)?(R(c.styles,s),a(e,s)):(c.styles??=[],c.styles.push(s),i(e,s)),o(c)}))}}let no;function eo(n,e){e.w??=48,e.h??=48,e.a??=1;const o=Ce(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)),Qe,null,lo);i(o.el,"shtxt"),i(o.el,`ta-${e.a}`);const a=()=>t(o.el,"text"),s=(t,n)=>{n&&co(t)&&t.append(ro());const o=oo(t);Ee(e,o)||(Te(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=-Ne(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,Tn(t),Re(t.el,"main",n.w,n.h,e,o),Re(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&&(so(o.el,l,e.a),l=e.a),r=e.w}c!==e.h&&(a().y.baseVal[0].value=ao(e.h),e.position.y+=Ne(e.h)-Ne(c),c=e.h),o.draw()}return d(),48!==e.w||48!==e.h?u(!0):o.draw(),o.el[Jt].patch=t=>{const n=t.position&&!K(e.position,t.position);n&&j(e.position,t.position);let i=!1;t.styles&&(e.styles=t.styles,jn(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=oo(a());Ee(e,t)||(Te(e,t),s=!0)}null==t.w||Ee(e,t)||(Te(e,t),d(),s=!0),null!=t.a&&e.a!==t.a&&(so(o.el,e.a,t.a),e.a=t.a,l=e.a,s=!0),s?(a().y.baseVal[0].value=ao(e.h),u(!0)):n&&o.draw(),t.styles&&(no=[...t.styles])},o.el}function oo(t){const n=t.getBBox();return{w:E(0,48,n.width+12),h:E(0,24,n.height+14)}}customElements.define("ap-rect-txt-settings",to),_t(3,(()=>{const t=En(3,U(no));return no?.includes("d-h")&&(t.w=96),t}));const io=t=>1===t.a?-16:2===t.a?0:16,ao=t=>24-Ne(t);function so(t,n,e){a(t,`ta-${n}`),i(t,`ta-${e}`)}const co=t=>[...t.childNodes].every((t=>![...t.childNodes].some((t=>t.nodeType===Node.TEXT_NODE&&t.textContent?.trim())))),ro=()=>{const t=v("tspan"," ➜");return t.setAttribute("fill","rgb(13, 110, 253)"),t},lo=(t,n,e)=>{ve(t,n,e),co(t)&&t.append(ro())};let uo;function po(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 ho(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}}}_t(4,(()=>En(4,U(uo))));const fo=(t,n)=>E(n,48,function(t){const n=y(t);return 2*(Math.abs(n.x)+Math.abs(n.y))}(t)-20);async function mo(t,n,e){return function(t,n,e){let o,i;const a=vo(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(),go(n),e)}function vo(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 go(t){return new DataView((new TextEncoder).encode(t).buffer).getUint32(0)}const wo=()=>"undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent||"")||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1),yo=(t,n,e)=>xo(t,W(n),null,e);function xo(t,n,e,o){const i=t.ownerSVGElement.cloneNode(!0),a=i.querySelector("#canvas");let c;i.style.backgroundImage=null,e?(c=b(Mo(t,bo)),P(a.children,(t=>((t,n)=>n.some((n=>s(t,n))))(t,bo)?(ko(t),!0):(t.remove(),!1)))):(c=t.getBoundingClientRect(),Mo(a,$o).forEach((t=>ko(t))));const r=i.getElementsByTagName("foreignObject");for(;r[0];)r[0].parentNode.removeChild(r[0]);const l=t[ct].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=A(wo()?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 mo(t,"dgRm",(new TextEncoder).encode(n)):t)))}const bo=["select","highlight"],$o=["select","highlight","highlight-e","highlight-s"],ko=t=>{a(t,...$o),t.querySelector(".resizer")?.remove()},Mo=(t,n)=>t.querySelectorAll(`.${n.join(", .")}`);async function Co(t){const n=await async function(t,n){return vo(await t.arrayBuffer(),go(n))}(t,"dgRm");return n?(new TextDecoder).decode(n):null}const Ho=navigator.clipboard.readText;async function Lo(t,n){const e=`web text/dgrm${W(en(n,!0))}`;await async function(t){try{await navigator.clipboard.writeText(t)}catch(t){alert(t)}}(e),window.ClipboardItem&&xo(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 Vo=t=>{if(!t?.startsWith("web text/dgrm"))return null;try{return q(t.slice("web text/dgrm".length))}catch{return null}};function zo(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(),Lo(t,o),o}return null}async function o(n){const o=await e(n);o&&So(t,o)}return document.addEventListener("copy",e),document.addEventListener("cut",o),function(){d(document,"copy",e),d(document,"cut",o)}}(t,n);function i(o){if(h(o)||"Delete"!==o.key&&"Backspace"!==o.key)"Escape"===o.key&&e();else{const e=n();e?.length&&So(t,e)}}return r(document,"keydown",i),function(){o(),d(document,"keydown",i)}}function So(t,n){t[ct].select(null),Cn(t,n)}const Do=(t,n,e,o,i,a)=>{t[Po]={i:n,n:e,e:o,m:i},Ao(t,0,a,null)},Bo=(t,n,e)=>{const o=X(n.name);t[Po]={f:n,n:o},Ao(t,1,null,e)},Zo=(t,n,e,o=null)=>{t[Po]={n:n},Ao(t,1,o,e)},Eo=t=>{t[Po]=void 0,Ao(t,null,null,null)},To=t=>t[Po],Ao=(t,n,e,o)=>t[ct].f(t,t[Po],n,e,o),Ro=t=>t?.replace(/[/\\?%*:|"<>]/g,"-"),Po=Symbol(0),Uo=async(t,n)=>{const e=`${To(t)?.n??"dgrm"}.png`;if(ot())return void await Oe(n,e);const o={files:[new File([n],e,{type:n.type})]};navigator.canShare&&navigator.canShare(o)?await navigator.share(o):await Oe(n,e)};class Io extends HTMLElement{constructor(t,n){super(),this.g=t,this.M=n}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML=`
${Dn}Create copy
Copy to clipboard
${ot()?Bn+"Download":Zn+"Send"} image
${Sn}Delete
`;const n=()=>pt(this)[yt].del();function e(e,o){r(t.getElementById(e),"click",(t=>{n(),o()}))}e("clone",(()=>bn(this.g,this.M()))),e("copy",(async()=>await Lo(this.g,this.M()))),e("save",(()=>xo(this.g,W(en(this.M(),!1)),!0,(async t=>Uo(this.g,t))))),e("del",(()=>Cn(this.g,this.M())))}}customElements.define("ap-grp-settings",Io);const No=Symbol("p"),Oo=Symbol(0),jo=Symbol(0),Fo=t=>Q(t,jo,(()=>function(t){const n=t.ownerSVGElement;let e,o=Jo();const i=()=>{e&&(e[yt]?.del(),e=null)},a=t=>{i(),e=t};let s,c;const l=e=>{if(i(),!e.isPrimary)return d(n,"pointermove",s),d(n,"pointerup",c),void t[ct].moveCapture();c=e=>{d(n,"pointermove",s),a(Ko(t,o,e))},r(n,"pointerup",c,!0),s=i=>{d(n,"pointerup",c),_o(t,o,i,Xt(e))},0===e.button&&r(n,"pointermove",s,!0)};r(n,"pointerdown",l);const u=zo(t,(()=>oi(o)),(()=>{e?i():di(o)&&!ri(o)&&t[ct].select(null)})),p=t=>{ei(o),o=t??Jo(),ii(o,null)};return t[ct].selectedSet=p,t[ct].select=t=>{i();const n=Jo();if(t?.length)for(const e of t)Qo(n,ui(e));p(n)},()=>{d(n,"pointerdown",l),u(),i(),t[ct].selectedSet=void 0,t[ct].select=void 0}}(t))),Yo=t=>J(t,jo);const Ko=(t,n,e)=>{if(e[No])return null;if("a"===e?.target?.tagName)return null;const o=Xt(e),i=ui(o);if(!i)return ei(n),null;const a=si(n,o),s=li(n);if(s&&a)return pi(i,e),null;if(e.shiftKey||e.ctrlKey){if(s){const t=ri(n);hi(t),Qo(n,t)}return a?ti(n,i):Qo(n,i),ii(n,e),null}return a?mt(new Io(t,(()=>oi(n))),e.clientX-10,e.clientY-10):(ei(n),Qo(n,i),ii(n,e),null)},_o=(t,n,e,o)=>{if(e[No])return;if(t[Oo]?.size)for(const n of t[Oo])if(n(e,o))return;if(o===t.ownerSVGElement)return void t[ct].moveCapture();const i=si(n,o);if(!i&&!f(e))return void t[ct].moveCapture();if(!i&&f(e))return ei(n),void fi(ui(o),e,o);const a=li(n);i&&a?fi(ui(o),e,o):i&&!a&&Xo(t,n,e)},Xo=(t,n,e)=>{const o=()=>Go(n),i=t=>Wo(n,t),a=o();L(t.ownerSVGElement,e,(n=>i((e=>it(e,t[ct].data.scale,n)))),(n=>{i((n=>Nt(n,t[ct].data.cell))),vn(t,a,o())}))},Go=t=>en([...t.shapesToMove,...mi(t.pathEndsToMove)],!1,!0),Wo=(t,n)=>{t.shapesToMove?.forEach((t=>{n(t[Jt].data.position),t[Jt].drawPosition()})),t.pathEndsToMove?.forEach((t=>{n(t.data.position),vi(t)[qt].drawPosition()}))},qo=t=>{t[ct].select(null),t[ct].select(t.children)},Jo=()=>({shapes:new Set,paths:new Set,pathEnds:new Set,shapesToMove:new Set,pathEndsToMove:new Set}),Qo=(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[qt].data.s),t.pathEnds.delete(n.path[qt].data.e);else if(n.pathEnd){const e=vi(n.pathEnd);if(t.paths.has(e))return;t.pathEnds.add(n.pathEnd),i(e,yi(n.pathEnd))}},ti=(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[qt].data.s),t.pathEnds.delete(n.path[qt].data.e),a(n.path,"highlight","highlight-s","highlight-e");else if(n.pathEnd){const e=vi(n.pathEnd);if(t.paths.delete(e)){a(e,"highlight","highlight-s","highlight-e");const o=wi(n.pathEnd);t.pathEnds.add(o),i(e,yi(o))}else t.pathEnds.delete(n.pathEnd),a(e,yi(n.pathEnd))}},ni=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(vi(t))))},ei=t=>{ni(t);const n=ri(t);n&&hi(n),t.pathEnds.clear(),t.pathEndsToMove.clear(),t.paths.clear(),t.shapes.clear(),t.shapesToMove.clear()},oi=t=>[...t.shapes,...t.paths,...mi(t.pathEnds)],ii=(t,n)=>{ai(t);const e=ci(t);e&&(ni(t),pi(e,n))},ai=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[qt].data.s),n(t[qt].data.e)})),t.pathEnds?.forEach(n)},si=(t,n)=>[...t.shapes,...[...t.pathEnds].map((t=>t.el)),...t.paths].some((t=>t.contains(n))),ci=t=>di(t)?ri(t):{},ri=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:I(t.pathEnds)}:{path:I(t.paths)}:{shape:I(t.shapes)},li=t=>!!ri(t),di=t=>t.shapes.size||t.pathEnds.size||t.paths.size,ui=t=>{const n=t[Jt]?{shape:t}:t.parentElement[Jt]?{shape:t.parentElement}:t.parentElement.parentElement[Jt]?{shape:t.parentElement.parentElement}:null;if(n)return n;const e=t[qt]?{path:t}:t.parentElement[qt]?{path:t.parentElement}:null;if(e)return e;const o=gi(t);return o?{pathEnd:o}:null},pi=(t,n)=>{t.shape?t.shape[Jt].click(n):t.path?t.path[qt].click(n):t.pathEnd&&vi(t.pathEnd)[qt].click(n,t.pathEnd.el)},hi=t=>{t.shape?t.shape[Jt].unselect():t.path?t.path[qt].unselect():t.pathEnd&&vi(t.pathEnd)[qt].unselect()},fi=(t,n,e)=>{t.shape?t.shape[Jt].moveCapture(n,e):t.path?t.path[qt].moveCapture(n,e):t.pathEnd&&vi(t.pathEnd)[qt].moveCapture(n,e)},mi=t=>[...t].map(vi),vi=t=>t.el.parentNode,gi=t=>{const n=t.hasAttribute("data-key")?t:t.parentElement.hasAttribute("data-key")?t.parentElement:null;if(!n)return null;const e=n.parentNode[qt].data;return e.s.el===n?e.s:e.e},wi=t=>{const n=vi(t)[qt].data;return n.s===t?n.e:n.s},yi=t=>vi(t)[qt].data.s===t?"highlight-s":"highlight-e";function xi(t){const n=(n,e)=>(function(t,n,e){const o=v("path");c(o),i(o,"mrkp"),t.append(o);const a=[],r=n=>a.push(Ut(t[ct].data,n.clientX,n.clientY)),l=new Set,d=t=>{s(t,"mrkt")&&l.add(t)};d(e),r(n),L(o,n,(t=>{r(t),o.setAttribute("d",Hi(a)),d(document.elementFromPoint(t.clientX,t.clientY))}),(n=>{let e=Li(b([o,...l]));o.remove(),e=Vi(Ut(t[ct].data,e.x,e.y));const i={id:_(),type:7,position:e,d:""},s=[{position:{x:0,y:0},d:Hi(a)}],c=[];l.forEach((t=>{const n=t.parentNode;c.push(n),s.push(n[Jt].data)}));for(const t of s)$i(i,t);c.length?Hn(t,c,on(i)):kn(t,on(i),!0)}))}(t,n,e),!0);return((t,n)=>{t[Oo]??=new Set,t[Oo].add(n)})(t,n),()=>{((t,n)=>{t[Oo]?.delete(n)})(t,n)}}const bi=t=>``;function $i(t,n){const e=ki(n.d),o=Y(n.position);N(o,t.position,-1);let i=n.d;for(const t of e){const n=Y(t);Vi(N(t,o)),i=Ci(i,n,t)}t.d+=i}const ki=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))}})),Mi=t=>`M${t.x} ${t.y}l`,Ci=(t,n,e)=>t.replaceAll(Mi(n),Mi(e));function Hi(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[p,h]=[t[1].x,t[1].y],[f,m]=[(c+p)/2,(r+h)/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 Li=t=>({x:Math.round(t.x+t.width/2),y:Math.round(t.y+t.height/2)}),Vi=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t);function zi(t){return!!Bi(t)&&(t.c[t.i].u(),t.i-=1,!0)}function Si(t){const n=Di(t);return null!==n&&(t.i=n,t.c[n].r(),!0)}const Di=t=>{if(!t)return null;const n=t.i+1;return n<=t.c.length-1?n:null},Bi=t=>t&&t.i>=0,Zi=(t,n,e)=>Ui(t,(()=>{Ri(t,mn(n,e)),sn(t,e),Nn(n)}),(()=>{Ri(t,fn(n,e)),sn(t,e)})),Ei=(t,n,e)=>Ui(t,(()=>{Ri(t,fn(n,e)),sn(t,e)}),(()=>{Ri(t,mn(n,e)),Nn(n)})),Ti=(t,n,e)=>Ui(t,(()=>{Ri(t,gn(e,n)),sn(t,n)}),(()=>{Ri(t,gn(n,e)),sn(t,e)})),Ai=(t,n,e,o,i)=>Ui(t,(()=>{Ri(t,fn(n,e)),sn(t,e),Ri(t,mn(o,i)),sn(t,i),Nn(o)}),(()=>{Ri(t,mn(n,e)),Nn(n),Ri(t,fn(o,i)),sn(t,i)})),Ri=(t,n)=>{n[Pi]=!0,B(t,n)},Pi=Symbol(0);function Ui(t,n,e){t[Yi]??={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[Yi],n,e),ji(t)}function Ii(t,n){n(t[Yi])&&(t[ct].select(null),ji(t))}const Ni=t=>Ii(t,zi),Oi=t=>Ii(t,Si);const ji=t=>{return B(t,D(Fi,(n=t[Yi],{u:Bi(n),r:null!==Di(n)})));var n},Fi="dgrmh",Yi=Symbol("h");class Ki 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");r(this.g,Fi,(t=>{const o=(t,n)=>n?i(t,"actv"):a(t,"actv");o(n,t.detail.u),o(e,t.detail.r)})),r(n,"click",(t=>Ni(this.g))),r(e,"click",(t=>Oi(this.g)))}}function _i(t,n){an(t,n),function(t){const n=t.getBoundingClientRect(),e=window.innerWidth/2,o=window.innerHeight/2;t[ct].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[ct].scale(a,{x:e,y:o})}(t)}customElements.define("ap-history",Ki);const Xi=async()=>{const t=await dt((()=>(async()=>(await $(`${St}l`)).json())())),e=!!t.b,o=wt(`
Your monthly payment is ${t.p}.
Your subscription ${tt(e,`
is paid for by ${t.b}`)}
Delete
${et(t.u,(t=>`
${t.n}
Delete
`))}
${tt(e,`\n\t\t\t\t\n\t\t\t\t\tYour subscription is paid for by ${t.b}.
To buy a subscription for a person you have to get your own subscription.\n\t\t\t\t\tBuy a subscription here.\n\t\t\t\t
`)}
`,null,"Team subscriptions",!1),i=async(t,e)=>{n(o,"pay").innerText=(await dt((()=>e(t)))).toString(),o.querySelector(`[usr="${t}"]`).remove()};u(o,"[del]",(t=>{const n=Number.parseInt(p(t,"del"));Gi((()=>i(n,Tt)),(()=>i(n,At)))})),u(o,"[inv]",(t=>Wi((()=>dt((async()=>{const t=Rt();await navigator.clipboard.writeText(`${Ht}subscription-invite/${t}`),await(t=>k(`${St}a`,t))(t),Ct()}))))))},Gi=(t,n)=>{const e=gt(g('\n\t\t\t\n\t\t\tPerson will lose access for all your diagrams and folders.'),null,!0),o=t=>{e[yt].del(),t()};u(e,"[del]",(()=>o(t))),u(e,"[dpr]",(()=>o(n)))},Wi=t=>{const n=gt(g('
Send the link to the person you want to buy a subscription to.

Subscription fees will be included in your monthly payment. You can cancel person subscription at any time.

Subscription fee is
270 ₽ per month.

The subscription link is one-time only and is active for 24 hours.'),null,!0);u(n,"[crt]",(()=>{n[yt].del(),t()}))};const qi=()=>{if(!document.cookie.includes("dgrma=1"))return null;const t=q(localStorage.getItem("dgrm"));return t&&new Date(t.e)>new Date?t:null},Ji=(t,n,e,o,i)=>{n&&na(Qi(),e,o,n.n,0===e?n.i:n.n,n.i,new Date,i)},Qi=()=>`dgrm${qi()?.l}`,ta=(t,n)=>sa(t,(t=>ea(t.transaction("r","readonly").objectStore("r"),n))),na=(t,n,e,o,i,a,s,c)=>sa(t,(t=>{const r=t.transaction("r","readwrite").objectStore("r");ea(r,(l=>{const d=l.find((t=>t.k===i));l.length>=5&&!d&&oa(t,r,l[l.length-1]);const u=d?.i??a??Rt();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})}))})),ea=(t,n)=>{t.getAll().onsuccess=t=>{n((t.target.result??[]).sort(((t,n)=>n.d.getTime()-t.d.getTime())))}},oa=(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()},ia=(t,n,e)=>sa(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)}})),aa=(t,n,e)=>sa(t,(t=>{const o=t.transaction("r","readwrite").objectStore("r");ea(o,(i=>{const a=i.find((t=>t.k===n));a?oa(t,o,a,e):e()}))})),sa=(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)}},ca=t=>C("k",t);function ra(t){B(t,D("dgrmn",null,!0))&&(!function(t){for(t[ct].select(null);t.firstChild;)On(t.firstChild);t[ct].move(0,0,1)}(t),function(t){var n;(n=t[Yi])&&(n.c=[],n.i=-1),ji(t)}(t),Eo(t))}async function la(t,n){if(!t?.i)return void ua({a:0,u:[]},!0,!0,n);const e=await dt((()=>(async t=>(await $(`${Vt}${t}`)).json())(t.i))),o=ua(e,!1,!t.m,n);t.m&&(ga(o,"[anon]",[wa[0],wa[1],wa[2]],(n=>dt((async()=>{var o,i;e.a!==n[1]&&(e.a=n[1],await(o=t.i,i=n[1],k(`${Vt}a/${o}`,i.toString())))})))),da(o,e.u,((n,e)=>{return o=t.i,M(`${Vt}${o}`,{i:n,r:e});var o})),u(o,"[inv]",(n=>ha((n=>dt((async()=>{const e=Rt();var o,i,a;await navigator.clipboard.writeText(`${Ht}invite/${e}`),await(o=t.i,i=e,a=n,M(`${Vt}i/${o}`,{i:i,r:a})),Ct()}))))))),u(o,"[cop]",(async n=>{await navigator.clipboard.writeText(ca(t.i)),Ct(),o[yt].del()}))}const da=(t,n,e)=>u(t,"[uu]",(o=>{const i=o.currentTarget,a=Number(o.currentTarget.getAttribute("uu")),s=t=>dt((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])}));va(o,[bt(wa[1][0],(()=>s(wa[1]))),bt(wa[2][0],(()=>s(wa[2]))),kt((()=>dt((async()=>{await e(a,wa[0][1]),t.querySelector(`[uitm="${a}"]`).remove()}))))])})),ua=(t,n,e,o)=>wt(`
${pa({i:0,n:"Anyone with the link",r:t.a})} ${et(t?.u,pa)}
${tt(n,'To share, save diagram to the cloud.')} ${tt(e&&!n,'You do not have access to manage permissions.')}
`,null,"Permissions",o),pa=t=>``,ha=t=>{const n=gt(g('
Send a link to the person you want to invite.

Person must have a DGRM subscription.
You can buy subscription for the person.

Permissions: Viewer
The invitation link is one-time only and is active for 24 hours.'),null,!0);let e=1;ga(n,"[prm]",[wa[1],wa[2]],(t=>{e=t[1]})),u(n,"[crt]",(o=>{n[yt].del(),t(e)})),u(n,"[sub]",(t=>{ht(),Xi()}))};async function fa(t){const n=await dt((()=>(async t=>(await $(`${zt}${t}`)).json())(t))),e=ma(n);da(e,n,((n,e)=>((t,n,e)=>M(`${zt}${t}`,{i:n,r:e}))(t,n,e))),u(e,"[inv]",(n=>ha((n=>dt((async()=>{const e=Rt();await navigator.clipboard.writeText(`${Ht}invite-folder/${e}`),await((t,n,e)=>M(`${zt}i/${t}`,{i:n,r:e}))(t,e,n),Ct()}))))))}const ma=t=>wt(`
${et(t,pa,'
The folder is not shared
')}
`,null,"Permissions",!0),va=(t,n)=>xt(t.currentTarget,n),ga=(t,n,e,o)=>u(t,n,(t=>{const n=t.currentTarget;va(t,e.map((t=>bt(t[0],(()=>(async t=>{n.textContent=t[0],o(t)})(t))))))})),wa=[["No access",0],["Viewer",1],["Editor",2]],ya=async t=>{const e=xa(`
${qi()?'':'
Log in to access cloud storage.
'}
`);e.s();const o=t=>{n(e.m,"ftr").style.display=t?"unset":"none"},i=async()=>{await ba(e.h,e.b,(()=>e.m[yt].del())),o(!0)};await i(),u(e.m,"[cld]",(()=>dt((async()=>{o(!1),await $a(t,e.h,e.b,!0,(async t=>await i()))})))),u(e.m,"[dvc]",(async()=>{e.m[yt].del(),await async function(t){try{const n=await je(Ke);if(!n)return;const e=await Za(t,n.f);if(!e)return void Ea();n.h?Bo(t,n.h,e):Zo(t,X(n.f.name),e)}catch(t){console.log(t),Ea()}}(t)}))};const xa=t=>{const e=wt(`
${t}`,g('
')),o=t=>n(e,t);return{m:e,h:o("hdr"),b:o("cnt"),s:()=>{pt(e).style.display="flex"}}},ba=async(t,n,e)=>{t.innerHTML='CloseRecent',u(t,"[c]",e);const o=await new Promise(((t,n)=>ta(Qi(),t)));n.innerHTML=o?.length?et(o,(t=>``)):Pa},$a=async(t,n,e,o,i)=>{let a=await Bt(),s={i:null,n:"Cloud",m:!0,r:!1};const c=[],r=n=>{a.d.delete(n),n===To(t)?.i&&Eo(t),d()},l=(n,e)=>{e&&Eo(t),a.f.delete(n),d()},d=()=>Ma(e,s,a,((n,e)=>dt((async()=>{a.d.get(n).n=await(async(t,n)=>(await k(`${Lt}a/n/${t}`,n)).text())(n,e),n===To(t)?.i&&((t,n,e)=>{t[Po].n=n,Ao(t,0,e,null)})(t,a.d.get(n).n,s?.n),d()}))),(t=>dt((async()=>{var n;await(n=t,M(`${Lt}a/d/${n}`)),r(t)}))),(t=>dt((async()=>{var n;await(n=t,M(`${Vt}r/${n}`)),r(t)}))),(t=>dt((async()=>{c.push(s),s=a.f.get(t),u(),a=await Bt(t),d()}))),((t,n)=>dt((async()=>{a.f.get(t).n=await(async(t,n)=>(await k(`${Lt}f/n/${t}`,n)).text())(t,n),d()}))),(n=>dt((async()=>l(n,await(async(t,n)=>{const e=new URL(`${Lt}f/d/${t}`);return Pt(e,"k",n),(await M(e.toString())).json()})(n,To(t)?.i))))),(n=>dt((async()=>l(n,await(async(t,n)=>(await k(`${zt}r/${t}`,n)).json())(n,To(t)?.i)))))),u=()=>ka(n,s,o,i,(()=>dt((async()=>{const t=c.pop();s=t,u(),a=await Bt(t.i),d()}))),(t=>dt((async()=>{const n=await(async t=>(await k(`${Lt}f/a`,t)).json())(t);n.m=!0,a.f.set(n.i,n),d()}))),((t,n)=>dt((async()=>{const e=Rt();a.d.set(e,{i:e,n:await Zt(e,t,n,tn()),d:Date.now(),m:!0,r:!1}),d()}))));return d(),u(),()=>({f:s,d:a})},ka=(t,n,e,o,i,a,s)=>{t.innerHTML=`\n\t\t${n.i||e?`${Aa}`:"Close"}\n\t\t${n.n??""}\n\t\t${n.m?`${Ta}`:''}`,u(t,"[c]",(t=>n.i?i():o()));const c=bt("Add diagram",(()=>Va("New diagram",(t=>s(n.i,t)))));u(t,"[af]",(t=>Ca(t,n.i?[c,La(n.i)]:[c,bt("Add folder",(()=>Va("New folder",a)))])))},Ma=(t,n,e,o,i,a,s,c,r,l)=>{t.innerHTML=`${et([...e.f],(t=>``))}\n\t\t${et([...e.d],(t=>``))}\n\t${e.f.size||e.d.size?"":Pa}`,u(t,"[fld]",(t=>s(Number(t.currentTarget.getAttribute("fld"))))),u(t,"[fedt]",(t=>{const n=e.f.get(Number(t.currentTarget.getAttribute("fedt"))),o=n.m?[Ha(n.n,(t=>c(n.i,t))),La(n.i),kt((()=>r(n.i)))]:[];n.r&&o.push($t("Remove from my cloud",(()=>l(n.i)))),Ca(t,o)})),u(t,"[edt]",(t=>{const n=e.d.get(t.currentTarget.getAttribute("edt")),s=n.m?[Ha(n.n,(t=>o(n.i,t))),bt("Share",(t=>la(n,!0))),kt((()=>i(n.i)))]:[];n.r&&s.push($t("Remove from my cloud",(()=>a(n.i)))),Ca(t,s)}))},Ca=(t,e)=>xt(n(t.currentTarget,"dts"),e),Ha=(t,n)=>bt("Rename",(()=>Va(t,(e=>{t!==e&&n(e)})))),La=t=>bt("Share",(()=>fa(t)));function Va(t,e){const o=gt(g(`
`),"mdm",!0);u(o,"[sv]",(t=>{o[yt].del(),e(Ro(n(o,"nm").value))}))}const za=Symbol(0),Sa=t=>J(t,za);function Da(t,n){const e=new AbortController;return document.body.addEventListener("dragover",(t=>t.preventDefault()),{signal:e.signal}),document.body.addEventListener("drop",(async e=>{if(e.preventDefault(),1===e.dataTransfer?.items?.length&&"file"===e.dataTransfer.items[0].kind&&e.dataTransfer.items[0].type.startsWith("image/"))if("getAsFileSystemHandle"in e.dataTransfer.items[0]){const o=await e.dataTransfer.items[0].getAsFileSystemHandle(),i=await n(t,await o.getFile(),e);i&&Bo(t,o,i)}else{const o=e.dataTransfer.items[0].getAsFile(),i=await n(t,o,e);i&&Zo(t,X(o.name),i)}else Ea()}),{signal:e.signal}),()=>e.abort()}async function Ba(t,n,e){const o=await Za(t,n);return o||(Ge(t,n,e.clientX,e.clientY),null)}async function Za(t,n){if("image/png"!==n.type)return null;const e=await Co(n);if(e){ra(t);const n=q(e);return _i(t,n),n}return null}const Ea=()=>alert("File cannot be read. Use the exact image file you got from the application."),Ta='',Aa='',Ra='',Pa='
No items
',Ua=()=>`User${Math.floor(100*Math.random())}`,Ia=(t,n)=>{if(n?.length)return n.forEach((n=>{t.s[n]=null})),console.log(t),t},Na=t=>{const n=Oa(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)",w(e),e},Oa=t=>`hsl(${[...t].reduce(((t,n)=>n.charCodeAt(0)+((t<<5)-t)),0)%360}, 97%, 47%)`,ja=(t,n,e,o)=>{const i=((t,n,e)=>({x:t.position.x+n*t.scale,y:t.position.y+e*t.scale}))(t[ct].data,e,o);n.style.transform=`translate(${i.x}px, ${i.y}px)`},Fa=async t=>{const n=To(t);if(n?.f){const e=nn(t);yo(t,e,(async o=>{const i=await n.f.createWritable();await i.write(o),await i.close(),Ji(0,n,1,null,e),Wa(t)}))}else if(n?.i)if(n.e){if(ss(t))return void Mt("Autosave is enabled. Manual saving is not necessary.");dt((async()=>{await Ga(t,n.i,!0),Wa(t),is(t,n,!1)}))}else alert('You do not have access to edit this diagram.\r\nUse "Save As" to make your own copy.');else Ya(t)},Ya=async t=>qi()?Ka(t):_a(t),Ka=async t=>{const e=await dt((()=>(async(t,n)=>{const e=xa(n),o=await $a(t,e.h,e.b,!1,(()=>e.m[yt].del()));return e.s(),{m:e.m,d:()=>o()}})(t,`
`))),o=()=>e.m[yt].del(),i=()=>Ro(n(e.m,"snm").value);u(e.m,"[dvc]",(n=>{o(),Xa(t,i())})),u(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=>{dt(t),o()},s=(e,o)=>{Do(t,e,o,!0,!0,n?.f?.n),Wa(t)},c=i(),r=Object.entries(n.d.d).find((t=>t[1].n===c));if(r){const n=To(t);return r[0]===n?.i&&n.m?void a((async()=>{await Ga(t,n.i,!0),Wa(t)})):void(confirm("Overwrite existing file?")&&a((async()=>s(r[0],await(async(t,n)=>(await M(`${Lt}a/o/${t}`,n)).text())(r[0],nn(t))))))}a((async()=>{const e=Rt();s(e,await Zt(e,n.f.i,c,nn(t)))}))}))},_a=t=>{const e=gt(g(`
Log in to access cloud storage.
`),"mdm");u(e,"[dvc]",(o=>{Xa(t,Ro(n(e,"nm").value)),e[yt].del()}))},Xa=(t,n)=>{const e=nn(t);yo(t,e,(async o=>{const i=Oe(o,n?.length?n:qa());if(i){const n=await i;n&&(Bo(t,n,e),Wa(t))}else Zo(t,n,e),Wa(t)}))},Ga=async(t,n,e)=>{let o;if(e&&ts(t)){const e=es(t),i=[...e.c,...e.u],a=function(t,n){for(const e in t.s)n.has(e)&&un(t.s[e]);return t}(en(i.length?[...document.querySelectorAll(i.map((t=>`[id="${t}"]`)).join(","))]:null,!1),e.u);e.d.forEach((t=>{a.s[t]=null})),o=await(async(t,n)=>(await M(`${Lt}u/${t}`,n)).json())(n,a)}else o=(await Dt(n)).d;sn(t,o),P(t.children,(t=>{Object.prototype.hasOwnProperty.call(o.s,t.id)||On(t)}))},Wa=(t,n)=>{ns(t),Mt(n??"Saved")},qa=()=>{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`},Ja=t=>{t[os]?.r(),t[os]=void 0},Qa=t=>{if(t[os])return;const n=new AbortController;t[os]={c:new Set,u:new Set,d:new Set,r:()=>{n.abort(),ns(t)}};const e=n=>{t[os].c.add(n),t[os].u.delete(n),t[os].d.delete(n)},o=n=>{t[os].c.has(n)||t[os].u.add(n),t[os].d.delete(n)},i=n=>n?.forEach((n=>{t[os].d.add(n),t[os].c.delete(n),t[os].u.delete(n)})),a=(e,o)=>l(n.signal,t,e,o);a("dgrmc",(t=>{t.detail.newIds?.forEach(e)})),a("dgrmu",(t=>{return n=t.detail.shapesToUpdData,Object.keys(n.s).forEach(o);var n})),a("dgrmd",(t=>i(t.detail.delIds))),a("dgrmdc",(t=>{i(t.detail.delIds),t.detail.newIds?.forEach(e)})),t.addEventListener("dgrmn",(n=>{!ts(t)||window.confirm("Changes you made may not be saved. Continue?")?ns(t):n.preventDefault()}),{signal:n.signal}),window.addEventListener("beforeunload",(n=>{ts(t)&&n.preventDefault()}),{signal:n.signal})},ts=t=>t[os]?.c.size||t[os]?.u.size||t[os]?.d.size,ns=t=>{t[os]?.c.clear(),t[os]?.u.clear(),t[os]?.d.clear()},es=t=>t[os],os=Symbol(0),is=(t,n,e)=>{const o=()=>{t[as]&&t[as](),delete t[as],Qa(t),cs(!1),ls()};o(),!e&&n?.i&&(lt(!0),t[as]=((t,n,e,o)=>{const i=_(),a=new AbortController,s=new Map,c=new WebSocket(`${Ht}w/${n.i}/${i}/${qi()?.n??Ua()}`),r=(t,n)=>l(a.signal,c,t,n);let d=t=>c.send(W(t));return r("open",(o=>{if(n.e){const n=t=>d([2,t]),e=(n,e)=>l(a.signal,t,n,e);e("dgrmc",(t=>n(t.detail.shapesToCreateData))),e("dgrmu",(t=>n(t.detail.shapesToUpdData))),e("dgrmd",(t=>n(Ia(tn(),t.detail.delIds)))),e("dgrmdc",(t=>n(Ia(t.detail.shapesToCreateData??tn(),t.detail.delIds))))}l(a.signal,t.ownerSVGElement,"pointermove",Z((n=>{const e=Ut(t[ct].data,n.clientX,n.clientY);d([1,i,Math.round(e.x),Math.round(e.y)])}),60)),e()})),r("message",(n=>{const e=q(n.data);switch(e[0]){case 1:ja(t,s.get(e[1]),e[2],e[3]);break;case 2:{const n=e[1],o=[];for(const[t,e]of Object.entries(n.s))e||(o.push(t),delete n.s[t]);o.length&&Nn(o),sn(t,n)}break;case 3:s.set(e[1],Na(e[2]));break;case 4:s.get(e[1]).remove(),s.delete(e[1])}})),r("close",(t=>{console.log(t),o(t.reason)})),()=>{d=t=>{},a.abort(),c?.readyState===WebSocket.OPEN&&c?.close(),s.forEach((t=>t.remove()))}})(t,n,(()=>{Ja(t),n.e&&cs(!0),lt(!1)}),(e=>{o(),lt(!1),rs(t,n)})))},as=Symbol(0),ss=t=>t[as],cs=t=>{e("menu").a=t},rs=(t,n)=>{const e=g('
Working offline. Connect.
');e.onclick=()=>dt((async()=>{await Ga(t,n.i,n.e),is(t,n,!1)})),w(e)},ls=()=>e("rcn")?.remove();class ds extends HTMLElement{constructor(t){super(),this.g=t}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML='';const e=e=>n(t,e);this.C=e;const o=t=>{this.contains(t.target)||s()};let i;let a=null;const s=()=>{a.remove(),a=null,d(document,"pointerdown",o),i&&i()},c=()=>{r(document,"pointerdown",o,!0),i=S(s),a=function(t,n,e){const o=qi(),i=To(t),a=o||Fe||i?.i&&i?.e,s=n?"Save (autosave enabled)":i?.i?"Save and sync with cloud":"Save",c=g(`
New
Open
${a?'
'+s+"
":""}
Save${Ye||a?" as":""}
${ot()?Bn+"Download":Zn+"Send"} image
Share
${o?o.n:"Log in"}
`);c.setAttribute("options","");const r=(t,n)=>u(c,t,(async t=>{e(),await n(t)}));u(c,"[menu2]",(t=>e())),r("[new]",(()=>{ra(t)})),a&&r("[save]",(async()=>await Fa(t)));return r("[saveas]",(()=>Ya(t))),r("[open]",(async()=>await ya(t))),r("[login]",(t=>function(){const t=qi(),n=gt(g(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
'));u(n,"[sbs]",(()=>{n[yt].del(),Xi()}))}())),r("[link]",(n=>(t=>la(To(t),!1))(t))),r("[down]",(n=>(t=>yo(t,nn(t),(async n=>await Uo(t,n))))(t))),c}(this.g,this.a,(()=>s())),t.append(a)};r(e("menu"),"click",(t=>c()))}a=!1}customElements.define("ap-menu",ds);class us 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=>{r(t,"pointerdown",this),r(t,"click",this)})),r(n,"pointerleave",this),r(n,"pointerup",this),r(n,"pointermove",this);const e=t.getElementById("m");let o;r(e,"click",(t=>{o?(o(),o=null,e.style.opacity="0.4"):(o=xi(this.g),e.style.opacity="1")}))}handleEvent(t){switch(t.type){case"pointermove":if(!this.H){const n=document.elementFromPoint(t.clientX,t.clientY);if(n===this.L)return;this.V===this.L&&this.g.ownerSVGElement.setPointerCapture(t.pointerId),this.L=n}break;case"pointerleave":if(this.H=!0,null!=this.S){const n=ps(this.g,this.S,!1,t.clientX,t.clientY)[0];f(t)||this.g[ct].select([n]),n[Jt]?n[Jt]?.moveCapture(t,n,!0):n[qt]?.moveCapture(t,n,!0)}this.D();break;case"pointerdown":this.S=parseInt(p(t,"data-cmd-arg")),this.V=document.elementFromPoint(t.clientX,t.clientY),this.L=this.V,this.H=null;break;case"pointerup":this.D();break;case"click":this.g.ownerSVGElement.focus(),this.g[ct].select(ps(this.g,parseInt(p(t,"data-cmd-arg")),!0))}}D(){this.S=null,this.V=null,this.L=null}}customElements.define("ap-menu-shape",us);const ps=(t,n,e,o,i)=>{return $n(t,on((a=n,Kt.get(a)())),e,o,i);var a};const hs=Symbol(0),fs=t=>Q(t,hs,(()=>function(t){const n=new AbortController;l(n.signal,document,"paste",(async n=>{h(n)||ms(t,(t=>{const n=t.getData("text/plain"),e=Vo(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 e=Z((async()=>await Fa(t)),500);return document.addEventListener("keydown",(async n=>{if((n.ctrlKey||n.metaKey)&&"KeyS"===n.code&&n.preventDefault(),(n.ctrlKey||n.metaKey)&&!n.repeat&&!h(n))switch(n.code){case"KeyZ":ht(),Ni(t);break;case"KeyY":ht(),Oi(t);break;case"KeyS":ht(),n.shiftKey?Ya(t):e();break;case"KeyA":ht(),qo(t)}}),{signal:n.signal}),()=>n.abort()}(t)));function ms(t,n,e,o){const i=n=>t[ct].select($n(t,n,!0,e,o));if(n?.data)i(function(t){if(!t)return null;const n=new Map,e=t=>{const e=_();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)We(n.img,(t=>i(on(t))));else if(n?.txt){const e=function(t,n){const e=v("text");lo(e,null,n),e.style.visibility="hidden",t.append(e);const o=oo(e);return e.remove(),o}(t,n.txt);i(on({id:_(),type:3,position:{x:0,y:0},title:n.txt,w:e.w,h:e.h}))}else Mt("Clipboard is empty")}const vs=Symbol(0),gs=t=>Q(t,vs,(()=>function(t){const n=t.ownerSVGElement,e=t.ownerDocument;let o,i,a,s;function c(n){d(e,"pointermove",m),d(e,"pointerup",h),a||(a=function(t,n,e,o){const i=g(`${Ho?'
Paste
':""}
Select all
Add image
`),a=(t,n)=>u(i,t,(async t=>{await n(),o()}));Ho&&a("[p]",(async()=>ms(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=Vo(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()=>qo(e))),a("[i]",(async()=>async function(t,n,e){const o=await je(_e);o&&Ge(t,o.f,n,e)}(e,t,n)));return{del:mt(i,t-10,n-10)[yt].del,el:i}}(n.clientX,n.clientY,t,h),r(e,"pointerdown",f))}function p(){a?.del(),a=null}function h(){clearTimeout(o),o=null,p(),d(e,"pointerdown",f),d(e,"pointerup",h),d(e,"wheel",h),d(e,"keydown",h),d(e,"pointerup",w),d(e,"pointercancel",w),d(e,"pointermove",v),i=!1,s=!1}function f(t){a.el.contains(t.target)||h()}function m(){h(),i=!0}function v(){s||h(),i=!0}function w(){s=!0}const y=new AbortController;async function x(t){t.isPrimary&&Xt(t)===n?(h(),r(e,"pointermove",m,!0),r(e,"pointerup",h,!0),r(e,"wheel",h,!0),r(e,"keydown",h,!0),2!==t.button&&(o=setTimeout((n=>{c(t),r(e,"pointerup",w,!0),r(e,"pointercancel",w,!0),r(e,"pointermove",v,!0)}),500))):h()}return l(y.signal,n,"pointerdown",x),n.addEventListener("contextmenu",(async t=>{n===Xt(t)&&(t.preventDefault(),i||c(t))}),{signal:y.signal}),()=>{y.abort(),h()}}(t)));const ws=Symbol(0),ys=t=>Q(t,ws,(()=>function(t){const n=t.ownerSVGElement;let e,a,s,c,u;const p=()=>{u?.remove(),u=null};let h=!1;function f(t){if(t[No]||!s)return void g();t[No]=!0,h&&(p(),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&&(c.x=t.clientX),e<0&&(c.y=t.clientY),s.style.transform=`translate(${c.x}px, ${c.y}px)`}function m(n){if(s&&!h){n[No]=!0;const e=n=>ks(Ut(t[ct].data,c.x,c.y),s.width.baseVal.value/t[ct].data.scale,s.height.baseVal.value/t[ct].data.scale,n.x,n.y);!function(t,n,e,o){const i=Jo(),a=t=>Qo(i,t),s=t=>t.shape&&e(t.shape.shapeEl)||o(t);for(const t of n)if(t[Jt])e(t)&&a({shape:t});else if(t[qt]){const n=s(t[qt].data.s),e=s(t[qt].data.e);n&&e?a({path:t}):n?a({pathEnd:t[qt].data.s}):e&&a({pathEnd:t[qt].data.e})}t[ct].selectedSet(i)}(t,t.children,(t=>e(t[Jt].data.position)),(t=>e(t.data.position)))}g()}function g(){clearTimeout(e),e=null,s?.remove(),s=null,p(),h=!1,d(n,"pointermove",f),d(n,"wheel",g),d(n,"pointercancel",g),d(n,"pointerup",m)}const w=new AbortController;return l(w.signal,n,"pointerdown",(l=>{if(!l.isPrimary||Xt(l)!==n||$s(l))return void g();r(n,"pointermove",f),r(n,"wheel",g,!0),r(n,"pointercancel",g,!0),r(n,"pointerup",m,!0);const d=()=>{t[ct].selectedSet(null),h=!0,n.setPointerCapture(l.pointerId),a={x:l.clientX,y:l.clientY},c={x:l.clientX,y:l.clientY},s=v("rect"),s.style.cssText="rx:8px; fill: rgb(108 187 247 / 51%)",o(s,c),n.append(s)};2!==l.button?e=setTimeout((t=>{d(),u=v("circle"),i(u,"ative-elem"),u.style.cssText="r:10px; fill: rgb(108 187 247 / 51%)",o(u,{x:l.clientX,y:l.clientY}),n.append(u)}),500):d()})),()=>{w.abort(),g()}}(t))),xs=t=>J(t,ws);const bs=-1!==window.navigator.userAgent.indexOf(" OPR"),$s=t=>bs&&0!==t.button,ks=(t,n,e,o,i)=>t.x<=o&&o<=t.x+n&&t.y<=i&&i<=t.y+e,Ms=t=>{document.title=t??"DGRM - Flowchart editor"},Cs=t=>{c(t),Ls().style.display="none",Vs(),(t=>{Sa(t),Q(t,za,(()=>Da(t,((t,n,e)=>Za(t,n)))))})(t),(t=>{J(t,vs)})(t),(t=>{J(t,hs)})(t),Ja(t),xs(t),Yo(t),Ft(t),Fo(t),jt(t)},Hs=t=>{c(t,!0),Ls().style.display="",zs(),(t=>{Sa(t),Q(t,za,(()=>Da(t,Ba)))})(t),gs(t),fs(t),Qa(t),xs(t),Yo(t),Ft(t),ys(t),Fo(t),jt(t)},Ls=()=>document.getElementsByTagName("ap-menu-shape")[0],Vs=()=>w(g('
Read only mode
')),zs=()=>e("rnl")?.remove();e("diagram").addEventListener("touchmove",(t=>t.preventDefault()),{passive:!1});const Ss=e("canvas");Ss[ct]={data:{position:{x:0,y:0},scale:1,cell:24},shapeMap:function(n){const e=(t,e)=>Yn(n,t,e);return{0:{create:t=>e(ae(n,t),3)},1:{create:i=>e(function(n,e){e.r??=48;let i,a=e.r;const s=Ce(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=O(e.position,-e.r),{x:e.r,y:e.r})),(r=>{let l=It(n[ct].data,r).x-i.x;l<48&&(l=48);const d=48*Math.round(l/48)/2;e.r!==d&&De(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=De(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,Tn(s),Se(s.el,"outer",e.r+24),Se(s.el,"main",e.r),s.draw()}return 48!==e.r?c():s.draw(),s.el[Jt].patch=t=>{const n=Un(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&&(ze=[...t.styles])},s.el}(n,i),2)},2:{create:t=>e(Ze(n,t),2)},3:{create:t=>e(eo(n,t),2)},4:{create:a=>e(function(n,e){e.w??=96;let a,s=e.w;const c=Ce(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=O(e.position,-t),{x:t,y:t}}),(i=>{let l=It(n[ct].data,i).x-a.x;l<48&&(l=48);const d=48*Math.round(l/48);if(e.w!==d&&fo(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=fo(t,s);n!==e.w&&(e.w=n,r())}));function r(){const t=ho(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,Tn(c);const n=ho(e.w,9);po(c.el,"main",n),po(c.el,"border",n),po(c.el,"outer",ho(e.w,-24)),c.draw()}return i(c.el,"shrhomb"),96!==e.w?r():c.draw(),c.el[Jt].patch=t=>{const n=Un(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&&(uo=[...t.styles])},c.el}(n,a),2)},5:{create:t=>e(Ue(n,t),1)},6:{create:t=>e(qe(n,t),0)},7:{create:t=>e(function(t,n){const e=He(t,n,bi(n),{},null,null,null,Xe,(()=>{Vi(n.position)}));return i(e.el,"shmrk"),e.el.style.mixBlendMode="multiply",e.draw(),e.el[Jt].patch=t=>{In(e,t)&&e.draw()},e.el}(n,t),4)}}}(Ss),f:(t,n,e,o,i)=>{const a="DGRM examples"===o;a||!n?.i||n.e?Hs(t):Cs(t),Ms(n?.n),Ji(0,n,e,o,i),is(t,n,a)}};{const t=new URL(window.location.href),n=n=>t.searchParams.get(n);n("usr")&&(Ds=n("usr"),Bs=n("usrn"),Zs=parseInt(n("expr")),localStorage.setItem("dgrm",W({l:Ds,n:Bs,e:Zs})),H("usr","usrn","expr"))}var Ds,Bs,Zs,Es,Ts;(t=>{const n=new ds(t);n.id="menu",w(n)})(Ss),w(new Ki(Ss)),w(new us(Ss)),Ss.ownerSVGElement.addEventListener("contextmenu",(async t=>{h(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[at]=e?t.clientX-e:0,t[st]=o?t.clientY-o:0,e=t.clientX,o=t.clientY):(t[at]=t.movementX,t[st]=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=>{d(t,"pointermove",i,!0)}),{capture:!0,once:!0,passive:!0})}),{capture:!0,passive:!0})}(document),(t=>{const n=(n,e)=>r(t,n,(t=>{t[Pi]||e(t)}));n("dgrmc",(n=>Zi(t,n.detail.newIds,n.detail.shapesToCreateData))),n("dgrmd",(n=>Ei(t,n.detail.delIds,n.detail.shapesToDelData))),n("dgrmu",(n=>Ti(t,n.detail.shapesBeforeUpdData,n.detail.shapesToUpdData))),n("dgrmdc",(n=>Ai(t,n.detail.delIds,n.detail.shapesToDelData,n.detail.newIds,n.detail.shapesToCreateData)))})(Ss);{const t=new URL(window.location.href),e=n=>t.searchParams.get(n);if(e("k")){lt(!0);const t=e("k");try{const n=await Dt(t);Do(Ss,t,n.n,n.e,n.m,n.l),_i(Ss,n.d)}catch(n){alert("The link is broken or you do not have permission. Try to relogin."),await(Ts=t,new Promise(((t,n)=>aa(Qi(),Ts,(()=>t()))))),Eo(Ss)}H("k"),lt(!1)}else if(e("l")){try{const t=e("l"),n=await(Es=t,new Promise(((t,n)=>ia(Qi(),Es,t))));n&&(Zo(Ss,n.n,n.s),_i(Ss,n.s))}catch{alert("The link is broken."),Eo(Ss)}H("l")}else if(e("u")){try{const t=new URL(e("u")),n=q(await Co(await(await fetch(t)).blob()));Zo(Ss,(t=>t.substring(t.lastIndexOf("/")+1))(t.href),n,t.hostname),_i(Ss,n)}catch{Ea(),Eo(Ss)}H("u")}else Eo(Ss),qi()||function(){const t=g('');function e(){t.remove(),d(document,"pointerdown",o),d(document,"wheel",e),d(document,"keydown",e),d(document,"dragover",e)}function o(n){t.contains(n.target)||e()}t.style.display="unset",r(document,"pointerdown",o),r(document,"wheel",e,!0),r(document,"keydown",e,!0),r(document,"dragover",e,!0),r(n(t,"cl"),"click",(t=>e()),!0),w(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)=>{t.style.pointerEvents=n?"unset":"none"},r=(t,n,e,o,i)=>(t.addEventListener(n,e,{passive:!0,once:o,signal:i}),e),l=(t,n,e,o)=>r(n,e,o,void 0,t),d=(t,n,e,o)=>t?.removeEventListener(n,e,{capture:o}),u=(t,n,e)=>t.querySelectorAll(n).forEach((t=>r(t,"click",e))),p=(t,n)=>t.currentTarget.getAttribute(n),h=t=>"TEXTAREA"===t.target.tagName.toUpperCase()||"INPUT"===t.target.tagName.toUpperCase(),f=t=>"mouse"===t.pointerType,m=t=>({x:t.clientX,y:t.clientY});function v(t,n){const e=document.createElementNS("http://www.w3.org/2000/svg",t);return n&&(e.innerHTML=n),e}const g=(t,n)=>{const e=document.createElement("div");return t&&(e.innerHTML=t),e.style.cssText=n,e},w=(...t)=>document.body.append(...t);function y(t){let n,e=0;for(const o of t.getElementsByTagName("tspan"))for(const t of x(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 b(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},k=(t,n)=>$(t,{method:"POST",body:n}),M=(t,n)=>$(t,{method:"POST",headers:{"Content-Type":"application/json;charset=utf-8"},body:n?W(n):null}),C=(t,n)=>{const e=new URL(window.location.href);return e.searchParams.set(t,n),e.toString()},H=(...t)=>{const n=new URL(window.location.href);t?.forEach((t=>n.searchParams.delete(t))),history.replaceState(null,null,n.toString())};function L(t,n,e,o){function i(n){d(t,"pointercancel",i),d(t,"pointerup",i),d(t,"wheel",i),d(document,"pointerdown",i),d(t,"pointermove",e),o(n)}r(t,"pointercancel",i,!0),r(t,"pointerup",i,!0),r(t,"wheel",i,!0),r(document,"pointerdown",i,!0),r(t,"pointermove",e),t.setPointerCapture(n.pointerId)}const V=(t,n)=>z(t.ownerSVGElement,t,n);function z(t,n,e,o){const i=()=>{d(t,"pointercancel",a),d(t,"wheel",a),d(t,"pointerdown",a)},a=t=>{o&&o(t),n.contains(t.target)||(i(),e(t))};return r(t,"pointercancel",a),r(t,"wheel",a),r(t,"pointerdown",a),i}const S=t=>{const n=n=>{"Escape"===n.key&&t()};return r(document,"keydown",n),()=>d(document,"keydown",n)},D=(t,n,e)=>new CustomEvent(t,{detail:n,cancelable:e}),B=(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 E(t,n,e){return t??=0,e<=t?t:t+Math.ceil((e-t)/n)*n}const T=t=>Math.round(100*(t+Number.EPSILON))/100,A=(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 R(t,n){const e=t.indexOf(n);e>-1&&t.splice(e,1)}function P(t,n){for(let e=t.length-1;e>=0;--e)n(t[e])}const U=t=>t?[...t]:t,I=t=>t.values().next().value;function N(t,n,e){const o=e??1;return t.x+=o*n.x,t.y+=o*n.y,t}const O=(t,n)=>({x:t.x+n,y:t.y+n}),j=(t,n)=>F(t,n.x,n.y),F=(t,n,e)=>(t.x=n,t.y=e,t),Y=t=>({x:t.x,y:t.y}),K=(t,n)=>t?.x===n?.x&&t?.y===n?.y;function _(){const t=new Uint8Array(4);return window.crypto.getRandomValues(t),Array.from(t,(t=>t.toString(16).padStart(2,"0"))).join("")}const X=t=>t?.substring(0,t.lastIndexOf("."))||t,G=t=>q(W(t)),W=t=>JSON.stringify(t),q=t=>JSON.parse(t),J=(t,n)=>{Object.hasOwn(t,n)&&(t[n](),delete t[n])},Q=(t,n,e)=>{Object.hasOwn(t,n)||(t[n]=e())},tt=(t,n)=>t?n:"",nt=t=>tt(t,"disabled"),et=(t,n,e)=>t?.length?t.map(n).join(" "):e??"",ot=()=>screen.width>768;function it(t,n,e){t.x+=e[at]/n,t.y+=e[st]/n}const at=Symbol("movementX"),st=Symbol("movementY"),ct=Symbol("Canvas");let rt;function lt(t){t&&!rt?(rt=g("","z-index: 2; position: fixed; left: 0; top: 0; width:100%; height:100%; background: #fff; opacity: 0"),rt.classList.add("blnk"),w(rt)):t||(rt?.remove(),rt=null)}const dt=async t=>{try{return lt(!0),await t()}catch(t){console.log(t),alert("Error")}finally{lt(!1)}};function ut(t,n,e,o,i){const a=g(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),w(a),null!=n?s(n,e):a.style.transform="translate(-50%, -30%)",a[yt]={position:s,del:()=>{a?.remove()}},a}const pt=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[yt]?.del()}};function ft(t,n,e,o,i,a){const s=g(null,"z-index: 2; position: fixed; left: 0; top: 0; width:100%; height:100%; "+(o?"background-color: rgba(52,71,103,.05);":""));w(s);const c=ut(t,n,e,i,a);s.append(c);const l=vt(s,c,(t=>{"pointerdown"===t?.type?r(s,"click",(t=>{t.stopImmediatePropagation(),u()}),!0):u()}),(t=>t.stopImmediatePropagation())),d=c[yt].del,u=()=>{d(),l(),s.remove()};return c[yt].del=u,c}function mt(t,n,e){const o=ut(t,n,e),i=o[yt].del,a=vt(document,o,(t=>s())),s=()=>{i(),a()};return o[yt].del=s,o}function vt(t,n,e,o){const i=((t,n,e,o)=>z(t,n,e,o))(t,n,e,o),a=S((()=>{((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 gt(t,n,e,o,i){const a=g(""+(o?"":`
Close ${i??""}
`),"display: flex; flex-flow: column; padding: 15px;");a.className=n??"mds",o?a.append(o):u(a,"[ap-close]",(t=>s[yt].del())),a.append(t);const s=e?ft(a,null,null,!0):mt(a);return s}function wt(t,n,e,o){const a=gt(g(`${t}`,"display: flex; flex-flow: column; height: 100%; overflow-y: overlay;"),"mdh",o,n,e);return i(pt(a),"mdhc"),a}const yt=Symbol(0);function xt(t,n){const e=t.getBoundingClientRect(),o=window.innerHeight-e.bottom<40*n.length;!function(t,n,e,o){const i=ft(g(`
${et(t,(t=>t[0]))}
`),n,e,!1,!0,!o);u(i,"a",(n=>{i[yt].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 bt=(t,n)=>[`${t}`,n],$t=(t,n)=>[`${t}`,()=>{confirm("Delete?")&&n()}],kt=t=>$t("Delete",t);function Mt(t){const n=g(`${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",w(n),setTimeout((t=>n.remove()),2800)}const Ct=()=>Mt("Link copied to clipboard"),Ht="https://api.dgrm.net/api/",Lt=`${Ht}s/`,Vt=`${Ht}r/d/`,zt=`${Ht}r/f/`,St=`${Ht}sb/`,Dt=async t=>{const n=await $(`${Lt}${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()}},Bt=async t=>{const n=await $(`${Lt}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(`${Lt}a/c`);return Pt(i,"k",t),n&&Pt(i,"f",n.toString()),Pt(i,"n",e),(await M(i.toString(),o)).text()}const Et=async(t,n)=>parseInt(await(await k(`${St}${t}`,n.toString())).text()),Tt=t=>Et("d",t),At=t=>Et("dp",t);function Rt(){const t=new Date;return`${t.getUTCFullYear()}${(t.getUTCMonth()+1).toString().padStart(2,"0")}${_()}`}const Pt=(t,n,e)=>t.searchParams.set(n,e),Ut=(t,n,e)=>({x:(n-t.position.x)/t.scale,y:(e-t.position.y)/t.scale}),It=(t,n)=>Ut(t,n.clientX,n.clientY);function Nt(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}const Ot=Symbol(0),jt=t=>Q(t,Ot,(()=>function(t){const n=t[ct].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()}const a=function(t,n,e,o){let i,a,s,c,l=!1;function u(t){s=null,c=null,i?.id===t.pointerId&&(i=null),a?.id===t.pointerId&&(a=null),i||a||(d(document,"pointermove",p),d(document,"pointercancel",u),d(document,"pointerup",u),l=!1)}function p(t){if(l){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 r=Math.hypot(i.pos.x-a.pos.x,i.pos.y-a.pos.y),l={x:(i.pos.x+a.pos.x)/2,y:(i.pos.y+a.pos.y)/2};s&&(n.position.x=n.position.x+l.x-c.x,n.position.y=n.position.y+l.y-c.y,e(n.scale/s*r,l)),s=r,c=l}i?.id===t.pointerId&&(i=Yt(t,n)),a?.id===t.pointerId&&(a=Yt(t,n))}const h=t=>{!i&&!t.isPrimary||i&&a||(i||(r(document,"pointermove",p),r(document,"pointercancel",u),r(document,"pointerup",u),i=Yt(t,n)),a||i?.id===t.pointerId||(a=Yt(t,n)))};return r(t.ownerSVGElement,"pointerdown",h),t[ct].moveCapture=()=>{l=!0},()=>{d(t.ownerSVGElement,"pointerdown",h),t[ct].moveCapture=void 0}}(t,n,i,o),s=t=>{t.preventDefault();const e=()=>{n.position.x-=t.deltaX,n.position.y-=t.deltaY,o()},a=e=>i(n.scale+e,m(t));Math.abs(t.deltaY)>50?t.ctrlKey?e():a(t.deltaY<0?.25:-.25):t.ctrlKey?a(-.01*t.deltaY):e()};return t.ownerSVGElement.addEventListener("wheel",s),t[ct].move=function(t,e,i){n.position.x=t,n.position.y=e,n.scale=i,o()},t[ct].scale=i,()=>{a(),t.ownerSVGElement.removeEventListener("wheel",s),t[ct].move=void 0,t[ct].scale=void 0}}(t))),Ft=t=>J(t,Ot);function Yt(t,n){return{id:t.pointerId,pos:m(t),shift:{x:n.position.x-t.clientX,y:n.position.y-t.clientY}}}const Kt=new Map,_t=(t,n)=>Kt.set(t,n);function Xt(t){return Wt(t).find((t=>!t.hasAttribute("data-evt-no")))}function Gt(t){return Wt(t)[0]}function Wt(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 qt=Symbol("path"),Jt=Symbol("shape"),Qt="1.2",tn=()=>({v:Qt,s:{}}),nn=t=>en([...t.children],!1);function en(t,n,e){const o=tn();if(!t?.length)return o;const i=new Map,a=t=>{let e=i.get(t);if(!e){const a=G(t[Jt].data);n&&(a.id=_(),e=a.id),i.set(t,e),o.s[a.id]=a}return e},s=i=>{if(o.s[i[qt].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:G(o.data)}):o.shape?(e&&a(o.shape.shapeEl),{s:o.shape.shapeEl[Jt].data.id,k:o.shape.connectorKey}):{p:G(o.data)};var i},c=i[qt].data,r={id:n?_():c.id,type:0,s:s(c.s),e:s(c.e)};c.styles&&(r.c=G(c.styles)),o.s[r.id]=r};for(const n of t)n[Jt]?(a(n),e&&n[Jt].paths?.forEach(s)):s(n);return o}function on(t){return{v:Qt,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 an=(t,n)=>sn(t,"1.1"===n.v?function(t){const n={v:Qt,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 sn(t,n){if(n.v!==Qt)return alert("Wrong format"),null;const o=new Map;function i(n){let e=o.get(n);return e||(e=rn(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=ln(t,n.s[e],a);o&&s.push(o);break}default:i(n.s[e])}return[...o.values(),...s]}function cn(t,n){const o=e(n.id);return o?((o[Jt]||o[qt]).patch(n),o):t[ct].shapeMap[n.type].create(n)}const rn=(t,n)=>cn(t,G(n)),ln=(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:Y(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?cn(t,o):null};function dn(t){for(const n in t.s)un(t.s[n]);return t}function un(t){switch(t.type){case 0:pn(t.s),pn(t.e);break;case 6:delete t.d,delete t.r;break;case 7:delete t.d}}function pn(t){t.p?(t.k=null,t.s=null):t.p=null}const hn=(t,n,e)=>B(t,fn(n,e)),fn=(t,n)=>D("dgrmc",{newIds:t,shapesToCreateData:n}),mn=(t,n)=>D("dgrmd",{delIds:t,shapesToDelData:n}),vn=(t,n,e)=>B(t,gn(dn(n),dn(e))),gn=(t,n)=>D("dgrmu",{shapesBeforeUpdData:t,shapesToUpdData:n}),wn=(t,n,e,o)=>D("dgrmdc",{delIds:t,shapesToDelData:n,newIds:e,shapesToCreateData:o});function yn(t,n,e,o){const i=N(((t,n,e)=>{const o=Ut(t,n,e);return Nt(o,t.cell),o})(t[ct].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 xn(t,(t=>{t&&(n.x>t.x&&(n.x=t.x),n.y>t.y&&(n.y=t.y),e.x{n&&Nt(N(n,i),t[ct].data.cell)}))}function xn(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 bn=(t,n)=>t[ct].select($n(t,en(n,!0),!0));function $n(t,n,e,o,i){return yn(t,n,null==o?window.innerWidth/2:o,null==i?window.innerHeight/2:i),kn(t,n,e)}function kn(t,n,e){return e&&hn(t,Vn(n),G(n)),Mn(t,n)}function Mn(t,n){return t[ct].select(null),sn(t,n)}function Cn(t,n){((t,n,e)=>{B(t,mn(n,e))})(t,Ln(n),en(n,!1,!0)),zn(n)}function Hn(t,n,e){((t,n,e,o,i)=>{B(t,wn(n,e,o,i))})(t,Ln(n),en(n,!1,!0),Vn(e),G(e)),zn(n),Mn(t,e)}const Ln=t=>t.map((t=>(t[Jt]||t[qt]).data.id)),Vn=t=>Object.keys(t.s),zn=t=>t.forEach((t=>(t[Jt]||t[qt]).del())),Sn='',Dn='',Bn='',Zn='',En=(t,n)=>({id:_(),type:t,position:{x:0,y:0},title:"Title",styles:n});function Tn(n){for(const e in n.cons)o(t(n.el,e),n.cons[e].position)}function An(t,n){const e=t.getBoundingClientRect(),o=ut(n,e.left+10,e.top+10);return{del:o[yt].del,updPos:()=>{const n=t.getBoundingClientRect();o[yt].position(n.left+10,n.top+10)}}}const Rn=(t,n)=>({del:ut(t,n.clientX-66,n.clientY-10)[yt].del}),Pn=(t,n,e)=>{const o=en([n],!1,!1);(n[Jt]??n[qt]).patch(e),vn(t,o,en([n],!1,!1))};function Un(t,n){return function(t,n){const e=t.el[Jt].data;null!=n.title&&e.title!==n.title&&(e.title=n.title,t.drawTxt());n.styles&&(e.styles=n.styles,jn(t.el))}(t,n),In(t,n)}function In(t,n){const e=n.position&&!K(t.el[Jt].data.position,n.position);return e&&j(t.el[Jt].data.position,n.position),e}const Nn=t=>t.forEach((t=>{const n=e(t);n&&On(n)})),On=t=>(t[Jt]||t[qt]).del();function jn(t){const n=(t[Jt]??t[qt]).data;n.styles||(n.styles=[]),P(t.classList,(n=>{n?.startsWith("d-")&&t.classList.remove(n)})),i(t,...n.styles)}const Fn=(t,n,e)=>{const o=(n[Jt]??n[qt]).data;o.styles||(o.styles=[]);const i={styles:G(o.styles)};Pn(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 Yn(t,n,e){return n.setAttribute("bg",e.toString()),Kn(t,n),n}function Kn(t,n){const e=Number(n.getAttribute("bg"));if(4===e)return void t.append(n);const o=t.querySelector(_n(e+1,4).map((t=>`[bg="${t}"]`)).join());o?o.before(n):t.append(n)}const _n=(t,n)=>[...Array(n-t+1).keys()].map((n=>n+t));class Xn extends HTMLElement{constructor(t,n){super(),this.o=n,this.g=t}connectedCallback(){const t=t=>this.o[qt].data.styles?.includes(t)?'class="actv"':"",n=this.attachShadow({mode:"closed"});n.innerHTML=`
`,r(n.getElementById("edit"),"cmd",(t=>{switch(t.detail.cmd){case"style":Fn(this.g,this.o,t.detail.arg);break;case"del":Cn(this.g,[this.o]);break;case"copy":bn(this.g,[this.o])}})),u(n,"[data-cmd]",(t=>{const n=p(t,"data-cmd-arg"),e={styles:this.o[qt].data.styles?G(this.o[qt].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")),Pn(this.g,this.o,e)}))}}function Gn(t,n,e,o){const i=ne(t,n);i.shape={shapeEl:e,connectorKey:o},Jn(t,i)}function Wn(t,n,e){const o=ne(t,n);o.shape.shapeEl!==ee(t,o)&&Qn(t,o),o.shape=null,o.data={dir:o.data.dir,position:e}}function qn(t,n){const e=t[qt].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&&Wn(t,o,a.data.position):function(t,n,e,o){const i=ne(t,n);if(i.shape.shapeEl===e&&i.shape.connectorKey===o)return;i.shape.shapeEl!==e&&i.shape.shapeEl!==ee(t,i)&&Qn(t,i);i.shape={shapeEl:e,connectorKey:o},Jn(t,i)}(t,o,a.shape.shapeEl,a.shape.connectorKey):null!=a.shape?Gn(t,o,a.shape.shapeEl,a.shape.connectorKey):j(i.data.position,a.data.position)};o("s"),o("e")}function Jn(t,n){n.data=te(n.shape).pathAdd(n.shape.connectorKey,t)}customElements.define("ap-path-settings",Xn);const Qn=(t,n)=>te(n.shape)?.pathDel(t),te=t=>t?.shapeEl[Jt],ne=(t,n)=>t[qt].data[n],ee=(t,n)=>(t[qt].data.e===n?t[qt].data.s:t[qt].data.e).shape?.shapeEl;let oe;const ie=(t,n)=>({id:_(),type:0,s:t,e:n,styles:U(oe)});_t(0,(()=>ie({data:{dir:"right",position:{x:-24,y:0}}},{data:{dir:"right",position:{x:24,y:0}}})));function ae(n,e){const o=v("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=pe(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 he(e,-.8,.8)?"left":he(e,.8,2.4)?"top":he(e,2.4,3.2)||he(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=ue(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))),re(e.s),re(e.e)}let r,l;let d,u,p=0;const h=()=>{u&&(u(),u=null)},m=t=>{h(),u=S(t)};function g(t){switch(p){case 0:y();break;case 1:p=2,d=V(o,(t=>w(!0))),m((()=>{w(!0),y()})),function(t){r||(r=Rn(new Xn(n,o),t))}(t)}}function w(t){t||(l=null),p=0,a(o,"select","highlight-s","highlight-e"),le(e.s,1),le(e.e,1),r?.del(),r=null,d&&(d(),d=null),h()}function y(){p=1,i(o,"s"===l?"highlight-s":"e"===l?"highlight-e":"select"),le(e.s,2),le(e.e,2),Kn(n,o),m((()=>{w(!0)}))}return o[qt]={data:e,drawPosition:c,click:(t,n)=>{if(0===p||l){const o=n||t?fe(e,n??Xt(t)):null;me(l,o)||w(),l=o}g(t)},patch:t=>{var n,i,a;e.styles&&(e.styles=t.styles,jn(o),n=[...t.styles],oe=n,R(oe,"d-arw-s"),a="d-arw-e",-1===(i=oe).indexOf(a)&&i.push(a)),t.s&&qn(o,t),c()},moveCapture:(t,i,a)=>{w(!0);const s=a?null:en([o],!1,!0),r=t=>{w(!0),s?vn(n,s,en([o],!1,!0)):hn(n,[e.id],en([o],!1,!0)),f(t)||g()},l=fe(e,i);l?ce(n,o,c,t,l,r):function(t,n,e,o,i){L(n,o,(o=>{!function(t,n,e,o){const i=n=>it(n,t.scale,o);se(n.s,i),n.s.shape?.shapeEl&&n.s.shape?.shapeEl===n.e.shape?.shapeEl||se(n.e,i);n.s.shape||n.e.shape||e()}(t[ct].data,n[qt].data,e,o)}),(o=>{!function(t,n,e){const o=n=>Nt(n,t.cell);se(n.s,o),se(n.e,o),n.s.shape&&n.e.shape||e()}(t[ct].data,n[qt].data,e),i(o)}))}(n,o,c,t,r)},unselect:w,del:function(){w(),Qn(o,e.s),Qn(o,e.e),o.remove()}},e.styles&&i(o,...e.styles),e.s.shape&&Jn(o,e.s),e.e.shape&&Jn(o,e.e),c(),o}function se(t,n){t.shape?(n(te(t.shape).data.position),te(t.shape).drawPosition()):n(t.data.position)}const ce=(t,n,e,o,l,u)=>{n[qt].data[l].shape&&Wn(n,l,It(t[ct].data,o)),c(n);const p=function(t){let n=null;function e(t){const e=Gt(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 r(t,"pointermove",e),function(){d(t,"pointermove",e),a(n,"hover"),a(n?.parentElement,"hover"),n=null}}(n.parentElement);L(n[qt].data[l].el,o,(o=>{it(n[qt].data[l].data.position,t[ct].data.scale,o),e()}),(o=>{const i=Gt(o),a=i?.getAttribute("data-connect");a?Gn(n,l,i.parentElement,a):Nt(n[qt].data[l].data.position,t[ct].data.cell),e(),p(),c(n,!0),u(o)}))};function re(t){t.el.style.transform=`translate(${t.data.position.x}px, ${t.data.position.y}px) rotate(${de(t.data.dir)}deg)`}function le(t,n){t.el.firstElementChild.setAttribute("data-evt-index",n.toString())}const de=t=>"right"===t?180:"left"===t?0:"bottom"===t?270:90,ue=t=>"left"===t?"right":"right"===t?"left":"top"===t?"bottom":"top";const pe=(n,...e)=>e.map((e=>t(n,e))),he=(t,n,e)=>n<=t&&t<=e,fe=(t,n)=>t.e.el.contains(n)?"e":t.s.el.contains(n)?"s":null,me=(t,n)=>!t||t===n,ve=(t,n,e)=>we(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}(ye(t)))),ge=(t,n,e)=>we(t,n,e,ye);function we(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 ye(t){return t.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'").replaceAll(" "," ")}const xe=(t,n)=>An(n,$e(t,n)),be=(t,n,e)=>Rn($e(t,n),e);function $e(t,n){const e=new ke;return r(e,"cmd",(e=>{switch(e.detail.cmd){case"style":Fn(t,n,e.detail.arg);break;case"del":Cn(t,[n]);break;case"copy":bn(t,[n])}})),e}class ke extends HTMLElement{connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML=`
${Dn} ${Sn}
`;{const n=t.getElementById("pnl");let e;u(t,"[data-toggle]",(o=>{const i=t=>{const e=pt(this),o=e.getBoundingClientRect().top,i=n.getBoundingClientRect().height;e.style.top=`${o+window.scrollY+t*i}px`};e&&(i(1),Me(e,!1));const a=t.getElementById(p(o,"data-toggle"));e!==a?(Me(a,!0),i(-1),e=a):e=null}))}u(t,"[data-cmd]",(t=>{this.dispatchEvent(new CustomEvent("cmd",{detail:{cmd:p(t,"data-cmd"),arg:p(t,"data-cmd-arg")}}))}))}}function Me(t,n){t.style.display=n?"unset":"none"}function Ce(n,e,o,i,a,s,c,r,l=0,d){const u=Le(e.id,o,i),p={el:t(u,"text"),vMid:l};d??=ve;const h=()=>d(p.el,p.vMid,e.title);h();return{el:u,cons:i,draw:Ve(n,u,e,i,p,r??xe,(t=>c(p.el,t)),a,s,null).draw,drawTxt:h}}function He(t,n,e,o,i,a,s,c,r){const l=Le(n.id,e,o);return{el:l,cons:o,draw:Ve(t,l,n,o,null,c??be,null,i,a,s,r).draw}}customElements.define("ap-shape-edit",ke);const Le=(t,n,e)=>{const o=v("g",`${n}\n\t${Object.entries(e).map((t=>``)).join()}`);return o.id=t,o};function Ve(t,n,e,s,c,r,l,d,u,p,h){let m,g,w,y;e.styles??=[];const x=()=>en([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 h=G(s),m=new Set;let g,w,y,x=0;function b(){g?.remove(),g=null}const $=()=>{y&&(y(),y=null)},k=t=>{$(),y=S(t)};function M(){n.style.transform=`translate(${e.position.x}px, ${e.position.y}px)`;for(const t in s)h[t].position={x:s[t].position.x+e.position.x,y:s[t].position.y+e.position.y};for(const t of m)t[qt].drawPosition()}function C(){x=1,i(n,"select"),l&&(g=function(t,n){const e=v("circle");return e.setAttribute("data-evt-index","2"),i(e,"resizer"),o(e,n),t.append(e),e}(n,l())),k((()=>H()))}function H(t){r(),x=0,a(n,"select","highlight"),t||b(),w&&(w(),w=null),$()}const z=t=>{switch(x){case 0:C();break;case 1:x=2,a(n,"select"),i(n,"highlight"),b(),w=V(n,(t=>H())),k((()=>{H(),C()}))}c(t,x)},D=(e,o,i)=>{if(o===g){H(!0);const o=en([n],!1,!1);return void L(g,e,d,(e=>{u&&u(),b(),C(),vn(t,o,en([n],!1,!1))}))}H();const a=o.getAttribute("data-connect");if(a){const o=((t,n,e)=>Yn(t,ae(t,ie(n,e)),3))(t,{shape:{shapeEl:n,connectorKey:a}},{data:{dir:ue(h[a].dir),position:It(t[ct].data,e)}});return t[ct].select(f(e)?null:[o]),o[qt].moveCapture(e,o[qt].data.e.el,!0),void m.add(o)}B(e,i)};p??=()=>Nt(e.position,t[ct].data.cell);const B=(o,i)=>{const a=i?null:en([n],!1,!1);L(n,o,(n=>{it(e.position,t[ct].data.scale,n),M()}),(o=>{p(),M(),a?vn(t,a,en([n],!1,!1)):hn(t,[e.id],en([n],!1)),f(o)||C()}))};return n[Jt]={data:e,drawPosition:M,click:z,moveCapture:D,unselect:H,del:function(){H();for(const t of m)t[qt].del();n.remove()},paths:m,pathAdd:function(t,n){return m.add(n),h[t]},pathDel:function(t){m.delete(t)}},M}(t,n,e,s,((o,i)=>{1===i&&Kn(t,n),2===i&&(c&&!m&&(w=e.title,g=x(),ge(c.el,c.vMid,e.title),l(),m=function(t,n,e,o,i){let a=v("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(){ge(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(){m&&(ve(c.el,c.vMid,e.title),l(!0),m?.dispose(),m=null),y?.del(),y=null,g&&w!==e.title&&vn(t,g,x()),g=null,w=null}),d,u,p,h);return e.styles&&i(n,...e.styles),{draw:()=>{$(),y?.updPos&&y?.updPos(),m?.draw()}}}let ze;function Se(n,e,o){t(n,e).r.baseVal.value=o}_t(1,(()=>En(1,U(ze))));const De=(t,n)=>function(t,n,e){const o=y(t);return E(n,e,Math.sqrt(o.x**2+o.y**2))}(t,n,24);let Be;function Ze(n,e){e.w??=96,e.h??=48;const a={w:e.w,h:e.h};let s;const c=Ce(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=N(It(t[ct].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??=Ae(t(c.el,"text")),l)))&&(Te(a,e),r())}),(t=>{const n=Ae(t,a);Ee(e,n)||(Te(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,Tn(t),Re(t.el,"main",n.w,n.h,e,o),Re(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[Jt].patch=t=>{const n=Un(c,t),o=(null!=t.w||null!=t.h)&&!Ee(e,t);o&&(Te(e,t),a.h=e.h,a.w=e.w),o?r():n&&c.draw(),t.styles&&(Be=[...t.styles])},c.el}_t(2,(()=>En(2,U(Be))));const Ee=(t,n)=>t.w===n.w&&t.h===n.h,Te=(t,n)=>{t.h=n.h,t.w=n.w};function Ae(t,n){const e=t.getBBox();return{w:E(n?.w,48,e.width),h:E(n?.h,48,e.height)}}const Re=(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 Pe;function Ue(t,n){let e;n.w??=96,n.h??=96;const a=He(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=Ie(n);return e=t.tCanvas,t.bInner}),(i=>s(function(t,n,e,i){const a=N(It(t[ct].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=Ie(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,Tn(a),Re(a.el,"main",n.w,n.h,t.x,t.y),Re(a.el,"selected",n.w,n.h,t.x,t.y),Re(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(Ie(n).tInner):a.draw(),a.el[Jt].patch=t=>{const e=Un(a,t),o=(null!=t.w||null!=t.h)&&!Ee(n,t);o&&Te(n,t),o?s(Ie(n).tInner):e&&a.draw(),t.styles&&(Pe=[...t.styles])},a.el}function Ie(t){const n=Ne(t.w),e=Ne(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}}}_t(5,(()=>({id:_(),type:5,position:{x:0,y:0},styles:U(Pe)})));const Ne=t=>24*Math.floor(t/2/24);function Oe(t,n){return Ye?async function(t,n){try{const e=await window.showSaveFilePicker({suggestedName:n,types:[Ke]}),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 je(t){const n="AbortError";try{return Fe?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,r(o,"cancel",(t=>e(t)),!0),r(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 Fe="showOpenFilePicker"in window,Ye="showSaveFilePicker"in window,Ke={accept:{"image/png":[".png"]},inputAccept:"image/png"},_e={accept:{"image/*":[".png",".gif",".jpeg",".jpg"]},inputAccept:"image/*"};function Xe(t,n,e){const o=g(`
${Dn} ${Sn}
`);return u(o,"[data-cmd]",(e=>{switch(p(e,"data-cmd")){case"del":Cn(t,[n]);break;case"copy":bn(t,[n])}})),Rn(o,e)}function Ge(t,n,e,o){We(n,(n=>t[ct].select($n(t,on(n),!0,e,o))))}function We(t,n){!function(t,n,e){const o=new Image;o.onload=function(){const i=A(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=A(Math.min(document.body.clientHeight/2,264),e,o),a={id:_(),type:6,position:{x:0,y:0},w:i.w,h:i.h,r:T(o/e),d:t};Je(a),n(a)}))}function qe(t,n){let e;const a=He(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=Ie(n);return e=t.tCanvas,t.bInner}),(i=>s(function(t,n,e,i){const a=N(It(t[ct].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){Je(t);const e=Ie(t);return t.position.x=n.x-e.tInner.x,t.position.y=n.y-e.tInner.y,e.tInner}(n,e))),Xe);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,Tn(a),Re(a.el,"main",n.w,n.h,t.x,t.y),Re(a.el,"selected",n.w,n.h,t.x,t.y),Re(a.el,"outer",n.w+48,n.h+48,t.x-24,t.y-24),a.draw()};return s(Ie(n).tInner),a.el[Jt].patch=t=>{const e=In(a,t),o=(null!=t.w||null!=t.h)&&!Ee(n,t);o&&Te(n,t),o?s(Ie(n).tInner):e&&a.draw()},a.el}function Je(t){t.w=24*Math.round(t.w/24),t.h=T(t.r*t.w)}const Qe=(t,n)=>An(n,new to(t,n));class to extends HTMLElement{constructor(t,n){super(),this.$=n,this.g=t}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML='
';const n=this.$[Jt].data,e=t.getElementById("edit");r(e,"cmd",(t=>{switch(t.detail.cmd){case"style":Fn(this.g,this.$,t.detail.arg);break;case"del":Cn(this.g,[this.$]);break;case"copy":bn(this.g,[this.$])}}));const o=t=>Pn(this.g,this.$,t);i(e,`ta-${n.a}`),u(t,'[data-cmd="a"]',(t=>{const s=Number.parseInt(p(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)})),u(t,'[data-cmd="s"]',(t=>{const s=p(t,"data-cmd-arg"),c={styles:n.styles?G(n.styles):[]};c.styles?.includes(s)?(R(c.styles,s),a(e,s)):(c.styles??=[],c.styles.push(s),i(e,s)),o(c)}))}}let no;function eo(n,e){e.w??=48,e.h??=48,e.a??=1;const o=Ce(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)),Qe,null,lo);i(o.el,"shtxt"),i(o.el,`ta-${e.a}`);const a=()=>t(o.el,"text"),s=(t,n)=>{n&&co(t)&&t.append(ro());const o=oo(t);Ee(e,o)||(Te(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=-Ne(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,Tn(t),Re(t.el,"main",n.w,n.h,e,o),Re(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&&(so(o.el,l,e.a),l=e.a),r=e.w}c!==e.h&&(a().y.baseVal[0].value=ao(e.h),e.position.y+=Ne(e.h)-Ne(c),c=e.h),o.draw()}return d(),48!==e.w||48!==e.h?u(!0):o.draw(),o.el[Jt].patch=t=>{const n=t.position&&!K(e.position,t.position);n&&j(e.position,t.position);let i=!1;t.styles&&(e.styles=t.styles,jn(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=oo(a());Ee(e,t)||(Te(e,t),s=!0)}null==t.w||Ee(e,t)||(Te(e,t),d(),s=!0),null!=t.a&&e.a!==t.a&&(so(o.el,e.a,t.a),e.a=t.a,l=e.a,s=!0),s?(a().y.baseVal[0].value=ao(e.h),u(!0)):n&&o.draw(),t.styles&&(no=[...t.styles])},o.el}function oo(t){const n=t.getBBox();return{w:E(0,48,n.width+12),h:E(0,24,n.height+14)}}customElements.define("ap-rect-txt-settings",to),_t(3,(()=>{const t=En(3,U(no));return no?.includes("d-h")&&(t.w=96),t}));const io=t=>1===t.a?-16:2===t.a?0:16,ao=t=>24-Ne(t);function so(t,n,e){a(t,`ta-${n}`),i(t,`ta-${e}`)}const co=t=>[...t.childNodes].every((t=>![...t.childNodes].some((t=>t.nodeType===Node.TEXT_NODE&&t.textContent?.trim())))),ro=()=>{const t=v("tspan"," ➜");return t.setAttribute("fill","rgb(13, 110, 253)"),t},lo=(t,n,e)=>{ve(t,n,e),co(t)&&t.append(ro())};let uo;function po(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 ho(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}}}_t(4,(()=>En(4,U(uo))));const fo=(t,n)=>E(n,48,function(t){const n=y(t);return 2*(Math.abs(n.x)+Math.abs(n.y))}(t)-20);async function mo(t,n,e){return function(t,n,e){let o,i;const a=vo(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(),go(n),e)}function vo(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 go(t){return new DataView((new TextEncoder).encode(t).buffer).getUint32(0)}const wo=()=>"undefined"!=typeof navigator&&(/iPad|iPhone|iPod/.test(navigator.userAgent||"")||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1),yo=(t,n,e)=>xo(t,W(n),null,e);function xo(t,n,e,o){const i=t.ownerSVGElement.cloneNode(!0),a=i.querySelector("#canvas");let c;i.style.backgroundImage=null,e?(c=b(Mo(t,bo)),P(a.children,(t=>((t,n)=>n.some((n=>s(t,n))))(t,bo)?(ko(t),!0):(t.remove(),!1)))):(c=t.getBoundingClientRect(),Mo(a,$o).forEach((t=>ko(t))));const r=i.getElementsByTagName("foreignObject");for(;r[0];)r[0].parentNode.removeChild(r[0]);const l=t[ct].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=A(wo()?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 mo(t,"dgRm",(new TextEncoder).encode(n)):t)))}const bo=["select","highlight"],$o=["select","highlight","highlight-e","highlight-s"],ko=t=>{a(t,...$o),t.querySelector(".resizer")?.remove()},Mo=(t,n)=>t.querySelectorAll(`.${n.join(", .")}`);async function Co(t){const n=await async function(t,n){return vo(await t.arrayBuffer(),go(n))}(t,"dgRm");return n?(new TextDecoder).decode(n):null}const Ho=navigator.clipboard.readText;async function Lo(t,n){const e=`web text/dgrm${W(en(n,!0))}`;await async function(t){try{await navigator.clipboard.writeText(t)}catch(t){alert(t)}}(e),window.ClipboardItem&&xo(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 Vo=t=>{if(!t?.startsWith("web text/dgrm"))return null;try{return q(t.slice("web text/dgrm".length))}catch{return null}};function zo(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(),Lo(t,o),o}return null}async function o(n){const o=await e(n);o&&So(t,o)}return document.addEventListener("copy",e),document.addEventListener("cut",o),function(){d(document,"copy",e),d(document,"cut",o)}}(t,n);function i(o){if(h(o)||"Delete"!==o.key&&"Backspace"!==o.key)"Escape"===o.key&&e();else{const e=n();e?.length&&So(t,e)}}return r(document,"keydown",i),function(){o(),d(document,"keydown",i)}}function So(t,n){t[ct].select(null),Cn(t,n)}const Do=(t,n,e,o,i,a)=>{t[Po]={i:n,n:e,e:o,m:i},Ao(t,0,a,null)},Bo=(t,n,e)=>{const o=X(n.name);t[Po]={f:n,n:o},Ao(t,1,null,e)},Zo=(t,n,e,o=null)=>{t[Po]={n:n},Ao(t,1,o,e)},Eo=t=>{t[Po]=void 0,Ao(t,null,null,null)},To=t=>t[Po],Ao=(t,n,e,o)=>t[ct].f(t,t[Po],n,e,o),Ro=t=>t?.replace(/[/\\?%*:|"<>]/g,"-"),Po=Symbol(0),Uo=async(t,n)=>{const e=`${To(t)?.n??"dgrm"}.png`;if(ot())return void await Oe(n,e);const o={files:[new File([n],e,{type:n.type})]};navigator.canShare&&navigator.canShare(o)?await navigator.share(o):await Oe(n,e)};class Io extends HTMLElement{constructor(t,n){super(),this.g=t,this.M=n}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML=`
${Dn}Create copy
Copy to clipboard
${ot()?Bn+"Download":Zn+"Send"} image
${Sn}Delete
`;const n=()=>pt(this)[yt].del();function e(e,o){r(t.getElementById(e),"click",(t=>{n(),o()}))}e("clone",(()=>bn(this.g,this.M()))),e("copy",(async()=>await Lo(this.g,this.M()))),e("save",(()=>xo(this.g,W(en(this.M(),!1)),!0,(async t=>Uo(this.g,t))))),e("del",(()=>Cn(this.g,this.M())))}}customElements.define("ap-grp-settings",Io);const No=Symbol("p"),Oo=Symbol(0),jo=Symbol(0),Fo=(t,n)=>Q(t,jo,(()=>function(t,n){const e=t.ownerSVGElement;let o,i=Jo();const a=()=>{o&&(o[yt]?.del(),o=null)},s=t=>{a(),o=t};let c,l;const u=o=>{if(a(),!o.isPrimary||n)return d(e,"pointermove",c),d(e,"pointerup",l),void t[ct].moveCapture();l=n=>{d(e,"pointermove",c),s(Ko(t,i,n))},r(e,"pointerup",l,!0),c=n=>{d(e,"pointerup",l),_o(t,i,n,Xt(o))},0===o.button&&r(e,"pointermove",c,!0)};r(e,"pointerdown",u);const p=zo(t,(()=>oi(i)),(()=>{o?a():di(i)&&!ri(i)&&t[ct].select(null)})),h=t=>{ei(i),i=t??Jo(),ii(i,null)};return t[ct].selectedSet=h,t[ct].select=t=>{a();const n=Jo();if(t?.length)for(const e of t)Qo(n,ui(e));h(n)},()=>{d(e,"pointerdown",u),p(),a(),t[ct].selectedSet=void 0,t[ct].select=void 0}}(t,n))),Yo=t=>J(t,jo);const Ko=(t,n,e)=>{if(e[No])return null;if("a"===e?.target?.tagName)return null;const o=Xt(e),i=ui(o);if(!i)return ei(n),null;const a=si(n,o),s=li(n);if(s&&a)return pi(i,e),null;if(e.shiftKey||e.ctrlKey){if(s){const t=ri(n);hi(t),Qo(n,t)}return a?ti(n,i):Qo(n,i),ii(n,e),null}return a?mt(new Io(t,(()=>oi(n))),e.clientX-10,e.clientY-10):(ei(n),Qo(n,i),ii(n,e),null)},_o=(t,n,e,o)=>{if(e[No])return;if(t[Oo]?.size)for(const n of t[Oo])if(n(e,o))return;if(o===t.ownerSVGElement)return void t[ct].moveCapture();const i=si(n,o);if(!i&&!f(e))return void t[ct].moveCapture();if(!i&&f(e))return ei(n),void fi(ui(o),e,o);const a=li(n);i&&a?fi(ui(o),e,o):i&&!a&&Xo(t,n,e)},Xo=(t,n,e)=>{const o=()=>Go(n),i=t=>Wo(n,t),a=o();L(t.ownerSVGElement,e,(n=>i((e=>it(e,t[ct].data.scale,n)))),(n=>{i((n=>Nt(n,t[ct].data.cell))),vn(t,a,o())}))},Go=t=>en([...t.shapesToMove,...mi(t.pathEndsToMove)],!1,!0),Wo=(t,n)=>{t.shapesToMove?.forEach((t=>{n(t[Jt].data.position),t[Jt].drawPosition()})),t.pathEndsToMove?.forEach((t=>{n(t.data.position),vi(t)[qt].drawPosition()}))},qo=t=>{t[ct].select(null),t[ct].select(t.children)},Jo=()=>({shapes:new Set,paths:new Set,pathEnds:new Set,shapesToMove:new Set,pathEndsToMove:new Set}),Qo=(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[qt].data.s),t.pathEnds.delete(n.path[qt].data.e);else if(n.pathEnd){const e=vi(n.pathEnd);if(t.paths.has(e))return;t.pathEnds.add(n.pathEnd),i(e,yi(n.pathEnd))}},ti=(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[qt].data.s),t.pathEnds.delete(n.path[qt].data.e),a(n.path,"highlight","highlight-s","highlight-e");else if(n.pathEnd){const e=vi(n.pathEnd);if(t.paths.delete(e)){a(e,"highlight","highlight-s","highlight-e");const o=wi(n.pathEnd);t.pathEnds.add(o),i(e,yi(o))}else t.pathEnds.delete(n.pathEnd),a(e,yi(n.pathEnd))}},ni=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(vi(t))))},ei=t=>{ni(t);const n=ri(t);n&&hi(n),t.pathEnds.clear(),t.pathEndsToMove.clear(),t.paths.clear(),t.shapes.clear(),t.shapesToMove.clear()},oi=t=>[...t.shapes,...t.paths,...mi(t.pathEnds)],ii=(t,n)=>{ai(t);const e=ci(t);e&&(ni(t),pi(e,n))},ai=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[qt].data.s),n(t[qt].data.e)})),t.pathEnds?.forEach(n)},si=(t,n)=>[...t.shapes,...[...t.pathEnds].map((t=>t.el)),...t.paths].some((t=>t.contains(n))),ci=t=>di(t)?ri(t):{},ri=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:I(t.pathEnds)}:{path:I(t.paths)}:{shape:I(t.shapes)},li=t=>!!ri(t),di=t=>t.shapes.size||t.pathEnds.size||t.paths.size,ui=t=>{const n=t[Jt]?{shape:t}:t.parentElement[Jt]?{shape:t.parentElement}:t.parentElement.parentElement[Jt]?{shape:t.parentElement.parentElement}:null;if(n)return n;const e=t[qt]?{path:t}:t.parentElement[qt]?{path:t.parentElement}:null;if(e)return e;const o=gi(t);return o?{pathEnd:o}:null},pi=(t,n)=>{t.shape?t.shape[Jt].click(n):t.path?t.path[qt].click(n):t.pathEnd&&vi(t.pathEnd)[qt].click(n,t.pathEnd.el)},hi=t=>{t.shape?t.shape[Jt].unselect():t.path?t.path[qt].unselect():t.pathEnd&&vi(t.pathEnd)[qt].unselect()},fi=(t,n,e)=>{t.shape?t.shape[Jt].moveCapture(n,e):t.path?t.path[qt].moveCapture(n,e):t.pathEnd&&vi(t.pathEnd)[qt].moveCapture(n,e)},mi=t=>[...t].map(vi),vi=t=>t.el.parentNode,gi=t=>{const n=t.hasAttribute("data-key")?t:t.parentElement.hasAttribute("data-key")?t.parentElement:null;if(!n)return null;const e=n.parentNode[qt].data;return e.s.el===n?e.s:e.e},wi=t=>{const n=vi(t)[qt].data;return n.s===t?n.e:n.s},yi=t=>vi(t)[qt].data.s===t?"highlight-s":"highlight-e";function xi(t){const n=(n,e)=>(function(t,n,e){const o=v("path");c(o),i(o,"mrkp"),t.append(o);const a=[],r=n=>a.push(Ut(t[ct].data,n.clientX,n.clientY)),l=new Set,d=t=>{s(t,"mrkt")&&l.add(t)};d(e),r(n),L(o,n,(t=>{r(t),o.setAttribute("d",Hi(a)),d(document.elementFromPoint(t.clientX,t.clientY))}),(n=>{let e=Li(b([o,...l]));o.remove(),e=Vi(Ut(t[ct].data,e.x,e.y));const i={id:_(),type:7,position:e,d:""},s=[{position:{x:0,y:0},d:Hi(a)}],c=[];l.forEach((t=>{const n=t.parentNode;c.push(n),s.push(n[Jt].data)}));for(const t of s)$i(i,t);c.length?Hn(t,c,on(i)):kn(t,on(i),!0)}))}(t,n,e),!0);return((t,n)=>{t[Oo]??=new Set,t[Oo].add(n)})(t,n),()=>{((t,n)=>{t[Oo]?.delete(n)})(t,n)}}const bi=t=>``;function $i(t,n){const e=ki(n.d),o=Y(n.position);N(o,t.position,-1);let i=n.d;for(const t of e){const n=Y(t);Vi(N(t,o)),i=Ci(i,n,t)}t.d+=i}const ki=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))}})),Mi=t=>`M${t.x} ${t.y}l`,Ci=(t,n,e)=>t.replaceAll(Mi(n),Mi(e));function Hi(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[p,h]=[t[1].x,t[1].y],[f,m]=[(c+p)/2,(r+h)/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 Li=t=>({x:Math.round(t.x+t.width/2),y:Math.round(t.y+t.height/2)}),Vi=t=>(t.x=Math.round(t.x),t.y=Math.round(t.y),t);function zi(t){return!!Bi(t)&&(t.c[t.i].u(),t.i-=1,!0)}function Si(t){const n=Di(t);return null!==n&&(t.i=n,t.c[n].r(),!0)}const Di=t=>{if(!t)return null;const n=t.i+1;return n<=t.c.length-1?n:null},Bi=t=>t&&t.i>=0,Zi=(t,n,e)=>Ui(t,(()=>{Ri(t,mn(n,e)),sn(t,e),Nn(n)}),(()=>{Ri(t,fn(n,e)),sn(t,e)})),Ei=(t,n,e)=>Ui(t,(()=>{Ri(t,fn(n,e)),sn(t,e)}),(()=>{Ri(t,mn(n,e)),Nn(n)})),Ti=(t,n,e)=>Ui(t,(()=>{Ri(t,gn(e,n)),sn(t,n)}),(()=>{Ri(t,gn(n,e)),sn(t,e)})),Ai=(t,n,e,o,i)=>Ui(t,(()=>{Ri(t,fn(n,e)),sn(t,e),Ri(t,mn(o,i)),sn(t,i),Nn(o)}),(()=>{Ri(t,mn(n,e)),Nn(n),Ri(t,fn(o,i)),sn(t,i)})),Ri=(t,n)=>{n[Pi]=!0,B(t,n)},Pi=Symbol(0);function Ui(t,n,e){t[Yi]??={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[Yi],n,e),ji(t)}function Ii(t,n){n(t[Yi])&&(t[ct].select(null),ji(t))}const Ni=t=>Ii(t,zi),Oi=t=>Ii(t,Si);const ji=t=>{return B(t,D(Fi,(n=t[Yi],{u:Bi(n),r:null!==Di(n)})));var n},Fi="dgrmh",Yi=Symbol("h");class Ki 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");r(this.g,Fi,(t=>{const o=(t,n)=>n?i(t,"actv"):a(t,"actv");o(n,t.detail.u),o(e,t.detail.r)})),r(n,"click",(t=>Ni(this.g))),r(e,"click",(t=>Oi(this.g)))}}function _i(t,n){an(t,n),function(t){const n=t.getBoundingClientRect(),e=window.innerWidth/2,o=window.innerHeight/2;t[ct].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[ct].scale(a,{x:e,y:o})}(t)}customElements.define("ap-history",Ki);const Xi=async()=>{const t=await dt((()=>(async()=>(await $(`${St}l`)).json())())),e=!!t.b,o=wt(`
Your monthly payment is ${t.p}.
Your subscription ${tt(e,`
is paid for by ${t.b}`)}
Delete
${et(t.u,(t=>`
${t.n}
Delete
`))}
${tt(e,`\n\t\t\t\t\n\t\t\t\t\tYour subscription is paid for by ${t.b}.
To buy a subscription for a person you have to get your own subscription.\n\t\t\t\t\tBuy a subscription here.\n\t\t\t\t
`)}
`,null,"Team subscriptions",!1),i=async(t,e)=>{n(o,"pay").innerText=(await dt((()=>e(t)))).toString(),o.querySelector(`[usr="${t}"]`).remove()};u(o,"[del]",(t=>{const n=Number.parseInt(p(t,"del"));Gi((()=>i(n,Tt)),(()=>i(n,At)))})),u(o,"[inv]",(t=>Wi((()=>dt((async()=>{const t=Rt();await navigator.clipboard.writeText(`${Ht}subscription-invite/${t}`),await(t=>k(`${St}a`,t))(t),Ct()}))))))},Gi=(t,n)=>{const e=gt(g('\n\t\t\t\n\t\t\tPerson will lose access for all your diagrams and folders.'),null,!0),o=t=>{e[yt].del(),t()};u(e,"[del]",(()=>o(t))),u(e,"[dpr]",(()=>o(n)))},Wi=t=>{const n=gt(g('
Send the link to the person you want to buy a subscription to.

Subscription fees will be included in your monthly payment. You can cancel person subscription at any time.

Subscription fee is
270 ₽ per month.

The subscription link is one-time only and is active for 24 hours.'),null,!0);u(n,"[crt]",(()=>{n[yt].del(),t()}))};const qi=()=>{if(!document.cookie.includes("dgrma=1"))return null;const t=q(localStorage.getItem("dgrm"));return t&&new Date(t.e)>new Date?t:null},Ji=(t,n,e,o,i)=>{n&&na(Qi(),e,o,n.n,0===e?n.i:n.n,n.i,new Date,i)},Qi=()=>`dgrm${qi()?.l}`,ta=(t,n)=>sa(t,(t=>ea(t.transaction("r","readonly").objectStore("r"),n))),na=(t,n,e,o,i,a,s,c)=>sa(t,(t=>{const r=t.transaction("r","readwrite").objectStore("r");ea(r,(l=>{const d=l.find((t=>t.k===i));l.length>=5&&!d&&oa(t,r,l[l.length-1]);const u=d?.i??a??Rt();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})}))})),ea=(t,n)=>{t.getAll().onsuccess=t=>{n((t.target.result??[]).sort(((t,n)=>n.d.getTime()-t.d.getTime())))}},oa=(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()},ia=(t,n,e)=>sa(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)}})),aa=(t,n,e)=>sa(t,(t=>{const o=t.transaction("r","readwrite").objectStore("r");ea(o,(i=>{const a=i.find((t=>t.k===n));a?oa(t,o,a,e):e()}))})),sa=(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)}},ca=t=>C("k",t);function ra(t){B(t,D("dgrmn",null,!0))&&(!function(t){for(t[ct].select(null);t.firstChild;)On(t.firstChild);t[ct].move(0,0,1)}(t),function(t){var n;(n=t[Yi])&&(n.c=[],n.i=-1),ji(t)}(t),Eo(t))}async function la(t,n){if(!t?.i)return void ua({a:0,u:[]},!0,!0,n);const e=await dt((()=>(async t=>(await $(`${Vt}${t}`)).json())(t.i))),o=ua(e,!1,!t.m,n);t.m&&(ga(o,"[anon]",[wa[0],wa[1],wa[2]],(n=>dt((async()=>{var o,i;e.a!==n[1]&&(e.a=n[1],await(o=t.i,i=n[1],k(`${Vt}a/${o}`,i.toString())))})))),da(o,e.u,((n,e)=>{return o=t.i,M(`${Vt}${o}`,{i:n,r:e});var o})),u(o,"[inv]",(n=>ha((n=>dt((async()=>{const e=Rt();var o,i,a;await navigator.clipboard.writeText(`${Ht}invite/${e}`),await(o=t.i,i=e,a=n,M(`${Vt}i/${o}`,{i:i,r:a})),Ct()}))))))),u(o,"[cop]",(async n=>{await navigator.clipboard.writeText(ca(t.i)),Ct(),o[yt].del()}))}const da=(t,n,e)=>u(t,"[uu]",(o=>{const i=o.currentTarget,a=Number(o.currentTarget.getAttribute("uu")),s=t=>dt((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])}));va(o,[bt(wa[1][0],(()=>s(wa[1]))),bt(wa[2][0],(()=>s(wa[2]))),kt((()=>dt((async()=>{await e(a,wa[0][1]),t.querySelector(`[uitm="${a}"]`).remove()}))))])})),ua=(t,n,e,o)=>wt(`
${pa({i:0,n:"Anyone with the link",r:t.a})} ${et(t?.u,pa)}
${tt(n,'To share, save diagram to the cloud.')} ${tt(e&&!n,'You do not have access to manage permissions.')}
`,null,"Permissions",o),pa=t=>``,ha=t=>{const n=gt(g('
Send a link to the person you want to invite.

Person must have a DGRM subscription.
You can buy subscription for the person.

Permissions: Viewer
The invitation link is one-time only and is active for 24 hours.'),null,!0);let e=1;ga(n,"[prm]",[wa[1],wa[2]],(t=>{e=t[1]})),u(n,"[crt]",(o=>{n[yt].del(),t(e)})),u(n,"[sub]",(t=>{ht(),Xi()}))};async function fa(t){const n=await dt((()=>(async t=>(await $(`${zt}${t}`)).json())(t))),e=ma(n);da(e,n,((n,e)=>((t,n,e)=>M(`${zt}${t}`,{i:n,r:e}))(t,n,e))),u(e,"[inv]",(n=>ha((n=>dt((async()=>{const e=Rt();await navigator.clipboard.writeText(`${Ht}invite-folder/${e}`),await((t,n,e)=>M(`${zt}i/${t}`,{i:n,r:e}))(t,e,n),Ct()}))))))}const ma=t=>wt(`
${et(t,pa,'
The folder is not shared
')}
`,null,"Permissions",!0),va=(t,n)=>xt(t.currentTarget,n),ga=(t,n,e,o)=>u(t,n,(t=>{const n=t.currentTarget;va(t,e.map((t=>bt(t[0],(()=>(async t=>{n.textContent=t[0],o(t)})(t))))))})),wa=[["No access",0],["Viewer",1],["Editor",2]],ya=async t=>{const e=xa(`
${qi()?'':'
Log in to access cloud storage.
'}
`);e.s();const o=t=>{n(e.m,"ftr").style.display=t?"unset":"none"},i=async()=>{await ba(e.h,e.b,(()=>e.m[yt].del())),o(!0)};await i(),u(e.m,"[cld]",(()=>dt((async()=>{o(!1),await $a(t,e.h,e.b,!0,(async t=>await i()))})))),u(e.m,"[dvc]",(async()=>{e.m[yt].del(),await async function(t){try{const n=await je(Ke);if(!n)return;const e=await Za(t,n.f);if(!e)return void Ea();n.h?Bo(t,n.h,e):Zo(t,X(n.f.name),e)}catch(t){console.log(t),Ea()}}(t)}))};const xa=t=>{const e=wt(`
${t}`,g('
')),o=t=>n(e,t);return{m:e,h:o("hdr"),b:o("cnt"),s:()=>{pt(e).style.display="flex"}}},ba=async(t,n,e)=>{t.innerHTML='CloseRecent',u(t,"[c]",e);const o=await new Promise(((t,n)=>ta(Qi(),t)));n.innerHTML=o?.length?et(o,(t=>``)):Pa},$a=async(t,n,e,o,i)=>{let a=await Bt(),s={i:null,n:"Cloud",m:!0,r:!1};const c=[],r=n=>{a.d.delete(n),n===To(t)?.i&&Eo(t),d()},l=(n,e)=>{e&&Eo(t),a.f.delete(n),d()},d=()=>Ma(e,s,a,((n,e)=>dt((async()=>{a.d.get(n).n=await(async(t,n)=>(await k(`${Lt}a/n/${t}`,n)).text())(n,e),n===To(t)?.i&&((t,n,e)=>{t[Po].n=n,Ao(t,0,e,null)})(t,a.d.get(n).n,s?.n),d()}))),(t=>dt((async()=>{var n;await(n=t,M(`${Lt}a/d/${n}`)),r(t)}))),(t=>dt((async()=>{var n;await(n=t,M(`${Vt}r/${n}`)),r(t)}))),(t=>dt((async()=>{c.push(s),s=a.f.get(t),u(),a=await Bt(t),d()}))),((t,n)=>dt((async()=>{a.f.get(t).n=await(async(t,n)=>(await k(`${Lt}f/n/${t}`,n)).text())(t,n),d()}))),(n=>dt((async()=>l(n,await(async(t,n)=>{const e=new URL(`${Lt}f/d/${t}`);return Pt(e,"k",n),(await M(e.toString())).json()})(n,To(t)?.i))))),(n=>dt((async()=>l(n,await(async(t,n)=>(await k(`${zt}r/${t}`,n)).json())(n,To(t)?.i)))))),u=()=>ka(n,s,o,i,(()=>dt((async()=>{const t=c.pop();s=t,u(),a=await Bt(t.i),d()}))),(t=>dt((async()=>{const n=await(async t=>(await k(`${Lt}f/a`,t)).json())(t);n.m=!0,a.f.set(n.i,n),d()}))),((t,n)=>dt((async()=>{const e=Rt();a.d.set(e,{i:e,n:await Zt(e,t,n,tn()),d:Date.now(),m:!0,r:!1}),d()}))));return d(),u(),()=>({f:s,d:a})},ka=(t,n,e,o,i,a,s)=>{t.innerHTML=`\n\t\t${n.i||e?`${Aa}`:"Close"}\n\t\t${n.n??""}\n\t\t${n.m?`${Ta}`:''}`,u(t,"[c]",(t=>n.i?i():o()));const c=bt("Add diagram",(()=>Va("New diagram",(t=>s(n.i,t)))));u(t,"[af]",(t=>Ca(t,n.i?[c,La(n.i)]:[c,bt("Add folder",(()=>Va("New folder",a)))])))},Ma=(t,n,e,o,i,a,s,c,r,l)=>{t.innerHTML=`${et([...e.f],(t=>``))}\n\t\t${et([...e.d],(t=>``))}\n\t${e.f.size||e.d.size?"":Pa}`,u(t,"[fld]",(t=>s(Number(t.currentTarget.getAttribute("fld"))))),u(t,"[fedt]",(t=>{const n=e.f.get(Number(t.currentTarget.getAttribute("fedt"))),o=n.m?[Ha(n.n,(t=>c(n.i,t))),La(n.i),kt((()=>r(n.i)))]:[];n.r&&o.push($t("Remove from my cloud",(()=>l(n.i)))),Ca(t,o)})),u(t,"[edt]",(t=>{const n=e.d.get(t.currentTarget.getAttribute("edt")),s=n.m?[Ha(n.n,(t=>o(n.i,t))),bt("Share",(t=>la(n,!0))),kt((()=>i(n.i)))]:[];n.r&&s.push($t("Remove from my cloud",(()=>a(n.i)))),Ca(t,s)}))},Ca=(t,e)=>xt(n(t.currentTarget,"dts"),e),Ha=(t,n)=>bt("Rename",(()=>Va(t,(e=>{t!==e&&n(e)})))),La=t=>bt("Share",(()=>fa(t)));function Va(t,e){const o=gt(g(`
`),"mdm",!0);u(o,"[sv]",(t=>{o[yt].del(),e(Ro(n(o,"nm").value))}))}const za=Symbol(0),Sa=t=>J(t,za);function Da(t,n){const e=new AbortController;return document.body.addEventListener("dragover",(t=>t.preventDefault()),{signal:e.signal}),document.body.addEventListener("drop",(async e=>{if(e.preventDefault(),1===e.dataTransfer?.items?.length&&"file"===e.dataTransfer.items[0].kind&&e.dataTransfer.items[0].type.startsWith("image/"))if("getAsFileSystemHandle"in e.dataTransfer.items[0]){const o=await e.dataTransfer.items[0].getAsFileSystemHandle(),i=await n(t,await o.getFile(),e);i&&Bo(t,o,i)}else{const o=e.dataTransfer.items[0].getAsFile(),i=await n(t,o,e);i&&Zo(t,X(o.name),i)}else Ea()}),{signal:e.signal}),()=>e.abort()}async function Ba(t,n,e){const o=await Za(t,n);return o||(Ge(t,n,e.clientX,e.clientY),null)}async function Za(t,n){if("image/png"!==n.type)return null;const e=await Co(n);if(e){ra(t);const n=q(e);return _i(t,n),n}return null}const Ea=()=>alert("File cannot be read. Use the exact image file you got from the application."),Ta='',Aa='',Ra='',Pa='
No items
',Ua=()=>`User${Math.floor(100*Math.random())}`,Ia=(t,n)=>{if(n?.length)return n.forEach((n=>{t.s[n]=null})),console.log(t),t},Na=t=>{const n=Oa(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)",w(e),e},Oa=t=>`hsl(${[...t].reduce(((t,n)=>n.charCodeAt(0)+((t<<5)-t)),0)%360}, 97%, 47%)`,ja=(t,n,e,o)=>{const i=((t,n,e)=>({x:t.position.x+n*t.scale,y:t.position.y+e*t.scale}))(t[ct].data,e,o);n.style.transform=`translate(${i.x}px, ${i.y}px)`},Fa=async t=>{const n=To(t);if(n?.f){const e=nn(t);yo(t,e,(async o=>{const i=await n.f.createWritable();await i.write(o),await i.close(),Ji(0,n,1,null,e),Wa(t)}))}else if(n?.i)if(n.e){if(ss(t))return void Mt("Autosave is enabled. Manual saving is not necessary.");dt((async()=>{await Ga(t,n.i,!0),Wa(t),is(t,n,!1)}))}else alert('You do not have access to edit this diagram.\r\nUse "Save As" to make your own copy.');else Ya(t)},Ya=async t=>qi()?Ka(t):_a(t),Ka=async t=>{const e=await dt((()=>(async(t,n)=>{const e=xa(n),o=await $a(t,e.h,e.b,!1,(()=>e.m[yt].del()));return e.s(),{m:e.m,d:()=>o()}})(t,`
`))),o=()=>e.m[yt].del(),i=()=>Ro(n(e.m,"snm").value);u(e.m,"[dvc]",(n=>{o(),Xa(t,i())})),u(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=>{dt(t),o()},s=(e,o)=>{Do(t,e,o,!0,!0,n?.f?.n),Wa(t)},c=i(),r=Object.entries(n.d.d).find((t=>t[1].n===c));if(r){const n=To(t);return r[0]===n?.i&&n.m?void a((async()=>{await Ga(t,n.i,!0),Wa(t)})):void(confirm("Overwrite existing file?")&&a((async()=>s(r[0],await(async(t,n)=>(await M(`${Lt}a/o/${t}`,n)).text())(r[0],nn(t))))))}a((async()=>{const e=Rt();s(e,await Zt(e,n.f.i,c,nn(t)))}))}))},_a=t=>{const e=gt(g(`
Log in to access cloud storage.
`),"mdm");u(e,"[dvc]",(o=>{Xa(t,Ro(n(e,"nm").value)),e[yt].del()}))},Xa=(t,n)=>{const e=nn(t);yo(t,e,(async o=>{const i=Oe(o,n?.length?n:qa());if(i){const n=await i;n&&(Bo(t,n,e),Wa(t))}else Zo(t,n,e),Wa(t)}))},Ga=async(t,n,e)=>{let o;if(e&&ts(t)){const e=es(t),i=[...e.c,...e.u],a=function(t,n){for(const e in t.s)n.has(e)&&un(t.s[e]);return t}(en(i.length?[...document.querySelectorAll(i.map((t=>`[id="${t}"]`)).join(","))]:null,!1),e.u);e.d.forEach((t=>{a.s[t]=null})),o=await(async(t,n)=>(await M(`${Lt}u/${t}`,n)).json())(n,a)}else o=(await Dt(n)).d;sn(t,o),P(t.children,(t=>{Object.prototype.hasOwnProperty.call(o.s,t.id)||On(t)}))},Wa=(t,n)=>{ns(t),Mt(n??"Saved")},qa=()=>{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`},Ja=t=>{t[os]?.r(),t[os]=void 0},Qa=t=>{if(t[os])return;const n=new AbortController;t[os]={c:new Set,u:new Set,d:new Set,r:()=>{n.abort(),ns(t)}};const e=n=>{t[os].c.add(n),t[os].u.delete(n),t[os].d.delete(n)},o=n=>{t[os].c.has(n)||t[os].u.add(n),t[os].d.delete(n)},i=n=>n?.forEach((n=>{t[os].d.add(n),t[os].c.delete(n),t[os].u.delete(n)})),a=(e,o)=>l(n.signal,t,e,o);a("dgrmc",(t=>{t.detail.newIds?.forEach(e)})),a("dgrmu",(t=>{return n=t.detail.shapesToUpdData,Object.keys(n.s).forEach(o);var n})),a("dgrmd",(t=>i(t.detail.delIds))),a("dgrmdc",(t=>{i(t.detail.delIds),t.detail.newIds?.forEach(e)})),t.addEventListener("dgrmn",(n=>{!ts(t)||window.confirm("Changes you made may not be saved. Continue?")?ns(t):n.preventDefault()}),{signal:n.signal}),window.addEventListener("beforeunload",(n=>{ts(t)&&n.preventDefault()}),{signal:n.signal})},ts=t=>t[os]?.c.size||t[os]?.u.size||t[os]?.d.size,ns=t=>{t[os]?.c.clear(),t[os]?.u.clear(),t[os]?.d.clear()},es=t=>t[os],os=Symbol(0),is=(t,n,e)=>{const o=()=>{t[as]&&t[as](),delete t[as],Qa(t),cs(!1),ls()};o(),!e&&n?.i&&(lt(!0),t[as]=((t,n,e,o)=>{const i=_(),a=new AbortController,s=new Map,c=new WebSocket(`${Ht}w/${n.i}/${i}/${qi()?.n??Ua()}`),r=(t,n)=>l(a.signal,c,t,n);let d=t=>c.send(W(t));return r("open",(o=>{if(n.e){const n=t=>d([2,t]),e=(n,e)=>l(a.signal,t,n,e);e("dgrmc",(t=>n(t.detail.shapesToCreateData))),e("dgrmu",(t=>n(t.detail.shapesToUpdData))),e("dgrmd",(t=>n(Ia(tn(),t.detail.delIds)))),e("dgrmdc",(t=>n(Ia(t.detail.shapesToCreateData??tn(),t.detail.delIds))))}l(a.signal,t.ownerSVGElement,"pointermove",Z((n=>{const e=Ut(t[ct].data,n.clientX,n.clientY);d([1,i,Math.round(e.x),Math.round(e.y)])}),60)),e()})),r("message",(n=>{const e=q(n.data);switch(e[0]){case 1:ja(t,s.get(e[1]),e[2],e[3]);break;case 2:{const n=e[1],o=[];for(const[t,e]of Object.entries(n.s))e||(o.push(t),delete n.s[t]);o.length&&Nn(o),sn(t,n)}break;case 3:s.set(e[1],Na(e[2]));break;case 4:s.get(e[1]).remove(),s.delete(e[1])}})),r("close",(t=>{console.log(t),o(t.reason)})),()=>{d=t=>{},a.abort(),c?.readyState===WebSocket.OPEN&&c?.close(),s.forEach((t=>t.remove()))}})(t,n,(()=>{Ja(t),n.e&&cs(!0),lt(!1)}),(e=>{o(),lt(!1),rs(t,n)})))},as=Symbol(0),ss=t=>t[as],cs=t=>{e("menu").a=t},rs=(t,n)=>{const e=g('
Working offline. Connect.
');e.onclick=()=>dt((async()=>{await Ga(t,n.i,n.e),is(t,n,!1)})),w(e)},ls=()=>e("rcn")?.remove();class ds extends HTMLElement{constructor(t){super(),this.g=t}connectedCallback(){const t=this.attachShadow({mode:"closed"});t.innerHTML='';const e=e=>n(t,e);this.C=e;const o=t=>{this.contains(t.target)||s()};let i;let a=null;const s=()=>{a.remove(),a=null,d(document,"pointerdown",o),i&&i()},c=()=>{r(document,"pointerdown",o,!0),i=S(s),a=function(t,n,e){const o=qi(),i=To(t),a=o||Fe||i?.i&&i?.e,s=n?"Save (autosave enabled)":i?.i?"Save and sync with cloud":"Save",c=g(`
New
Open
${a?'
'+s+"
":""}
Save${Ye||a?" as":""}
${ot()?Bn+"Download":Zn+"Send"} image
Share
${o?o.n:"Log in"}
`);c.setAttribute("options","");const r=(t,n)=>u(c,t,(async t=>{e(),await n(t)}));u(c,"[menu2]",(t=>e())),r("[new]",(()=>{ra(t)})),a&&r("[save]",(async()=>await Fa(t)));return r("[saveas]",(()=>Ya(t))),r("[open]",(async()=>await ya(t))),r("[login]",(t=>function(){const t=qi(),n=gt(g(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
'));u(n,"[sbs]",(()=>{n[yt].del(),Xi()}))}())),r("[link]",(n=>(t=>la(To(t),!1))(t))),r("[down]",(n=>(t=>yo(t,nn(t),(async n=>await Uo(t,n))))(t))),c}(this.g,this.a,(()=>s())),t.append(a)};r(e("menu"),"click",(t=>c()))}a=!1}customElements.define("ap-menu",ds);class us 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=>{r(t,"pointerdown",this),r(t,"click",this)})),r(n,"pointerleave",this),r(n,"pointerup",this),r(n,"pointermove",this);const e=t.getElementById("m");let o;r(e,"click",(t=>{o?(o(),o=null,e.style.opacity="0.4"):(o=xi(this.g),e.style.opacity="1")}))}handleEvent(t){switch(t.type){case"pointermove":if(!this.H){const n=document.elementFromPoint(t.clientX,t.clientY);if(n===this.L)return;this.V===this.L&&this.g.ownerSVGElement.setPointerCapture(t.pointerId),this.L=n}break;case"pointerleave":if(this.H=!0,null!=this.S){const n=ps(this.g,this.S,!1,t.clientX,t.clientY)[0];f(t)||this.g[ct].select([n]),n[Jt]?n[Jt]?.moveCapture(t,n,!0):n[qt]?.moveCapture(t,n,!0)}this.D();break;case"pointerdown":this.S=parseInt(p(t,"data-cmd-arg")),this.V=document.elementFromPoint(t.clientX,t.clientY),this.L=this.V,this.H=null;break;case"pointerup":this.D();break;case"click":this.g.ownerSVGElement.focus(),this.g[ct].select(ps(this.g,parseInt(p(t,"data-cmd-arg")),!0))}}D(){this.S=null,this.V=null,this.L=null}}customElements.define("ap-menu-shape",us);const ps=(t,n,e,o,i)=>{return $n(t,on((a=n,Kt.get(a)())),e,o,i);var a};const hs=Symbol(0),fs=t=>Q(t,hs,(()=>function(t){const n=new AbortController;l(n.signal,document,"paste",(async n=>{h(n)||ms(t,(t=>{const n=t.getData("text/plain"),e=Vo(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 e=Z((async()=>await Fa(t)),500);return document.addEventListener("keydown",(async n=>{if((n.ctrlKey||n.metaKey)&&"KeyS"===n.code&&n.preventDefault(),(n.ctrlKey||n.metaKey)&&!n.repeat&&!h(n))switch(n.code){case"KeyZ":ht(),Ni(t);break;case"KeyY":ht(),Oi(t);break;case"KeyS":ht(),n.shiftKey?Ya(t):e();break;case"KeyA":ht(),qo(t)}}),{signal:n.signal}),()=>n.abort()}(t)));function ms(t,n,e,o){const i=n=>t[ct].select($n(t,n,!0,e,o));if(n?.data)i(function(t){if(!t)return null;const n=new Map,e=t=>{const e=_();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)We(n.img,(t=>i(on(t))));else if(n?.txt){const e=function(t,n){const e=v("text");lo(e,null,n),e.style.visibility="hidden",t.append(e);const o=oo(e);return e.remove(),o}(t,n.txt);i(on({id:_(),type:3,position:{x:0,y:0},title:n.txt,w:e.w,h:e.h}))}else Mt("Clipboard is empty")}const vs=Symbol(0),gs=t=>Q(t,vs,(()=>function(t){const n=t.ownerSVGElement,e=t.ownerDocument;let o,i,a,s;function c(n){d(e,"pointermove",m),d(e,"pointerup",h),a||(a=function(t,n,e,o){const i=g(`${Ho?'
Paste
':""}
Select all
Add image
`),a=(t,n)=>u(i,t,(async t=>{await n(),o()}));Ho&&a("[p]",(async()=>ms(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=Vo(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()=>qo(e))),a("[i]",(async()=>async function(t,n,e){const o=await je(_e);o&&Ge(t,o.f,n,e)}(e,t,n)));return{del:mt(i,t-10,n-10)[yt].del,el:i}}(n.clientX,n.clientY,t,h),r(e,"pointerdown",f))}function p(){a?.del(),a=null}function h(){clearTimeout(o),o=null,p(),d(e,"pointerdown",f),d(e,"pointerup",h),d(e,"wheel",h),d(e,"keydown",h),d(e,"pointerup",w),d(e,"pointercancel",w),d(e,"pointermove",v),i=!1,s=!1}function f(t){a.el.contains(t.target)||h()}function m(){h(),i=!0}function v(){s||h(),i=!0}function w(){s=!0}const y=new AbortController;async function x(t){t.isPrimary&&Xt(t)===n?(h(),r(e,"pointermove",m,!0),r(e,"pointerup",h,!0),r(e,"wheel",h,!0),r(e,"keydown",h,!0),2!==t.button&&(o=setTimeout((n=>{c(t),r(e,"pointerup",w,!0),r(e,"pointercancel",w,!0),r(e,"pointermove",v,!0)}),500))):h()}return l(y.signal,n,"pointerdown",x),n.addEventListener("contextmenu",(async t=>{n===Xt(t)&&(t.preventDefault(),i||c(t))}),{signal:y.signal}),()=>{y.abort(),h()}}(t)));const ws=Symbol(0),ys=t=>Q(t,ws,(()=>function(t){const n=t.ownerSVGElement;let e,a,s,c,u;const p=()=>{u?.remove(),u=null};let h=!1;function f(t){if(t[No]||!s)return void g();t[No]=!0,h&&(p(),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&&(c.x=t.clientX),e<0&&(c.y=t.clientY),s.style.transform=`translate(${c.x}px, ${c.y}px)`}function m(n){if(s&&!h){n[No]=!0;const e=n=>ks(Ut(t[ct].data,c.x,c.y),s.width.baseVal.value/t[ct].data.scale,s.height.baseVal.value/t[ct].data.scale,n.x,n.y);!function(t,n,e,o){const i=Jo(),a=t=>Qo(i,t),s=t=>t.shape&&e(t.shape.shapeEl)||o(t);for(const t of n)if(t[Jt])e(t)&&a({shape:t});else if(t[qt]){const n=s(t[qt].data.s),e=s(t[qt].data.e);n&&e?a({path:t}):n?a({pathEnd:t[qt].data.s}):e&&a({pathEnd:t[qt].data.e})}t[ct].selectedSet(i)}(t,t.children,(t=>e(t[Jt].data.position)),(t=>e(t.data.position)))}g()}function g(){clearTimeout(e),e=null,s?.remove(),s=null,p(),h=!1,d(n,"pointermove",f),d(n,"wheel",g),d(n,"pointercancel",g),d(n,"pointerup",m)}const w=new AbortController;return l(w.signal,n,"pointerdown",(l=>{if(!l.isPrimary||Xt(l)!==n||$s(l))return void g();r(n,"pointermove",f),r(n,"wheel",g,!0),r(n,"pointercancel",g,!0),r(n,"pointerup",m,!0);const d=()=>{t[ct].selectedSet(null),h=!0,n.setPointerCapture(l.pointerId),a={x:l.clientX,y:l.clientY},c={x:l.clientX,y:l.clientY},s=v("rect"),s.style.cssText="rx:8px; fill: rgb(108 187 247 / 51%)",o(s,c),n.append(s)};2!==l.button?e=setTimeout((t=>{d(),u=v("circle"),i(u,"ative-elem"),u.style.cssText="r:10px; fill: rgb(108 187 247 / 51%)",o(u,{x:l.clientX,y:l.clientY}),n.append(u)}),500):d()})),()=>{w.abort(),g()}}(t))),xs=t=>J(t,ws);const bs=-1!==window.navigator.userAgent.indexOf(" OPR"),$s=t=>bs&&0!==t.button,ks=(t,n,e,o,i)=>t.x<=o&&o<=t.x+n&&t.y<=i&&i<=t.y+e,Ms=t=>{document.title=t??"DGRM - Flowchart editor"},Cs=t=>{c(t),Ls().style.display="none",Vs(),(t=>{Sa(t),Q(t,za,(()=>Da(t,((t,n,e)=>Za(t,n)))))})(t),(t=>{J(t,vs)})(t),(t=>{J(t,hs)})(t),Ja(t),xs(t),Yo(t),Ft(t),Fo(t,!0),jt(t)},Hs=t=>{c(t,!0),Ls().style.display="",zs(),(t=>{Sa(t),Q(t,za,(()=>Da(t,Ba)))})(t),gs(t),fs(t),Qa(t),xs(t),Yo(t),Ft(t),ys(t),Fo(t,!1),jt(t)},Ls=()=>document.getElementsByTagName("ap-menu-shape")[0],Vs=()=>w(g('
Read only mode
')),zs=()=>e("rnl")?.remove();e("diagram").addEventListener("touchmove",(t=>t.preventDefault()),{passive:!1});const Ss=e("canvas");Ss[ct]={data:{position:{x:0,y:0},scale:1,cell:24},shapeMap:function(n){const e=(t,e)=>Yn(n,t,e);return{0:{create:t=>e(ae(n,t),3)},1:{create:i=>e(function(n,e){e.r??=48;let i,a=e.r;const s=Ce(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=O(e.position,-e.r),{x:e.r,y:e.r})),(r=>{let l=It(n[ct].data,r).x-i.x;l<48&&(l=48);const d=48*Math.round(l/48)/2;e.r!==d&&De(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=De(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,Tn(s),Se(s.el,"outer",e.r+24),Se(s.el,"main",e.r),s.draw()}return 48!==e.r?c():s.draw(),s.el[Jt].patch=t=>{const n=Un(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&&(ze=[...t.styles])},s.el}(n,i),2)},2:{create:t=>e(Ze(n,t),2)},3:{create:t=>e(eo(n,t),2)},4:{create:a=>e(function(n,e){e.w??=96;let a,s=e.w;const c=Ce(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=O(e.position,-t),{x:t,y:t}}),(i=>{let l=It(n[ct].data,i).x-a.x;l<48&&(l=48);const d=48*Math.round(l/48);if(e.w!==d&&fo(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=fo(t,s);n!==e.w&&(e.w=n,r())}));function r(){const t=ho(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,Tn(c);const n=ho(e.w,9);po(c.el,"main",n),po(c.el,"border",n),po(c.el,"outer",ho(e.w,-24)),c.draw()}return i(c.el,"shrhomb"),96!==e.w?r():c.draw(),c.el[Jt].patch=t=>{const n=Un(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&&(uo=[...t.styles])},c.el}(n,a),2)},5:{create:t=>e(Ue(n,t),1)},6:{create:t=>e(qe(n,t),0)},7:{create:t=>e(function(t,n){const e=He(t,n,bi(n),{},null,null,null,Xe,(()=>{Vi(n.position)}));return i(e.el,"shmrk"),e.el.style.mixBlendMode="multiply",e.draw(),e.el[Jt].patch=t=>{In(e,t)&&e.draw()},e.el}(n,t),4)}}}(Ss),f:(t,n,e,o,i)=>{const a="DGRM examples"===o;a||!n?.i||n.e?Hs(t):Cs(t),Ms(n?.n),Ji(0,n,e,o,i),is(t,n,a)}};{const t=new URL(window.location.href),n=n=>t.searchParams.get(n);n("usr")&&(Ds=n("usr"),Bs=n("usrn"),Zs=parseInt(n("expr")),localStorage.setItem("dgrm",W({l:Ds,n:Bs,e:Zs})),H("usr","usrn","expr"))}var Ds,Bs,Zs,Es,Ts;(t=>{const n=new ds(t);n.id="menu",w(n)})(Ss),w(new Ki(Ss)),w(new us(Ss)),Ss.ownerSVGElement.addEventListener("contextmenu",(async t=>{h(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[at]=e?t.clientX-e:0,t[st]=o?t.clientY-o:0,e=t.clientX,o=t.clientY):(t[at]=t.movementX,t[st]=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=>{d(t,"pointermove",i,!0)}),{capture:!0,once:!0,passive:!0})}),{capture:!0,passive:!0})}(document),(t=>{const n=(n,e)=>r(t,n,(t=>{t[Pi]||e(t)}));n("dgrmc",(n=>Zi(t,n.detail.newIds,n.detail.shapesToCreateData))),n("dgrmd",(n=>Ei(t,n.detail.delIds,n.detail.shapesToDelData))),n("dgrmu",(n=>Ti(t,n.detail.shapesBeforeUpdData,n.detail.shapesToUpdData))),n("dgrmdc",(n=>Ai(t,n.detail.delIds,n.detail.shapesToDelData,n.detail.newIds,n.detail.shapesToCreateData)))})(Ss);{const t=new URL(window.location.href),e=n=>t.searchParams.get(n);if(e("k")){lt(!0);const t=e("k");try{const n=await Dt(t);Do(Ss,t,n.n,n.e,n.m,n.l),_i(Ss,n.d)}catch(n){alert("The link is broken or you do not have permission. Try to relogin."),await(Ts=t,new Promise(((t,n)=>aa(Qi(),Ts,(()=>t()))))),Eo(Ss)}H("k"),lt(!1)}else if(e("l")){try{const t=e("l"),n=await(Es=t,new Promise(((t,n)=>ia(Qi(),Es,t))));n&&(Zo(Ss,n.n,n.s),_i(Ss,n.s))}catch{alert("The link is broken."),Eo(Ss)}H("l")}else if(e("u")){try{const t=new URL(e("u")),n=q(await Co(await(await fetch(t)).blob()));Zo(Ss,(t=>t.substring(t.lastIndexOf("/")+1))(t.href),n,t.hostname),_i(Ss,n)}catch{Ea(),Eo(Ss)}H("u")}else Eo(Ss),qi()||function(){const t=g('');function e(){t.remove(),d(document,"pointerdown",o),d(document,"wheel",e),d(document,"keydown",e),d(document,"dragover",e)}function o(n){t.contains(n.target)||e()}t.style.display="unset",r(document,"pointerdown",o),r(document,"wheel",e,!0),r(document,"keydown",e,!0),r(document,"dragover",e,!0),r(n(t,"cl"),"click",(t=>e()),!0),w(t)}()}