diff --git a/lib/sequence-diagram.js b/lib/sequence-diagram.js index 09cc14d..52bfb8d 100644 --- a/lib/sequence-diagram.js +++ b/lib/sequence-diagram.js @@ -3969,8 +3969,8 @@ define('sequence/components/Connect',[ ) => { 'use strict'; - function drawHorizontalArrowHead(container, {x, y, dx, dy, attrs}) { - container.appendChild(svg.make( + function drawHorizontalArrowHead({x, y, dx, dy, attrs}) { + return svg.make( attrs.fill === 'none' ? 'polyline' : 'polygon', Object.assign({ 'points': ( @@ -3979,7 +3979,7 @@ define('sequence/components/Connect',[ (x + dx) + ' ' + (y + dy) ), }, attrs) - )); + ); } class Arrowhead { @@ -4006,15 +4006,16 @@ define('sequence/components/Connect',[ } } - render(layer, theme, {x, y, dir}) { + render(layer, theme, pt, dir) { const config = this.getConfig(theme); - drawHorizontalArrowHead(layer, { - x: x + this.short(theme) * dir, - y, + const func = config.render || drawHorizontalArrowHead; + layer.appendChild(func({ + x: pt.x + this.short(theme) * dir, + y: pt.y, dx: config.width * dir, dy: config.height / 2, attrs: config.attrs, - }); + })); } width(theme) { @@ -4063,91 +4064,99 @@ define('sequence/components/Connect',[ ]; } - class ConnectingLine { - renderFlat(container, {x1, x2, y}, attrs) { - const ww = attrs['wave-width']; - const hh = attrs['wave-height']; + function renderFlat({x1, dx1, x2, dx2, y}, attrs) { + const ww = attrs['wave-width']; + const hh = attrs['wave-height']; - if(!ww || !hh) { - container.appendChild(svg.make('line', Object.assign({ - 'x1': x1, + if(!ww || !hh) { + return { + shape: svg.make('line', Object.assign({ + 'x1': x1 + dx1, 'y1': y, - 'x2': x2, + 'x2': x2 + dx2, 'y2': y, - }, attrs))); - return; - } - - const heights = makeWavyLineHeights(hh); - const dw = ww / heights.length; - let p = 0; - - let points = ''; - for(let x = x1; x + dw <= x2; x += dw) { - points += ( - x + ' ' + - (y + heights[(p ++) % heights.length]) + ' ' - ); - } - points += x2 + ' ' + y; - container.appendChild(svg.make('polyline', Object.assign({ - points, - }, attrs))); + }, attrs)), + p1: {x: x1, y}, + p2: {x: x2, y}, + }; } - renderRev(container, {xL1, xL2, y1, y2, xR}, attrs) { - const r = (y2 - y1) / 2; - const ww = attrs['wave-width']; - const hh = attrs['wave-height']; + const heights = makeWavyLineHeights(hh); + const dw = ww / heights.length; + let p = 0; - if(!ww || !hh) { - container.appendChild(svg.make('path', Object.assign({ - 'd': ( - 'M' + xL1 + ' ' + y1 + - 'L' + xR + ' ' + y1 + - 'A' + r + ' ' + r + ' 0 0 1 ' + xR + ' ' + y2 + - 'L' + xL2 + ' ' + y2 - ), - }, attrs))); - return; - } - - const heights = makeWavyLineHeights(hh); - const dw = ww / heights.length; - let p = 0; - - let points = ''; - for(let x = xL1; x + dw <= xR; x += dw) { - points += ( - x + ' ' + - (y1 + heights[(p ++) % heights.length]) + ' ' - ); - } - - const ym = (y1 + y2) / 2; - for(let t = 0; t + dw / r <= Math.PI; t += dw / r) { - const h = heights[(p ++) % heights.length]; - points += ( - (xR + Math.sin(t) * (r - h)) + ' ' + - (ym - Math.cos(t) * (r - h)) + ' ' - ); - } - - for(let x = xR; x - dw >= xL2; x -= dw) { - points += ( - x + ' ' + - (y2 - heights[(p ++) % heights.length]) + ' ' - ); - } - - points += xL2 + ' ' + y2; - container.appendChild(svg.make('polyline', Object.assign({ - points, - }, attrs))); + let points = ''; + const xL = Math.min(x1 + dx1, x2 + dx2); + const xR = Math.max(x1 + dx1, x2 + dx2); + for(let x = xL; x + dw <= xR; x += dw) { + points += ( + x + ' ' + + (y + heights[(p ++) % heights.length]) + ' ' + ); } + points += xR + ' ' + y; + return { + shape: svg.make('polyline', Object.assign({points}, attrs)), + p1: {x: x1, y}, + p2: {x: x2, y}, + }; } - const CONNECTING_LINE = new ConnectingLine(); + function renderRev({xL, dx1, dx2, y1, y2, xR}, attrs) { + const r = (y2 - y1) / 2; + const ww = attrs['wave-width']; + const hh = attrs['wave-height']; + + if(!ww || !hh) { + return { + shape: svg.make('path', Object.assign({ + 'd': ( + 'M' + (xL + dx1) + ' ' + y1 + + 'L' + xR + ' ' + y1 + + 'A' + r + ' ' + r + ' 0 0 1 ' + xR + ' ' + y2 + + 'L' + (xL + dx2) + ' ' + y2 + ), + }, attrs)), + p1: {x: xL, y: y1}, + p2: {x: xL, y: y2}, + }; + } + + const heights = makeWavyLineHeights(hh); + const dw = ww / heights.length; + let p = 0; + + let points = ''; + for(let x = xL + dx1; x + dw <= xR; x += dw) { + points += ( + x + ' ' + + (y1 + heights[(p ++) % heights.length]) + ' ' + ); + } + + const ym = (y1 + y2) / 2; + for(let t = 0; t + dw / r <= Math.PI; t += dw / r) { + const h = heights[(p ++) % heights.length]; + points += ( + (xR + Math.sin(t) * (r - h)) + ' ' + + (ym - Math.cos(t) * (r - h)) + ' ' + ); + } + + for(let x = xR; x - dw >= xL + dx2; x -= dw) { + points += ( + x + ' ' + + (y2 - heights[(p ++) % heights.length]) + ' ' + ); + } + + points += (xL + dx2) + ' ' + y2; + return { + shape: svg.make('polyline', Object.assign({points}, attrs)), + p1: {x: xL, y: y1}, + p2: {x: xL, y: y2}, + }; + } class Connect extends BaseComponent { separation({label, agentNames, options}, env) { @@ -4237,17 +4246,19 @@ define('sequence/components/Connect',[ const x1 = Math.max(lineX + rArrow.width(env.theme), x0 + labelW); const y1 = y0 + r * 2; - const lineAttrs = config.lineAttrs[options.line]; - CONNECTING_LINE.renderRev(env.shapeLayer, { - xL1: lineX + lArrow.lineGap(env.theme, lineAttrs), - xL2: lineX + rArrow.lineGap(env.theme, lineAttrs), + const line = config.line[options.line]; + const rendered = (line.renderRev || renderRev)({ + xL: lineX, + dx1: lArrow.lineGap(env.theme, line.attrs), + dx2: rArrow.lineGap(env.theme, line.attrs), y1: y0, y2: y1, xR: x1, - }, lineAttrs); + }, line.attrs); + env.shapeLayer.appendChild(rendered.shape); - lArrow.render(env.shapeLayer, env.theme, {x: lineX, y: y0, dir: 1}); - rArrow.render(env.shapeLayer, env.theme, {x: lineX, y: y1, dir: 1}); + lArrow.render(env.shapeLayer, env.theme, rendered.p1, 1); + rArrow.render(env.shapeLayer, env.theme, rendered.p2, 1); const raise = Math.max(height, lArrow.height(env.theme) / 2); const arrowDip = rArrow.height(env.theme) / 2; @@ -4299,15 +4310,18 @@ define('sequence/components/Connect',[ SVGTextBlockClass: env.SVGTextBlockClass, }); - const lineAttrs = config.lineAttrs[options.line]; - CONNECTING_LINE.renderFlat(env.shapeLayer, { - x1: x0 + lArrow.lineGap(env.theme, lineAttrs) * dir, - x2: x1 - rArrow.lineGap(env.theme, lineAttrs) * dir, + const line = config.line[options.line]; + const rendered = (line.render || renderFlat)({ + x1: x0, + dx1: lArrow.lineGap(env.theme, line.attrs) * dir, + x2: x1, + dx2: -rArrow.lineGap(env.theme, line.attrs) * dir, y, - }, lineAttrs); + }, line.attrs); + env.shapeLayer.appendChild(rendered.shape); - lArrow.render(env.shapeLayer, env.theme, {x: x0, y, dir}); - rArrow.render(env.shapeLayer, env.theme, {x: x1, y, dir: -dir}); + lArrow.render(env.shapeLayer, env.theme, rendered.p1, dir); + rArrow.render(env.shapeLayer, env.theme, rendered.p2, -dir); const arrowSpread = Math.max( lArrow.height(env.theme), @@ -5344,30 +5358,36 @@ define('sequence/themes/Basic',[ connect: { loopbackRadius: 6, - lineAttrs: { + line: { 'solid': { - 'fill': 'none', - 'stroke': '#000000', - 'stroke-width': 1, + attrs: { + 'fill': 'none', + 'stroke': '#000000', + 'stroke-width': 1, + }, }, 'dash': { - 'fill': 'none', - 'stroke': '#000000', - 'stroke-width': 1, - 'stroke-dasharray': '4, 2', + attrs: { + 'fill': 'none', + 'stroke': '#000000', + 'stroke-width': 1, + 'stroke-dasharray': '4, 2', + }, }, 'wave': { - 'fill': 'none', - 'stroke': '#000000', - 'stroke-width': 1, - 'stroke-linejoin': 'round', - 'stroke-linecap': 'round', - 'wave-width': 6, - 'wave-height': 0.5, + attrs: { + 'fill': 'none', + 'stroke': '#000000', + 'stroke-width': 1, + 'stroke-linejoin': 'round', + 'stroke-linecap': 'round', + 'wave-width': 6, + 'wave-height': 0.5, + }, }, }, arrow: { - single: { + 'single': { width: 5, height: 10, attrs: { @@ -5376,7 +5396,7 @@ define('sequence/themes/Basic',[ 'stroke-linejoin': 'miter', }, }, - double: { + 'double': { width: 4, height: 6, attrs: { @@ -5684,26 +5704,32 @@ define('sequence/themes/Chunky',[ connect: { loopbackRadius: 8, - lineAttrs: { + line: { 'solid': { - 'fill': 'none', - 'stroke': '#000000', - 'stroke-width': 3, + attrs: { + 'fill': 'none', + 'stroke': '#000000', + 'stroke-width': 3, + }, }, 'dash': { - 'fill': 'none', - 'stroke': '#000000', - 'stroke-width': 3, - 'stroke-dasharray': '10, 4', + attrs: { + 'fill': 'none', + 'stroke': '#000000', + 'stroke-width': 3, + 'stroke-dasharray': '10, 4', + }, }, 'wave': { - 'fill': 'none', - 'stroke': '#000000', - 'stroke-width': 3, - 'stroke-linejoin': 'round', - 'stroke-linecap': 'round', - 'wave-width': 10, - 'wave-height': 1, + attrs: { + 'fill': 'none', + 'stroke': '#000000', + 'stroke-width': 3, + 'stroke-linejoin': 'round', + 'stroke-linecap': 'round', + 'wave-width': 10, + 'wave-height': 1, + }, }, }, arrow: { @@ -6386,7 +6412,6 @@ define('sequence/themes/Sketch',[ 'use strict'; // TODO: - // * arrows // * fade starter/terminator sometimes does not fully cover line // * blocks (if/else/repeat/ref) @@ -6407,6 +6432,13 @@ define('sequence/themes/Sketch',[ return r; } + const PENCIL = { + 'stroke': 'rgba(0,0,0,0.7)', + 'stroke-width': 0.8, + 'stroke-linejoin': 'round', + 'stroke-linecap': 'round', + }; + const SETTINGS = { titleMargin: 10, outerMargin: 5, @@ -6451,47 +6483,50 @@ define('sequence/themes/Sketch',[ connect: { loopbackRadius: 6, - lineAttrs: { + line: { 'solid': { - 'fill': 'none', - 'stroke': '#000000', - 'stroke-width': 1, + attrs: Object.assign({ + 'fill': 'none', + }, PENCIL), + render: null, + renderRev: null, }, 'dash': { - 'fill': 'none', - 'stroke': '#000000', - 'stroke-width': 1, - 'stroke-dasharray': '4, 2', + attrs: Object.assign({ + 'fill': 'none', + 'stroke-dasharray': '4, 2', + }, PENCIL), + render: null, + renderRev: null, }, 'wave': { - 'fill': 'none', - 'stroke': '#000000', - 'stroke-width': 1, - 'stroke-linejoin': 'round', - 'stroke-linecap': 'round', - 'wave-width': 6, - 'wave-height': 0.5, + attrs: Object.assign({ + 'fill': 'none', + 'stroke-linejoin': 'round', + 'stroke-linecap': 'round', + 'wave-width': 6, + 'wave-height': 0.5, + }, PENCIL), + render: null, + renderRev: null, }, }, arrow: { - single: { + 'single': { width: 5, - height: 10, - attrs: { - 'fill': '#000000', - 'stroke-width': 0, - 'stroke-linejoin': 'miter', - }, - }, - double: { - width: 4, height: 6, - attrs: { + attrs: Object.assign({ + 'fill': 'rgba(0,0,0,0.9)', + }, PENCIL), + render: null, + }, + 'double': { + width: 4, + height: 8, + attrs: Object.assign({ 'fill': 'none', - 'stroke': '#000000', - 'stroke-width': 1, - 'stroke-linejoin': 'miter', - }, + }, PENCIL), + render: null, }, }, label: { @@ -6704,6 +6739,10 @@ define('sequence/themes/Sketch',[ this.agentCap.cross.render = this.renderCross.bind(this); this.agentCap.bar.render = this.renderBar.bind(this); this.agentCap.box.boxRenderer = this.renderBox.bind(this); + this.connect.arrow.single.render = this.renderArrowHead.bind(this); + this.connect.arrow.double.render = this.renderArrowHead.bind(this); + this.connect.line.solid.render = this.renderConnect.bind(this); + this.connect.line.dash.render = this.renderConnect.bind(this); this.notes.note.boxRenderer = this.renderNote.bind(this); this.notes.state.boxRenderer = this.renderState.bind(this); } @@ -6748,16 +6787,22 @@ define('sequence/themes/Sketch',[ return Math.asin(rand * 2 - 1) * 2 * range / Math.PI; } - lineNodes(p1, p2, {var1 = 1, var2 = 1, move = true}) { + lineNodes(p1, p2, { + var1 = 1, + var2 = 1, + varX = 1, + varY = 1, + move = true, + }) { const length = Math.sqrt( (p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y) ); const rough = Math.min(Math.sqrt(length) * 0.2, 5); - const x1 = p1.x + this.vary(var1 * rough); - const y1 = p1.y + this.vary(var1 * rough); - const x2 = p2.x + this.vary(var2 * rough); - const y2 = p2.y + this.vary(var2 * rough); + const x1 = p1.x + this.vary(var1 * varX * rough); + const y1 = p1.y + this.vary(var1 * varY * rough); + const x2 = p2.x + this.vary(var2 * varX * rough); + const y2 = p2.y + this.vary(var2 * varY * rough); // -1 = p1 higher, 1 = p2 higher const upper = Math.max(-1, Math.min(1, @@ -6784,14 +6829,12 @@ define('sequence/themes/Sketch',[ }; } - renderLine(p1, p2, {var1 = 1, var2 = 1}) { - const line = this.lineNodes(p1, p2, {var1, var2}); - const shape = svg.make('path', { + renderLine(p1, p2, lineOptions) { + const line = this.lineNodes(p1, p2, lineOptions); + const shape = svg.make('path', Object.assign({ 'd': line.nodes, - 'stroke': 'rgba(0,0,0,0.7)', - 'stroke-width': 0.8, 'fill': 'none', - }); + }, PENCIL)); return shape; } @@ -6817,12 +6860,10 @@ define('sequence/themes/Sketch',[ {var1: 0, var2: 0.3, move: false} ); - const shape = svg.make('path', { + const shape = svg.make('path', Object.assign({ 'd': lT.nodes + lR.nodes + lB.nodes + lL.nodes, - 'stroke': 'rgba(0,0,0,0.7)', - 'stroke-width': 0.8, 'fill': fill || '#FFFFFF', - }); + }, PENCIL)); return shape; } @@ -6866,7 +6907,7 @@ define('sequence/themes/Sketch',[ ); const g = svg.make('g'); - g.appendChild(svg.make('path', { + g.appendChild(svg.make('path', Object.assign({ 'd': ( lT.nodes + lF.nodes + @@ -6874,20 +6915,52 @@ define('sequence/themes/Sketch',[ lB.nodes + lL.nodes ), - 'stroke': 'rgba(0,0,0,0.7)', - 'stroke-width': 0.8, 'fill': '#FFFFFF', - })); - g.appendChild(svg.make('path', { + }, PENCIL))); + g.appendChild(svg.make('path', Object.assign({ 'd': lF1.nodes + lF2.nodes, - 'stroke': 'rgba(0,0,0,0.7)', - 'stroke-width': 0.8, 'fill': 'none', - })); + }, PENCIL))); return g; } + renderConnect({x1, dx1, x2, dx2, y}, attrs) { + const ln = this.lineNodes( + {x: x1 + dx1, y}, + {x: x2 + dx2, y}, + {varX: 0.3} + ); + return { + shape: svg.make('path', Object.assign({'d': ln.nodes}, attrs)), + p1: {x: ln.p1.x - dx1, y: ln.p2.y}, + p2: {x: ln.p2.x - dx2, y: ln.p2.y}, + }; + } + + renderArrowHead({x, y, dx, dy, attrs}) { + const w = dx * (1 + this.vary(0.2)); + const h = dy * (1 + this.vary(0.3)); + const l1 = this.lineNodes( + {x: x + w, y: y - h}, + {x, y}, + {var1: 2.0, var2: 0.2} + ); + const l2 = this.lineNodes( + l1.p2, + {x: x + w, y: y + h}, + {var1: 0, var2: 2.0, move: false} + ); + const l3 = (attrs.fill === 'none') ? {nodes: ''} : this.lineNodes( + l2.p2, + l1.p1, + {var1: 0, var2: 0, move: false} + ); + return svg.make('path', Object.assign({ + 'd': l1.nodes + l2.nodes + l3.nodes, + }, attrs)); + } + renderState({x, y, width, height}) { // TODO: rounded corners return this.renderBox({x, y, width, height}); @@ -6911,12 +6984,10 @@ define('sequence/themes/Sketch',[ {} ); - return svg.make('path', { + return svg.make('path', Object.assign({ 'd': l1.nodes + l2.nodes, - 'stroke': 'rgba(0,0,0,0.7)', - 'stroke-width': 0.8, 'fill': 'none', - }); + }, PENCIL)); } getNote(type) { @@ -6937,7 +7008,7 @@ define('sequence/themes/Sketch',[ const shape = this.renderLine( {x, y: y0}, {x, y: y1}, - {} + {varY: 0.3} ); shape.setAttribute('class', className); container.appendChild(shape); diff --git a/lib/sequence-diagram.min.js b/lib/sequence-diagram.min.js index 418d410..ee7b527 100644 --- a/lib/sequence-diagram.min.js +++ b/lib/sequence-diagram.min.js @@ -1 +1 @@ -!function(){var e,t,n;!function(s){function i(e,t){return x.call(e,t)}function r(e,t){var n,s,i,r,a,o,h,l,g,d,c,u=t&&t.split("/"),p=b.map,m=p&&p["*"]||{};if(e){for(a=(e=e.split("/")).length-1,b.nodeIdCompat&&w.test(e[a])&&(e[a]=e[a].replace(w,"")),"."===e[0].charAt(0)&&u&&(e=u.slice(0,u.length-1).concat(e)),g=0;g0&&(e.splice(g-1,2),g-=2)}e=e.join("/")}if((u||m)&&p){for(g=(n=e.split("/")).length;g>0;g-=1){if(s=n.slice(0,g).join("/"),u)for(d=u.length;d>0;d-=1)if((i=p[u.slice(0,d).join("/")])&&(i=i[s])){r=i,o=g;break}if(r)break;!h&&m&&m[s]&&(h=m[s],l=g)}!r&&h&&(r=h,o=l),r&&(n.splice(0,o,r),e=n.join("/"))}return e}function a(e,t){return function(){var n=k.call(arguments,0);return"string"!=typeof n[0]&&1===n.length&&n.push(null),c.apply(s,n.concat([e,t]))}}function o(e){return function(t){m[e]=t}}function h(e){if(i(f,e)){var t=f[e];delete f[e],y[e]=!0,d.apply(s,t)}if(!i(m,e)&&!i(y,e))throw new Error("No "+e);return m[e]}function l(e){var t,n=e?e.indexOf("!"):-1;return n>-1&&(t=e.substring(0,n),e=e.substring(n+1,e.length)),[t,e]}function g(e){return e?l(e):[]}var d,c,u,p,m={},f={},b={},y={},x=Object.prototype.hasOwnProperty,k=[].slice,w=/\.js$/;u=function(e,t){var n,s=l(e),i=s[0],a=t[1];return e=s[1],i&&(n=h(i=r(i,a))),i?e=n&&n.normalize?n.normalize(e,function(e){return function(t){return r(t,e)}}(a)):r(e,a):(i=(s=l(e=r(e,a)))[0],e=s[1],i&&(n=h(i))),{f:i?i+"!"+e:e,n:e,pr:i,p:n}},p={require:function(e){return a(e)},exports:function(e){var t=m[e];return void 0!==t?t:m[e]={}},module:function(e){return{id:e,uri:"",exports:m[e],config:function(e){return function(){return b&&b.config&&b.config[e]||{}}}(e)}}},d=function(e,t,n,r){var l,d,c,b,x,k,w,A=[],v=typeof n;if(r=r||e,k=g(r),"undefined"===v||"function"===v){for(t=!t.length&&n.length?["require","exports","module"]:t,x=0;x{"use strict";return class{constructor(){this.listeners=new Map,this.forwards=new Set}addEventListener(e,t){const n=this.listeners.get(e);n?n.push(t):this.listeners.set(e,[t])}removeEventListener(e,t){const n=this.listeners.get(e);if(!n)return;const s=n.indexOf(t);-1!==s&&n.splice(s,1)}countEventListeners(e){return(this.listeners.get(e)||[]).length}removeAllEventListeners(e){e?this.listeners.delete(e):this.listeners.clear()}addEventForwarding(e){this.forwards.add(e)}removeEventForwarding(e){this.forwards.delete(e)}removeAllEventForwardings(){this.forwards.clear()}trigger(e,t=[]){(this.listeners.get(e)||[]).forEach(e=>e.apply(null,t)),this.forwards.forEach(n=>n.trigger(e,t))}}}),n("core/ArrayUtilities",[],()=>{"use strict";function e(e,t,n=null){if(null===n)return e.indexOf(t);for(let s=0;s=e.length)return void i.push(s.slice());const r=e[n];if(!Array.isArray(r))return s.push(r),t(e,n+1,s,i),void s.pop();for(let a=0;a{n.push(...t(e))}),n}}}),n("sequence/CodeMirrorMode",["core/ArrayUtilities"],e=>{"use strict";function t(e,t,n,s){return""===t?function(e,t,n){return"object"==typeof n.suggest&&n.suggest.global?[n.suggest]:"string"!=typeof n.suggest||t.suggest===n.suggest?null:e["known"+n.suggest]}(e,n,s):!0===s.suggest?[function(e,t){return Object.keys(t.then).length>0?e+" ":e+"\n"}(t,s)]:Array.isArray(s.suggest)?s.suggest:s.suggest?[s.suggest]:null}function n(n,s){const i=[],r=e.last(s);return Object.keys(r.then).forEach(a=>{let o=r.then[a];"number"==typeof o&&(o=s[s.length-o-1]),e.mergeSets(i,t(n,a,r,o))}),i}function s(t,n,s,{suggest:i,override:r}){n.type&&i!==n.type&&(r&&(n.type=r),e.mergeSets(t["known"+n.type],[n.value+" "]),n.type="",n.value=""),"string"==typeof i&&t["known"+i]&&(n.type=i,n.value&&(n.value+=s.s),n.value+=s.v)}function i(t,i,r){const o={type:"",value:""};let h=r;const l=[h];return t.line.forEach((i,r)=>{r===t.line.length-1&&(t.completions=n(t,l));const g=i.q?"":i.v,d=h.then[g]||h.then[""];"number"==typeof d?l.length-=d:l.push(d||a),h=e.last(l),s(t,o,i,h)}),i&&s(t,o,null,{}),t.nextCompletions=n(t,l),t.valid=Boolean(h.then["\n"])||0===Object.keys(h.then).length,h.type}function r(e){const t=e.baseToken||{};return{value:t.v||"",quoted:t.q||!1}}const a={type:"error line-error",then:{"":0}},o=(()=>{function e(e){return{type:"string",then:Object.assign({"":0},e)}}function t(e){return{type:"variable",suggest:"Agent",then:Object.assign({},e,{"":0,",":{type:"operator",suggest:!0,then:{"":1}}})}}function n(e){return{type:"keyword",suggest:[e+" of ",e+": "],then:{of:{type:"keyword",suggest:!0,then:{"":h}},":":{type:"operator",suggest:!0,then:{"":r}},"":h}}}function s(e){const t={type:"operator",suggest:!0,then:{"+":a,"-":a,"*":a,"!":a,"":e}};return{"+":{type:"operator",suggest:!0,then:{"+":a,"-":a,"*":t,"!":a,"":e}},"-":{type:"operator",suggest:!0,then:{"+":a,"-":a,"*":t,"!":{type:"operator",then:{"+":a,"-":a,"*":a,"!":a,"":e}},"":e}},"*":{type:"operator",suggest:!0,then:{"+":t,"-":t,"*":a,"!":a,"":e}},"!":t,"":e}}const i={type:"",suggest:"\n",then:{}},r=e({"\n":i}),o={type:"variable",suggest:"Agent",then:{"":0,"\n":i,",":{type:"operator",suggest:!0,then:{"":1}},as:{type:"keyword",suggest:!0,then:{"":{type:"variable",suggest:"Agent",then:{"":0,",":{type:"operator",suggest:!0,then:{"":3}},"\n":i}}}}}},h=t({":":{type:"operator",suggest:!0,then:{"":r}}}),l={type:"variable",suggest:"Agent",then:{"":0,",":{type:"operator",suggest:!0,then:{"":h}},":":a}},g={type:"variable",suggest:"Agent",then:{"":0,",":a,":":{type:"operator",suggest:!0,then:{"":r}}}},d={type:"variable",suggest:"Agent",then:{"":0,":":{type:"operator",suggest:!0,then:{"":r,"\n":{type:"",then:{}}}},"\n":i}},c={":":{type:"operator",suggest:!0,then:{"":e({as:{type:"keyword",suggest:!0,then:{"":{type:"variable",suggest:"Agent",then:{"":0,"\n":i}}}}})}}},u={type:"keyword",suggest:!0,then:Object.assign({over:{type:"keyword",suggest:!0,then:{"":t(c)}}},c)},p={title:{type:"keyword",suggest:!0,then:{"":r}},theme:{type:"keyword",suggest:!0,then:{"":{type:"string",suggest:{global:"themes",suffix:"\n"},then:{"":0,"\n":i}}}},headers:{type:"keyword",suggest:!0,then:{none:{type:"keyword",suggest:!0,then:{}},cross:{type:"keyword",suggest:!0,then:{}},box:{type:"keyword",suggest:!0,then:{}},fade:{type:"keyword",suggest:!0,then:{}},bar:{type:"keyword",suggest:!0,then:{}}}},terminators:{type:"keyword",suggest:!0,then:{none:{type:"keyword",suggest:!0,then:{}},cross:{type:"keyword",suggest:!0,then:{}},box:{type:"keyword",suggest:!0,then:{}},fade:{type:"keyword",suggest:!0,then:{}},bar:{type:"keyword",suggest:!0,then:{}}}},define:{type:"keyword",suggest:!0,then:{"":o,as:a}},begin:{type:"keyword",suggest:!0,then:{"":o,reference:u,as:a}},end:{type:"keyword",suggest:!0,then:{"":o,as:a,"\n":i}},if:{type:"keyword",suggest:!0,then:{"":r,":":{type:"operator",suggest:!0,then:{"":r}},"\n":i}},else:{type:"keyword",suggest:["else\n","else if: "],then:{if:{type:"keyword",suggest:"if: ",then:{"":r,":":{type:"operator",suggest:!0,then:{"":r}}}},"\n":i}},repeat:{type:"keyword",suggest:!0,then:{"":r,":":{type:"operator",suggest:!0,then:{"":r}},"\n":i}},note:{type:"keyword",suggest:!0,then:{over:{type:"keyword",suggest:!0,then:{"":h}},left:n("left"),right:n("right"),between:{type:"keyword",suggest:!0,then:{"":l}}}},state:{type:"keyword",suggest:"state over ",then:{over:{type:"keyword",suggest:!0,then:{"":g}}}},text:{type:"keyword",suggest:!0,then:{left:n("left"),right:n("right")}},autolabel:{type:"keyword",suggest:!0,then:{off:{type:"keyword",suggest:!0,then:{}},"":r}},simultaneously:{type:"keyword",suggest:!0,then:{":":{type:"operator",suggest:!0,then:{}},with:{type:"keyword",suggest:!0,then:{"":{type:"variable",suggest:"Label",then:{"":0,":":{type:"operator",suggest:!0,then:{}}}}}}}}};return e=>({type:"error line-error",then:Object.assign({},p,function(e){const t={type:"keyword",suggest:!0,then:s(d)},n={"":0};return e.forEach(e=>n[e]=t),n[":"]={type:"operator",suggest:!0,override:"Label",then:{}},s({type:"variable",suggest:"Agent",then:n})}(e))})})();return class{constructor(e,t){this.tokenDefinitions=e,this.commands=o(t),this.lineComment="#"}startState(){return{currentType:-1,current:"",currentSpace:"",currentQuoted:!1,knownAgent:[],knownLabel:[],beginCompletions:n({},[this.commands]),completions:[],nextCompletions:[],valid:!0,line:[],indent:0}}_matchPattern(e,t,n){return t?(t.lastIndex=0,e.match(t,n)):null}_tokenBegin(e,t){t.currentSpace="";let n="";for(;;){if(e.eol())return!1;t.currentSpace+=n;for(let n=0;n{"use strict";function t(e,t,n){return t.lastIndex=n,t.exec(e)}function n(e){return"n"===e[1]?"\n":e[1]}function s(e,n,s){return s?function(e,n,s){if(s.escape){const i=t(e,s.escape,n);if(i)return{newBlock:null,end:!1,appendSpace:"",appendValue:s.escapeWith(i),skip:i[0].length}}const i=t(e,s.end,n);return i?{newBlock:null,end:!0,appendSpace:"",appendValue:"",skip:i[0].length}:{newBlock:null,end:!1,appendSpace:"",appendValue:e[n],skip:1}}(e,n,s):function(e,n){for(let s=0;s,])/y,end:/(?=[ \t\r\n:+\-~*!<>,])|$/y},{start:/(?=[\-~<>])/y,end:/(?=[^\-~<>])|$/y},{start:/,/y,baseToken:{v:","}},{start:/:/y,baseToken:{v:":"}},{start:/!/y,baseToken:{v:"!"}},{start:/\+/y,baseToken:{v:"+"}},{start:/\*/y,baseToken:{v:"*"}},{start:/\n/y,baseToken:{v:"\n"}}];class a{constructor(e){this.src=e,this.block=null,this.token=null,this.pos={i:0,ln:0,ch:0},this.reset()}isOver(){return this.pos.i>this.src.length}reset(){this.token={s:"",v:"",q:!1,b:null,e:null},this.block=null}beginToken(e){this.block=e.newBlock,Object.assign(this.token,this.block.baseToken),this.token.b=i(this.pos)}endToken(){let e=null;return this.block.omit||(this.token.e=i(this.pos),e=this.token),this.reset(),e}advance(){const e=s(this.src,this.pos.i,this.block);return e.newBlock&&this.beginToken(e),this.token.s+=e.appendSpace,this.token.v+=e.appendValue,function(e,t,n){for(let s=0;s{e.q||"\n"!==e.v?n.push(e):n.length>0&&(t.push(n),n=[])}),n.length>0&&t.push(n),t}}}),n("sequence/LabelPatternParser",[],()=>{"use strict";function e(e){const t=s.exec(e);return t&&t[1]?t[1].length:0}function t(t){if("label"===t)return{token:"label"};const n=t.indexOf(" ");let s=null,i=null;return-1===n?(s=t,i=[]):(s=t.substr(0,n),i=t.substr(n+1).split(",")),"inc"===s?function(t){let n=1,s=1,i=0;return t[0]&&(n=Number(t[0]),i=Math.max(i,e(t[0]))),t[1]&&(s=Number(t[1]),i=Math.max(i,e(t[1]))),{start:n,inc:s,dp:i}}(i):"<"+t+">"}const n=/(.*?)<([^<>]*)>/g,s=/\.([0-9]*)/;return function(e){const s=[];let i=null,r=0;for(n.lastIndex=0;i=n.exec(e);)i[1]&&s.push(i[1]),i[2]&&s.push(t(i[2])),r=n.lastIndex;const a=e.substr(r);return a&&s.push(a),s}}),n("sequence/CodeMirrorHints",["core/ArrayUtilities"],e=>{"use strict";function t(e,t){return{text:e,displayText:"\n"===e?"":e.trim(),className:"\n"===e?"pick-virtual":null,from:i.test(e)?t.squashFrom:t.wordFrom,to:r.test(e)?t.squashTo:t.wordTo}}function n({global:e,prefix:t="",suffix:n=""},s){const i=s[e];return i?i.map(e=>t+e+n):[]}const s=/^([ \t]*)(.*)$/,i=/^[ \t\r\n:,]/,r=/[ \t\r\n]$/;return{getHints:function(i,r){const a=i.getCursor(),o=i.getTokenAt(a);let h=o.string;o.end>a.ch&&(h=h.substr(0,a.ch-o.start));const l=s.exec(h);h=l[2];const g=o.start+l[1].length,d=a.ch>0&&o.state.line.length>0;let c=d?o.state.completions:o.state.beginCompletions;d||(c=c.concat(o.state.knownAgent)),function(t,s={}){for(let i=0;i0&&" "===i[n-1]&&r.squashFrom.ch--," "===i[s]&&r.squashTo.ch++,r}(i,a.line,g,o.end);let p=!1;const m=c.filter(e=>e.startsWith(h)).map(e=>e!==h+" "||r.completeSingle?t(e,u):(p=!0,null)).filter(e=>null!==e);return p&&m.length>0&&m.unshift(t(h+" ",u)),{list:m,from:u.wordFrom,to:u.wordTo}}}}),n("sequence/Parser",["core/ArrayUtilities","./Tokeniser","./LabelPatternParser","./CodeMirrorHints"],(e,t,n,s)=>{"use strict";function i(e,t=null){let n="";return t&&(n=" at line "+(t.b.ln+1)+", character "+t.b.ch),new Error(e+n)}function r(e,t=0,n=null){if(null===n&&(n=e.length),n<=t)return"";let s=e[t].v;for(let i=t+1;i=s)&&(o=s),n>=o)throw i("Missing agent name",function(t,n){if(n{const t=e.combine([[{tok:"",type:0},{tok:"<",type:1},{tok:"<<",type:2}],[{tok:"-",type:"solid"},{tok:"--",type:"dash"},{tok:"~",type:"wave"}],[{tok:"",type:0},{tok:">",type:1},{tok:">>",type:2}]]).filter(e=>0!==e[0].type||0!==e[2].type),n=new Map;return t.forEach(e=>{n.set(e.map(e=>e.tok).join(""),{line:e[1].type,left:e[0].type,right:e[2].type})}),n})(),p={"*":"begin","+":"start","-":"stop","!":"end"},m=["none","box","cross","fade","bar"],f={text:{mode:"text",types:{left:{type:"note left",skip:["of"],min:0,max:null},right:{type:"note right",skip:["of"],min:0,max:null}}},note:{mode:"note",types:{over:{type:"note over",skip:[],min:0,max:null},left:{type:"note left",skip:["of"],min:0,max:null},right:{type:"note right",skip:["of"],min:0,max:null},between:{type:"note between",skip:[],min:2,max:null}}},state:{mode:"state",types:{over:{type:"note over",skip:[],min:1,max:1}}}},b={define:{type:"agent define"},begin:{type:"agent begin",mode:"box"},end:{type:"agent end",mode:"cross"}},y=[(e,t)=>"title"!==a(e[0])?null:(t.title=r(e,1),!0),(e,t)=>"theme"!==a(e[0])?null:(t.theme=r(e,1),!0),(e,t)=>{if("terminators"!==a(e[0]))return null;const n=a(e[1]);if(!n)throw i("Unspecified termination",e[0]);if(-1===m.indexOf(n))throw i('Unknown termination "'+n+'"',e[1]);return t.terminators=n,!0},(e,t)=>{if("headers"!==a(e[0]))return null;const n=a(e[1]);if(!n)throw i("Unspecified header",e[0]);if(-1===m.indexOf(n))throw i('Unknown header "'+n+'"',e[1]);return t.headers=n,!0},e=>{if("autolabel"!==a(e[0]))return null;let t=null;return t="off"===a(e[1])?"