From a60d8fb0cb5b9f7e24a8e8cfb6859410ec48e4c5 Mon Sep 17 00:00:00 2001 From: David Evans Date: Sat, 12 May 2018 15:44:49 +0100 Subject: [PATCH] Add person indicator, add sketch rendering for databases [#36] --- lib/sequence-diagram-web.js | 267 ++++++++++++++++-- lib/sequence-diagram-web.min.js | 2 +- lib/sequence-diagram.js | 267 ++++++++++++++++-- scripts/sequence/codemirror/Mode.mjs | 1 + scripts/sequence/codemirror/Mode_webspec.mjs | 1 + .../sequence/renderer/components/AgentCap.mjs | 20 +- scripts/sequence/themes/BaseTheme.mjs | 45 ++- scripts/sequence/themes/Basic.mjs | 28 +- scripts/sequence/themes/Chunky.mjs | 31 +- scripts/sequence/themes/Monospace.mjs | 28 +- scripts/sequence/themes/Sketch.mjs | 114 +++++++- web/lib/editor.js | 5 + web/lib/editor.min.js | 2 +- web/scripts/interface/ComponentsLibrary.mjs | 5 + 14 files changed, 742 insertions(+), 74 deletions(-) diff --git a/lib/sequence-diagram-web.js b/lib/sequence-diagram-web.js index 2ba5131..b5e6178 100644 --- a/lib/sequence-diagram-web.js +++ b/lib/sequence-diagram-web.js @@ -207,17 +207,52 @@ return g; } - renderDB(attrs, position) { - const z = attrs['db-z']; + renderPerson({iconHeight, iconWidth}, iconAttrs, boxAttrs, position) { + const cx = position.x + position.width / 2; + const sx = iconWidth / 2; + const sy = iconHeight; + + return this.svg.el('g').add( + this.svg.el('path') + .attr('d', ( + 'M' + (cx - sx) + ' ' + (position.y + iconHeight) + + 'a' + sx + ' ' + (sy * 0.3) + ' 0 0 1' + + ' ' + (sx * 2) + ' 0' + )) + .attrs(iconAttrs), + this.svg.el('path') + .attr('d', ( + 'M' + cx + ' ' + position.y + + 'c' + (sx * 0.224) + ' 0' + + ' ' + (sx * 0.4) + ' ' + (sy * 0.1) + + ' ' + (sx * 0.4) + ' ' + (sy * 0.275) + + 's' + (-sx * 0.176) + ' ' + (sy * 0.35) + + ' ' + (-sx * 0.4) + ' ' + (sy * 0.35) + + 's' + (-sx * 0.4) + ' ' + (-sy * 0.175) + + ' ' + (-sx * 0.4) + ' ' + (-sy * 0.35) + + 's' + (sx * 0.176) + ' ' + (-sy * 0.275) + + ' ' + (sx * 0.4) + ' ' + (-sy * 0.275) + )) + .attrs(iconAttrs), + this.svg.box(boxAttrs, { + height: position.height - iconHeight, + width: position.width, + x: position.x, + y: position.y + iconHeight, + }) + ); + } + + renderDB({tilt}, attrs, position) { return this.svg.el('g').add( this.svg.box({ 'rx': position.width / 2, - 'ry': z, + 'ry': tilt, }, position).attrs(attrs), this.svg.el('path') .attr('d', ( - 'M' + position.x + ' ' + (position.y + z) + - 'a' + (position.width / 2) + ' ' + z + + 'M' + position.x + ' ' + (position.y + tilt) + + 'a' + (position.width / 2) + ' ' + tilt + ' 0 0 0 ' + position.width + ' 0' )) .attrs(attrs) @@ -527,6 +562,31 @@ 'text-anchor': 'middle', }, }, + person: { + padding: { + top: 20, + left: 10, + right: 10, + bottom: 5, + }, + arrowBottom: 5 + 12 * 1.3 / 2, + boxRenderer: this.renderPerson.bind(this, { + iconHeight: 15, + iconWidth: 18, + }, { + 'fill': '#000000', + }, { + 'fill': '#FFFFFF', + 'stroke': '#000000', + 'stroke-width': 1, + }), + labelAttrs: { + 'font-family': FONT, + 'font-size': 12, + 'line-height': LINE_HEIGHT, + 'text-anchor': 'middle', + }, + }, database: { padding: { top: 12, @@ -535,11 +595,10 @@ bottom: 3, }, arrowBottom: 5 + 12 * 1.3 / 2, - boxRenderer: this.renderDB.bind(this, { + boxRenderer: this.renderDB.bind(this, {tilt: 5}, { 'fill': '#FFFFFF', 'stroke': '#000000', 'stroke-width': 1, - 'db-z': 5, }), labelAttrs: { 'font-family': FONT, @@ -912,6 +971,34 @@ 'text-anchor': 'middle', }, }, + person: { + padding: { + top: 16, + left: 3, + right: 3, + bottom: 1, + }, + arrowBottom: 2 + 14 * 1.3 / 2, + 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': FONT$1, + 'font-weight': 'bold', + 'font-size': 14, + 'line-height': LINE_HEIGHT$1, + 'text-anchor': 'middle', + }, + }, database: { padding: { top: 4, @@ -920,11 +1007,10 @@ bottom: 0, }, arrowBottom: 2 + 14 * 1.3 / 2, - boxRenderer: this.renderDB.bind(this, { + boxRenderer: this.renderDB.bind(this, {tilt: 2}, { 'fill': '#FFFFFF', 'stroke': '#000000', 'stroke-width': 3, - 'db-z': 2, }), labelAttrs: { 'font-family': FONT$1, @@ -2899,6 +2985,31 @@ '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': FONT$2, + 'font-size': 12, + 'line-height': LINE_HEIGHT$2, + 'text-anchor': 'middle', + }, + }, database: { padding: { top: 9, @@ -2907,11 +3018,10 @@ bottom: 3, }, arrowBottom: 12, - boxRenderer: this.renderDB.bind(this, { + boxRenderer: this.renderDB.bind(this, {tilt: 4}, { 'fill': '#FFFFFF', 'stroke': '#000000', 'stroke-width': 1, - 'db-z': 4, }), labelAttrs: { 'font-family': FONT$2, @@ -3210,6 +3320,7 @@ } const AGENT_INFO_TYPES = [ + 'person', 'database', 'red', ]; @@ -5183,21 +5294,23 @@ }; class CapBox { - getConfig(options, env) { + getConfig(options, env, isBegin) { let config = null; if(options.includes('database')) { config = env.theme.agentCap.database; + } else if(isBegin && options.includes('person')) { + config = env.theme.agentCap.person; } return config || env.theme.agentCap.box; } - prepareMeasurements({formattedLabel, options}, env) { - const config = this.getConfig(options, env); + prepareMeasurements({formattedLabel, options}, env, isBegin) { + const config = this.getConfig(options, env, isBegin); env.textSizer.expectMeasure(config.labelAttrs, formattedLabel); } - separation({formattedLabel, options}, env) { - const config = this.getConfig(options, env); + separation({formattedLabel, options}, env, isBegin) { + const config = this.getConfig(options, env, isBegin); const width = ( env.textSizer.measure(config.labelAttrs, formattedLabel).width + config.padding.left + @@ -5211,8 +5324,8 @@ }; } - topShift({formattedLabel, options}, env) { - const config = this.getConfig(options, env); + topShift({formattedLabel, options}, env, isBegin) { + const config = this.getConfig(options, env, isBegin); const height = ( env.textSizer.measureHeight(config.labelAttrs, formattedLabel) + config.padding.top + @@ -5221,8 +5334,8 @@ return Math.max(0, height - config.arrowBottom); } - render(y, {x, formattedLabel, options}, env) { - const config = this.getConfig(options, env); + render(y, {x, formattedLabel, options}, env, isBegin) { + const config = this.getConfig(options, env, isBegin); const text = env.svg.boxedText(config, formattedLabel, {x, y}); @@ -9091,6 +9204,22 @@ }, boxRenderer: this.renderBox.bind(this), }, + person: { + padding: { + top: 20, + left: 10, + right: 10, + bottom: 5, + }, + arrowBottom: 5 + 12 * 1.3 / 2, + labelAttrs: { + 'font-family': FONT_FAMILY, + 'font-size': 12, + 'line-height': LINE_HEIGHT$3, + 'text-anchor': 'middle', + }, + boxRenderer: this.renderPerson.bind(this), + }, database: { padding: { top: 12, @@ -9099,10 +9228,7 @@ bottom: 2, }, arrowBottom: 5 + 12 * 1.3 / 2, - boxRenderer: this.renderDB.bind(this, Object.assign({ - 'fill': '#FFFFFF', - 'db-z': 5, - }, PENCIL.normal)), + boxRenderer: this.renderDB.bind(this), labelAttrs: { 'font-family': FONT$3, 'font-size': 12, @@ -9414,6 +9540,99 @@ .attrs(attrs || (thick ? PENCIL.thick : PENCIL.normal)); } + renderPerson(position) { + const sx = 18 / 2; + const sy = 15; + const iconAttrs = Object.assign({'fill': 'none'}, PENCIL.normal); + const cx = position.x + position.width / 2; + + const v = this.vary.bind(this); + const lean = v(0.1, 0.05 * this.handedness); + const skew = v(0.1, 0.05 * this.handedness); + const shoulders = v(0.05, 0.35); + + return this.svg.el('g').add( + this.svg.el('path') + .attr('d', ( + 'M' + (cx - sx) + ' ' + (position.y + sy) + + 'c' + (sx * lean) + ' ' + (-sy * (shoulders - skew)) + + ' ' + (sx * (2 + lean)) + ' ' + (-sy * (shoulders + skew)) + + ' ' + (sx * 2) + ' 0' + )) + .attrs(iconAttrs), + this.svg.el('path') + .attr('d', ( + 'M' + cx + ' ' + position.y + + 'c' + (sx * v(0.05, 0.224)) + ' ' + v(0.02, 0) + + ' ' + (sx * v(0.07, 0.4)) + ' ' + (sy * v(0.02, 0.1)) + + ' ' + (sx * 0.4) + ' ' + (sy * v(0.05, 0.275)) + + 's' + (-sx * v(0.05, 0.176)) + ' ' + (sy * 0.35) + + ' ' + (-sx * 0.4) + ' ' + (sy * v(0.05, 0.35)) + + 's' + (-sx * v(0.07, 0.4)) + ' ' + (-sy * 0.175) + + ' ' + (-sx * 0.4) + ' ' + (-sy * v(0.05, 0.35)) + + 's' + (sx * v(0.05, 0.176)) + ' ' + (-sy * 0.275) + + ' ' + (sx * v(0.05, 0.4)) + ' ' + (-sy * v(0.02, 0.275)) + )) + .attrs(iconAttrs), + this.renderBox({ + height: position.height - sy, + width: position.width, + x: position.x, + y: position.y + sy, + }) + ); + } + + renderDB(pos) { + const tilt = 5; + const tiltC = tilt * 1.2; + + const l1 = this.lineNodes( + {x: pos.x, y: pos.y + tilt}, + {x: pos.x, y: pos.y + pos.height - tilt}, + {} + ); + + const l2 = this.lineNodes( + {x: pos.x + pos.width, y: pos.y + pos.height - tilt}, + {x: pos.x + pos.width, y: pos.y + tilt}, + {move: false} + ); + + const v = this.vary.bind(this); + + const cx = pos.x + pos.width / 2; + const dx = -pos.width * this.handedness / 2; + const topX1 = cx - dx * v(0.03, 1.02); + const topY1 = pos.y + tilt * v(0.15, 1); + const topX2 = cx + dx * v(0.03, 1.02); + const topY2 = pos.y + tilt * v(0.15, 1); + + return this.svg.el('g').add( + this.svg.el('path') + .attr('d', ( + l1.nodes + + 'C' + l1.p2.x + ' ' + (l1.p2.y + v(0.1, tiltC)) + + ' ' + l2.p1.x + ' ' + (l2.p1.y + v(0.1, tiltC)) + + ' ' + l2.p1.x + ' ' + l2.p1.y + + l2.nodes + )) + .attrs(PENCIL.normal) + .attr('fill', '#FFFFFF'), + this.svg.el('path') + .attr('d', ( + 'M' + topX1 + ' ' + topY1 + + 'C' + (topX1 + dx * 0.2) + ' ' + (topY1 - v(0.2, tiltC)) + + ' ' + topX2 + ' ' + (topY2 - v(0.2, tiltC)) + + ' ' + topX2 + ' ' + topY2 + + 'S' + topX1 + ' ' + (topY1 + v(0.2, tiltC)) + + ' ' + v(1, topX1) + ' ' + v(0.5, topY1) + )) + .attrs(PENCIL.normal) + .attr('fill', '#FFFFFF') + ); + } + renderNote({x, y, width, height}) { const flickSize = 5; const lT = this.lineNodes( diff --git a/lib/sequence-diagram-web.min.js b/lib/sequence-diagram-web.min.js index b061933..e276070 100644 --- a/lib/sequence-diagram-web.min.js +++ b/lib/sequence-diagram-web.min.js @@ -1 +1 @@ -!function(){"use strict";function t(t,e,n=null){if(null===n)return t.indexOf(e);for(let s=0;s=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{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{for(let s=0;st);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!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 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"}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 rt.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=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 H(t,e,n,s){const r=[];let i=-1;for(let a=e;a{const r=t.get(e);(null===n||r.indexs.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.indexs.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]&&(Ke.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||!$e.test(t)?r:'"';return n+(i&&e?i+t.replace(tn,"\\$&")+i:t)+s}(t,n),r=t.q?e.fromVar:e.fromKey;return"\n"===s?{className:"pick-virtual",displayFrom:null,displayText:"",from:r.squash,text:"\n",to:e.to.squash}:{className:null,displayFrom:r.word,displayText:s.trim(),from:Ke.start.test(s)?r.squash:r.word,text:s,to:Ke.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=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=Ze.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=Ze.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);return d&&g.length>0&&g.unshift($(d,h,a.quote)),{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}}function st(t,e="sequence"){const n=t||window.CodeMirror;n.defineMode(e,()=>rn),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 an(null===e?t.textContent:e,Object.assign(s,n)),i=r.dom(),a=t.attributes;for(let t=0;tat(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}renderDB(t,e){const n=t["db-z"];return this.svg.el("g").add(this.svg.box({rx:e.width/2,ry:n},e).attrs(t),this.svg.el("path").attr("d","M"+e.x+" "+(e.y+n)+"a"+e.width/2+" "+n+" 0 0 0 "+e.width+" 0").attrs(t).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 n0?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,agentLineHighlightRadius: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"}},database:{padding:{top:12,left:10,right:10,bottom:3},arrowBottom:12.8,boxRenderer:this.renderDB.bind(this,{fill:"#FFFFFF",stroke:"#000000","stroke-width":1,"db-z":5}),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,agentLineHighlightRadius: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"}},database:{padding:{top:4,left:3,right:3,bottom:0},arrowBottom:11.1,boxRenderer:this.renderDB.bind(this,{fill:"#FFFFFF",stroke:"#000000","stroke-width":3,"db-z":2}),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=/'+(e=e.replace(Ft,'{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,highlighted:s=!1,locked:r=!1,visible:i=!1}={}){this.blocked=t,this.covered=e,this.group=n,this.highlighted=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;rt(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 begin":{check:["mode"],merge:["agentIDs"],siblings:new Set(["agent highlight"])},"agent end":{check:["mode"],merge:["agentIDs"],siblings:new Set(["agent highlight"])},"agent highlight":{check:["highlighted"],merge:["agentIDs"],siblings:new Set(["agent begin","agent end"])}},Dt=["agent begin","agent end","agent highlight","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 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"})}setGAgentHighlight(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 highlight agent: "+t.id);return!1}return s.visible&&s.highlighted!==e});return 0===s.length?null:(s.forEach(t=>{this.updateGAgentState(t,{highlighted:e})}),{agentIDs:s.map(t=>t.id),highlighted:e,type:"agent highlight"})}_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{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{"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!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.setGAgentHighlight(t.startGAgents,!0,!0),e,this.setGAgentHighlight(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)})}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.setGAgentHighlight(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.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.setGAgentHighlight(this.gAgents,!1),this.setGAgentVis(this.gAgents,!1,s)])),this._finalise(n),function(t,e){for(let n=0;n({})},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}},Ht=["database","red"],Pt=["begin","end","note","state","text"],jt=(()=>{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",Ht,{"\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}},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:"/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://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://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://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://g,skip:0},end:{matcher:/<\/u>/g,skip:0}},{attrs:{"baseline-shift":"70%","font-size":"0.6em"},begin:{matcher://g,skip:0},end:{matcher:/<\/sup>/g,skip:0}},{attrs:{"baseline-shift":"-20%","font-size":"0.6em"},begin:{matcher://g,skip:0},end:{matcher:/<\/sub>/g,skip:0}},{attrs:{fill:"#DD0000"},begin:{matcher://g,skip:0},end:{matcher:/<\/red>/g,skip:0}},{attrs:{filter:"highlight"},begin:{matcher://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=[{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])?"