1 line
148 KiB
JavaScript
1 line
148 KiB
JavaScript
!function(){"use strict";function t(t,e,n=null){if(null===n)return t.indexOf(e);for(let s=0;s<t.length;++s)if(n(t[s],e))return s;return-1}function e(e,n=null,s=null){if(n)for(let r=0;r<n.length;++r)-1===t(e,n[r],s)&&e.push(n[r])}function n(e,n=null,s=null){if(n)for(let r=0;r<n.length;++r){const i=t(e,n[r],s);-1!==i&&e.splice(i,1)}}function s(e,n,s=null){const r=t(e,n,s);-1!==r&&e.splice(r,1)}function r(t){return t[t.length-1]}function i(t,e,n,s){if(e>=t.length)return void s.push(n.slice());const r=t[e];if(!Array.isArray(r))return n.push(r),i(t,e+1,n,s),void n.pop();for(let a=0;a<r.length;++a)n.push(r[a]),i(t,e+1,n,s),n.pop()}function a(t,e){const n=[];return t.forEach(t=>{n.push(...e(t))}),n}function o(t,e){const n=Gt[t.type];return!(!n||t.type!==e.type)&&!n.check.some(n=>t[n]!==e[n])}function l(t,n){Gt[t.type].merge.forEach(s=>{e(t[s],n[s])})}function h(t,e){for(let n=0;n<t.length;){e(t[n],n)?t.splice(n,1):++n}}function d(t){h(t,(e,n)=>{for(let s=0;s<n;++s)if(o(t[s],e))return l(t[s],e),!0;return!1})}function g(t){const e=new Set,n=t.map(({type:t})=>t);return n.forEach(t=>{const s=Gt[t];s&&n.every(e=>t===e||s.siblings.has(e))&&e.add(t)}),e}function c(t,e,n,s){h(s,s=>{if(!t.has(s.type)||!e.has(s.type))return!1;for(let t=0;t<n.length;++t)if(o(n[t],s))return l(n[t],s),!0;return!1})}function u(t,e){for(const n of e)n&&("parallel"===n.type?u(t,n.stages):t.push(n))}function p(t,e){if(!t)return"Nothing to run statement in parallel with";const n=[];return u(n,[t]),u(n,[e]),n.some(t=>!Dt.includes(t.type))?"Cannot use parallel here":function(t){const e=a(t.filter(t=>"agent begin"===t.type),t=>t.agentIDs);for(const n of t)if("agent end"===n.type)for(const t of n.agentIDs)if(-1!==e.indexOf(t))return"Cannot create and destroy "+t+" simultaneously";return null}(n)||function(t){const e=t.filter(t=>"block begin"===t.type||"block end"===t.type).length;if(!e)return null;if(e!==t.length)return"Cannot use parallel here";const n=t.filter(t=>"block begin"===t.type).map(t=>t.left);for(const e of t)if("block end"===e.type&&-1!==n.indexOf(e.left))return"Cannot create and destroy reference simultaneously";return null}(n)||function(t){const e=t.filter(t=>"connect-delay-begin"===t.type).map(t=>t.tag);for(const n of t)if("connect-delay-end"===n.type&&-1!==e.indexOf(n.tag))return"Cannot start and finish delayed connection simultaneously";return null}(n)||function(t){const e=new Set;for(const n of t)if("agent activation"===n.type)for(const t of n.agentIDs){if(e.has(t))return"Conflicting agent activation";e.add(t)}return null}(n)}function f(t,e){if("agent begin"===t.type)return t.mode=e,!0;if("parallel"===t.type){let n=!1;return t.stages.forEach(t=>{"agent begin"===t.type&&(t.mode=e,n=!0)}),n}return!1}function m(t,e,n,r=null){s(t,e,Ct.equals),s(t,n,Ct.equals);let i=0,a=t.length;if(r){const e=r.map(e=>Ct.indexOf(t,e)).filter(t=>-1!==t);i=e.reduce((t,e)=>Math.min(t,e),t.length),a=e.reduce((t,e)=>Math.max(t,e),i)+1}return t.splice(i,0,e),t.splice(a+1,0,n),{indexL:i,indexR:a+1}}function b(t,e=[]){return{type:"string",suggest:e,then:Object.assign({"":0},t)}}function y(t,e){return t.v===e.v&&t.prefix===e.prefix&&t.suffix===e.suffix&&t.q===e.q}function x(t,e,n){return a(n.suggest||[""],s=>{if("object"==typeof s)return s.known?t["known"+s.known]||[]:[s];if(""===s)return[function(t,e){return Object.keys(e.then).length>0?{q:!1,suffix:" ",v:t}:{q:!1,suffix:"\n",v:t}}(e,n)];if("string"==typeof s)return[{q:""===e,v:s}];throw new Error("Invalid suggestion type "+s)})}function k(t,n){const s=[],i=r(n);return Object.keys(i.then).forEach(r=>{let a=i.then[r];"number"==typeof a&&(a=n[n.length-a-1]),e(s,x(t,r,a),y)}),s}function w(t,n,s,r){const i=function(t){for(const e of t)if("object"==typeof e&&e.known)return e.known;return null}(r.suggest||[""]);n.type&&i!==n.type&&(!function(t,n,s){e(t["known"+n],[{q:!0,suffix:" ",v:s}],y)}(t,r.override||n.type,n.value),n.value=""),i&&(n.value=function(t,e){return t+(t?e.s:"")+e.v}(n.value,s)),n.type=i}function v(t,e,n){const s={type:"",value:""};let i=n;const a=[i];return t.line.forEach((e,n)=>{n===t.line.length-1&&(t.completions=k(t,a));const o=e.q?"":e.v;let l=i.then[o];void 0===l?(l=i.then[""],t.isVar=!0):t.isVar=e.q,"number"==typeof l?a.length-=l:a.push(l||Vt),i=r(a),w(t,s,e,i)}),e&&w(t,s,null,{}),t.nextCompletions=k(t,a),t.valid=Boolean(i.then["\n"])||0===Object.keys(i.then).length,i.type}function A(t){const e=t.baseToken||{};return{quoted:e.q||!1,value:e.v||""}}function F(t,e,n){return e.lastIndex=n,e.exec(t)}function M(t,e,n){return n?function(t,e,n){if(n.escape){const s=F(t,n.escape,e);if(s)return{appendSpace:"",appendValue:n.escapeWith(s),end:!1,newBlock:null,skip:s[0].length}}const s=F(t,n.end,e);return s?{appendSpace:"",appendValue:n.includeEnd?s[0]:"",end:!0,newBlock:null,skip:s[0].length}:{appendSpace:"",appendValue:t[e],end:!1,newBlock:null,skip:1}}(t,e,n):function(t,e){for(let n=0;n<Ut.length;++n){const s=Ut[n],r=F(t,s.start,e);if(r)return{appendSpace:"",appendValue:"",end:!s.end,newBlock:s,skip:r[0].length}}return{appendSpace:t[e],appendValue:"",end:!1,newBlock:null,skip:1}}(t,e)}function S(t){return{ch:t.ch,i:t.i,ln:t.ln}}function R(t){const e=Jt.exec(t);return e&&e[1]?e[1].length:0}function C(t){if("label"===t)return{token:"label"};const e=t.indexOf(" ");let n=null,s=null;-1===e?(n=t,s=[]):(n=t.substr(0,e),s=t.substr(e+1).split(","));let r=null;return"inc"===n&&(r=function(t){let e=1,n=1,s=0;return t[0]&&(e=Number(t[0]),s=Math.max(s,R(t[0]))),t[1]&&(n=Number(t[1]),s=Math.max(s,R(t[1]))),Number.isNaN(e)||Number.isNaN(n)?null:{dp:s,inc:n,start:e}}(s)),r||"<"+t+">"}function I(t,e,n){const s=" "+t+" ",r=e+1;let i={end:0,match:null,start:s.length,styleIndex:-1};const a=s.indexOf("",r);return-1!==a&&(i={end:a+1,match:null,start:a,styleIndex:te}),Kt.forEach(({all:t,begin:e,end:a},o)=>{const l=t||(null===n[o]?e:a);l.matcher.lastIndex=r-l.skip,i=function(t,e,n,s){if(!s)return t;const r=s.index+n.skip,i=n.matcher.lastIndex;return r<t.start||r===t.start&&i>t.end?{end:i,match:s,start:r,styleIndex:e}:t}(i,o,l,l.matcher.exec(s))}),-1===i.styleIndex?null:(--i.end,--i.start,i)}function E(t){return t.replace($t,"")}function G(t,e){return"function"==typeof t?t(...e):t}function D(t){if(!t)return[];const e=Kt.map(()=>null);return E(t).split("\n").map(t=>{const n=[];return function(t,e,n){let s=t,r=0,i=0;for(let t=null;t=I(s,r,e);){const{styleIndex:a,start:o,end:l,match:h}=t;if(a!==te){if(n(s.substring(i,o)),null===e[a]){const t=Kt[a];e[a]=G(t.attrs,[h]),t.all&&(n(G(t.text,[h])),e[a]=null)}else e[a]=null;i=l,r=l}else s=s.substr(0,o)+s.substr(l),r=o+1}n(s.substr(i))}(function(t){return t.replace(_t," ")}(E(t)),e,t=>{t&&n.push({attrs:function(t){const e={},n=[];let s=!1;return t.forEach(t=>{if(!t)return;const r=t["text-decoration"];r&&!n.includes(r)&&n.push(r),Object.assign(e,t),s=!0}),n.length>1&&(e["text-decoration"]=n.join(" ")),s?e:null}(e),text:t})}),n})}function L(t,e=null){let n="";return e&&(n=" at line "+(e.b.ln+1)+", character "+e.b.ch),new Error(t+n)}function N(t,e=null){return null===e?t.length:e}function z(t,e=0,n=null){const s=N(t,n);if(s<=e)return"";let r=t[e].v;for(let n=e+1;n<s;++n)r+=t[n].s+t[n].v;return r}function O(t){return!t||t.q?null:t.v}function T(t,e,n,s=null){for(let r=0;r<n.length;++r){const i=n[r],a=t[e+r];if(O(a)!==i){if(s)throw L(s+'; expected "'+i+'"',a);return e}}return e+n.length}function B(t,e,{start:n=0,limit:s=null,orEnd:r=!1}={}){const i=N(t,s);for(let s=n;s<=i-e.length;++s)if(T(t,s,e)!==s)return s;return r?i:-1}function V(t,e,n,{flagTypes:s={},aliases:i=!1}={}){const a=[],o=[];let l=e,h=!1;for(;l<n;++l){const e=t[l],n=O(e),r=s[n];if(!r)break;if(a.includes(r.flag))throw L("Duplicate agent flag: "+n,e);h=h||Boolean(r.allowBlankName),a.push(r.flag),o.push(r.blankNameFlag)}const{name:d,alias:g}=function(t,e,n,{enableAlias:s,allowBlankName:i}){let a=n;if(s&&(a=B(t,["as"],{limit:n,orEnd:!0,start:e})),e>=a&&!i){let n=t[e];throw n||(n={b:r(t).e}),L("Missing agent name",n)}return{alias:z(t,a+1,n),name:z(t,e,a)}}(t,l,n,{allowBlankName:h,enableAlias:i});return{alias:g,flags:d?a:o,name:d}}function P(t,e,n,s){const r=[];let i=-1;for(let a=e;a<n;++a){","===O(t[a])?-1!==i&&(r.push(V(t,i,a,s)),i=-1):-1===i&&(i=a)}return-1!==i&&r.push(V(t,i,n,s)),r}function j(t,{meta:e,stages:n}){let s=!1;const[r]=t;"&"===O(r)&&(s=!0,t.splice(0,1));const i=function(t,e){for(const{begin:n,fn:s}of le){if(T(t,0,n)!==n.length)continue;const r=s(t,e);if(r)return r}return null}(t,e);if(!i)throw L("Unrecognised command: "+z(t),t[0]);if("object"==typeof i)i.ln=r.b.ln,i.parallel=s,n.push(i);else if(s)throw L("Metadata cannot be parallel",r)}function H({agentIDs:t=[],topShift:e=0,y:n=null,asynchronousY:s=null}={},r=null){let i=e;return null!==n&&null!==r&&(i=Math.max(i,n-r)),{agentIDs:t,asynchronousY:null===s?r:s,topShift:i,y:n}}function q(t,e){ce.set(t,e)}function Y(t,e,n,s){if(!e.length)return;const r=n.svg.el("mask").attr("maskUnits","userSpaceOnUse").add(n.svg.box({fill:"#FFFFFF"},s),...e);t.attr("mask","url(#"+n.addDef(r)+")")}function U(t,e){let n=null,s=null;return e.forEach(e=>{const r=t.get(e);(null===n||r.index<n.index)&&(n=r),(null===s||r.index>s.index)&&(s=r)}),{left:n.id,right:s.id}}function W(t=null,e=null){return null===t?e:null===e?t:Math.max(t,e)}function X(t,n){return e(t.agentIDs,n.agentIDs),{agentIDs:t.agentIDs,asynchronousY:W(t.asynchronousY,n.asynchronousY),topShift:Math.max(t.topShift,n.topShift),y:W(t.y,n.y)}}function Q(t){return null===t?null:t.element?t.element:t}function J(t,e,n){if(!Array.isArray(n))throw new Error("Invalid formatted text line: "+n);n.forEach(({text:n,attrs:s})=>{let r=n;s&&((r=s.href?t.el("a").attrs({cursor:"pointer",rel:"nofollow",target:"_blank"}):t.el("tspan")).attrs(s).add(n),s.filter&&r.attr("filter",t.getTextFilter(s.filter))),e.add(r)})}function Z(t,e){let n=null,s=null;return e.forEach(e=>{const r=t.get(e);(null===n||r.index<n.index)&&(n=r),(null===s||r.index>s.index)&&(s=r)}),{left:n.id,right:s.id}}function K(t,e){return t.v===e.v&&t.prefix===e.prefix&&t.suffix===e.suffix&&t.q===e.q}function _(t,e,n){const s=t.getLine(e),r={squash:{ch:n,line:e},word:{ch:n,line:e}};return n>0&&" "===s[n-1]&&(_e.after.includes(s[n-2])&&r.word.ch--,r.squash.ch--),r}function $(t,e,n){const s=function({v:t,q:e,prefix:n="",suffix:s=""},r){const i=r||!tn.test(t)?r:'"';return n+(i&&e?i+t.replace(en,"\\$&")+i:t)+s}(t,n),r=t.q?e.fromVar:e.fromKey;return"\n"===s?{className:"pick-virtual",displayFrom:null,displayText:"<END>",from:r.squash,text:"\n",to:e.to.squash}:{className:null,displayFrom:r.word,displayText:s.trim(),from:_e.start.test(s)?r.squash:r.word,text:s,to:_e.end.test(s)?e.to.squash:e.to.word}}function tt({global:t,prefix:e="",suffix:n=""},s){const r=s[t];return r?r.map(t=>({prefix:e,q:!0,suffix:n,v:t})):[]}function et(t,n,s){let r=null;return r=t.ch>0&&n.state.line.length>0?n.state.completions.slice():n.state.beginCompletions.concat(n.state.knownAgent),function(t,n={}){for(let s=0;s<t.length;)t[s].global?(e(t,tt(t[s],n),K),t.splice(s,1)):++s}(r,s),r}function nt(t,e){const n=t.getCursor(),s=function(t,e){const n=t.getLineTokens(e.line);for(let t=0;t<n.length;++t)if(n[t].end>=e.ch){n.length=t+1;break}return n}(t,n),i=r(s)||t.getTokenAt(n),a=function(t,e){let n="",s=0,r=0;t.forEach(t=>{t.state.isVar?(n+=t.string,r=t.end):(n="",s=t.end)}),r>e.ch&&(n=n.substr(0,e.ch-s));const i=Ke.exec(n);n=i[2];let a="";return $e.test(n)&&(a=n.charAt(0),n=n.substr(1)),{from:s+i[1].length,partial:n,quote:a,valid:r>=s}}(s,n),o=function(t,e){let n=t.string;t.end>e.ch&&(n=n.substr(0,e.ch-t.start));const s=Ke.exec(n);return{from:t.start+s[1].length,partial:s[2],valid:!0}}(i,n),l=et(n,i,t.options.globals),h={fromKey:_(t,n.line,o.from),fromVar:_(t,n.line,a.from),to:function(t,e,n){const s={squash:{ch:n,line:e},word:{ch:n,line:e}};return" "===t.getLine(e)[n]&&s.squash.ch++,s}(t,n.line,i.end)};let d=null;const g=l.filter(t=>(t.q||!a.quote)&&function(t,e){return e.valid&&t.startsWith(e.partial)}(t.v,t.q?a:o)).map(t=>e.completeSingle||t.v!==(t.q?a:o).partial?$(t,h,a.quote):(d=t,null)).filter(t=>null!==t);d&&g.length>0&&g.unshift($(d,h,a.quote));const c={from:function(t,e){let n=null;return t.forEach(({displayFrom:t})=>{t&&(!n||t.line>n.line||t.line===n.line&&t.ch>n.ch)&&(n=t)}),n||e.word}(g,h.fromKey),list:g,to:h.to.word},u=t.constructor;return u.on(c,"shown",u.signal.bind(t,t,"hint-shown")),c}function st(t,e="sequence"){const n=t||window.CodeMirror;n.defineMode(e,()=>an),n.registerHelper("hint",e,nt)}function rt(t){const e=(new DOMParser).parseFromString(t,"image/svg+xml").querySelector("metadata");return e?e.textContent:""}function it(t){function e(t,e){n.push(e)}const n=[];if(t.forEach(t=>{t.addEventListener("error",e),t.optimisedRenderPreReflow()}),t.forEach(t=>{t.optimisedRenderReflow()}),t.forEach(t=>{t.optimisedRenderPostReflow(),t.removeEventListener("error",e)}),n.length>0)throw n}function at(t,e=null,n={}){if("svg"===t.tagName)return null;const s=function(t){return{interactive:function(t){return void 0!==t&&"false"!==t}(t.dataset.sdInteractive),namespace:t.dataset.sdNamespace||null}}(t),r=new on(null===e?t.textContent:e,Object.assign(s,n)),i=r.dom(),a=t.attributes;for(let t=0;t<a.length;++t)i.setAttribute(a[t].nodeName,a[t].nodeValue);return t.parentNode.replaceChild(i,t),r}function ot(t,e=null,n={}){let s=null,r=null;if(e&&"object"==typeof e?s=(r=e).code:(r=n,s=e),Array.isArray(t)){const e=Object.assign({},r,{render:!1}),n=t.map(t=>at(t,s,e)).filter(t=>null!==t);return!1!==r.render&&it(n),n}return at(t,s,r)}class lt{constructor(t,e){Array.isArray(e)?this.deltas=e:this.deltas=[0,2*-e/3,-e,2*-e/3,0,2*e/3,e,2*e/3],this.partWidth=t/this.deltas.length}getDelta(t){return this.deltas[t%this.deltas.length]}}class ht{constructor(t,e){this.svg=t,this.baseFontAttrs=e,this.fontSize=this.baseFontAttrs["font-size"],this.connectLines=new Map}addConnectLine(t,{attrs:e={},pattern:n=null}={}){const s=this.connectLines.get("solid")||{attrs:{}},r=Object.assign({fill:"none"},s.attrs,e);this.connectLines.set(t,{attrs:r,renderFlat:this.renderFlatConnect.bind(this,n,r),renderRev:this.renderRevConnect.bind(this,n,r)})}reset(){}addDefs(t,e){e("highlight",()=>this.svg.el("filter").add(this.svg.el("feMorphology").attrs({in:"SourceAlpha",operator:"dilate",radius:"4"}),this.svg.el("feGaussianBlur").attrs({edgeMode:"none",stdDeviation:"3, 1.5"}),this.svg.el("feComponentTransfer").add(this.svg.el("feFuncA").attrs({intercept:-70,slope:100,type:"linear"})),this.svg.el("feComponentTransfer").add(this.svg.el("feFuncR").attrs({intercept:1,slope:0,type:"linear"}),this.svg.el("feFuncG").attrs({intercept:.875,slope:0,type:"linear"}),this.svg.el("feFuncB").attrs({intercept:0,slope:0,type:"linear"}),this.svg.el("feFuncA").attrs({slope:.8,type:"linear"})),this.svg.el("feMerge").add(this.svg.el("feMergeNode"),this.svg.el("feMergeNode").attr("in","SourceGraphic"))))}getTitleAttrs(){return Object.assign({},this.baseFontAttrs,{"font-size":2.5*this.fontSize,"text-anchor":"middle"})}getConnectLine(t){const e=this.connectLines;return e.get(t)||e.get("solid")}getBlock(t){return this.blocks[t]||this.blocks[""]}getNote(t){return this.notes[t]||this.notes[""]}getDivider(t){return this.dividers[t]||this.dividers[""]}optionsAttributes(t,e){return function(t,e){const n=Object.assign({},t[""]);return e.forEach(e=>{Object.assign(n,t[e]||{})}),n}(t,e)}renderAgentLine({className:t,options:e,width:n,x:s,y0:r,y1:i}){const a=this.optionsAttributes(this.agentLineAttrs,e);return n>0?this.svg.box(a,{height:i-r,width:n,x:s-n/2,y:r}).addClass(t):this.svg.line(a,{x1:s,x2:s,y1:r,y2:i}).addClass(t)}renderArrowHead(t,{dir:e,height:n,width:s,x:r,y:i}){const a=s*e.dx,o=s*e.dy,l=.5*n*e.dx,h=.5*-n*e.dy;return this.svg.el("none"===t.fill?"polyline":"polygon").attr("points",r+a-h+" "+(i+o-l)+" "+r+" "+i+" "+(r+a+h)+" "+(i+o+l)).attrs(t)}renderTag(t,{height:e,width:n,x:s,y:r}){const{rx:i,ry:a}=t,o=s+n,l=r+e,h="M"+o+" "+r+"L"+o+" "+(l-a)+"L"+(o-i)+" "+l+"L"+s+" "+l,d=this.svg.el("g");return"none"!==t.fill&&d.add(this.svg.el("path").attr("d",h+"L"+s+" "+r).attrs(t).attr("stroke","none")),"none"!==t.stroke&&d.add(this.svg.el("path").attr("d",h).attrs(t).attr("fill","none")),d}renderPerson({iconHeight:t,iconWidth:e},n,s,r){const i=r.x+r.width/2,a=e/2,o=t;return this.svg.el("g").add(this.svg.el("path").attr("d","M"+(i-a)+" "+(r.y+t)+"a"+a+" "+.3*o+" 0 0 1 "+2*a+" 0").attrs(n),this.svg.el("path").attr("d","M"+i+" "+r.y+"c"+.224*a+" 0 "+.4*a+" "+.1*o+" "+.4*a+" "+.275*o+"s"+.176*-a+" "+.35*o+" "+.4*-a+" "+.35*o+"s"+.4*-a+" "+.175*-o+" "+.4*-a+" "+.35*-o+"s"+.176*a+" "+.275*-o+" "+.4*a+" "+.275*-o).attrs(n),this.svg.box(s,{height:r.height-t,width:r.width,x:r.x,y:r.y+t}))}renderDB({tilt:t},e,n){return this.svg.el("g").add(this.svg.box({rx:n.width/2,ry:t},n).attrs(e),this.svg.el("path").attr("d","M"+n.x+" "+(n.y+t)+"a"+n.width/2+" "+t+" 0 0 0 "+n.width+" 0").attrs(e).attr("fill","none"))}renderRef(t,e){return{fill:this.svg.box(t,e).attrs({stroke:"none"}),mask:this.svg.box(t,e).attrs({fill:"#000000",stroke:"none"}),shape:this.svg.box(t,e).attrs({fill:"none"})}}renderFlatConnect(t,e,{x1:n,y1:s,x2:r,y2:i}){return{p1:{x:n,y:s},p2:{x:r,y:i},shape:this.svg.el("path").attr("d",this.svg.patternedLine(t).move(n,s).line(r,i).cap().asPath()).attrs(e)}}renderRevConnect(t,e,{rad:n,x1:s,x2:r,xR:i,y1:a,y2:o}){const l=(o-a)/2,h=this.svg.patternedLine(t).move(s,a).line(i,a);return n<l?h.arc(i,a+n,Math.PI/2).line(i+n,o-n).arc(i,o-n,Math.PI/2):h.arc(i,(a+o)/2,Math.PI),{p1:{x:s,y:a},p2:{x:r,y:o},shape:this.svg.el("path").attr("d",h.line(r,o).cap().asPath()).attrs(e)}}renderLineDivider({lineAttrs:t},{height:e,labelWidth:n,width:s,x:r,y:i}){let a=null;const o=i+e/2;return a=n>0?this.svg.el("g").add(this.svg.line({fill:"none"},{x1:r,x2:r+(s-n)/2,y1:o,y2:o}).attrs(t),this.svg.line({fill:"none"},{x1:r+(s+n)/2,x2:r+s,y1:o,y2:o}).attrs(t)):this.svg.line({fill:"none"},{x1:r,x2:r+s,y1:o,y2:o}).attrs(t),{shape:a}}renderDelayDivider({dotSize:t,gapSize:e},{height:n,width:s,x:r,y:i}){const a=this.svg.el("g");for(let o=0;o+e<=n;o+=t+e)a.add(this.svg.box({fill:"#000000"},{height:e,width:s,x:r,y:i+o}));return{mask:a}}renderTearDivider({fadeBegin:t,fadeSize:e,lineAttrs:n,pattern:s,zigHeight:r,zigWidth:i},{env:a,height:o,labelHeight:l,labelWidth:h,width:d,x:g,y:c}){const u=a.addDef("tear-grad",()=>{const n=100/d;return this.svg.linearGradient({},[{offset:t*n+"%","stop-color":"#000000"},{offset:(t+e)*n+"%","stop-color":"#FFFFFF"},{offset:100-(t+e)*n+"%","stop-color":"#FFFFFF"},{offset:100-t*n+"%","stop-color":"#000000"}])}),p=this.svg.el("mask").attr("maskUnits","userSpaceOnUse").add(this.svg.box({fill:"url(#"+u+")"},{height:o+10,width:d,x:g,y:c-5})),f=a.addDef(p);h>0&&p.add(this.svg.box({fill:"#000000",rx:2,ry:2},{height:l+2,width:h,x:g+(d-h)/2,y:c+(o-l)/2-1}));const m=s||new lt(i,[r,-r]);let b=null;const y=this.svg.patternedLine(m).move(g,c).line(g+d,c),x=this.svg.el("g").attr("mask","url(#"+f+")").add(this.svg.el("path").attrs({d:y.asPath(),fill:"none"}).attrs(n));if(o>0){const t=this.svg.patternedLine(m).move(g,c+o).line(g+d,c+o);x.add(this.svg.el("path").attrs({d:t.asPath(),fill:"none"}).attrs(n)),y.line(t.x,t.y,{patterned:!1}).cap(),y.points.push(...t.points.reverse()),b=this.svg.el("path").attrs({d:y.asPath(),fill:"#000000"})}return{mask:b,shape:x}}}const dt="Helvetica,Arial,Liberation Sans,sans-serif",gt=1.3,ct={"font-family":dt,"font-size":8,"line-height":gt},ut={"font-family":dt,"font-size":8,"line-height":gt,"text-anchor":"middle"};class pt extends ht{constructor(t){super(t,{"font-family":dt,"font-size":8,"line-height":gt});const e={padding:{top:3,bottom:2},tag:{padding:{top:1,left:3,right:3,bottom:0},boxRenderer:this.renderTag.bind(this,{fill:"#FFFFFF",stroke:"#000000","stroke-width":1,rx:2,ry:2}),labelAttrs:{"font-family":dt,"font-weight":"bold","font-size":9,"line-height":gt,"text-anchor":"left"}},label:{minHeight:4,padding:{top:1,left:5,right:3,bottom:1},labelAttrs:{"font-family":dt,"font-size":8,"line-height":gt,"text-anchor":"left"}}};Object.assign(this,{titleMargin:10,outerMargin:5,agentMargin:10,actionMargin:10,minActionMargin:3,agentLineActivationRadius:4,agentCap:{box:{padding:{top:5,left:10,right:10,bottom:5},arrowBottom:12.8,boxAttrs:{fill:"#FFFFFF",stroke:"#000000","stroke-width":1},labelAttrs:{"font-family":dt,"font-size":12,"line-height":gt,"text-anchor":"middle"}},person:{padding:{top:20,left:10,right:10,bottom:5},arrowBottom:12.8,boxRenderer:this.renderPerson.bind(this,{iconHeight:15,iconWidth:18},{fill:"#000000"},{fill:"#FFFFFF",stroke:"#000000","stroke-width":1}),labelAttrs:{"font-family":dt,"font-size":12,"line-height":gt,"text-anchor":"middle"}},database:{padding:{top:12,left:10,right:10,bottom:3},arrowBottom:12.8,boxRenderer:this.renderDB.bind(this,{tilt:5},{fill:"#FFFFFF",stroke:"#000000","stroke-width":1}),labelAttrs:{"font-family":dt,"font-size":12,"line-height":gt,"text-anchor":"middle"}},cross:{size:20,render:t.crossFactory({fill:"none",stroke:"#000000","stroke-width":1})},bar:{height:4,render:t.boxFactory({fill:"#000000",stroke:"#000000","stroke-width":1})},fade:{width:5,height:6,extend:1},none:{height:10}},connect:{loopbackRadius:6,arrow:{single:{width:5,height:10,render:this.renderArrowHead.bind(this),attrs:{fill:"#000000","stroke-width":0,"stroke-linejoin":"miter"}},double:{width:4,height:6,render:this.renderArrowHead.bind(this),attrs:{fill:"none",stroke:"#000000","stroke-width":1,"stroke-linejoin":"miter"}},fade:{short:2,size:16},cross:{short:7,radius:3,render:t.crossFactory({fill:"none",stroke:"#000000","stroke-width":1})}},label:{padding:6,margin:{top:2,bottom:1},attrs:{"font-family":dt,"font-size":8,"line-height":gt,"text-anchor":"middle"},loopbackAttrs:{"font-family":dt,"font-size":8,"line-height":gt}},source:{radius:2,render:t.circleFactory({fill:"#000000",stroke:"#000000","stroke-width":1})},mask:{padding:{top:0,left:3,right:3,bottom:1}}},agentLineAttrs:{"":{fill:"none",stroke:"#000000","stroke-width":1},red:{stroke:"#CC0000"}},blocks:{ref:{margin:{top:0,bottom:0},boxRenderer:this.renderRef.bind(this,{fill:"#FFFFFF",stroke:"#000000","stroke-width":1.5,rx:2,ry:2}),section:e},"":{margin:{top:0,bottom:0},boxRenderer:t.boxFactory({fill:"none",stroke:"#000000","stroke-width":1.5,rx:2,ry:2}),collapsedBoxRenderer:this.renderRef.bind(this,{fill:"#FFFFFF",stroke:"#000000","stroke-width":1.5,rx:2,ry:2}),section:e,sepRenderer:t.lineFactory({stroke:"#000000","stroke-width":1.5,"stroke-dasharray":"4, 2"})}},notes:{text:{margin:{top:0,left:2,right:2,bottom:0},padding:{top:2,left:2,right:2,bottom:2},overlap:{left:10,right:10},boxRenderer:t.boxFactory({fill:"#FFFFFF"}),labelAttrs:ct},note:{margin:{top:0,left:5,right:5,bottom:0},padding:{top:5,left:5,right:10,bottom:5},overlap:{left:10,right:10},boxRenderer:t.noteFactory({fill:"#FFFFFF",stroke:"#000000","stroke-width":1},{fill:"none",stroke:"#000000","stroke-width":1}),labelAttrs:ct},state:{margin:{top:0,left:5,right:5,bottom:0},padding:{top:7,left:7,right:7,bottom:7},overlap:{left:10,right:10},boxRenderer:t.boxFactory({fill:"#FFFFFF",stroke:"#000000","stroke-width":1,rx:10,ry:10}),labelAttrs:ct}},dividers:{"":{labelAttrs:ut,padding:{top:2,left:5,right:5,bottom:2},extend:0,margin:0,render:()=>({})},line:{labelAttrs:ut,padding:{top:2,left:5,right:5,bottom:2},extend:10,margin:0,render:this.renderLineDivider.bind(this,{lineAttrs:{stroke:"#000000"}})},delay:{labelAttrs:ut,padding:{top:2,left:5,right:5,bottom:2},extend:0,margin:0,render:this.renderDelayDivider.bind(this,{dotSize:1,gapSize:2})},tear:{labelAttrs:ut,padding:{top:2,left:5,right:5,bottom:2},extend:10,margin:10,render:this.renderTearDivider.bind(this,{fadeBegin:5,fadeSize:10,zigWidth:6,zigHeight:1,lineAttrs:{stroke:"#000000"}})}}}),this.addConnectLine("solid",{attrs:{stroke:"#000000","stroke-width":1}}),this.addConnectLine("dash",{attrs:{"stroke-dasharray":"4, 2"}}),this.addConnectLine("wave",{attrs:{"stroke-linejoin":"round","stroke-linecap":"round"},pattern:new lt(6,.5)})}}const ft="Helvetica,Arial,Liberation Sans,sans-serif",mt=1.3,bt={"font-family":ft,"font-size":8,"line-height":mt},yt={"font-family":ft,"font-size":8,"line-height":mt,"text-anchor":"middle"};class xt extends ht{constructor(t){super(t,{"font-family":ft,"font-size":8,"line-height":mt});const e={padding:{top:3,bottom:4},tag:{padding:{top:2,left:5,right:5,bottom:1},boxRenderer:this.renderTag.bind(this,{fill:"#FFFFFF",stroke:"#000000","stroke-width":2,rx:3,ry:3}),labelAttrs:{"font-family":ft,"font-weight":"bold","font-size":9,"line-height":mt,"text-anchor":"left"}},label:{minHeight:5,padding:{top:2,left:5,right:3,bottom:1},labelAttrs:{"font-family":ft,"font-size":8,"line-height":mt,"text-anchor":"left"}}};Object.assign(this,{titleMargin:12,outerMargin:5,agentMargin:8,actionMargin:5,minActionMargin:5,agentLineActivationRadius:4,agentCap:{box:{padding:{top:1,left:3,right:3,bottom:1},arrowBottom:11.1,boxAttrs:{fill:"#FFFFFF",stroke:"#000000","stroke-width":3,rx:4,ry:4},labelAttrs:{"font-family":ft,"font-weight":"bold","font-size":14,"line-height":mt,"text-anchor":"middle"}},person:{padding:{top:16,left:3,right:3,bottom:1},arrowBottom:11.1,boxRenderer:this.renderPerson.bind(this,{iconHeight:15,iconWidth:18},{fill:"#000000"},{fill:"#FFFFFF",stroke:"#000000","stroke-width":3,rx:4,ry:4}),labelAttrs:{"font-family":ft,"font-weight":"bold","font-size":14,"line-height":mt,"text-anchor":"middle"}},database:{padding:{top:4,left:3,right:3,bottom:0},arrowBottom:11.1,boxRenderer:this.renderDB.bind(this,{tilt:2},{fill:"#FFFFFF",stroke:"#000000","stroke-width":3}),labelAttrs:{"font-family":ft,"font-weight":"bold","font-size":14,"line-height":mt,"text-anchor":"middle"}},cross:{size:20,render:t.crossFactory({fill:"none",stroke:"#000000","stroke-width":3,"stroke-linecap":"round"})},bar:{height:4,render:t.boxFactory({fill:"#000000",stroke:"#000000","stroke-width":3,rx:2,ry:2})},fade:{width:5,height:10,extend:1},none:{height:10}},connect:{loopbackRadius:8,arrow:{single:{width:10,height:12,render:this.renderArrowHead.bind(this),attrs:{fill:"#000000",stroke:"#000000","stroke-width":3,"stroke-linejoin":"round"}},double:{width:10,height:12,render:this.renderArrowHead.bind(this),attrs:{fill:"none",stroke:"#000000","stroke-width":3,"stroke-linejoin":"round","stroke-linecap":"round"}},fade:{short:3,size:12},cross:{short:10,radius:5,render:t.crossFactory({fill:"none",stroke:"#000000","stroke-width":3,"stroke-linejoin":"round","stroke-linecap":"round"})}},label:{padding:7,margin:{top:2,bottom:3},attrs:{"font-family":ft,"font-size":8,"line-height":mt,"text-anchor":"middle"},loopbackAttrs:{"font-family":ft,"font-size":8,"line-height":mt}},source:{radius:5,render:t.circleFactory({fill:"#000000",stroke:"#000000","stroke-width":3})},mask:{padding:{top:1,left:5,right:5,bottom:3}}},agentLineAttrs:{"":{fill:"none",stroke:"#000000","stroke-width":3},red:{stroke:"#DD0000"}},blocks:{ref:{margin:{top:0,bottom:0},boxRenderer:this.renderRef.bind(this,{fill:"#FFFFFF",stroke:"#000000","stroke-width":4,rx:5,ry:5}),section:e},"":{margin:{top:0,bottom:0},boxRenderer:t.boxFactory({fill:"none",stroke:"#000000","stroke-width":4,rx:5,ry:5}),collapsedBoxRenderer:this.renderRef.bind(this,{fill:"#FFFFFF",stroke:"#000000","stroke-width":4,rx:5,ry:5}),section:e,sepRenderer:t.lineFactory({stroke:"#000000","stroke-width":2,"stroke-dasharray":"5, 3"})}},notes:{text:{margin:{top:0,left:2,right:2,bottom:0},padding:{top:2,left:2,right:2,bottom:2},overlap:{left:10,right:10},boxRenderer:t.boxFactory({fill:"#FFFFFF"}),labelAttrs:bt},note:{margin:{top:0,left:5,right:5,bottom:0},padding:{top:3,left:3,right:10,bottom:3},overlap:{left:10,right:10},boxRenderer:t.noteFactory({fill:"#FFFFFF",stroke:"#000000","stroke-width":2,"stroke-linejoin":"round"},{fill:"none",stroke:"#000000","stroke-width":1}),labelAttrs:bt},state:{margin:{top:0,left:5,right:5,bottom:0},padding:{top:5,left:7,right:7,bottom:5},overlap:{left:10,right:10},boxRenderer:t.boxFactory({fill:"#FFFFFF",stroke:"#000000","stroke-width":3,rx:10,ry:10}),labelAttrs:bt}},dividers:{"":{labelAttrs:yt,padding:{top:2,left:5,right:5,bottom:2},extend:0,margin:0,render:()=>({})},line:{labelAttrs:yt,padding:{top:2,left:5,right:5,bottom:2},extend:10,margin:0,render:this.renderLineDivider.bind(this,{lineAttrs:{stroke:"#000000","stroke-width":2,"stroke-linecap":"round"}})},delay:{labelAttrs:yt,padding:{top:2,left:5,right:5,bottom:2},extend:0,margin:0,render:this.renderDelayDivider.bind(this,{dotSize:3,gapSize:3})},tear:{labelAttrs:yt,padding:{top:2,left:5,right:5,bottom:2},extend:10,margin:10,render:this.renderTearDivider.bind(this,{fadeBegin:5,fadeSize:10,zigWidth:6,zigHeight:1,lineAttrs:{stroke:"#000000","stroke-width":2,"stroke-linejoin":"round"}})}}}),this.addConnectLine("solid",{attrs:{stroke:"#000000","stroke-width":3}}),this.addConnectLine("dash",{attrs:{"stroke-dasharray":"10, 4"}}),this.addConnectLine("wave",{attrs:{"stroke-linejoin":"round","stroke-linecap":"round"},pattern:new lt(10,1)})}getTitleAttrs(){return Object.assign(super.getTitleAttrs(),{"font-weight":"bolder"})}}class kt{constructor(){this.listeners=new Map,this.forwards=new Set}addEventListener(t,e){const n=this.listeners.get(t);n?n.push(e):this.listeners.set(t,[e])}removeEventListener(t,e){const n=this.listeners.get(t);if(!n)return;const s=n.indexOf(e);-1!==s&&n.splice(s,1)}on(t,e){return this.addEventListener(t,e),this}off(t,e){return this.removeEventListener(t,e),this}countEventListeners(t){return(this.listeners.get(t)||[]).length}removeAllEventListeners(t){t?this.listeners.delete(t):this.listeners.clear()}addEventForwarding(t){this.forwards.add(t)}removeEventForwarding(t){this.forwards.delete(t)}removeAllEventForwardings(){this.forwards.clear()}trigger(t,e=[]){(this.listeners.get(t)||[]).forEach(t=>t(...e)),this.forwards.forEach(n=>n.trigger(t,e))}}const wt="undefined"==typeof window,vt=!wt&&/^((?!chrome|android).)*safari/i.test(window.navigator.userAgent),At=!wt&&void 0!==window.InstallTrigger,Ft=/<svg ?/;class Mt{constructor(){this.latestSVG=null,this.latestInternalSVG=null,this.canvas=null,this.context=null,this.indexPNG=0,this.latestPNGIndex=0,this.latestPNG=null}getSVGContent(t){let e=t.dom().outerHTML;return'<?xml version="1.0" encoding="UTF-8" ?>'+(e=e.replace(Ft,'<svg width="'+(t.width||1)+'" height="'+(t.height||1)+'" '))}getSVGBlob(t){return new Blob([this.getSVGContent(t)],{type:"image/svg+xml"})}getSVGURL(t){const e=this.getSVGBlob(t);return this.latestSVG&&URL.revokeObjectURL(this.latestSVG),this.latestSVG=URL.createObjectURL(e),this.latestSVG}getCanvas(t,e,n){this.canvas||(window.devicePixelRatio=1,this.canvas=document.createElement("canvas"),this.context=this.canvas.getContext("2d"));const s=(t.width||1)*e,r=(t.height||1)*e,i=new Image(s,r);let a=null;vt&&((a=document.createElement("div")).style.position="absolute",a.style.visibility="hidden",a.appendChild(i),document.body.appendChild(a));const o=()=>{this.canvas.width=s,this.canvas.height=r,this.context.drawImage(i,0,0,s,r),a&&document.body.removeChild(a),n(this.canvas)};i.addEventListener("load",()=>{a?setTimeout(o,50):o()},{once:!0}),i.src=this.getSVGURL(t)}getPNGBlob(t,e,n){this.getCanvas(t,e,t=>{t.toBlob(n,"image/png")})}getPNGURL(t,e,n){++this.indexPNG;const s=this.indexPNG;this.getPNGBlob(t,e,t=>{const e=URL.createObjectURL(t);s>=this.latestPNGIndex?(this.latestPNG&&URL.revokeObjectURL(this.latestPNG),this.latestPNG=e,this.latestPNGIndex=s,n(e,!0)):(n(e,!1),URL.revokeObjectURL(e))})}}class St{constructor({blocked:t=!1,covered:e=!1,group:n=null,activated:s=!1,locked:r=!1,visible:i=!1}={}){this.blocked=t,this.covered=e,this.group=n,this.activated=s,this.locked=r,this.visible=i}}St.LOCKED=new St({locked:!0}),St.DEFAULT=new St;const Rt={equals:(t,e)=>t.name===e.name,hasFlag:(t,e=!0)=>n=>n.flags.includes(t)===e},Ct={addNearby:(e,n,s,r)=>{const i=t(e,n,Ct.equals);-1===i?e.push(s):e.splice(i+r,0,s)},equals:(t,e)=>t.id===e.id,hasIntersection:(e,n)=>(function(e,n,s=null){for(let r=0;r<n.length;++r)if(-1!==t(e,n[r],s))return!0;return!1})(e,n,Ct.equals),indexOf:(e,n)=>t(e,n,Ct.equals),make:(t,{anchorRight:e=!1,isVirtualSource:n=!1}={})=>({anchorRight:e,id:t,isVirtualSource:n,options:[]})},It={"note left":[Ct.make("[")],"note over":[Ct.make("["),Ct.make("]")],"note right":[Ct.make("]")]},Et=["[","]"],Gt={"agent activation":{check:["activated"],merge:["agentIDs"],siblings:new Set(["agent begin","agent end"])},"agent begin":{check:["mode"],merge:["agentIDs"],siblings:new Set(["agent activation"])},"agent end":{check:["mode"],merge:["agentIDs"],siblings:new Set(["agent activation"])}},Dt=["agent begin","agent end","agent activation","block begin","block end","connect","connect-delay-begin","connect-delay-end","note over","note right","note left","note between"];class Lt{constructor(){this.agentStates=new Map,this.agentAliases=new Map,this.activeGroups=new Map,this.gAgents=[],this.labelPattern=null,this.nextID=0,this.nesting=[],this.markers=new Set,this.currentSection=null,this.currentNest=null,this.stageHandlers={"agent activation":this.handleAgentActivation.bind(this),"agent begin":this.handleAgentBegin.bind(this),"agent define":this.handleAgentDefine.bind(this),"agent end":this.handleAgentEnd.bind(this),"agent options":this.handleAgentOptions.bind(this),async:this.handleAsync.bind(this),"block begin":this.handleBlockBegin.bind(this),"block end":this.handleBlockEnd.bind(this),"block split":this.handleBlockSplit.bind(this),connect:this.handleConnect.bind(this),"connect-delay-begin":this.handleConnectDelayBegin.bind(this),"connect-delay-end":this.handleConnectDelayEnd.bind(this),divider:this.handleDivider.bind(this),"group begin":this.handleGroupBegin.bind(this),"label pattern":this.handleLabelPattern.bind(this),mark:this.handleMark.bind(this),"note between":this.handleNote.bind(this),"note left":this.handleNote.bind(this),"note over":this.handleNote.bind(this),"note right":this.handleNote.bind(this)},this.expandGroupedGAgent=this.expandGroupedGAgent.bind(this),this.handleStage=this.handleStage.bind(this),this.toGAgent=this.toGAgent.bind(this),this.endGroup=this.endGroup.bind(this)}_aliasInUse(t){const e=this.agentAliases.get(t);return!(!e||e===t)||this.gAgents.some(e=>e.id===t)}toGAgent({name:t,alias:e,flags:n}){if(e){if(this.agentAliases.has(t))throw new Error("Cannot alias "+t+"; it is already an alias");if(this._aliasInUse(e))throw new Error("Cannot use "+e+" as an alias; it is already in use");this.agentAliases.set(e,t)}return Ct.make(this.agentAliases.get(t)||t,{isVirtualSource:n.includes("source")})}addStage(t,{isVisible:e=!0,parallel:n=!1}={}){if(!t)return;e&&(this.currentNest.hasContent=!0),void 0===t.ln&&(t.ln=this.latestLine);const{stages:s}=this.currentSection;if(n){const e=r(s),n=p(e,t);if(n)throw new Error(n);const i=this.makeParallel([e,t]);i.ln=t.ln,--s.length,s.push(i)}else s.push(t)}addImpStage(t,{parallel:e=!1}={}){if(!t)return;void 0===t.ln&&(t.ln=this.latestLine);const{stages:n}=this.currentSection;if(e){const e=n[n.length-2];if(0===n.length)throw new Error("Nothing to run statement in parallel with");if(p(e,t))n.splice(n.length-1,0,t);else{const s=this.makeParallel([e,t]);s.ln=t.ln,n.splice(n.length-2,1,s)}}else n.push(t)}makeParallel(t){const e=[];return u(e,t),0===e.length?null:1===e.length?e[0]:(e.forEach(t=>{void 0===t.ln&&(t.ln=this.latestLine)}),{stages:e,type:"parallel"})}defineGAgents(t){e(this.currentNest.gAgents,t.filter(t=>!Et.includes(t.id)),Ct.equals),e(this.gAgents,t,Ct.equals)}getGAgentState(t){return this.agentStates.get(t.id)||St.DEFAULT}updateGAgentState(t,e){const n=this.agentStates.get(t.id);n?Object.assign(n,e):this.agentStates.set(t.id,new St(e))}replaceGAgentState(t,e){this.agentStates.set(t.id,e)}validateGAgents(t,{allowGrouped:e=!1,allowCovered:n=!1,allowVirtual:s=!1}={}){t.forEach(t=>{const r=this.getGAgentState(t),i=t.id;if(function(t){return t.blocked&&null===t.group}(r))throw new Error("Duplicate agent name: "+i);if(!n&&r.covered)throw new Error("Agent "+i+" is hidden behind group");if(!e&&null!==r.group)throw new Error("Agent "+i+" is in a group");if(!s&&t.isVirtualSource)throw new Error("Cannot use message source here");if(function(t){return t.startsWith("__")}(i))throw new Error(i+" is a reserved name")})}setGAgentVis(t,e,n,s=!1){const r=new Set,i=t.filter(t=>{if(r.has(t.id))return!1;r.add(t.id);const n=this.getGAgentState(t);if(n.locked||n.blocked){if(s)throw new Error("Cannot begin/end agent: "+t.id);return!1}return n.visible!==e});return 0===i.length?null:(i.forEach(t=>{this.updateGAgentState(t,{visible:e})}),this.defineGAgents(i),{agentIDs:i.map(t=>t.id),mode:n,type:e?"agent begin":"agent end"})}setGAgentActivation(t,e,n=!1){const s=t.filter(t=>{const s=this.getGAgentState(t);if(s.locked||s.blocked){if(n)throw new Error("Cannot activate agent: "+t.id);return!1}return s.visible&&s.activated!==e});return 0===s.length?null:(s.forEach(t=>{this.updateGAgentState(t,{activated:e})}),{activated:e,agentIDs:s.map(t=>t.id),type:"agent activation"})}_makeSection(t,e){return{delayedConnections:new Map,header:t,stages:e}}_checkSectionEnd(){const t=this.currentSection.delayedConnections;if(t.size>0){const e=t.values().next().value;throw new Error('Unused delayed connection "'+e.tag+'" at line '+(e.ln+1))}}beginNested(t,{tag:e,label:n,name:s,ln:r}){const i=Ct.make(s+"[",{anchorRight:!0}),a=Ct.make(s+"]"),o=[i,a],l=[];return this.currentSection=this._makeSection({blockType:t,canHide:!0,label:this.textFormatter(n),left:i.id,ln:r,right:a.id,tag:this.textFormatter(e),type:"block begin"},l),this.currentNest={blockType:t,gAgents:o,hasContent:!1,leftGAgent:i,rightGAgent:a,sections:[this.currentSection]},this.replaceGAgentState(i,St.LOCKED),this.replaceGAgentState(a,St.LOCKED),this.nesting.push(this.currentNest),{stages:l}}nextBlockName(){const t="__BLOCK"+this.nextID;return++this.nextID,t}nextVirtualAgentName(){const t="__"+this.nextID;return++this.nextID,t}handleBlockBegin({ln:t,blockType:e,tag:n,label:s,parallel:r}){if(r)throw new Error("Cannot use parallel here");this.beginNested(e,{label:s,ln:t,name:this.nextBlockName(),tag:n})}handleBlockSplit({ln:t,blockType:e,tag:n,label:s,parallel:r}){if(r)throw new Error("Cannot use parallel here");if("if"!==this.currentNest.blockType)throw new Error('Invalid block nesting ("else" inside '+this.currentNest.blockType+")");this._checkSectionEnd(),this.currentSection=this._makeSection({blockType:e,label:this.textFormatter(s),left:this.currentNest.leftGAgent.id,ln:t,right:this.currentNest.rightGAgent.id,tag:this.textFormatter(n),type:"block split"},[]),this.currentNest.sections.push(this.currentSection)}handleBlockEnd({parallel:t}){if(this.nesting.length<=1)throw new Error('Invalid block nesting (too many "end"s)');this._checkSectionEnd();const e=this.nesting.pop();if(this.currentNest=r(this.nesting),this.currentSection=r(this.currentNest.sections),!e.hasContent)throw new Error("Empty block");this.defineGAgents(e.gAgents),m(this.gAgents,e.leftGAgent,e.rightGAgent,e.gAgents),e.sections.forEach(t=>{this.currentSection.stages.push(t.header),this.currentSection.stages.push(...t.stages)}),this.addStage({left:e.leftGAgent.id,right:e.rightGAgent.id,type:"block end"},{parallel:t})}makeGroupDetails(t,e){const s=t.map(this.toGAgent);if(this.validateGAgents(s),this.agentStates.has(e))throw new Error("Duplicate agent name: "+e);const r=this.nextBlockName(),i=Ct.make(r+"[",{anchorRight:!0}),a=Ct.make(r+"]");this.replaceGAgentState(i,St.LOCKED),this.replaceGAgentState(a,St.LOCKED),this.updateGAgentState(Ct.make(e),{blocked:!0,group:e}),this.defineGAgents([...s,i,a]);const{indexL:o,indexR:l}=m(this.gAgents,i,a,s),h=[],d=s.slice();for(let t=o+1;t<l;++t)h.push(this.gAgents[t]);return n(h,d,Ct.equals),{gAgents:s,gAgentsContained:d,gAgentsCovered:h,leftGAgent:i,rightGAgent:a}}handleGroupBegin({agents:t,blockType:e,tag:n,label:s,alias:r,parallel:i}){const a=this.makeGroupDetails(t,r);a.gAgentsContained.forEach(t=>{this.updateGAgentState(t,{group:r})}),a.gAgentsCovered.forEach(t=>{this.updateGAgentState(t,{covered:!0})}),this.activeGroups.set(r,a),this.addImpStage(this.setGAgentVis(a.gAgents,!0,"box"),{parallel:i}),this.addStage({blockType:e,canHide:!1,label:this.textFormatter(s),left:a.leftGAgent.id,right:a.rightGAgent.id,tag:this.textFormatter(n),type:"block begin"},{parallel:i})}endGroup({name:t}){const e=this.activeGroups.get(t);return e?(this.activeGroups.delete(t),e.gAgentsContained.forEach(t=>{this.updateGAgentState(t,{group:null})}),e.gAgentsCovered.forEach(t=>{this.updateGAgentState(t,{covered:!1})}),this.updateGAgentState(Ct.make(t),{group:null}),{left:e.leftGAgent.id,right:e.rightGAgent.id,type:"block end"}):null}handleMark({name:t,parallel:e}){this.markers.add(t),this.addStage({name:t,type:"mark"},{isVisible:!1,parallel:e})}handleDivider({mode:t,height:e,label:n,parallel:s}){this.addStage({formattedLabel:this.textFormatter(n),height:e,mode:t,type:"divider"},{isVisible:!1,parallel:s})}handleAsync({target:t,parallel:e}){if(""!==t&&!this.markers.has(t))throw new Error("Unknown marker: "+t);this.addStage({target:t,type:"async"},{isVisible:!1,parallel:e})}handleLabelPattern({pattern:t}){this.labelPattern=t.slice();for(let t=0;t<this.labelPattern.length;++t){const e=this.labelPattern[t];"object"==typeof e&&void 0!==e.start&&(this.labelPattern[t]=Object.assign({current:e.start},e))}}applyLabelPattern(t){let e="";const n={label:t};return this.labelPattern.forEach(t=>{"string"==typeof t?e+=t:void 0!==t.token?e+=n[t.token]:void 0!==t.current&&(e+=t.current.toFixed(t.dp),t.current+=t.inc)}),e}expandGroupedGAgent(t){const{group:e}=this.getGAgentState(t);if(!e)return[t];const n=this.activeGroups.get(e);return[n.leftGAgent,n.rightGAgent]}expandGroupedGAgentConnection(t){const e=this.expandGroupedGAgent(t[0]),n=this.expandGroupedGAgent(t[1]);let s=Ct.indexOf(this.gAgents,e[0]),i=Ct.indexOf(this.gAgents,n[0]);return-1===s&&(s=e[0].isVirtualSource?-1:this.gAgents.length),-1===i&&(i=this.gAgents.length),s===i?[r(e),r(n)]:s<i?[r(e),n[0]]:[e[0],r(n)]}filterConnectFlags(t){const n=t.filter(Rt.hasFlag("begin")).map(this.toGAgent),s=t.filter(Rt.hasFlag("end")).map(this.toGAgent);if(Ct.hasIntersection(n,s))throw new Error("Cannot set agent visibility multiple times");const r=t.filter(Rt.hasFlag("start")).map(this.toGAgent),i=t.filter(Rt.hasFlag("stop")).map(this.toGAgent);if(e(i,s),Ct.hasIntersection(r,i))throw new Error("Cannot set agent activation multiple times");return this.validateGAgents(n),this.validateGAgents(s),this.validateGAgents(r),this.validateGAgents(i),{beginGAgents:n,endGAgents:s,startGAgents:r,stopGAgents:i}}makeVirtualAgent(t){const e=Ct.make(this.nextVirtualAgentName(),{anchorRight:t,isVirtualSource:!0});return this.replaceGAgentState(e,St.LOCKED),e}addNearbyAgent(t,e,n){Ct.addNearby(this.currentNest.gAgents,t,e,n),Ct.addNearby(this.gAgents,t,e,n)}expandVirtualSourceAgents(t){if(t[0].isVirtualSource){if(t[1].isVirtualSource)throw new Error("Cannot connect found messages");if(Et.includes(t[1].id))throw new Error("Cannot connect found messages to special agents");const e=this.makeVirtualAgent(!0);return this.addNearbyAgent(t[1],e,0),[e,t[1]]}if(t[1].isVirtualSource){if(Et.includes(t[0].id))throw new Error("Cannot connect found messages to special agents");const e=this.makeVirtualAgent(!1);return this.addNearbyAgent(t[0],e,1),[t[0],e]}return t}_handlePartialConnect(t,e){const n=this.filterConnectFlags(t),s=t.map(this.toGAgent);this.validateGAgents(s,{allowGrouped:!0,allowVirtual:!0}),this.defineGAgents(a(s,this.expandGroupedGAgent).filter(t=>!t.isVirtualSource));const r=t.filter(Rt.hasFlag("begin",!1)).map(this.toGAgent).filter(t=>!t.isVirtualSource);return this.addImpStage(this.setGAgentVis(r,!0,"box"),{parallel:e}),{flags:n,gAgents:s}}_makeConnectParallelStages(t,e){return this.makeParallel([this.setGAgentVis(t.beginGAgents,!0,"box",!0),this.setGAgentActivation(t.startGAgents,!0,!0),e,this.setGAgentActivation(t.stopGAgents,!1,!0),this.setGAgentVis(t.endGAgents,!1,"cross",!0)])}_isSelfConnect(t){const e=t.map(this.toGAgent),n=this.expandGroupedGAgentConnection(e);return n[0].id===n[1].id&&!n.some(t=>t.isVirtualSource)}handleConnect({agents:t,label:e,options:n,parallel:s}){if(this._isSelfConnect(t)){const r={};return this.handleConnectDelayBegin({agent:t[0],ln:0,options:n,parallel:s,tag:r}),void this.handleConnectDelayEnd({agent:t[1],label:e,options:n,tag:r})}let{flags:r,gAgents:i}=this._handlePartialConnect(t,s);i=this.expandGroupedGAgentConnection(i);const a={agentIDs:(i=this.expandVirtualSourceAgents(i)).map(t=>t.id),label:this.textFormatter(this.applyLabelPattern(e)),options:n,type:"connect"};this.addStage(this._makeConnectParallelStages(r,a),{parallel:s})}handleConnectDelayBegin({agent:t,tag:e,options:n,ln:s,parallel:r}){const i=this.currentSection.delayedConnections;if(i.has(e))throw new Error('Duplicate delayed connection "'+e+'"');const{flags:a,gAgents:o}=this._handlePartialConnect([t],r),l=this.nextVirtualAgentName(),h={agentIDs:null,label:null,options:n,tag:l,type:"connect-delay-begin"};i.set(e,{connectStage:h,gAgents:o,ln:s,tag:e,uniqueTag:l}),this.addStage(this._makeConnectParallelStages(a,h),{parallel:r})}handleConnectDelayEnd({agent:t,tag:e,label:n,options:s,parallel:r}){const i=this.currentSection.delayedConnections,a=i.get(e);if(!a)throw new Error('Unknown delayed connection "'+e+'"');let{flags:o,gAgents:l}=this._handlePartialConnect([t],r);l=this.expandGroupedGAgentConnection([...a.gAgents,...l]),l=this.expandVirtualSourceAgents(l);let h=a.connectStage.options;if(h.line!==s.line)throw new Error("Mismatched delayed connection arrows");s.right&&(h=Object.assign({},h,{right:s.right})),Object.assign(a.connectStage,{agentIDs:l.map(t=>t.id),label:this.textFormatter(this.applyLabelPattern(n)),options:h});const d={tag:a.uniqueTag,type:"connect-delay-end"};this.addStage(this._makeConnectParallelStages(o,d),{parallel:r}),i.delete(e)}handleNote({type:t,agents:e,mode:n,label:s,parallel:r}){let i=null;i=0===e.length?It[t]||[]:e.map(this.toGAgent),this.validateGAgents(i,{allowGrouped:!0});const o=(i=a(i,this.expandGroupedGAgent)).map(t=>t.id),l=new Set(o).size;if("note between"===t&&l<2)throw new Error("note between requires at least 2 agents");this.defineGAgents(i),this.addImpStage(this.setGAgentVis(i,!0,"box"),{parallel:r}),this.addStage({agentIDs:o,label:this.textFormatter(s),mode:n,type:t},{parallel:r})}handleAgentDefine({agents:t}){const n=t.map(this.toGAgent);this.validateGAgents(n,{allowCovered:!0,allowGrouped:!0}),e(this.gAgents,n,Ct.equals)}handleAgentOptions({agent:t,options:n}){const s=this.toGAgent(t),r=[s];this.validateGAgents(r,{allowCovered:!0,allowGrouped:!0}),e(this.gAgents,r,Ct.equals),this.gAgents.filter(({id:t})=>t===s.id).forEach(t=>{e(t.options,n)})}handleAgentActivation({agents:t,activated:e,parallel:n}){const s=t.map(this.toGAgent);this.validateGAgents(s),this.defineGAgents(s),this.addImpStage(this.setGAgentVis(s,!0,"box"),{parallel:n}),this.addStage(this.setGAgentActivation(s,e),{parallel:n})}handleAgentBegin({agents:t,mode:e,parallel:n}){const s=t.map(this.toGAgent);this.validateGAgents(s),this.addStage(this.setGAgentVis(s,!0,e,!0),{parallel:n})}handleAgentEnd({agents:t,mode:e,parallel:n}){const s=t.filter(t=>this.activeGroups.has(t.name)),r=t.filter(t=>!this.activeGroups.has(t.name)).map(this.toGAgent);this.validateGAgents(r),this.addStage(this.makeParallel([this.setGAgentActivation(r,!1),this.setGAgentVis(r,!1,e,!0),...s.map(this.endGroup)]),{parallel:n})}handleStage(t){this.latestLine=t.ln;try{const e=this.stageHandlers[t.type];if(!e)throw new Error("Unknown command: "+t.type);e(t)}catch(e){if("object"==typeof e&&e.message)throw e.message+=" at line "+(t.ln+1),e}}_reset(){this.agentStates.clear(),this.markers.clear(),this.agentAliases.clear(),this.activeGroups.clear(),this.gAgents.length=0,this.nextID=0,this.nesting.length=0,this.labelPattern=[{token:"label"}]}_finalise(t){m(this.gAgents,this.currentNest.leftGAgent,this.currentNest.rightGAgent),function(t){let e=[],n=new Set;for(let s=0;s<t.length;){const r=t[s];let i=null;d(i="parallel"===r.type?r.stages:[r]);const a=g(i);c(n,a,e,i),0===i.length?t.splice(s,1):("parallel"===r.type&&1===i.length&&t.splice(s,1,i[0]),n=a,e=i,++s)}}(t.stages),this.gAgents.forEach(t=>{t.formattedLabel=this.textFormatter(t.id)})}generate({stages:t,meta:e={}}){this._reset(),this.textFormatter=e.textFormatter;const n=this.beginNested("global",{label:"",ln:0,name:"",tag:""});if(t.forEach(this.handleStage),1!==this.nesting.length)throw new Error("Unterminated section at line "+(this.currentSection.header.ln+1));if(this.activeGroups.size>0)throw new Error("Unterminated group");this._checkSectionEnd();const s=e.terminators||"none";return this.addStage(this.makeParallel([this.setGAgentActivation(this.gAgents,!1),this.setGAgentVis(this.gAgents,!1,s)])),this._finalise(n),function(t,e){for(let n=0;n<t.length&&!f(t[n],e);++n);}(n.stages,e.headers||"box"),{agents:this.gAgents.slice(),meta:{code:e.code,theme:e.theme,title:this.textFormatter(e.title)},stages:n.stages}}}const Nt="Courier New,Liberation Mono,monospace",zt=1.3,Ot={"font-family":Nt,"font-size":8,"line-height":zt},Tt={"font-family":Nt,"font-size":8,"line-height":zt,"text-anchor":"middle"};class Bt extends ht{constructor(t){super(t,{"font-family":Nt,"font-size":8,"line-height":zt});const e={padding:{top:3,bottom:2},tag:{padding:{top:2,left:4,right:4,bottom:2},boxRenderer:this.renderTag.bind(this,{fill:"#FFFFFF",stroke:"#000000","stroke-width":1,rx:3,ry:3}),labelAttrs:{"font-family":Nt,"font-weight":"bold","font-size":9,"line-height":zt,"text-anchor":"left"}},label:{minHeight:8,padding:{top:2,left:8,right:8,bottom:2},labelAttrs:{"font-family":Nt,"font-size":8,"line-height":zt,"text-anchor":"left"}}};Object.assign(this,{titleMargin:8,outerMargin:4,agentMargin:12,actionMargin:12,minActionMargin:4,agentLineActivationRadius:4,agentCap:{box:{padding:{top:4,left:8,right:8,bottom:4},arrowBottom:12,boxAttrs:{fill:"#FFFFFF",stroke:"#000000","stroke-width":1},labelAttrs:{"font-family":Nt,"font-size":12,"line-height":zt,"text-anchor":"middle"}},person:{padding:{top:16,left:8,right:8,bottom:4},arrowBottom:12,boxRenderer:this.renderPerson.bind(this,{iconHeight:12,iconWidth:14},{fill:"#000000"},{fill:"#FFFFFF",stroke:"#000000","stroke-width":1}),labelAttrs:{"font-family":Nt,"font-size":12,"line-height":zt,"text-anchor":"middle"}},database:{padding:{top:9,left:8,right:8,bottom:3},arrowBottom:12,boxRenderer:this.renderDB.bind(this,{tilt:4},{fill:"#FFFFFF",stroke:"#000000","stroke-width":1}),labelAttrs:{"font-family":Nt,"font-size":12,"line-height":zt,"text-anchor":"middle"}},cross:{size:16,render:t.crossFactory({fill:"none",stroke:"#000000","stroke-width":1})},bar:{height:4,render:t.boxFactory({fill:"#000000",stroke:"#000000","stroke-width":1})},fade:{width:5,height:8,extend:1},none:{height:8}},connect:{loopbackRadius:4,arrow:{single:{width:4,height:8,render:this.renderArrowHead.bind(this),attrs:{fill:"#000000","stroke-width":0,"stroke-linejoin":"miter"}},double:{width:3,height:6,render:this.renderArrowHead.bind(this),attrs:{fill:"none",stroke:"#000000","stroke-width":1,"stroke-linejoin":"miter"}},fade:{short:2,size:10},cross:{short:8,radius:4,render:t.crossFactory({fill:"none",stroke:"#000000","stroke-width":1})}},label:{padding:4,margin:{top:2,bottom:1},attrs:{"font-family":Nt,"font-size":8,"line-height":zt,"text-anchor":"middle"},loopbackAttrs:{"font-family":Nt,"font-size":8,"line-height":zt}},source:{radius:2,render:t.circleFactory({fill:"#000000",stroke:"#000000","stroke-width":1})},mask:{padding:{top:0,left:3,right:3,bottom:1}}},agentLineAttrs:{"":{fill:"none",stroke:"#000000","stroke-width":1},red:{stroke:"#AA0000"}},blocks:{ref:{margin:{top:0,bottom:0},boxRenderer:this.renderRef.bind(this,{fill:"#FFFFFF",stroke:"#000000","stroke-width":2}),section:e},"":{margin:{top:0,bottom:0},boxRenderer:t.boxFactory({fill:"none",stroke:"#000000","stroke-width":2}),collapsedBoxRenderer:this.renderRef.bind(this,{fill:"#FFFFFF",stroke:"#000000","stroke-width":2}),section:e,sepRenderer:t.lineFactory({stroke:"#000000","stroke-width":2,"stroke-dasharray":"8, 4"})}},notes:{text:{margin:{top:0,left:8,right:8,bottom:0},padding:{top:4,left:4,right:4,bottom:4},overlap:{left:8,right:8},boxRenderer:t.boxFactory({fill:"#FFFFFF"}),labelAttrs:Ot},note:{margin:{top:0,left:8,right:8,bottom:0},padding:{top:8,left:8,right:8,bottom:8},overlap:{left:8,right:8},boxRenderer:t.noteFactory({fill:"#FFFFFF",stroke:"#000000","stroke-width":1},{fill:"none",stroke:"#000000","stroke-width":1}),labelAttrs:Ot},state:{margin:{top:0,left:8,right:8,bottom:0},padding:{top:8,left:8,right:8,bottom:8},overlap:{left:8,right:8},boxRenderer:t.boxFactory({fill:"#FFFFFF",stroke:"#000000","stroke-width":1,rx:8,ry:8}),labelAttrs:Ot}},dividers:{"":{labelAttrs:Tt,padding:{top:2,left:5,right:5,bottom:2},extend:0,margin:0,render:()=>({})},line:{labelAttrs:Tt,padding:{top:2,left:5,right:5,bottom:2},extend:8,margin:0,render:this.renderLineDivider.bind(this,{lineAttrs:{stroke:"#000000"}})},delay:{labelAttrs:Tt,padding:{top:2,left:5,right:5,bottom:2},extend:0,margin:0,render:this.renderDelayDivider.bind(this,{dotSize:2,gapSize:2})},tear:{labelAttrs:Tt,padding:{top:2,left:5,right:5,bottom:2},extend:8,margin:8,render:this.renderTearDivider.bind(this,{fadeBegin:4,fadeSize:4,zigWidth:4,zigHeight:1,lineAttrs:{stroke:"#000000"}})}}}),this.addConnectLine("solid",{attrs:{stroke:"#000000","stroke-width":1}}),this.addConnectLine("dash",{attrs:{"stroke-dasharray":"4, 4"}}),this.addConnectLine("wave",{pattern:new lt(6,[0,-.25,-.5,-.25,0,.25,.5,.25])})}}const Vt={type:"error line-error",suggest:[],then:{"":0}},Pt=["person","database","red"],jt=["activate","begin","deactivate","end","note","state","text"],Ht=(()=>{function t(t,e=1){return{type:"variable",suggest:[{known:"Agent"}],then:Object.assign({},t,{"":0,",":{type:"operator",then:{"":e}}})}}function e(t){return{type:"keyword",suggest:[t+" of ",t+": "],then:{of:{type:"keyword",then:{"":l}},":":{type:"operator",then:{"":i}},"":l}}}function n({exit:t,sourceExit:e,blankExit:n}){const s={type:"operator",then:{"+":Vt,"-":Vt,"*":Vt,"!":Vt,"":t}};return{"+":{type:"operator",then:{"+":Vt,"-":Vt,"*":s,"!":Vt,"":t}},"-":{type:"operator",then:{"+":Vt,"-":Vt,"*":s,"!":{type:"operator",then:{"+":Vt,"-":Vt,"*":Vt,"!":Vt,"":t}},"":t}},"*":{type:"operator",then:Object.assign({"+":s,"-":s,"*":Vt,"!":Vt,"":t},e||t)},"!":s,"":n||t}}const s={type:"",suggest:["\n"],then:{}},r={type:"",suggest:[],then:{}},i=b({"\n":s}),a={type:"operator",then:{"":i,"\n":r}},o=t({"\n":s,as:{type:"keyword",then:{"":{type:"variable",suggest:[{known:"Agent"}],then:{"":0,",":{type:"operator",then:{"":3}},"\n":s}}}}}),l=t({":":a}),h={type:"variable",suggest:[{known:"Agent"}],then:{"":0,":":{type:"operator",then:{"":i,"\n":r}},"\n":s}},d={":":{type:"operator",then:{"":b({as:{type:"keyword",then:{"":{type:"variable",suggest:[{known:"Agent"}],then:{"":0,"\n":s}}}}})}}},g={type:"keyword",then:Object.assign({over:{type:"keyword",then:{"":t(d)}}},d)},c={"\n":s,":":{type:"operator",then:{"":i,"\n":r}},with:{type:"keyword",suggest:["with height "],then:{height:{type:"keyword",then:{"":{type:"number",suggest:["6 ","30 "],then:{"\n":s,":":{type:"operator",then:{"":i,"\n":r}}}}}}}}},u=function(t,e,n){const s=Object.assign({},n);return e.forEach(e=>{s[e]={type:t,then:n}}),s}("keyword",["a","an"],function(t,e,n){const s={},r=Object.assign({},n);return e.forEach(e=>{s[e]={type:t,then:r},r[e]=0}),s}("keyword",Pt,{"\n":s})),p={type:"keyword",then:{"":i,":":{type:"operator",then:{"":i}},"\n":s}},f={title:{type:"keyword",then:{"":i}},theme:{type:"keyword",then:{"":{type:"string",suggest:[{global:"themes",suffix:"\n"}],then:{"":0,"\n":s}}}},headers:{type:"keyword",then:{none:{type:"keyword",then:{}},cross:{type:"keyword",then:{}},box:{type:"keyword",then:{}},fade:{type:"keyword",then:{}},bar:{type:"keyword",then:{}}}},terminators:{type:"keyword",then:{none:{type:"keyword",then:{}},cross:{type:"keyword",then:{}},box:{type:"keyword",then:{}},fade:{type:"keyword",then:{}},bar:{type:"keyword",then:{}}}},divider:{type:"keyword",then:Object.assign({line:{type:"keyword",then:c},space:{type:"keyword",then:c},delay:{type:"keyword",then:c},tear:{type:"keyword",then:c}},c)},define:{type:"keyword",then:{"":o,as:Vt}},begin:{type:"keyword",then:{"":o,reference:g,as:Vt}},end:{type:"keyword",then:{"":o,as:Vt,"\n":s}},activate:{type:"keyword",then:{"":t({"\n":s})}},deactivate:{type:"keyword",then:{"":t({"\n":s})}},if:p,else:{type:"keyword",suggest:["else\n","else if: "],then:{if:{type:"keyword",suggest:["if: "],then:{"":i,":":{type:"operator",then:{"":i}}}},"\n":s}},repeat:p,group:p,note:{type:"keyword",then:{over:{type:"keyword",then:{"":l}},left:e("left"),right:e("right"),between:{type:"keyword",then:{"":t({":":Vt},l)}}}},state:{type:"keyword",suggest:["state over "],then:{over:{type:"keyword",then:{"":{type:"variable",suggest:[{known:"Agent"}],then:{"":0,",":Vt,":":a}}}}}},text:{type:"keyword",then:{left:e("left"),right:e("right")}},autolabel:{type:"keyword",then:{off:{type:"keyword",then:{}},"":b({"\n":s},[{v:"<label>",suffix:"\n",q:!0},{v:"[<inc>] <label>",suffix:"\n",q:!0},{v:"[<inc 1,0.01>] <label>",suffix:"\n",q:!0}])}},simultaneously:{type:"keyword",then:{":":{type:"operator",then:{}},with:{type:"keyword",then:{"":{type:"variable",suggest:[{known:"Label"}],then:{"":0,":":{type:"operator",then:{}}}}}}}}};return t=>{const e=function(t){const e={type:"keyword",then:Object.assign({},n({exit:h,sourceExit:{":":a,"\n":r}}),{"...":{type:"operator",then:{"":{type:"variable",suggest:[{known:"DelayedAgent"}],then:{"":0,":":Vt,"\n":s}}}}})},i={};t.forEach(t=>i[t]=e);const o={type:"operator",suggest:[],override:"Label",then:{}},l={type:"variable",suggest:[{known:"Agent"}],then:Object.assign({"":0},i,{":":{type:"operator",override:"Label",then:{}}})},d={type:"variable",suggest:[{known:"DelayedAgent"}],then:Object.assign({"":0,":":o},i)},g=Object.assign({},l,{then:Object.assign({},l.then,{is:{type:"keyword",then:u}})});return Object.assign({"...":{type:"operator",then:{"":d}}},n({exit:l,sourceExit:Object.assign({"":l,":":o},i),blankExit:g}))}(t),i={};for(const t of jt)i[t]=f[t];return Object.assign(i,e),{type:"error line-error",then:Object.assign({},f,{"&":{type:"keyword",then:i}},e)}}})(),qt=-1;class Yt{constructor(t,e){this.tokenDefinitions=t,this.commands=Ht(e),this.lineComment="#"}startState(){return{beginCompletions:k({},[this.commands]),completions:[],current:"",currentQuoted:!1,currentSpace:"",currentType:qt,indent:0,isVar:!0,knownAgent:[],knownDelayedAgent:[],knownLabel:[],line:[],nextCompletions:[],valid:!0}}_matchPattern(t,e,n){return e?(e.lastIndex=0,t.match(e,n)):null}_tokenBegin(t,e){e.currentSpace="";for(let n="";!t.eol();n=t.next()){e.currentSpace+=n;for(let n=0;n<this.tokenDefinitions.length;++n){const s=this.tokenDefinitions[n];if(this._matchPattern(t,s.start,!0)){e.currentType=n;const{value:t,quoted:r}=A(s);return e.current=t,e.currentQuoted=r,!0}}}return!1}_tokenCheckEscape(t,e,n){const s=this._matchPattern(t,n.escape,!0);s&&(e.current+=n.escapeWith(s))}_addToken(t){t.line.push({q:t.currentQuoted,s:t.currentSpace,v:t.current})}_tokenEndFound(t,e,n,s){return e.currentType=qt,n.includeEnd&&(e.current+=s[0]),n.omit?"comment":(this._addToken(e),v(e,t.eol(),this.commands))}_tokenEOLFound(t,e,n){if(e.current+="\n",n.omit)return"comment";this._addToken(e);const s=v(e,!1,this.commands);return e.line.pop(),s}_tokenEnd(t,e){for(;;){const n=this.tokenDefinitions[e.currentType];if(this._tokenCheckEscape(t,e,n),!n.end)return this._tokenEndFound(t,e,n,null);{const s=this._matchPattern(t,n.end,!0);if(s)return this._tokenEndFound(t,e,n,s)}if(t.eol())return this._tokenEOLFound(t,e,n);e.current+=t.next()}}_tokenContinueOrBegin(t,e){return e.currentType!==qt||(t.sol()&&(e.line.length=0,e.valid=!0),this._tokenBegin(t,e))?this._tokenEnd(t,e):""}_isLineTerminated(t){return t.currentType!==qt||t.valid}token(t,e){e.completions=e.nextCompletions,e.isVar=!0;const n=this._tokenContinueOrBegin(t,e);return t.eol()&&!this._isLineTerminated(e)?"line-error "+n:n}indent(t){return t.indent}}const Ut=[{end:/(?=\n)|$/y,omit:!0,start:/#/y},{baseToken:{q:!0},end:/"/y,escape:/\\(.)/y,escapeWith:function(t){return"n"===t[1]?"\n":-1!=='"\\'.indexOf(t[1])?t[1]:""+t[1]},start:/"/y},{baseToken:{v:"..."},start:/\.\.\./y},{end:/(?=[ \t\r\n:+~\-*!<,])|$/y,start:/(?=[^ \t\r\n:+~\-*!<,])/y},{end:/(?=[^~\-<>x])|[-~]x|[<>](?=x)|$/y,includeEnd:!0,start:/(?=[~\-<])/y},{baseToken:{v:","},start:/,/y},{baseToken:{v:":"},start:/:/y},{baseToken:{v:"!"},start:/!/y},{baseToken:{v:"+"},start:/\+/y},{baseToken:{v:"*"},start:/\*/y},{baseToken:{v:"\n"},start:/\n/y}],Wt=/[\x00-\x08\x0E-\x1F]/g;class Xt{constructor(t){this.src=t.replace(Wt,""),this.block=null,this.token=null,this.pos={ch:0,i:0,ln:0},this.reset()}isOver(){return this.pos.i>this.src.length}reset(){this.token={b:null,e:null,q:!1,s:"",v:""},this.block=null}beginToken(t){this.block=t.newBlock,Object.assign(this.token,this.block.baseToken),this.token.b=S(this.pos)}endToken(){let t=null;return this.block.omit||(this.token.e=S(this.pos),t=this.token),this.reset(),t}advance(){const t=M(this.src,this.pos.i,this.block);return t.newBlock&&this.beginToken(t),this.token.s+=t.appendSpace,this.token.v+=t.appendValue,function(t,e,n){for(let s=0;s<n;++s)++t.ch,"\n"===e[t.i+s]&&(++t.ln,t.ch=0);t.i+=n}(this.pos,this.src,t.skip),t.end?this.endToken():null}}const Qt=/(.*?)<([^<>]*)>/g,Jt=/\.([0-9]*)/,Zt=/[\x00-\x08\x0E-\x1F]/g,Kt=[{attrs:{"font-style":"italic"},begin:{matcher:/<i>/g,skip:0},end:{matcher:/<\/i>/g,skip:0}},{attrs:{"font-style":"italic"},begin:{matcher:/[\s_~`>]\*(?=\S)/g,skip:1},end:{matcher:/\S\*(?=[\s_~`<])/g,skip:1}},{attrs:{"font-style":"italic"},begin:{matcher:/[\s*~`>]_(?=\S)/g,skip:1},end:{matcher:/\S_(?=[\s*~`<])/g,skip:1}},{attrs:{"font-weight":"bolder"},begin:{matcher:/<b>/g,skip:0},end:{matcher:/<\/b>/g,skip:0}},{attrs:{"font-weight":"bolder"},begin:{matcher:/[\s_~`>]\*\*(?=\S)/g,skip:1},end:{matcher:/\S\*\*(?=[\s_~`<])/g,skip:1}},{attrs:{"font-weight":"bolder"},begin:{matcher:/[\s*~`>]__(?=\S)/g,skip:1},end:{matcher:/\S__(?=[\s*~`<])/g,skip:1}},{attrs:{"text-decoration":"line-through"},begin:{matcher:/<s>/g,skip:0},end:{matcher:/<\/s>/g,skip:0}},{attrs:{"text-decoration":"line-through"},begin:{matcher:/[\s_*`>]~(?=\S)/g,skip:1},end:{matcher:/\S~(?=[\s_*`<])/g,skip:1}},{attrs:{"text-decoration":"overline"},begin:{matcher:/<o>/g,skip:0},end:{matcher:/<\/o>/g,skip:0}},{attrs:{"font-family":"Courier New,Liberation Mono,monospace"},begin:{matcher:/[\s_*~.>]`(?=\S)/g,skip:1},end:{matcher:/\S`(?=[\s_*~.<])/g,skip:1}},{attrs:{"text-decoration":"underline"},begin:{matcher:/<u>/g,skip:0},end:{matcher:/<\/u>/g,skip:0}},{attrs:{"baseline-shift":"70%","font-size":"0.6em"},begin:{matcher:/<sup>/g,skip:0},end:{matcher:/<\/sup>/g,skip:0}},{attrs:{"baseline-shift":"-20%","font-size":"0.6em"},begin:{matcher:/<sub>/g,skip:0},end:{matcher:/<\/sub>/g,skip:0}},{attrs:{fill:"#DD0000"},begin:{matcher:/<red>/g,skip:0},end:{matcher:/<\/red>/g,skip:0}},{attrs:{filter:"highlight"},begin:{matcher:/<highlight>/g,skip:0},end:{matcher:/<\/highlight>/g,skip:0}},{all:{matcher:/\[([^\]]+)\]\(([^)]+?)(?: "([^"]+)")?\)/g,skip:0},attrs:t=>({href:t[2].replace(Zt,""),"text-decoration":"underline"}),text:t=>t[1].replace(Zt,"")},{all:{matcher:/<([a-z]+:\/\/[^>]*)>/g,skip:0},attrs:t=>({href:t[1].replace(Zt,""),"text-decoration":"underline"}),text:t=>t[1].replace(Zt,"")}],_t=/[\f\n\r\t\v ]+/g,$t=/^[\t-\r ]+|[\t-\r ]+$/g,te=-2,ee=new Map;ee.set("if",{blockType:"if",skip:[],tag:"if",type:"block begin"}),ee.set("else",{blockType:"else",skip:["if"],tag:"else",type:"block split"}),ee.set("repeat",{blockType:"repeat",skip:[],tag:"repeat",type:"block begin"}),ee.set("group",{blockType:"group",skip:[],tag:"",type:"block begin"});const ne={agentFlags:{"!":{flag:"end"},"*":{allowBlankName:!0,blankNameFlag:"source",flag:"begin"},"+":{flag:"start"},"-":{flag:"stop"}},types:(()=>{const t=new Map;return function(t){const e=[];return i(t,0,[],e),e}([[{tok:"",type:0},{tok:"<",type:1},{tok:"<<",type:2},{tok:"~",type:3}],[{tok:"-",type:"solid"},{tok:"--",type:"dash"},{tok:"~",type:"wave"}],[{tok:"",type:0},{tok:">",type:1},{tok:">>",type:2},{tok:"~",type:3},{tok:"x",type:4}]]).forEach(e=>{const[n,s,r]=e;0===n.type&&0===r.type||3===n.type&&"wave"===s.type&&0===r.type||t.set(e.map(t=>t.tok).join(""),{left:n.type,line:s.type,right:r.type})}),t})()},se=["none","box","cross","fade","bar"],re=new Map;re.set("text",{mode:"text",types:{left:{max:Number.POSITIVE_INFINITY,min:0,skip:["of"],type:"note left"},right:{max:Number.POSITIVE_INFINITY,min:0,skip:["of"],type:"note right"}}}),re.set("note",{mode:"note",types:{between:{max:Number.POSITIVE_INFINITY,min:2,skip:[],type:"note between"},left:{max:Number.POSITIVE_INFINITY,min:0,skip:["of"],type:"note left"},over:{max:Number.POSITIVE_INFINITY,min:0,skip:[],type:"note over"},right:{max:Number.POSITIVE_INFINITY,min:0,skip:["of"],type:"note right"}}}),re.set("state",{mode:"state",types:{over:{max:1,min:1,skip:[],type:"note over"}}});const ie=new Map;ie.set("line",{defaultHeight:6}),ie.set("space",{defaultHeight:6}),ie.set("delay",{defaultHeight:30}),ie.set("tear",{defaultHeight:6});const ae=new Map;ae.set("define",{type:"agent define"}),ae.set("begin",{mode:"box",type:"agent begin"}),ae.set("end",{mode:"cross",type:"agent end"});const oe=new Map;ae.set("activate",{activated:!0,type:"agent activation"}),ae.set("deactivate",{activated:!1,type:"agent activation"});const le=[{begin:["title"],fn:(t,e)=>(e.title=z(t,1),!0)},{begin:["theme"],fn:(t,e)=>(e.theme=z(t,1),!0)},{begin:["terminators"],fn:(t,e)=>{const n=O(t[1]);if(!n)throw L("Unspecified termination",t[0]);if(-1===se.indexOf(n))throw L('Unknown termination "'+n+'"',t[1]);return e.terminators=n,!0}},{begin:["headers"],fn:(t,e)=>{const n=O(t[1]);if(!n)throw L("Unspecified header",t[0]);if(-1===se.indexOf(n))throw L('Unknown header "'+n+'"',t[1]);return e.headers=n,!0}},{begin:["divider"],fn:t=>{const e=B(t,[":"],{orEnd:!0}),n=B(t,["with","height"],{limit:e,orEnd:!0}),s=z(t,1,n)||"line";if(!ie.has(s))throw L("Unknown divider type",t[1]);const r=function(t,e=0,n=null,s=Number.NAN){const r=z(t,e,n);return Number(r||s)}(t,n+2,e,ie.get(s).defaultHeight);if(Number.isNaN(r)||r<0)throw L("Invalid divider height",t[n+2]);return{height:r,label:z(t,e+1),mode:s,type:"divider"}}},{begin:["autolabel"],fn:t=>{let e=null;return e="off"===O(t[1])?"<label>":z(t,1),{pattern:function(t){const e=[];let n=null,s=0;for(Qt.lastIndex=0;n=Qt.exec(t);)n[1]&&e.push(n[1]),n[2]&&e.push(C(n[2])),s=Qt.lastIndex;const r=t.substr(s);return r&&e.push(r),e}(e),type:"label pattern"}}},{begin:["end"],fn:t=>1!==t.length?null:{type:"block end"}},{begin:[],fn:t=>{const e=ee.get(O(t[0]));if(!e)return null;let n=1;return t.length>n&&(n=T(t,n,e.skip,"Invalid block command")),n=T(t,n,[":"]),{blockType:e.blockType,label:z(t,n),tag:e.tag,type:e.type}}},{begin:["begin","reference"],fn:t=>{let e=[];const n=B(t,[":"]);if("over"===O(t[2])&&n>3)e=P(t,3,n);else if(2!==n)throw L('Expected ":" or "over"',t[2]);const s=V(t,n+1,t.length,{aliases:!0});if(!s.alias)throw L("Reference must have an alias",t[n]);return{agents:e,alias:s.alias,blockType:"ref",label:s.name,tag:"ref",type:"group begin"}}},{begin:[],fn:t=>{const e=ae.get(O(t[0]));return!e||t.length<=1?null:Object.assign({agents:P(t,1,t.length,{aliases:!0})},e)}},{begin:[],fn:t=>{const e=oe.get(O(t[0]));return!e||t.length<=1?null:Object.assign({agents:P(t,1,t.length,{aliases:!1})},e)}},{begin:["simultaneously"],fn:t=>{if(":"!==O(r(t)))return null;let e="";if(t.length>2){if("with"!==O(t[1]))return null;e=z(t,2,t.length-1)}return{target:e,type:"async"}}},{begin:[],fn:t=>{const e=re.get(O(t[0])),n=B(t,[":"]);if(!e||-1===n)return null;const s=e.types[O(t[1])];if(!s)return null;let r=2;const i=P(t,r=T(t,r,s.skip),n);if(i.length<s.min)throw L("Too few agents for "+e.mode,t[0]);if(i.length>s.max)throw L("Too many agents for "+e.mode,t[0]);return{agents:i,label:z(t,n+1),mode:e.mode,type:s.type}}},{begin:[],fn:t=>{const e=B(t,[":"],{orEnd:!0}),n=function(t,e,{start:n=0,limit:s=null}={}){const r=N(t,s);for(let s=n;s<r;++s){const n=e.get(O(t[s]));if(n)return{pos:s,value:n}}return null}(t,ne.types,{limit:e-1,start:0});if(!n)return null;const s=n.pos,r={flagTypes:ne.agentFlags};if("..."===O(t[0]))return{agent:V(t,s+1,e,r),label:z(t,e+1),options:n.value,tag:z(t,1,s),type:"connect-delay-end"};if("..."===O(t[s+1])){if(e!==t.length)throw L("Cannot label beginning of delayed connection",t[e]);return{agent:V(t,0,s,r),options:n.value,tag:z(t,s+2,e),type:"connect-delay-begin"}}return{agents:[V(t,0,s,r),V(t,s+1,e,r)],label:z(t,e+1),options:n.value,type:"connect"}}},{begin:[],fn:t=>t.length<2||":"!==O(r(t))?null:{name:z(t,0,t.length-1),type:"mark"}},{begin:[],fn:t=>{const e=B(t,["is"]);if(e<1)return null;let n=e+1;if(["a","an"].includes(O(t[n]))&&++n,n===t.length)throw L("Empty agent options",{b:r(t).e});const s=V(t,0,e),i=[];for(let e=n;e<t.length;++e)i.push(t[e].v);return{agent:s,options:i,type:"agent options"}}}],he=new class{tokenise(t){const e=[],n=new Xt(t);for(;!n.isOver();){const t=n.advance();t&&e.push(t)}if(n.block)throw new Error("Unterminated literal (began at "+function(t){return"line "+(t.ln+1)+", character "+t.ch}(n.token.b)+")");return e}getCodeMirrorMode(t){return new Yt(Ut,t)}splitLines(t){const e=[];let n=[];return t.forEach(t=>{t.q||"\n"!==t.v?n.push(t):n.length>0&&(e.push(n),n=[])}),n.length>0&&e.push(n),e}};class de{getCodeMirrorMode(){return he.getCodeMirrorMode(Array.from(ne.types.keys()))}parseLines(t,e){const n={meta:{code:e,headers:"box",terminators:"none",textFormatter:D,theme:"",title:""},stages:[]};return t.forEach(t=>j(t,n)),n}parse(t){const e=he.tokenise(t),n=he.splitLines(e);return this.parseLines(n,t)}}class ge{makeState(){}resetState(t){this.makeState(t)}prepareMeasurements(){}separationPre(){}separation(){}renderPre(){}render(){}renderHidden(){}shouldHide(){}}const ce=new Map;q("agent activation",new class extends ge{radius(t,e){return t?e.theme.agentLineActivationRadius:0}separationPre({agentIDs:t,activated:e},n){const s=this.radius(e,n);t.forEach(t=>{const e=n.agentInfos.get(t);e.currentRad=s,e.currentMaxRad=Math.max(e.currentMaxRad,s)})}renderPre({agentIDs:t,activated:e},n){const s=this.radius(e,n);t.forEach(t=>{const e=n.agentInfos.get(t);e.currentMaxRad=Math.max(e.currentMaxRad,s)})}render({agentIDs:t,activated:e},n){const s=this.radius(e,n);return t.forEach(t=>{n.drawAgentLine(t,n.primaryY),n.agentInfos.get(t).currentRad=s}),n.primaryY+n.theme.actionMargin}renderHidden(t,e){this.render(t,e)}});const ue={class:"outline",fill:"transparent"};const pe={bar:new class{prepareMeasurements({formattedLabel:t},e){const n=e.theme.agentCap.box;e.textSizer.expectMeasure(n.labelAttrs,t)}separation({formattedLabel:t},e){const n=e.theme.agentCap.box,s=e.textSizer.measure(n.labelAttrs,t).width+n.padding.left+n.padding.right;return{left:s/2,radius:s/2,right:s/2}}topShift(t,e){return e.theme.agentCap.bar.height/2}render(t,{x:e,formattedLabel:n,options:s},r){const i=r.theme.agentCap.box,a=r.theme.agentCap.bar,o=r.textSizer.measure(i.labelAttrs,n).width+i.padding.left+i.padding.right,{height:l}=a;return r.makeRegion().add(a.render({height:l,options:s,width:o,x:e-o/2,y:t}),r.svg.box(ue,{height:l,width:o,x:e-o/2,y:t})),{height:l,lineBottom:l,lineTop:0}}},box:new class{getConfig(t,e,n){let s=null;return t.includes("database")?s=e.theme.agentCap.database:n&&t.includes("person")&&(s=e.theme.agentCap.person),s||e.theme.agentCap.box}prepareMeasurements({formattedLabel:t,options:e},n,s){const r=this.getConfig(e,n,s);n.textSizer.expectMeasure(r.labelAttrs,t)}separation({formattedLabel:t,options:e},n,s){const r=this.getConfig(e,n,s),i=n.textSizer.measure(r.labelAttrs,t).width+r.padding.left+r.padding.right;return{left:i/2,radius:i/2,right:i/2}}topShift({formattedLabel:t,options:e},n,s){const r=this.getConfig(e,n,s),i=n.textSizer.measureHeight(r.labelAttrs,t)+r.padding.top+r.padding.bottom;return Math.max(0,i-r.arrowBottom)}render(t,{x:e,formattedLabel:n,options:s},r,i){const a=this.getConfig(s,r,i),o=r.svg.boxedText(a,n,{x:e,y:t});return r.makeRegion().add(o,r.svg.box(ue,{height:o.height,width:o.width,x:e-o.width/2,y:t})),{height:o.height,lineBottom:o.height,lineTop:0}}},cross:new class{prepareMeasurements(){}separation(t,e){const n=e.theme.agentCap.cross;return{left:n.size/2,radius:0,right:n.size/2}}topShift(t,e){return e.theme.agentCap.cross.size/2}render(t,{x:e,options:n},s){const r=s.theme.agentCap.cross,i=r.size/2;return s.makeRegion().add(r.render({options:n,radius:i,x:e,y:t+i}),s.svg.box(ue,{height:2*i,width:2*i,x:e-i,y:t})),{height:2*i,lineBottom:i,lineTop:i}}},fade:new class{prepareMeasurements(){}separation({currentRad:t}){return{left:t,radius:t,right:t}}topShift(t,e,n){const s=e.theme.agentCap.fade;return n?s.height:0}render(t,{x:e},n,s){const r=n.theme.agentCap.fade,i=r.height/(r.height+r.extend),a=n.addDef(s?"FadeIn":"FadeOut",()=>n.svg.linearGradient({x1:"0%",x2:"0%",y1:s?"100%":"0%",y2:s?"0%":"100%"},[{offset:"0%","stop-color":"#FFFFFF"},{offset:(100*i).toFixed(3)+"%","stop-color":"#000000"}]));return n.lineMaskLayer.add(n.svg.box({fill:"url(#"+a+")"},{height:r.height+r.extend,width:r.width,x:e-r.width/2,y:t-(s?r.extend:0)})),n.makeRegion().add(n.svg.box(ue,{height:r.height,width:r.width,x:e-r.width/2,y:t})),{height:r.height,lineBottom:0,lineTop:r.height}}},none:new class{prepareMeasurements(){}separation({currentRad:t}){return{left:t,radius:t,right:t}}topShift(t,e){return e.theme.agentCap.none.height}render(t,{x:e},n){const s=n.theme.agentCap.none;return n.makeRegion().add(n.svg.box(ue,{height:s.height,width:10,x:e-5,y:t})),{height:s.height,lineBottom:0,lineTop:s.height}}}};class fe extends ge{constructor(t){super(),this.begin=t}prepareMeasurements({mode:t,agentIDs:e},n){e.forEach(e=>{const s=n.agentInfos.get(e);pe[t].prepareMeasurements(s,n,this.begin)})}separationPre({mode:t,agentIDs:e},n){e.forEach(e=>{const s=n.agentInfos.get(e),r=pe[t].separation(s,n,this.begin);n.addSpacing(e,r),s.currentMaxRad=Math.max(s.currentMaxRad,r.radius)})}separation({agentIDs:t},s){this.begin?e(s.visibleAgentIDs,t):n(s.visibleAgentIDs,t)}renderPre({mode:t,agentIDs:e},n){let s=0;return e.forEach(e=>{const r=n.agentInfos.get(e),i=pe[t],a=i.topShift(r,n,this.begin);s=Math.max(s,a);const o=i.separation(r,n,this.begin).radius;r.currentMaxRad=Math.max(r.currentMaxRad,o)}),{agentIDs:e,topShift:s}}render({mode:t,agentIDs:e},n){let s=0;return e.forEach(e=>{const r=n.agentInfos.get(e),i=pe[t],a=i.topShift(r,n,this.begin),o=n.primaryY-a,l=i.render(o,r,n,this.begin);s=Math.max(s,o+l.height),this.begin?n.drawAgentLine(e,o+l.lineBottom):n.drawAgentLine(e,o+l.lineTop,!0)}),s+n.theme.actionMargin}renderHidden({agentIDs:t},e){t.forEach(t=>{e.drawAgentLine(t,e.topY,!this.begin)})}}q("agent begin",new fe(!0)),q("agent end",new fe(!1));const me={class:"outline",fill:"transparent"};class be extends ge{prepareMeasurements({left:t,tag:e,label:n},s){const r=s.state.blocks.get(t),i=s.theme.getBlock(r.type).section;s.textSizer.expectMeasure(i.tag.labelAttrs,e),s.textSizer.expectMeasure(i.label.labelAttrs,n)}separation({left:t,right:e,tag:n,label:s},r){const i=r.state.blocks.get(t),a=r.theme.getBlock(i.type).section,o=r.textSizer.measure(a.tag.labelAttrs,n).width+a.tag.padding.left+a.tag.padding.right+r.textSizer.measure(a.label.labelAttrs,s).width+a.label.padding.left+a.label.padding.right;r.addSeparation(t,e,o)}renderPre({left:t,right:e}){return{agentIDs:[t,e]}}render({left:t,right:e,tag:n,label:s},r,i=!1){const a=r.state.blocks.get(t),o=r.theme.getBlock(a.type),l=r.agentInfos.get(t),h=r.agentInfos.get(e);let d=r.primaryY;i||(d+=o.section.padding.bottom);const g=r.makeRegion(),c=r.svg.boxedText({boxAttrs:o.section.tag.boxAttrs,boxRenderer:o.section.tag.boxRenderer,labelAttrs:o.section.tag.labelAttrs,padding:o.section.tag.padding},n,{x:l.x,y:d}),u=r.svg.boxedText({boxAttrs:{fill:"#000000"},labelAttrs:o.section.label.labelAttrs,padding:o.section.label.padding},s,{x:l.x+c.width,y:d}),p=Math.max(Math.max(c.height,u.height),o.section.label.minHeight);return a.hold.add(c.box),r.lineMaskLayer.add(u.box),g.add(r.svg.box(me,{height:p,width:h.x-l.x,x:l.x,y:d}),c.label,u.label),i?a.canHide&&g.addClass(a.hide?"collapsed":"expanded"):a.hold.add(o.sepRenderer({x1:l.x,x2:h.x,y1:d,y2:d})),d+p+o.section.padding.top}}q("block begin",new class extends be{makeState(t){t.blocks=new Map}resetState(t){t.blocks.clear()}storeBlockInfo(t,e){const{canHide:n}=t,s={canHide:n,hide:n&&e.renderer.isCollapsed(t.ln),hold:null,startY:null,type:t.blockType};return e.state.blocks.set(t.left,s),s}prepareMeasurements(t,e){this.storeBlockInfo(t,e),super.prepareMeasurements(t,e)}separationPre(t,e){this.storeBlockInfo(t,e),super.separationPre(t,e)}separation(t,n){e(n.visibleAgentIDs,[t.left,t.right]),super.separation(t,n)}renderPre(t,e){const n=this.storeBlockInfo(t,e),s=e.theme.getBlock(n.type);return{agentIDs:[t.left,t.right],topShift:s.margin.top}}render(t,e){const n=e.svg.el("g");e.blockLayer.add(n);const s=e.state.blocks.get(t.left);return s.hold=n,s.startY=e.primaryY,super.render(t,e,!0)}shouldHide({left:t},e){return{nest:e.state.blocks.get(t).hide?1:0,self:!1}}}),q("block split",new be),q("block end",new class extends ge{separation({left:t,right:e},s){n(s.visibleAgentIDs,[t,e])}renderPre({left:t,right:e},n){const s=n.state.blocks.get(t);return{agentIDs:[t,e],topShift:n.theme.getBlock(s.type).section.padding.bottom}}render({left:t,right:e},n){const s=n.state.blocks.get(t),r=n.theme.getBlock(s.type),i=n.agentInfos.get(t),a=n.agentInfos.get(e);let o=r.boxRenderer;s.hide&&(o=r.collapsedBoxRenderer||o);let l=o({height:n.primaryY-s.startY,width:a.x-i.x,x:i.x,y:s.startY});return l.shape||(l={shape:l}),s.hold.add(l.shape),n.fillLayer.add(l.fill),n.lineMaskLayer.add(l.mask),n.primaryY+r.margin.bottom+n.theme.actionMargin}shouldHide({left:t},e){return{nest:e.state.blocks.get(t).hide?-1:0,self:!1}}});const ye={class:"outline",fill:"transparent"},xe=5;class ke{constructor(t){this.propName=t}getConfig(t){return t.connect.arrow[this.propName]}short(t){const e=this.getConfig(t),n=e.attrs["stroke-linejoin"]||"miter",s=.5*e.attrs["stroke-width"],r=.5*t.agentLineAttrs[""]["stroke-width"];if("round"===n)return r+s;{const t=e.height/2,n=e.width;return r+s*Math.sqrt(n*n/(t*t)+1)}}render({layer:t},e,n,s){const r=this.getConfig(e.theme),i=this.short(e.theme);t.add(r.render(r.attrs,{dir:s,height:r.height,width:r.width,x:n.x+i*s.dx,y:n.y+i*s.dy}))}width(t){return this.short(t)+this.getConfig(t).width}height(t){return this.getConfig(t).height}lineGap(t,e){const n=this.getConfig(t),s=this.short(t);if("none"===n.attrs.fill){const t=n.height/2,r=n.width;return(s+(s+e.attrs["stroke-width"]/2*(r/t)))/2}return s+n.width/2}}const we=[{height:()=>0,lineGap:()=>0,render:()=>null,width:()=>0},new ke("single"),new ke("double"),new class{getConfig(t){return t.connect.arrow.fade}render({lineMask:t},e,n,s){const r=this.getConfig(e.theme),{short:i,size:a}=r;let o=null;const l=xe/(a+2*xe);o=s.dx>=0?e.addDef("arrowFadeL",()=>e.svg.linearGradient({},[{offset:100*l+"%","stop-color":"#000000"},{offset:100-100*l+"%","stop-color":"#FFFFFF"}])):e.addDef("arrowFadeR",()=>e.svg.linearGradient({},[{offset:100*l+"%","stop-color":"#FFFFFF"},{offset:100-100*l+"%","stop-color":"#000000"}]));const h={x:n.x+s.dx*i,y:n.y+s.dy*i},d={x:h.x+s.dx*a,y:h.y+s.dy*a},g=e.svg.box({fill:"url(#"+o+")"},{height:Math.abs(h.y-d.y)+2*xe,width:a+2*xe,x:Math.min(h.x,d.x)-xe,y:Math.min(h.y,d.y)-xe});t.push(g)}width(t){return this.getConfig(t).short}height(){return 0}lineGap(t){return this.getConfig(t).short}},new class{getConfig(t){return t.connect.arrow.cross}render({layer:t},e,n,s){const r=this.getConfig(e.theme);t.add(r.render({radius:r.radius,x:n.x+r.short*s.dx,y:n.y+r.short*s.dy}))}width(t){const e=this.getConfig(t);return e.short+e.radius}height(t){return 2*this.getConfig(t).radius}lineGap(t){return this.getConfig(t).short}}];class ve extends ge{prepareMeasurements({agentIDs:t,label:e},n){const s=n.theme.connect,r=t[0]===t[1]?s.label.loopbackAttrs:s.label.attrs;n.textSizer.expectMeasure(r,e)}separationPre({agentIDs:t},e){const n=e.theme.connect.source.radius;t.forEach(t=>{const s=e.agentInfos.get(t);s.isVirtualSource&&(s.currentRad=n,s.currentMaxRad=Math.max(s.currentMaxRad,n))})}separation({label:t,agentIDs:n,options:s},r){const i=r.theme.connect,a=we[s.left],o=we[s.right],l=n[0]===n[1],h=l?i.label.loopbackAttrs:i.label.attrs;let d=r.textSizer.measure(h,t).width;d>0&&(d+=2*i.label.padding);const g=r.agentInfos.get(n[0]);if(l)r.addSpacing(n[0],{left:0,right:g.currentMaxRad+Math.max(d+a.width(r.theme),o.width(r.theme))+i.loopbackRadius});else{const t=r.agentInfos.get(n[1]);r.addSeparation(n[0],n[1],g.currentMaxRad+t.currentMaxRad+d+2*Math.max(a.width(r.theme),o.width(r.theme)))}e(r.momentaryAgentIDs,n)}renderRevArrowLine({x1:t,y1:e,x2:n,y2:s,xR:r},i,a,o){const l=a.theme.getConnectLine(i.line),h=we[i.left],d=we[i.right],g=h.lineGap(a.theme,l),c=d.lineGap(a.theme,l),u=a.theme.connect.loopbackRadius,p=l.renderRev({rad:u,x1:t+g,x2:n+c,xR:r,y1:e,y2:s});o.add(p.shape);const f=[];h.render({layer:o,lineMask:f},a,{x:p.p1.x-g,y:p.p1.y},{dx:1,dy:0}),d.render({layer:o,lineMask:f},a,{x:p.p2.x-c,y:p.p2.y},{dx:1,dy:0}),Y(p.shape,f,a,{height:s-e+2*xe,width:r+u-Math.min(t,n)+2*xe,x:Math.min(t,n)-xe,y:e-xe})}renderSelfConnect({label:t,agentIDs:e,options:n},s,r,i){const a=s.theme.connect,o=we[n.left],l=we[n.right],h=s.agentInfos.get(e[1]),d=t?s.textSizer.measureHeight(a.label.attrs,t)+a.label.margin.top+a.label.margin.bottom:0,g=r.x+r.currentMaxRad+o.width(s.theme)+(t?a.label.padding:0),c=s.svg.boxedText({boxAttrs:{fill:"#000000"},labelAttrs:a.label.loopbackAttrs,padding:a.mask.padding},t,{x:g-a.mask.padding.left,y:i-d+a.label.margin.top}),u=t?c.width+a.label.padding-a.mask.padding.left-a.mask.padding.right:0,p=Math.max(h.x+h.currentMaxRad+l.width(s.theme),g+u),f=Math.max(d,o.height(s.theme)/2),m=l.height(s.theme)/2;s.lineMaskLayer.add(c.box);const b=s.makeRegion().add(s.svg.box(ye,{height:f+s.primaryY-i+m,width:p+a.loopbackRadius-r.x,x:r.x,y:i-f}),c.label);return this.renderRevArrowLine({x1:r.x+r.currentMaxRad,x2:h.x+h.currentMaxRad,xR:p,y1:i,y2:s.primaryY},n,s,b),s.primaryY+Math.max(m,0)+s.theme.actionMargin}renderArrowLine({x1:t,y1:e,x2:n,y2:s},r,i,a){const o=i.theme.getConnectLine(r.line),l=we[r.left],h=we[r.right],d=Math.sqrt((n-t)*(n-t)+(s-e)*(s-e)),g=l.lineGap(i.theme,o),c=h.lineGap(i.theme,o),u=(n-t)/d,p=(s-e)/d,f=o.renderFlat({x1:t+g*u,x2:n-c*u,y1:e+g*p,y2:s-c*p});a.add(f.shape);const m={x:f.p1.x-g*u,y:f.p1.y-g*p},b={x:f.p2.x+c*u,y:f.p2.y+c*p},y=[];return l.render({layer:a,lineMask:y},i,m,{dx:u,dy:p}),h.render({layer:a,lineMask:y},i,b,{dx:-u,dy:-p}),Y(f.shape,y,i,{height:Math.abs(s-e)+2*xe,width:Math.abs(n-t)+2*xe,x:Math.min(t,n)-xe,y:Math.min(e,s)-xe}),{lArrow:l,p1:m,p2:b,rArrow:h}}renderVirtualSources({from:t,to:e,rendered:n},s,r){const i=s.theme.connect.source;t.isVirtualSource&&r.add(i.render({radius:i.radius,x:n.p1.x-i.radius,y:n.p1.y})),e.isVirtualSource&&r.add(i.render({radius:i.radius,x:n.p2.x+i.radius,y:n.p2.y}))}renderSimpleLabel(t,{layer:e,x1:n,x2:s,y1:r,y2:i,height:a},o){const l=o.theme.connect,h=(n+s)/2,d=(r+i)/2;let g=e;const c={fill:"#000000"};if(r!==i){const t="rotate("+180*Math.atan((i-r)/(s-n))/Math.PI+" "+h+","+d+")";c.transform=t,g=o.svg.el("g").attr("transform",t),e.add(g)}const u=o.svg.boxedText({boxAttrs:c,labelAttrs:l.label.attrs,padding:l.mask.padding},t,{x:h,y:d+l.label.margin.top-a});o.lineMaskLayer.add(u.box),g.add(u.label)}renderSimpleConnect({label:t,agentIDs:e,options:n},s,r,i){const a=s.theme.connect,o=s.agentInfos.get(e[1]),l=r.x<o.x?1:-1,h=s.textSizer.measureHeight(a.label.attrs,t)+a.label.margin.top+a.label.margin.bottom,d=r.x+r.currentMaxRad*l,g=o.x-o.currentMaxRad*l,c=s.makeRegion(),u=this.renderArrowLine({x1:d,x2:g,y1:i,y2:s.primaryY},n,s,c),p=Math.max(u.lArrow.height(s.theme),u.rArrow.height(s.theme))/2,f=Math.max(h,p);return this.renderVirtualSources({from:r,rendered:u,to:o},s,c),c.add(s.svg.el("path").attrs(ye).attr("d","M"+d+","+(i-f)+"L"+g+","+(s.primaryY-f)+"L"+g+","+(s.primaryY+p)+"L"+d+","+(i+p)+"Z")),this.renderSimpleLabel(t,{height:h,layer:c,x1:d,x2:g,y1:i,y2:s.primaryY},s),s.primaryY+Math.max(p+s.theme.minActionMargin,s.theme.actionMargin)}renderPre({label:t,agentIDs:e,options:n},s){const r=s.theme.connect,i=we[n.left],a=we[n.right],o=s.textSizer.measureHeight(r.label.attrs,t)+r.label.margin.top+r.label.margin.bottom;let l=i.height(s.theme);return e[0]!==e[1]&&(l=Math.max(l,a.height(s.theme))),{agentIDs:e,topShift:Math.max(l/2,o)}}render(t,e,n=null,s=null){let r=s,i=n;return null===n&&(i=e.agentInfos.get(t.agentIDs[0]),r=e.primaryY),t.agentIDs[0]===t.agentIDs[1]?this.renderSelfConnect(t,e,i,r):this.renderSimpleConnect(t,e,i,r)}}q("connect",new ve),q("connect-delay-begin",new class extends ve{makeState(t){t.delayedConnections=new Map}resetState(t){t.delayedConnections.clear()}separation(t,n){super.separation(t,n),e(n.momentaryAgentIDs,[t.agentIDs[0]])}renderPre(t,e){return Object.assign(super.renderPre(t,e),{agentIDs:[t.agentIDs[0]]})}render(t,e){return e.state.delayedConnections.set(t.tag,{from:Object.assign({},e.agentInfos.get(t.agentIDs[0])),stage:t,y:e.primaryY}),e.primaryY+e.theme.actionMargin}renderHidden(t,e){this.render(t,e)}}),q("connect-delay-end",new class extends ve{prepareMeasurements(){}separationPre(){}separation(){}renderPre({tag:t},e){const n=e.theme.connect,s=e.state.delayedConnections.get(t),r=s.stage,i=[r.agentIDs[1]];return r.agentIDs[0]===r.agentIDs[1]?{agentIDs:i,y:s.y+2*n.loopbackRadius}:Object.assign(super.renderPre(r,e),{agentIDs:i})}render({tag:t},e){const n=e.state.delayedConnections.get(t);return super.render(n.stage,e,n.from,n.y)}});const Ae={class:"outline",fill:"transparent"};q("divider",new class extends ge{prepareMeasurements({mode:t,formattedLabel:e},n){const s=n.theme.getDivider(t);n.textSizer.expectMeasure(s.labelAttrs,e)}separation({mode:t,formattedLabel:e},n){const s=n.theme.getDivider(t),r=n.textSizer.measure(s.labelAttrs,e).width+s.padding.left+s.padding.right;n.addSeparation("[","]",r),n.addSpacing("[",{left:s.extend,right:0}),n.addSpacing("]",{left:0,right:s.extend})}renderPre(){return{agentIDs:["[","]"]}}render({mode:t,height:e,formattedLabel:n},s){const r=s.theme.getDivider(t),i=s.agentInfos.get("["),a=s.agentInfos.get("]");let o=0,l=0;n&&(l=s.textSizer.measureHeight(r.labelAttrs,n));const h=Math.max(e,l)+r.margin;let d=null;if(n){const t=s.svg.boxedText({boxAttrs:{fill:"#000000"},labelAttrs:r.labelAttrs,padding:r.padding},n,{x:(i.x+a.x)/2,y:s.primaryY+(h-l)/2-r.padding.top});s.fullMaskLayer.add(t.box),d=t.label,o=t.width}const{shape:g,mask:c}=r.render({env:s,height:e,labelHeight:l,labelWidth:o,width:a.x-i.x+2*r.extend,x:i.x-r.extend,y:s.primaryY+(h-e)/2});return s.fullMaskLayer.add(c),s.makeRegion({unmasked:!0}).add(s.svg.box(Ae,{height:h,width:a.x-i.x+2*r.extend,x:i.x-r.extend,y:s.primaryY}),g,d),s.primaryY+h+s.theme.actionMargin}});q("mark",new class extends ge{makeState(t){t.marks=new Map}resetState(t){t.marks.clear()}render({name:t},{topY:e,state:n}){n.marks.set(t,e)}renderHidden(t,e){this.render(t,e)}}),q("async",new class extends ge{renderPre({target:t},{state:e}){let n=0;return t&&e.marks&&(n=e.marks.get(t)||0),{asynchronousY:n}}});const Fe={class:"outline",fill:"transparent"};class Me extends ge{prepareMeasurements({mode:t,label:e},n){const s=n.theme.getNote(t);n.textSizer.expectMeasure(s.labelAttrs,e)}renderPre({agentIDs:t}){return{agentIDs:t}}renderNote({label:t,mode:e,position:n},s){const r=s.theme.getNote(e),{padding:i}=r,a=s.topY+r.margin.top+i.top,o=s.svg.formattedText(r.labelAttrs,t),l=s.textSizer.measure(o),h=l.width+i.left+i.right,d=l.height+i.top+i.bottom,g=function(t,{x0:e=null,x1:n=null,xMid:s=null}){let r=e,i=n;return null===r&&null!==s&&(r=s-t/2),null===i&&null!==r?i=r+t:null===r&&(r=i-t),{xL:r,xR:i}}(h,n);o.set({x:function(t,{xL:e,xR:n},s){switch(t){case"middle":return(e+s.left+n-s.right)/2;case"end":return n-s.right;default:return e+s.left}}(r.labelAttrs["text-anchor"],g,i),y:a});const c={height:d,width:g.xR-g.xL,x:g.xL,y:s.topY+r.margin.top};return s.makeRegion().add(r.boxRenderer(c),s.svg.box(Fe,c),o),s.topY+r.margin.top+d+r.margin.bottom+s.theme.actionMargin}}class Se extends Me{constructor(t){super(),this.isRight=t}separation({agentIDs:t,mode:e,label:n},s){const r=s.theme.getNote(e),{left:i,right:a}=U(s.agentInfos,t),o=s.textSizer.measure(r.labelAttrs,n).width+r.padding.left+r.padding.right+r.margin.left+r.margin.right;if(this.isRight){const t=s.agentInfos.get(a);s.addSpacing(a,{left:0,right:o+t.currentMaxRad})}else{const t=s.agentInfos.get(i);s.addSpacing(i,{left:o+t.currentMaxRad,right:0})}}render({agentIDs:t,mode:e,label:n},s){const r=s.theme.getNote(e),{left:i,right:a}=U(s.agentInfos,t);if(this.isRight){const t=s.agentInfos.get(a),i=t.x+t.currentMaxRad+r.margin.left;return this.renderNote({label:n,mode:e,position:{x0:i}},s)}{const t=s.agentInfos.get(i),a=t.x-t.currentMaxRad-r.margin.right;return this.renderNote({label:n,mode:e,position:{x1:a}},s)}}}q("note over",new class extends Me{separation({agentIDs:t,mode:e,label:n},s){const r=s.theme.getNote(e),i=s.textSizer.measure(r.labelAttrs,n).width+r.padding.left+r.padding.right,{left:a,right:o}=U(s.agentInfos,t),l=s.agentInfos.get(a),h=s.agentInfos.get(o);if(l===h)s.addSpacing(a,{left:i/2,right:i/2});else{const t=l.currentMaxRad+r.overlap.left,e=h.currentMaxRad+r.overlap.right;s.addSeparation(a,o,i-t-e),s.addSpacing(a,{left:t,right:0}),s.addSpacing(o,{left:0,right:e})}}render({agentIDs:t,mode:e,label:n},s){const r=s.theme.getNote(e),{left:i,right:a}=U(s.agentInfos,t),o=s.agentInfos.get(i),l=s.agentInfos.get(a);if(o===l){const t=o.x;return this.renderNote({label:n,mode:e,position:{xMid:t}},s)}return this.renderNote({label:n,mode:e,position:{x0:o.x-o.currentMaxRad-r.overlap.left,x1:l.x+l.currentMaxRad+r.overlap.right}},s)}}),q("note left",new Se(!1)),q("note right",new Se(!0)),q("note between",new class extends Me{separation({agentIDs:t,mode:e,label:n},s){const r=s.theme.getNote(e),{left:i,right:a}=U(s.agentInfos,t),o=s.agentInfos.get(i),l=s.agentInfos.get(a);s.addSeparation(i,a,s.textSizer.measure(r.labelAttrs,n).width+r.padding.left+r.padding.right+r.margin.left+r.margin.right+o.currentMaxRad+l.currentMaxRad)}render({agentIDs:t,mode:e,label:n},s){const{left:r,right:i}=U(s.agentInfos,t),a=s.agentInfos.get(r),o=s.agentInfos.get(i),l=(a.x+a.currentMaxRad+o.x-o.currentMaxRad)/2;return this.renderNote({label:n,mode:e,position:{xMid:l}},s)}});q("parallel",new class extends ge{invokeChildren(t,e,n){return t.stages.map(t=>e.components.get(t.type)[n](t,e))}prepareMeasurements(t,e){this.invokeChildren(t,e,"prepareMeasurements")}separationPre(t,e){this.invokeChildren(t,e,"separationPre")}separation(t,e){this.invokeChildren(t,e,"separation")}renderPre(t,e){return this.invokeChildren(t,e,"renderPre").map(t=>H(t)).reduce(X,{agentIDs:[],asynchronousY:null,topShift:0})}render(t,e){const n=e.makeRegion;let s=0;return t.stages.forEach(t=>{e.makeRegion=((e={})=>n(Object.assign({stageOverride:t},e)));const r=e.components.get(t.type).render(t,e)||0;s=Math.max(s,r)}),e.makeRegion=n,s}renderHidden(t,e){this.invokeChildren(t,e,"renderHidden")}shouldHide(t,e){return this.invokeChildren(t,e,"shouldHide").reduce((t,{self:e=!1,nest:n=0}={})=>({nest:t.nest+n,self:t.self||Boolean(e)}),{nest:0,self:!1})}});class Re{constructor(t){this.element=t}addBefore(t=null,e=null){if(null===t)return this;if(Array.isArray(t))for(const n of t)this.addBefore(n,e);else{const n=function(t,e){return"string"==typeof t?e.createTextNode(t):"number"==typeof t?e.createTextNode(t.toString(10)):"object"==typeof t&&t.element?t.element:t}(t,this.element.ownerDocument);this.element.insertBefore(n,Q(e))}return this}add(...t){return this.addBefore(t,null)}del(t=null){return null!==t&&this.element.removeChild(Q(t)),this}attr(t,e){return this.element.setAttribute(t,e),this}attrs(t){for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&this.element.setAttribute(e,t[e]);return this}styles(t){for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&(this.element.style[e]=t[e]);return this}setClass(t){return this.attr("class",t)}addClass(t){const e=this.element.getAttribute("class");if(!e)return this.setClass(t);const n=e.split(" ");return n.includes(t)?this:(n.push(t),this.attr("class",n.join(" ")))}delClass(t){const e=this.element.getAttribute("class");if(!e)return this;const n=e.split(" "),s=n.indexOf(t);return-1!==s&&(n.splice(s,1),this.attr("class",n.join(" "))),this}text(t){return this.element.textContent=t,this}on(t,e,n={}){if(Array.isArray(t))for(const s of t)this.on(s,e,n);else this.element.addEventListener(t,e,n);return this}off(t,e,n={}){if(Array.isArray(t))for(const s of t)this.off(s,e,n);else this.element.removeEventListener(t,e,n);return this}val(t){return this.element.value=t,this}select(t,e=null){return this.element.selectionStart=t,this.element.selectionEnd=null===e?t:e,this}focus(){return this.element.focus(),this}focussed(){return this.element===this.element.ownerDocument.activeElement}empty(){for(;this.element.childNodes.length>0;)this.element.removeChild(this.element.lastChild);return this}attach(t){return Q(t).appendChild(this.element),this}detach(){return this.element.parentNode&&this.element.parentNode.removeChild(this.element),this}}class Ce{constructor(t){if(!t)throw new Error("Missing document!");this.document=t,this.wrap=this.wrap.bind(this),this.el=this.el.bind(this),this.txt=this.txt.bind(this)}wrap(t){return t.element?t:new Re(t)}el(t,e=null){let n=null;return n=null===e?this.document.createElement(t):this.document.createElementNS(e,t),new Re(n)}txt(t=""){return this.document.createTextNode(t)}}Ce.WrappedElement=Re;const Ie=[];class Ee{constructor(t,e,n={}){this.container=t,this.svg=e,this.state={attrs:{},formatted:Ie,x:0,y:0},this.lines=[],this.set(n)}_rebuildLines(t){if(t>this.lines.length)for(;this.lines.length<t;)this.lines.push({latest:"",node:this.svg.el("text").attr("x",this.state.x).attrs(this.state.attrs).attach(this.container)});else for(;this.lines.length>t;)this.lines.pop().node.detach()}_reset(){this._rebuildLines(0)}_renderText(){const{formatted:t}=this.state;if(t&&t.length){if(!Array.isArray(t))throw new Error("Invalid formatted text: "+t);this._rebuildLines(t.length),this.lines.forEach((e,n)=>{const s=JSON.stringify(t[n]);s!==e.latest&&(e.node.empty(),J(this.svg,e.node,t[n]),e.latest=s)})}else this._reset()}_updateX(){this.lines.forEach(({node:t})=>{t.attr("x",this.state.x)})}_updateY(){const t=this.svg.textSizer;let e=this.state.y;for(let n=0;n<this.lines.length;++n){const s=[this.state.formatted[n]],r=t.baseline(this.state.attrs,s);this.lines[n].node.attr("y",e+r),e+=t.measureHeight(this.state.attrs,s)}}set(t){const e=Object.assign({},this.state);!function(t,e){for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&null!==e[n]&&void 0!==e[n]&&(t[n]=e[n])}(this.state,t),this.state.attrs!==e.attrs&&(this._reset(),e.formatted=Ie);const n=this.lines.length;this.state.formatted!==e.formatted&&this._renderText(),this.state.x!==e.x&&this._updateX(),this.state.y===e.y&&this.lines.length===n||this._updateY()}}class Ge{constructor(t=null,e=0){this.pattern=t,this.dw=t&&t.partWidth,this.points=[],this.phase=e,this.x=null,this.y=null,this.disconnect=0}_nextDelta(){return this.pattern.getDelta(this.phase++)}_link(){2===this.disconnect&&(this.points.push(this.x+" "+this.y),this.disconnect=0)}cap(){return this.disconnect>0&&(this.points.push(this.x+" "+this.y),this.disconnect=0),this}move(t,e){return this.cap(),this.x=t,this.y=e,this.disconnect=2,this}line(t,e,{patterned:n=!0}={}){if(this.pattern&&n){const n=Math.sqrt((t-this.x)*(t-this.x)+(e-this.y)*(e-this.y)),s=(t-this.x)/n,r=(e-this.y)/n,i=-r,a=s;for(let t=0;t+this.dw<=n;t+=this.dw){const e=this._nextDelta();this.points.push(this.x+t*s+e*i+" "+(this.y+t*r+e*a))}this.disconnect=1}else this._link(),this.disconnect=2;return this.x=t,this.y=e,this}arc(t,e,n){const s=Math.sqrt((t-this.x)*(t-this.x)+(e-this.y)*(e-this.y)),r=Math.atan2(this.x-t,e-this.y),i=t+Math.sin(r+n)*s,a=e-Math.cos(r+n)*s;if(this.pattern){const i=n<0?1:-1,a=this.dw/s;for(let o=r;o+a<=r+n;o+=a){const n=this._nextDelta()*i;this.points.push(t+Math.sin(o)*(s+n)+" "+(e-Math.cos(o)*(s+n)))}this.disconnect=1}else this.points.push(this.x+" "+this.y+"A"+s+" "+s+" 0 "+(Math.abs(n)>=Math.PI?"1 ":"0 ")+(n<0?"0 ":"1 ")+i+" "+a),this.disconnect=0;return this.x=i,this.y=a,this}asPath(){return this._link(),"M"+this.points.join("L")}}const De="http://www.w3.org/2000/svg",Le=t=>new class{constructor(t){this.svg=t,this.testers=this.svg.el("g").attrs({display:At?"block":"none",visibility:"hidden"}),this.container=t.body}baseline({attrs:t}){return Number(t["font-size"])}measureHeight({attrs:t,formatted:e}){const n=this.baseline({attrs:t,formatted:e})*(Number(t["line-height"])||1);return e.length*n}prepMeasurement(t,e){const n=this.svg.el("text").attrs(t).attach(this.testers);return J(this.svg,n,e),n}prepComplete(){this.container.add(this.testers)}performMeasurement(t){return t.element.getComputedTextLength()}teardown(){this.container.del(this.testers.empty())}}(t);class Ne{constructor(t){this.sizer=t,this.cache=new Map,this.active=null}_expectMeasure({attrs:t,formatted:e}){if(!e.length)return null;const n=JSON.stringify(t);let s=this.cache.get(n);return s||(s={attrs:t,lines:new Map},this.cache.set(n,s)),e.forEach(t=>{if(!t.length)return;const e=JSON.stringify(t);s.lines.has(e)||s.lines.set(e,{formatted:t,width:null})}),s}_measureLine(t,e){if(!e.length)return 0;const n=JSON.stringify(e),s=t.lines.get(n);if(null===s.width)throw new Error("Unexpected measurement of "+e);return s.width}_measureWidth(t){if(!t.formatted.length)return 0;const e=this._expectMeasure(t);return t.formatted.map(t=>this._measureLine(e,t)).reduce((t,e)=>Math.max(t,e),0)}_getMeasurementOpts(t,e){const n={attrs:t,formatted:e};if(e||(t.textBlock?(n.attrs=t.textBlock.state.attrs,n.formatted=t.textBlock.state.formatted):t.state&&(n.attrs=t.state.attrs,n.formatted=t.state.formatted),n.formatted=n.formatted||[]),!Array.isArray(n.formatted))throw new Error("Invalid formatted text: "+n.formatted);return n}expectMeasure(t,e){const n=this._getMeasurementOpts(t,e);this._expectMeasure(n)}performMeasurementsPre(){this.active=[],this.cache.forEach(({attrs:t,lines:e})=>{e.forEach(e=>{null===e.width&&this.active.push({cacheLine:e,data:this.sizer.prepMeasurement(t,e.formatted)})})}),this.active.length&&this.sizer.prepComplete()}performMeasurementsAct(){this.active.forEach(({data:t,cacheLine:e})=>{e.width=this.sizer.performMeasurement(t)})}performMeasurementsPost(){this.active.length&&this.sizer.teardown(),this.active=null}performMeasurements(){try{this.performMeasurementsPre(),this.performMeasurementsAct()}finally{this.performMeasurementsPost()}}measure(t,e){const n=this._getMeasurementOpts(t,e);return{height:this.sizer.measureHeight(n),width:this._measureWidth(n)}}baseline(t,e){const n=this._getMeasurementOpts(t,e);return this.sizer.baseline(n)}measureHeight(t,e){const n=this._getMeasurementOpts(t,e);return this.sizer.measureHeight(n)}resetCache(){this.cache.clear()}}class ze{constructor(t,e=null){this.dom=t,this.body=this.el("svg").attr("xmlns",De).attr("version","1.1");const n=e||Le;this.textFilters=new Map,this.textSizer=new Ne(n(this)),this.txt=this.txt.bind(this),this.el=this.el.bind(this)}resetTextFilters(){this.textFilters.clear()}registerTextFilter(t,e){this.textFilters.set(t,{id:e,used:!1})}getTextFilter(t){const e=this.textFilters.get(t);return e?(e.used=!0,"url(#"+e.id+")"):"none"}getUsedTextFilterNames(){const t=[];for(const[e,n]of this.textFilters)n.used&&t.push(e);return t}linearGradient(t,e){return this.el("linearGradient").attrs(t).add(e.map(t=>this.el("stop").attrs(t)))}patternedLine(t=null,e=0){return new Ge(t,e)}txt(t){return this.dom.txt(t)}el(t,e=De){return this.dom.el(t,e)}box(t,{height:e,width:n,x:s,y:r}){return this.el("rect").attrs(t).attrs({height:e,width:n,x:s,y:r})}boxFactory(t){return this.box.bind(this,t)}line(t,{x1:e,x2:n,y1:s,y2:r}){return this.el("line").attrs(t).attrs({x1:e,x2:n,y1:s,y2:r})}lineFactory(t){return this.line.bind(this,t)}circle(t,{x:e,y:n,radius:s}){return this.el("circle").attrs({cx:e,cy:n,r:s}).attrs(t)}circleFactory(t){return this.circle.bind(this,t)}cross(t,{x:e,y:n,radius:s}){return this.el("path").attr("d","M"+(e-s)+" "+(n-s)+"l"+2*s+" "+2*s+"m0 "+2*-s+"l"+2*-s+" "+2*s).attrs(t)}crossFactory(t){return this.cross.bind(this,t)}note(t,e,{height:n,width:s,x:r,y:i}){const a=r,o=r+s,l=i,h=i+n;return this.el("g").add(this.el("polygon").attr("points",a+" "+l+" "+(o-7)+" "+l+" "+o+" "+(l+7)+" "+o+" "+h+" "+a+" "+h).attrs(t),this.el("polyline").attr("points",o-7+" "+l+" "+(o-7)+" "+(l+7)+" "+o+" "+(l+7)).attrs(e))}noteFactory(t,e){return this.note.bind(this,t,e)}formattedText(t={},e=[],{x:n,y:s}={}){const r=this.el("g"),i=new Ee(r,this,{attrs:t,formatted:e,x:n,y:s});return Object.assign(r,{set:t=>i.set(t),textBlock:i})}formattedTextFactory(t){return this.formattedText.bind(this,t)}boxedText({padding:t,labelAttrs:e,boxAttrs:n={},boxRenderer:s=null},r,{x:i,y:a}){if(!r||!r.length)return Object.assign(this.el("g"),{box:null,height:0,label:null,width:0});const{shift:o,anchorX:l}=function(t,e,n){let s=0,r=t;switch(e["text-anchor"]){case"middle":s=.5,r+=(n.left-n.right)/2;break;case"end":s=1,r-=n.right;break;default:s=0,r+=n.left}return{anchorX:r,shift:s}}(i,e,t),h=this.formattedText(e,r,{x:l,y:a+t.top}),d=this.textSizer.measure(h),g=d.width+t.left+t.right,c=d.height+t.top+t.bottom,u=(s||this.boxFactory(n))({height:c,width:g,x:l-d.width*o-t.left,y:a});return Object.assign(this.el("g").add(u,h),{box:u,height:c,label:h,width:g})}boxedTextFactory(t){return this.boxedText.bind(this,t)}}let Oe=0;class Te extends kt{constructor({themes:t=[],namespace:e=null,components:n=null,document:s,textSizerFactory:r=null}={}){super(),this._bindMethods(),this.state={},this.width=0,this.height=0,this.themes=function(t){if(0===t.length)throw new Error("Cannot render without a theme");const e=new Map;return t.forEach(t=>{e.set(t.name,t)}),e.set("",t[0]),e}(t),this.themeBuilder=null,this.theme=null,this.namespace=function(t){return null===t?"R"+Oe++:t}(e),this.components=n||ce,this.svg=new ze(new Ce(s),r),this.knownThemeDefs=new Set,this.knownTextFilterDefs=new Map,this.knownDefs=new Set,this.highlights=new Map,this.collapsed=new Set,this.currentHighlight=-1,this.buildStaticElements(),this.components.forEach(t=>{t.makeState(this.state)})}_bindMethods(){this.separationStage=this.separationStage.bind(this),this.prepareMeasurementsStage=this.prepareMeasurementsStage.bind(this),this.renderStage=this.renderStage.bind(this),this.addThemeDef=this.addThemeDef.bind(this),this.addThemeTextDef=this.addThemeTextDef.bind(this),this.addDef=this.addDef.bind(this)}addTheme(t){this.themes.set(t.name,t)}buildStaticElements(){const{el:t}=this.svg;this.metaCode=this.svg.txt(),this.themeDefs=t("defs"),this.defs=t("defs"),this.fullMask=t("mask").attrs({id:this.namespace+"FullMask",maskUnits:"userSpaceOnUse"}),this.lineMask=t("mask").attrs({id:this.namespace+"LineMask",maskUnits:"userSpaceOnUse"}),this.fullMaskReveal=t("rect").attr("fill","#FFFFFF"),this.lineMaskReveal=t("rect").attr("fill","#FFFFFF"),this.backgroundFills=t("g"),this.agentLines=t("g").attr("mask","url(#"+this.namespace+"LineMask)"),this.blocks=t("g"),this.shapes=t("g"),this.unmaskedShapes=t("g"),this.title=this.svg.formattedText(),this.svg.body.add(this.svg.el("metadata").add(this.metaCode),this.themeDefs,this.defs,this.backgroundFills,this.title,this.unmaskedShapes,t("g").attr("mask","url(#"+this.namespace+"FullMask)").add(this.agentLines,this.blocks,this.shapes))}addThemeDef(t,e){const n=this.namespace+t;return this.knownThemeDefs.has(t)||(this.knownThemeDefs.add(t),this.themeDefs.add(e().attr("id",n))),n}addThemeTextDef(t,e){const n=this.namespace+t;if(!this.knownTextFilterDefs.has(t)){const s=e().attr("id",n);this.knownTextFilterDefs.set(t,s)}this.svg.registerTextFilter(t,n)}addDef(t,e){let n=t,s=e;"function"!=typeof e&&(n="P"+this.knownDefs.size,s=(()=>t));const r=this.namespace+n;return this.knownDefs.has(n)||(this.knownDefs.add(n),this.defs.add(s().attr("id",r))),r}addSeparation(t,e,n){const s=this.agentInfos.get(t),r=this.agentInfos.get(e),i=s.separations.get(e)||0;s.separations.set(e,Math.max(i,n));const a=r.separations.get(t)||0;r.separations.set(t,Math.max(a,n))}checkHidden(t){const e=this.components.get(t.type),n={agentInfos:this.agentInfos,components:this.components,renderer:this,state:this.state,textSizer:this.svg.textSizer,theme:this.theme},s=e.shouldHide(t,n)||{},r=this.hideNest>0;this.hideNest+=s.nest||0;const i=this.hideNest>0;if(this.hideNest<0)throw new Error("Unexpected nesting in "+t.type);return r===i?i:Boolean(s.self)}separationStage(t){const n=new Map,s=this.visibleAgentIDs.slice(),r=[];this.agentInfos.forEach(t=>{const e=t.currentRad;t.currentMaxRad=e,n.set(t.id,{left:e,right:e})});const i={addSeparation:(t,e,n)=>{r.push({agentID1:t,agentID2:e,dist:n})},addSpacing:(t,{left:e,right:s})=>{const r=n.get(t);r.left=Math.max(r.left,e),r.right=Math.max(r.right,s)},agentInfos:this.agentInfos,components:this.components,momentaryAgentIDs:s,renderer:this,state:this.state,textSizer:this.svg.textSizer,theme:this.theme,visibleAgentIDs:this.visibleAgentIDs},a=this.components.get(t.type);if(!a)throw new Error("Unknown component: "+t.type);a.separationPre(t,i),a.separation(t,i),this.checkHidden(t)||(e(s,this.visibleAgentIDs),r.forEach(({agentID1:t,agentID2:e,dist:n})=>{this.addSeparation(t,e,n)}),s.forEach(t=>{const e=this.agentInfos.get(t),r=n.get(t);e.maxRPad=Math.max(e.maxRPad,r.right),e.maxLPad=Math.max(e.maxLPad,r.left),s.forEach(s=>{if(this.agentInfos.get(s).index>=e.index)return;const i=n.get(s);this.addSeparation(t,s,r.left+i.right+this.theme.agentMargin)})}))}prepareMeasurementsStage(t){const e={agentInfos:this.agentInfos,components:this.components,renderer:this,state:this.state,textSizer:this.svg.textSizer,theme:this.theme},n=this.components.get(t.type);if(!n)throw new Error("Unknown component: "+t.type);n.prepareMeasurements(t,e)}checkAgentRange(t,e=0){if(0===t.length)return e;const{left:n,right:s}=Z(this.agentInfos,t),r=this.agentInfos.get(n).x,i=this.agentInfos.get(s).x;let a=e;return this.agentInfos.forEach(t=>{t.x>=r&&t.x<=i&&(a=Math.max(a,t.latestY))}),a}markAgentRange(t,e){if(0===t.length)return;const{left:n,right:s}=Z(this.agentInfos,t),r=this.agentInfos.get(n).x,i=this.agentInfos.get(s).x;this.agentInfos.forEach(t=>{t.x>=r&&t.x<=i&&(t.latestY=e)})}drawAgentLine(t,e){null!==t.latestYStart&&e>t.latestYStart&&this.agentLines.add(this.theme.renderAgentLine({className:"agent-"+t.index+"-line",options:t.options,width:2*t.currentRad,x:t.x,y0:t.latestYStart,y1:e}))}addHighlightObject(t,e){let n=this.highlights.get(t);n||(n=[],this.highlights.set(t,n)),n.push(e)}forwardEvent(t,e,n,s){t.on(e,this.trigger.bind(this,n,s))}renderStage(t){this.agentInfos.forEach(t=>{const e=t.currentRad;t.currentMaxRad=e});const e={agentInfos:this.agentInfos,components:this.components,renderer:this,state:this.state,textSizer:this.svg.textSizer,theme:this.theme},n=this.components.get(t.type),s=n.renderPre(t,e),{agentIDs:r,topShift:i,asynchronousY:a}=H(s,this.currentY),o=this.checkAgentRange(r,a),l={addDef:this.addDef,agentInfos:this.agentInfos,blockLayer:this.blocks,components:this.components,drawAgentLine:(t,e,n=!1)=>{const s=this.agentInfos.get(t);this.drawAgentLine(s,e),s.latestYStart=n?null:e},fillLayer:this.backgroundFills,fullMaskLayer:this.fullMask,lineMaskLayer:this.lineMask,makeRegion:({stageOverride:e=null,unmasked:n=!1}={})=>{const s=this.svg.el("g").setClass("region"),r=e||t;return this.addHighlightObject(r.ln,s),this.forwardEvent(s,"mouseenter","mouseover",[r]),this.forwardEvent(s,"mouseleave","mouseout",[r]),this.forwardEvent(s,"click","click",[r]),this.forwardEvent(s,"dblclick","dblclick",[r]),s.attach(n?this.unmaskedShapes:this.shapes)},primaryY:o+i,renderer:this,state:this.state,svg:this.svg,textSizer:this.svg.textSizer,theme:this.theme,topY:o};let h=o;this.checkHidden(t)?(l.primaryY=o,n.renderHidden(t,l)):h=Math.max(h,n.render(t,l)||0),this.markAgentRange(r,h),this.currentY=h}positionAgents(){const t=[];this.agentInfos.forEach(e=>{let n=0;e.separations.forEach((t,s)=>{const r=this.agentInfos.get(s);r.index<e.index&&(n=Math.max(n,r.x+t))}),e.x=n,t.push(e)});let e={x:0};t.reverse().forEach(t=>{let n=e.x;e=t,t.anchorRight&&(t.separations.forEach((e,s)=>{const r=this.agentInfos.get(s);r.index>t.index&&(n=Math.min(n,r.x-e))}),t.x=n)}),this.agentInfos.forEach(({x:t,maxRPad:e,maxLPad:n})=>{this.minX=Math.min(this.minX,t-n),this.maxX=Math.max(this.maxX,t+e)})}buildAgentInfos(t){this.agentInfos=new Map,t.forEach((t,e)=>{this.agentInfos.set(t.id,{anchorRight:t.anchorRight,currentMaxRad:0,currentRad:0,formattedLabel:t.formattedLabel,id:t.id,index:e,isVirtualSource:t.isVirtualSource,latestY:0,latestYStart:null,maxLPad:0,maxRPad:0,options:t.options,separations:new Map,x:null})})}updateBounds(t){const e=(this.minX+this.maxX)/2,n=this.svg.textSizer.measure(this.title),s=n.height>0?-this.theme.titleMargin-n.height:0;this.title.set({x:e,y:s});const r=n.width/2,i=this.theme.outerMargin,a=Math.min(this.minX,e-r)-i,o=Math.max(this.maxX,e+r)+i,l=s-i,h=t+i;this.width=o-a,this.height=h-l;const d={height:this.height,width:this.width,x:a,y:l};this.fullMaskReveal.attrs(d),this.lineMaskReveal.attrs(d),this.svg.body.attr("viewBox",a+" "+l+" "+this.width+" "+this.height)}_resetState(){this.components.forEach(t=>{t.resetState(this.state)}),this.currentY=0,this.hideNest=0}_reset(t){t&&(this.knownThemeDefs.clear(),this.knownTextFilterDefs.clear(),this.themeDefs.empty()),this.knownDefs.clear(),this.highlights.clear(),this.defs.empty(),this.fullMask.empty(),this.lineMask.empty(),this.backgroundFills.empty(),this.agentLines.empty(),this.blocks.empty(),this.shapes.empty(),this.unmaskedShapes.empty(),this.defs.add(this.fullMask.add(this.fullMaskReveal),this.lineMask.add(this.lineMaskReveal)),this._resetState()}setHighlight(t=null){const e=null===t?-1:t;this.currentHighlight!==e&&(this.highlights.has(this.currentHighlight)&&this.highlights.get(this.currentHighlight).forEach(t=>{t.delClass("focus")}),this.highlights.has(e)&&this.highlights.get(e).forEach(t=>{t.addClass("focus")}),this.currentHighlight=e)}isCollapsed(t){return this.collapsed.has(t)}setCollapseAll(t){if(t)throw new Error("Cannot collapse all");return 0!==this.collapsed.size&&(this.collapsed.clear(),!0)}_setCollapsed(t,e){return"number"==typeof t&&(e!==this.isCollapsed(t)&&(e?this.collapsed.add(t):this.collapsed.delete(t),!0))}setCollapsed(t,e=!0){return null===t?this.setCollapseAll(e):Array.isArray(t)?t.map(t=>this._setCollapsed(t,e)).some(t=>t):this._setCollapsed(t,e)}_switchTheme(t){const e=this.themeBuilder;return this.themeBuilder=this.getThemeNamed(t),this.themeBuilder!==e&&(this.theme=this.themeBuilder.build(this.svg)),this.theme.reset(),this.themeBuilder!==e}optimisedRenderPreReflow(t){const e=this._switchTheme(t.meta.theme);this._reset(e),this.metaCode.nodeValue=t.meta.code,this.svg.resetTextFilters(),this.theme.addDefs(this.addThemeDef,this.addThemeTextDef);for(const t of this.knownTextFilterDefs.values())t.detach();this.title.set({attrs:Object.assign({class:"title"},this.theme.getTitleAttrs()),formatted:t.meta.title}),this.svg.textSizer.expectMeasure(this.title),this.minX=0,this.maxX=0,this.buildAgentInfos(t.agents),t.stages.forEach(this.prepareMeasurementsStage),this._resetState(),this.svg.textSizer.performMeasurementsPre()}optimisedRenderReflow(){this.svg.textSizer.performMeasurementsAct()}optimisedRenderPostReflow(t){this.visibleAgentIDs=["[","]"],t.stages.forEach(this.separationStage),this._resetState(),this.positionAgents(),t.stages.forEach(this.renderStage);const e=this.checkAgentRange(["[","]"],this.currentY);this.svg.getUsedTextFilterNames().forEach(t=>{this.themeDefs.add(this.knownTextFilterDefs.get(t))});const n=Math.max(e-this.theme.actionMargin,0);this.updateBounds(n);const s=this.currentHighlight;this.currentHighlight=-1,this.setHighlight(s),this.svg.textSizer.performMeasurementsPost(),this.svg.textSizer.resetCache()}render(t){this.optimisedRenderPreReflow(t),this.optimisedRenderReflow(),this.optimisedRenderPostReflow(t)}getThemeNames(){return Array.from(this.themes.keys()).filter(t=>""!==t)}getThemes(){return this.getThemeNames().map(t=>this.themes.get(t))}getThemeNamed(t){const e=this.themes.get(t);return e||this.themes.get("")}getAgentX(t){return this.agentInfos.get(t).x}dom(){return this.svg.body.element}}var Be={name:"Handlee",woff2:"d09GMgABAAAAAD3EAA4AAAAAi4QAAD1qAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGhYbxV4cKgZgAIF8EQgKgbpIgZNlC4MGAAE2AiQDhggEIAWEDgeDKxuhdSXsmCEeByC2jBgVNYuS+mQUpZq0k+z/vyY3BgzxIa3ugqhFRlV1T4WqHliFgkLvX+Fguaf/tXTReCMU5hvZIfpErawhdoJhvGi60udSmcpUmZV+33txIHLMbEhRhomyZs7N2odsiOl7OmXseNPFL9fnzsBxPmouBP/3/Wbmvt+Om/2FCihaDcM063gCEX9NLAt4u0Mwt27RRQwYMGqMWgUxxtioahM7sANfMfL9svpDv1r7QwmKw9y7bx3k5w1Kx2CplAiGqIJEAx6gUICjf39+y0xK/qS6vwbT8sAy+yrlEHe3vNdJ+jauiqvOOWRpffhe8mecSXiGF4IGTtgLKLV2M6lzDvAXO0QkRtk8v62KREEBwaihHQPHQUZ7YfchZmHtcm8+Z6+az/v4cS/auKr51LlyEhygfzOnr94kmRQnbJcIXjvUGdVV1xbM/AtMwQWbE4NkWTgj7VNM7tsSphi6w7Xer64GAF9ZWaEQhamQGZvYSbJ32eOle7QPGCaZ8v8BQACca4LR5sPtg6JABnLj1wL8AT7Ig0UXwD88/7/XfvbvhPOLI9BloMsIxZsiDEJjTHLfvMw6c9alqsNd71f1JrRMfmuZUDJl+RESNELxW1Gh1Kq+QyiUQwiLBqH532XN5lbd0eXiwCGbNynX8me2JbTMXE2omWuTmaWEddCFA4eSW9ospRR3QvI8/vf70bJLSBvaprCxqOq7/933bfWsOurVtGuIZKolhswQGbJVhtI2JyxEQs+omyBJQJ8+owwHUkQk9Jq/DeT7/htzRkREiHgi8hDpxlIJr0M6CN3euB9bfbmXPn+2CXsKDDCEMYJ7/34IcA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cTpEt/ESbltZDh9u8bk8JQE1DVEy0XA2irYO2lZPBw6H6HauFnDO3MMz/C1LhyUQVQzZlSEK1O60MCxHhA/5uzlDr5PBx+JaSjdQwMgpQZwWptFdOijlYbr3JAOS+5nabThuIu4DmSmae14QhnVwI+Dp23SwAhhIE9MUwZu7IYguAJUbd8Po+OpuOKHCuxG4xivyJt5PiijSx2kzNjZ1t1RXVrWJL24CCSF29dEIWx+X1Vd39ZTy1tYbGlpDT0fNJu1l/d0dqpfaV5Rd71wbN40WOkHfDW+rCus0VOUtHaFlh6uNos0bxbaWDy8Vn1VZXTlWUb2b91eV7XWsWhyNNNdm3lDK1bXdq4nbx7Rbv5Am864ZdqJRxa5GO9PHpglZjqn0ZulqqamNlzDq6nWqV1sqQ5uWZG99lRlTP3z4/iVw968DnxaQhFS/xRpWdHxXGG53OF1uj9fnPydIimZYLnARDIUjfPRyp3+9Qly8TiRT6Uw2l38kyXqD0WS2WG12hzM5JTXNle7O8GR6fVnZObl5+QWFRcVbxsZRWmHCAvOst8tco5aatNJsFy++s9uUfT5Z/09J6SJln916dWt/Z3fvttsHh/9Tudi9k8Ydc9RU19bXNWzS2NzU0tre1tHZ1dPd2993wmaDA0OGnXR/wCEPzjtDjjhu2qURx1x+3R5nnI2W/z0OAAA="};class Ve{constructor(){this.s=new Uint32Array(4)}reset(){this.s[0]=394173556,this.s[1]=2926575054,this.s[2]=1022685995,this.s[3]=1178902408}nextFloat(){let t=this.s[0],e=this.s[1];const n=this.s[2],s=this.s[3];return this.s[0]=n,this.s[1]=s,t^=t<<23|e>>>9,e^=e<<23,this.s[2]=t^n^t>>>17^n>>>26,this.s[3]=e^s^(t<<15|e>>>17)^(n<<6|s>>>26),(this.s[3]+s>>>0)%4294967296/4294967296}}const Pe=Be.name,je=Pe+",cursive",He=1.5,qe=5,Ye={normal:{stroke:"rgba(0,0,0,0.7)","stroke-width":.8,"stroke-linejoin":"round","stroke-linecap":"round"},thick:{stroke:"rgba(0,0,0,0.8)","stroke-width":1.2,"stroke-linejoin":"round","stroke-linecap":"round"}},Ue={"font-family":je,"font-size":8,"line-height":He},We={"font-family":je,"font-size":8,"line-height":He,"text-anchor":"middle"},Xe={};class Qe{constructor(t,e){this.deltas=[0,-.3,-.6,-.75,-.45,0,.45,.75,.6,.3],e!==Xe&&this.deltas.reverse(),this.partWidth=6/this.deltas.length}getDelta(t){return this.deltas[t%this.deltas.length]+.5*Math.sin(.03*t)}}class Je extends ht{constructor(t,e=Xe){super(t,{"font-family":Pe,"font-size":8,"line-height":He}),this.handedness=e===Xe?1:-1,this.random=new Ve;const n=new Qe(4,e),s={padding:{top:3,bottom:2},tag:{padding:{top:2,left:3,right:5,bottom:0},boxRenderer:this.renderTag.bind(this),labelAttrs:{"font-family":je,"font-weight":"bold","font-size":9,"line-height":He,"text-anchor":"left"}},label:{minHeight:6,padding:{top:2,left:5,right:3,bottom:1},labelAttrs:{"font-family":je,"font-size":8,"line-height":He,"text-anchor":"left"}}};Object.assign(this,{titleMargin:10,outerMargin:5,agentMargin:10,actionMargin:10,minActionMargin:3,agentLineActivationRadius:4,agentCap:{box:{padding:{top:5,left:10,right:10,bottom:5},arrowBottom:12.8,labelAttrs:{"font-family":je,"font-size":12,"line-height":He,"text-anchor":"middle"},boxRenderer:this.renderBox.bind(this)},person:{padding:{top:20,left:10,right:10,bottom:5},arrowBottom:12.8,labelAttrs:{"font-family":je,"font-size":12,"line-height":He,"text-anchor":"middle"},boxRenderer:this.renderPerson.bind(this)},database:{padding:{top:12,left:10,right:10,bottom:2},arrowBottom:12.8,boxRenderer:this.renderDB.bind(this),labelAttrs:{"font-family":Pe,"font-size":12,"line-height":He,"text-anchor":"middle"}},cross:{size:15,render:this.renderCross.bind(this)},bar:{height:6,render:this.renderBar.bind(this)},fade:{width:Math.ceil(2*qe+2),height:6,extend:Math.ceil(.3*qe+1)},none:{height:10}},connect:{loopbackRadius:6,arrow:{single:{width:5,height:6,attrs:Object.assign({fill:"rgba(0,0,0,0.9)"},Ye.normal),render:this.renderArrowHead.bind(this)},double:{width:4,height:8,attrs:Object.assign({fill:"none"},Ye.normal),render:this.renderArrowHead.bind(this)},fade:{short:0,size:12},cross:{short:5,radius:3,render:this.renderCross.bind(this)}},label:{padding:6,margin:{top:2,bottom:1},attrs:{"font-family":je,"font-size":8,"line-height":He,"text-anchor":"middle"},loopbackAttrs:{"font-family":je,"font-size":8,"line-height":He}},source:{radius:1,render:t.circleFactory({fill:"#000000",stroke:"#000000","stroke-width":1})},mask:{padding:{top:0,left:3,right:3,bottom:1}}},agentLineAttrs:{"":Object.assign({fill:"none"},Ye.normal),red:{stroke:"rgba(200,40,0,0.8)"}},blocks:{ref:{margin:{top:0,bottom:0},boxRenderer:this.renderRefBlock.bind(this),section:s},"":{margin:{top:0,bottom:0},boxRenderer:this.renderBlock.bind(this),collapsedBoxRenderer:this.renderMinBlock.bind(this),section:s,sepRenderer:this.renderSeparator.bind(this)}},notes:{text:{margin:{top:0,left:6,right:6,bottom:0},padding:{top:2,left:2,right:2,bottom:2},overlap:{left:10,right:10},boxRenderer:t.boxFactory({fill:"#FFFFFF"}),labelAttrs:Ue},note:{margin:{top:0,left:5,right:5,bottom:0},padding:{top:5,left:5,right:10,bottom:5},overlap:{left:10,right:10},boxRenderer:this.renderNote.bind(this),labelAttrs:Ue},state:{margin:{top:0,left:5,right:5,bottom:0},padding:{top:7,left:7,right:7,bottom:7},overlap:{left:10,right:10},boxRenderer:this.renderState.bind(this),labelAttrs:Ue}},dividers:{"":{labelAttrs:We,padding:{top:2,left:5,right:5,bottom:2},extend:0,margin:0,render:()=>({})},line:{labelAttrs:We,padding:{top:2,left:5,right:5,bottom:2},extend:10,margin:0,render:this.renderLineDivider.bind(this)},delay:{labelAttrs:We,padding:{top:2,left:5,right:5,bottom:2},extend:0,margin:0,render:this.renderDelayDivider.bind(this,{dotSize:1,gapSize:2})},tear:{labelAttrs:We,padding:{top:2,left:5,right:5,bottom:2},extend:10,margin:10,render:this.renderTearDivider.bind(this,{fadeBegin:5,fadeSize:10,pattern:n,lineAttrs:Ye.normal})}}}),this.addConnectLine("solid",{attrs:Ye.normal}),this.addConnectLine("dash",{attrs:{"stroke-dasharray":"4, 2"}}),this.addConnectLine("wave",{attrs:{"stroke-linejoin":"round","stroke-linecap":"round"},pattern:n})}reset(){this.random.reset()}addDefs(t,e){t("sketch_font",()=>{const t=this.svg.el("style",null);return t.text("@font-face{font-family:"+Be.name+';src:url("data:font/woff2;base64,'+Be.woff2+'");}'),t}),super.addDefs(t,e)}vary(t,e=0){if(!t)return e;const n=this.random.nextFloat();return e+2*Math.asin(2*n-1)*t/Math.PI}lineNodes(t,e,{var1:n=1,var2:s=1,varX:r=1,varY:i=1,move:a=!0}){const o=Math.sqrt((e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y)),l=Math.min(.2*Math.sqrt(o),qe),h=this.vary(n*r*l,t.x),d=this.vary(n*i*l,t.y),g=this.vary(s*r*l,e.x),c=this.vary(s*i*l,e.y),u=function(t,e,n){return Math.max(e,Math.min(n,t))}((d-c)/(Math.abs(h-g)+.001),-1,1)/6+.5,p=this.vary(.5,.5)*l,f=this.vary(.5,.5)*l,m=h*(1-u)+g*u-p*this.handedness;return{nodes:(a?"M"+h+" "+d:"")+"C"+m+" "+(d*(1-u)+c*u-f)+","+g+" "+c+","+g+" "+c,p1:{x:h,y:d},p2:{x:g,y:c}}}renderLine(t,e,n){const s=this.lineNodes(t,e,n);return this.svg.el("path").attrs({d:s.nodes,fill:"none","stroke-dasharray":n.dash?"6, 5":"none"}).attrs(n.attrs||(n.thick?Ye.thick:Ye.normal))}boxNodes({x:t,y:e,width:n,height:s}){const r=this.lineNodes({x:t,y:e},{x:t+n,y:e},{}),i=this.lineNodes({x:t+n,y:e+s},{x:t,y:e+s},{move:!1}),a=this.lineNodes(r.p2,i.p1,{var1:0,var2:0,move:!1}),o=this.lineNodes(i.p2,r.p1,{var1:0,var2:.3,move:!1});return r.nodes+a.nodes+i.nodes+o.nodes}renderBox(t,{fill:e=null,thick:n=!1,attrs:s=null}={}){return this.svg.el("path").attrs({d:this.boxNodes(t),fill:e||"#FFFFFF"}).attrs(s||(n?Ye.thick:Ye.normal))}renderPerson(t){const e=Object.assign({fill:"none"},Ye.normal),n=t.x+t.width/2,s=this.vary.bind(this),r=s(.1,.05*this.handedness),i=s(.1,.05*this.handedness),a=s(.05,.35);return this.svg.el("g").add(this.svg.el("path").attr("d","M"+(n-9)+" "+(t.y+15)+"c"+9*r+" "+-15*(a-i)+" "+9*(2+r)+" "+-15*(a+i)+" 18 0").attrs(e),this.svg.el("path").attr("d","M"+n+" "+t.y+"c"+9*s(.05,.224)+" "+s(.02,0)+" "+9*s(.07,.4)+" "+15*s(.02,.1)+" 3.6 "+15*s(.05,.275)+"s"+-9*s(.05,.176)+" 5.25 "+-3.6+" "+15*s(.05,.35)+"s"+-9*s(.07,.4)+" "+-2.625+" "+-3.6+" "+-15*s(.05,.35)+"s"+9*s(.05,.176)+" "+-4.125+" "+9*s(.05,.4)+" "+-15*s(.02,.275)).attrs(e),this.renderBox({height:t.height-15,width:t.width,x:t.x,y:t.y+15}))}renderDB(t){const e=this.lineNodes({x:t.x,y:t.y+5},{x:t.x,y:t.y+t.height-5},{}),n=this.lineNodes({x:t.x+t.width,y:t.y+t.height-5},{x:t.x+t.width,y:t.y+5},{move:!1}),s=this.vary.bind(this),r=t.x+t.width/2,i=-t.width*this.handedness/2,a=r-i*s(.03,1.02),o=t.y+5*s(.15,1),l=r+i*s(.03,1.02),h=t.y+5*s(.15,1);return this.svg.el("g").add(this.svg.el("path").attr("d",e.nodes+"C"+e.p2.x+" "+(e.p2.y+s(.1,6))+" "+n.p1.x+" "+(n.p1.y+s(.1,6))+" "+n.p1.x+" "+n.p1.y+n.nodes).attrs(Ye.normal).attr("fill","#FFFFFF"),this.svg.el("path").attr("d","M"+a+" "+o+"C"+(a+.2*i)+" "+(o-s(.2,6))+" "+l+" "+(h-s(.2,6))+" "+l+" "+h+"S"+a+" "+(o+s(.2,6))+" "+s(1,a)+" "+s(.5,o)).attrs(Ye.normal).attr("fill","#FFFFFF"))}renderNote({x:t,y:e,width:n,height:s}){const r=this.lineNodes({x:t,y:e},{x:t+n-5,y:e},{}),i=this.lineNodes(r.p2,{x:t+n,y:e+5},{move:!1,var1:0}),a=this.lineNodes({x:t+n,y:e+s},{x:t,y:e+s},{move:!1}),o=this.lineNodes(i.p2,a.p1,{var1:0,var2:0,move:!1}),l=this.lineNodes(a.p2,r.p1,{var1:0,var2:.3,move:!1}),h=this.lineNodes(i.p1,{x:t+n-5,y:e+5},{var1:.3}),d=this.lineNodes(h.p2,i.p2,{var1:0,move:!1});return this.svg.el("g").add(this.svg.el("path").attrs({d:r.nodes+i.nodes+o.nodes+a.nodes+l.nodes,fill:"#FFFFFF"}).attrs(Ye.normal),this.svg.el("path").attrs({d:h.nodes+d.nodes,fill:"none"}).attrs(Ye.normal))}renderLineDivider({x:t,y:e,labelWidth:n,width:s,height:r}){let i=null;const a=e+r/2;return i=n>0?this.svg.el("g").add(this.renderLine({x:t,y:a},{x:t+(s-n)/2,y:a},{}),this.renderLine({x:t+(s+n)/2,y:a},{x:t+s,y:a},{})):this.renderLine({x:t,y:a},{x:t+s,y:a},{}),{shape:i}}renderFlatConnect(t,e,{x1:n,y1:s,x2:r,y2:i}){if(t){const a=n+this.vary(.3),o=r+this.vary(.3),l=s+this.vary(1),h=i+this.vary(1);return{shape:this.svg.el("path").attr("d",this.svg.patternedLine(t).move(a,l).line(o,h).cap().asPath()).attrs(e),p1:{x:a,y:l},p2:{x:o,y:h}}}{const t=this.lineNodes({x:n,y:s},{x:r,y:i},{varX:.3});return{shape:this.svg.el("path").attr("d",t.nodes).attrs(e),p1:t.p1,p2:t.p2}}}renderRevConnect(t,e,{x1:n,y1:s,x2:r,y2:i,xR:a}){if(t){const o=n+this.vary(.3),l=r+this.vary(.3),h=s+this.vary(1),d=i+this.vary(1);return{shape:this.svg.el("path").attr("d",this.svg.patternedLine(t).move(o,h).line(a,s).arc(a,(s+i)/2,Math.PI).line(l,d).cap().asPath()).attrs(e),p1:{x:o,y:h},p2:{x:l,y:d}}}{const t=Math.min(.06*(a-n),3),o=Math.min(.5*(a-n),6),l=n+this.vary(t,-1),h=s+this.vary(t,-1),d=a-o*this.vary(.2,1),g=s-this.vary(1,2),c=a,u=s+this.vary(1,1),p=a,f=i+this.vary(2),m=r+this.vary(t,-1),b=i+this.vary(t,-1);return{shape:this.svg.el("path").attr("d","M"+l+" "+h+"C"+l+" "+h+","+d+" "+g+","+c+" "+u+"S"+p+" "+f+","+m+" "+b).attrs(e),p1:{x:l,y:h},p2:{x:m,y:b}}}}renderArrowHead(t,{x:e,y:n,width:s,height:r,dir:i}){const a=s*this.vary(.2,1),o=r*this.vary(.3,1),l=a*i.dx,h=a*i.dy,d=.5*o*i.dx,g=.5*-o*i.dy,c=this.lineNodes({x:e+l-g,y:n+h-d},{x:e,y:n},{var1:2,var2:.2}),u=this.lineNodes(c.p2,{x:e+l+g,y:n+h+d},{var1:0,var2:2,move:!1}),p="none"===t.fill?{nodes:""}:this.lineNodes(u.p2,c.p1,{var1:0,var2:0,move:!1});return this.svg.el("path").attr("d",c.nodes+u.nodes+p.nodes).attrs(t)}renderState({x:t,y:e,width:n,height:s}){const r=Math.min(.06*n,3),i=Math.min(.06*s,3),a=t+r*this.vary(.6,1),o=e+i*this.vary(.6,1),l=t+n-r*this.vary(.6,1),h=e+i*this.vary(.6,1),d=t+r*this.vary(.6,1),g=e+s-i*this.vary(.6,1),c=t+n-r*this.vary(.6,1),u=e+s-i*this.vary(.6,1),p=t+n/2,f=e+s/2,m=r*this.vary(.2,1.2),b=i*this.vary(.2,1.2),y=e-Math.min(.005*n,1),x=e+s-Math.min(.01*n,2),k=t-Math.min(.01*s,2)*this.handedness,w=k+n;return this.svg.el("path").attr("d","M"+a+" "+o+"C"+(a+m)+" "+(o-b)+","+(p-n*this.vary(.03,.3))+" "+y+","+p+" "+y+"S"+(l-m)+" "+(h-b)+","+l+" "+h+"S"+w+" "+(f-s*this.vary(.03,.3))+","+w+" "+f+"S"+(c+m)+" "+(u-b)+","+c+" "+u+"S"+(p+n*this.vary(.03,.3))+" "+x+","+p+" "+x+"S"+(d+m)+" "+(g+b)+","+d+" "+g+"S"+k+" "+(f+s*this.vary(.03,.3))+","+k+" "+f+"S"+(a-m)+" "+(o+b)+","+a+" "+o+"Z").attr("fill","#FFFFFF").attrs(Ye.normal)}renderRefBlock(t){const e=this.boxNodes(t);return{shape:this.svg.el("path").attrs({d:e,fill:"none"}).attrs(Ye.thick),mask:this.svg.el("path").attrs({d:e,fill:"#000000"}),fill:this.svg.el("path").attrs({d:e,fill:"#FFFFFF"})}}renderBlock(t){return this.renderBox(t,{fill:"none",thick:!0})}renderMinBlock(t){return this.renderRefBlock(t)}renderTag({x:t,y:e,width:n,height:s}){const r=t+n,i=e+s,a=this.lineNodes({x:r+3,y:e},{x:r-2,y:i},{}),o=this.lineNodes(a.p2,{x:t,y:i+1},{var1:0,move:!1}),l=a.nodes+o.nodes;return this.svg.el("g").add(this.svg.el("path").attrs({d:l+"L"+t+" "+e,fill:"#FFFFFF"}),this.svg.el("path").attrs({d:l,fill:"#FFFFFF"}).attrs(Ye.normal))}renderSeparator({x1:t,y1:e,x2:n,y2:s}){return this.renderLine({x:t,y:e},{x:n,y:s},{thick:!0,dash:!0})}renderBar({x:t,y:e,width:n,height:s}){return this.renderBox({x:t,y:e,width:n,height:s},{fill:"#000000"})}renderCross({x:t,y:e,radius:n}){const s=this.vary(.2,1)*n,r=this.lineNodes({x:t-s,y:e-s},{x:t+s,y:e+s},{}),i=this.vary(.2,1)*n,a=this.lineNodes({x:t+i,y:e-i},{x:t-i,y:e+i},{});return this.svg.el("path").attrs({d:r.nodes+a.nodes,fill:"none"}).attrs(Ye.normal)}renderAgentLine({x:t,y0:e,y1:n,width:s,className:r,options:i}){const a=this.optionsAttributes(this.agentLineAttrs,i);return s>0?this.renderBox({x:t-s/2,y:e,width:s,height:n-e},{fill:"none",attrs:a}).setClass(r):this.renderLine({x:t,y:e},{x:t,y:n},{varY:.3,attrs:a}).setClass(r)}}class Ze{constructor(t=Xe){const e=t===Xe;this.name=e?"sketch":"sketch left handed",this.handedness=t}build(t){return new Je(t,this.handedness)}}Object.assign(Ze,{RIGHT:Xe,LEFT:{}});const Ke=/^([ \t]*)(.*)$/,_e={after:".!+",end:/[ \t\r\n]$/,start:/^[ \t\r\n:,]/},$e=/^"(\\.|[^"])*$/,tn=/[\r\n:,"<>\-~]/,en=/["\\]/g,nn=[new class{constructor(){this.name="basic"}build(t){return new pt(t)}},new class{constructor(){this.name="monospace"}build(t){return new Bt(t)}},new class{constructor(){this.name="chunky"}build(t){return new xt(t)}},new Ze(Ze.RIGHT),new Ze(Ze.LEFT)],sn=new de,rn=new Lt,an=sn.getCodeMirrorMode();class on extends kt{constructor(t=null,e={}){super();let n=null;t&&"object"==typeof t?(n=t,this.code=n.code):(n=e,this.code=t),Object.assign(this,{exporter:new Mt,generator:rn,isInteractive:!1,latestProcessed:null,parser:sn,registerCodeMirrorMode:st,renderer:new Te(Object.assign({document:function(t){return t?t.ownerDocument||null:"undefined"==typeof window?null:window.document}(n.container),themes:nn},n)),textSizerFactory:n.textSizerFactory||null}),this.renderer.addEventForwarding(this),n.container&&n.container.appendChild(this.dom()),n.interactive&&this.addInteractivity(),"string"==typeof this.code&&!1!==n.render&&this.render()}clone(t={}){const e=t.container||this.renderer.dom();return new on(Object.assign({code:this.code,components:this.renderer.components,container:null,document:e.ownerDocument,interactive:this.isInteractive,namespace:null,textSizerFactory:this.textSizerFactory,themes:this.renderer.getThemes()},t))}set(t="",{render:e=!0}={}){this.code!==t&&(this.code=t,e&&this.render())}process(t){const e=this.parser.parse(t);return this.generator.generate(e)}addTheme(t){this.renderer.addTheme(t)}setHighlight(t){this.renderer.setHighlight(t)}isCollapsed(t){return this.renderer.isCollapsed(t)}setCollapsed(t,e=!0,{render:n=!0}={}){return!!this.renderer.setCollapsed(t,e)&&(n&&this.latestProcessed&&this.render(this.latestProcessed),!0)}collapse(t,e){return this.setCollapsed(t,!0,e)}expand(t,e){return this.setCollapsed(t,!1,e)}toggleCollapsed(t,e){return this.setCollapsed(t,!this.isCollapsed(t),e)}expandAll(t){return this.setCollapsed(null,!1,t)}getThemeNames(){return this.renderer.getThemeNames()}getThemes(){return this.renderer.getThemes()}_updateSize({width:t=null,height:e=null,zoom:n=null}){null!==t?(null===e?this.renderer.height*=t/this.renderer.width:this.renderer.height=e,this.renderer.width=t):null!==e?(this.renderer.width*=e/this.renderer.height,this.renderer.height=e):null!==n&&(this.renderer.width*=n,this.renderer.height*=n)}getSVGCodeSynchronous({size:t={}}={}){return this._updateSize(t),this.exporter.getSVGContent(this.renderer)}getSVGCode(t){return Promise.resolve(this.getSVGCodeSynchronous(t))}getSVGSynchronous({size:t={}}={}){return this._updateSize(t),this.exporter.getSVGURL(this.renderer)}getSVG({size:t={}}={}){return this._updateSize(t),Promise.resolve({latest:!0,url:this.getSVGSynchronous()})}getCanvas({resolution:t=1,size:e={}}={}){return this._updateSize(e),new Promise(e=>{this.exporter.getCanvas(this.renderer,t,e)})}getPNG({resolution:t=1,size:e={}}={}){return this._updateSize(e),new Promise(e=>{this.exporter.getPNGURL(this.renderer,t,(t,n)=>{e({latest:n,url:t})})})}getSize(){return{height:this.renderer.height,width:this.renderer.width}}_revertParent(t){const e=this.renderer.dom();e.parentNode!==t.originalParent&&(e.parentNode.removeChild(e),t.originalParent&&t.originalParent.appendChild(e))}_sendRenderError(t){this._revertParent(this.renderState),this.renderState.error=!0,this.trigger("error",[this,t])}optimisedRenderPreReflow(t=null){const e=this.renderer.dom();this.renderState={error:!1,originalParent:e.parentNode,processed:t};const n=this.renderState;e.isConnected||(n.originalParent&&n.originalParent.removeChild(e),e.ownerDocument.body.appendChild(e));try{n.processed||(n.processed=this.process(this.code)),this.renderer.optimisedRenderPreReflow(n.processed)}catch(t){this._sendRenderError(t)}}optimisedRenderReflow(){try{this.renderState.error||this.renderer.optimisedRenderReflow()}catch(t){this._sendRenderError(t)}}optimisedRenderPostReflow(){const t=this.renderState;try{t.error||this.renderer.optimisedRenderPostReflow(t.processed)}catch(t){this._sendRenderError(t)}this.renderState=null,t.error||(this._revertParent(t),this.latestProcessed=t.processed,this.trigger("render",[this]))}render(t=null){function e(t,e){n=e}let n=null;if(this.addEventListener("error",e),this.optimisedRenderPreReflow(t),this.optimisedRenderReflow(),this.optimisedRenderPostReflow(),this.removeEventListener("error",e),n)throw n}setContainer(t=null){const e=this.dom();e.parentNode&&e.parentNode.removeChild(e),t&&t.appendChild(e)}addInteractivity(){this.isInteractive||(this.isInteractive=!0,this.addEventListener("click",t=>{this.toggleCollapsed(t.ln)}))}extractCodeFromSVG(t){return rt(t)}renderAll(t){return it(t)}dom(){return this.renderer.dom()}}Object.assign(on,{Exporter:Mt,Generator:Lt,Parser:de,Renderer:Te,addTheme:function(t){nn.push(t)},convert:ot,convertAll:function(t=null,e="sequence-diagram"){let n=null,s=null;"string"==typeof t?(n=null,s=t):(n=t,s=e);let r=null;r=n&&void 0!==n.length?n:(n||window.document).getElementsByClassName(s);const i=[];for(let t=0;t<r.length;++t)i.push(r[t]);ot(i)},extractCodeFromSVG:rt,getDefaultThemeNames:function(){return nn.map(t=>t.name)},registerCodeMirrorMode:st,renderAll:it,themes:nn});const ln={SequenceDiagram:on};"undefined"!=typeof exports?Object.assign(exports,ln):window.define&&window.define.amd?(Object.assign(on,ln),window.define(()=>on)):(window.document.addEventListener("DOMContentLoaded",()=>{on.convertAll()},{once:!0}),window.CodeMirror&&on.registerCodeMirrorMode(window.CodeMirror),Object.assign(window,ln))}(); |