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