From dce39792ac7d7c7943a5a1cab00c9eb769a95de1 Mon Sep 17 00:00:00 2001 From: David Evans Date: Fri, 24 Nov 2017 23:15:39 +0000 Subject: [PATCH] Support requirejs loading [#25] --- index.html | 111 +++++++++++++++++++++++++----------- lib/sequence-diagram.js | 8 +++ lib/sequence-diagram.min.js | 2 +- package.json | 4 +- scripts/standalone.js | 8 +++ styles/home.css | 12 ---- 6 files changed, 97 insertions(+), 48 deletions(-) diff --git a/index.html b/index.html index a90729b..9de7191 100644 --- a/index.html +++ b/index.html @@ -4,8 +4,8 @@ + + + + + + + + + + + - @@ -76,8 +113,16 @@ This library renders sequence diagrams from code. It is open-source (LGPL-3.0), and including it in a website is as simple as adding the script:

-
-<script src="lib/sequence-diagram.min.js"></script>
+
+<script src="lib/sequence-diagram.min.js"></script>
+
+ +

Or if you are using requirejs:

+ +
+requirejs(['lib/sequence-diagram.min'], (SequenceDiagram) => {
+  SequenceDiagram.convertAll();
+});
 

@@ -86,23 +131,23 @@ converted when the page loads:

-
+
   A -> B: foo
   B -> A: bar
 
-
-<pre class="sequence-diagram">
+
+<pre class="sequence-diagram">
   A -> B: foo
   B -> A: bar
-</pre>
+</pre>
 

Language

Connection Types

-
+
 title Connection Types
 
 begin Foo, Bar, Baz
@@ -135,7 +180,7 @@ Foo <- ]: From the right
 

Notes & State

-
+
 title Note Placements
 
 note over Foo: Foo says something
@@ -151,7 +196,7 @@ state over Foo: Foo is ponderous
 

Logic

-
+
 title At the Bank
 
 begin Person, ATM, Bank
@@ -173,7 +218,7 @@ end
 

Label Templates

-
+
 autolabel "[<inc>] <label>"
 
 begin "Underpants\nGnomes" as A
@@ -183,7 +228,7 @@ A <- ]: Profit!
 

Multiline Text

-
+
 title 'My Multiline
 Title'
 
@@ -200,7 +245,7 @@ too!'
 

Short-Lived Agents

-
+
 title "Baz doesn't live long"
 
 note over Foo, Bar: Using begin / end
@@ -222,7 +267,7 @@ terminators bar
 

Agent Aliases

-
+
 define My complicated agent name as A
 define "Another agent name,
 and this one's multi-line!" as B
@@ -232,7 +277,7 @@ A <- B: than writing the whole name
 

Alternative Agent Ordering

-
+
 define Baz, Foo
 
 Foo -> Bar
@@ -265,7 +310,7 @@ For more advanced usage, an API is available:
 
 
-
+
 var diagram = new SequenceDiagram();
 diagram.set('A -> B\nB -> A');
 document.body.appendChild(diagram.dom());
@@ -274,7 +319,7 @@ diagram.setHighlight(1); // Highlight elements created in line 1 (0-based)
 
 

Constructor

-
+
 diagram = new SequenceDiagram(code, options);
 diagram = new SequenceDiagram(code);
 diagram = new SequenceDiagram(options);
@@ -293,7 +338,7 @@ Creates a new SequenceDiagram object. Options is an object which can contain:
 
 

.clone

-
+
 newDiagram = diagram.clone(options);
 newDiagram = diagram.clone();
 
@@ -306,7 +351,7 @@ so all the same options are available).

.set

-
+
 diagram.set(code);
 
@@ -316,7 +361,7 @@ Changes the code for the diagram and causes a re-render.

.process

-
+
 processed = diagram.process(code);
 
@@ -329,7 +374,7 @@ error notifications. The resulting object can be passed to

.render

-
+
 diagram.render();
 diagram.render(processed);
 
@@ -342,7 +387,7 @@ Optionally, the result of an earlier call to

.setHighlight

-
+
 diagram.setHighlight(line);
 diagram.setHighlight();
 
@@ -355,7 +400,7 @@ with no parameter (or null) will remove the highlighting.

.addTheme

-
+
 diagram.addTheme(theme);
 
@@ -370,7 +415,7 @@ useful.

.getThemeNames

-
+
 names = diagram.getThemeNames();
 
@@ -381,7 +426,7 @@ can be specified in a theme <name> line in the code.

.getThemes

-
+
 themes = diagram.getThemes();
 
@@ -391,7 +436,7 @@ Returns a list of themes which are available to this diagram.

.getSVGSynchronous

-
+
 svgURL = diagram.getSVGSynchronous();
 
@@ -401,7 +446,7 @@ Returns a blob URL which contains the SVG code for the current diagram.

.getSVG

-
+
 diagram.getSVG().then(({url, latest}) => { ... });
 
@@ -419,7 +464,7 @@ which has no synchronous equivalent.

.getPNG

-
+
 diagram.getPNG(options).then(({url, latest}) => { ... });
 
@@ -439,7 +484,7 @@ Generates a PNG image and returns a blob URL.

.getSize

-
+
 size = diagram.getSize();
 
@@ -450,7 +495,7 @@ properties, corresponding to the size of the diagram in units.

.setContainer

-
+
 diagram.setContainer(node);
 
@@ -460,7 +505,7 @@ Same as calling node.appendChild(diagram.dom()).

.dom

-
+
 node = diagram.dom();
 
diff --git a/lib/sequence-diagram.js b/lib/sequence-diagram.js index 7bed586..a3f987d 100644 --- a/lib/sequence-diagram.js +++ b/lib/sequence-diagram.js @@ -6075,6 +6075,14 @@ define('sequence/SequenceDiagram',[ requirejs(['sequence/SequenceDiagram'], (SequenceDiagram) => { 'use strict'; + const def = window.define; + if(def && def.amd) { + def(() => { + return SequenceDiagram; + }); + return; + } + document.addEventListener('DOMContentLoaded', () => { SequenceDiagram.convertAll(); }, {once: true}); diff --git a/lib/sequence-diagram.min.js b/lib/sequence-diagram.min.js index e1b7eb4..7af1b9a 100644 --- a/lib/sequence-diagram.min.js +++ b/lib/sequence-diagram.min.js @@ -1 +1 @@ -!function(){var requirejs,require,define;!function(undef){function hasProp(obj,prop){return hasOwn.call(obj,prop)}function normalize(name,baseName){var nameParts,nameSegment,mapValue,foundMap,lastIndex,foundI,foundStarMap,starI,i,j,part,baseParts=baseName&&baseName.split("/"),map=config.map,starMap=map&&map["*"]||{};if(name){for(lastIndex=(name=name.split("/")).length-1,config.nodeIdCompat&&jsSuffixRegExp.test(name[lastIndex])&&(name[lastIndex]=name[lastIndex].replace(jsSuffixRegExp,"")),"."===name[0].charAt(0)&&baseParts&&(name=baseParts.slice(0,baseParts.length-1).concat(name)),i=0;i0&&(name.splice(i-1,2),i-=2)}name=name.join("/")}if((baseParts||starMap)&&map){for(i=(nameParts=name.split("/")).length;i>0;i-=1){if(nameSegment=nameParts.slice(0,i).join("/"),baseParts)for(j=baseParts.length;j>0;j-=1)if((mapValue=map[baseParts.slice(0,j).join("/")])&&(mapValue=mapValue[nameSegment])){foundMap=mapValue,foundI=i;break}if(foundMap)break;!foundStarMap&&starMap&&starMap[nameSegment]&&(foundStarMap=starMap[nameSegment],starI=i)}!foundMap&&foundStarMap&&(foundMap=foundStarMap,foundI=starI),foundMap&&(nameParts.splice(0,foundI,foundMap),name=nameParts.join("/"))}return name}function makeRequire(relName,forceSync){return function(){var args=aps.call(arguments,0);return"string"!=typeof args[0]&&1===args.length&&args.push(null),req.apply(undef,args.concat([relName,forceSync]))}}function makeLoad(depName){return function(value){defined[depName]=value}}function callDep(name){if(hasProp(waiting,name)){var args=waiting[name];delete waiting[name],defining[name]=!0,main.apply(undef,args)}if(!hasProp(defined,name)&&!hasProp(defining,name))throw new Error("No "+name);return defined[name]}function splitPrefix(name){var prefix,index=name?name.indexOf("!"):-1;return index>-1&&(prefix=name.substring(0,index),name=name.substring(index+1,name.length)),[prefix,name]}function makeRelParts(relName){return relName?splitPrefix(relName):[]}var main,req,makeMap,handlers,defined={},waiting={},config={},defining={},hasOwn=Object.prototype.hasOwnProperty,aps=[].slice,jsSuffixRegExp=/\.js$/;makeMap=function(name,relParts){var plugin,parts=splitPrefix(name),prefix=parts[0],relResourceName=relParts[1];return name=parts[1],prefix&&(plugin=callDep(prefix=normalize(prefix,relResourceName))),prefix?name=plugin&&plugin.normalize?plugin.normalize(name,function(relName){return function(name){return normalize(name,relName)}}(relResourceName)):normalize(name,relResourceName):(prefix=(parts=splitPrefix(name=normalize(name,relResourceName)))[0],name=parts[1],prefix&&(plugin=callDep(prefix))),{f:prefix?prefix+"!"+name:name,n:name,pr:prefix,p:plugin}},handlers={require:function(name){return makeRequire(name)},exports:function(name){var e=defined[name];return void 0!==e?e:defined[name]={}},module:function(name){return{id:name,uri:"",exports:defined[name],config:function(name){return function(){return config&&config.config&&config.config[name]||{}}}(name)}}},main=function(name,deps,callback,relName){var cjsModule,depName,ret,map,i,relParts,usingExports,args=[],callbackType=typeof callback;if(relName=relName||name,relParts=makeRelParts(relName),"undefined"===callbackType||"function"===callbackType){for(deps=!deps.length&&callback.length?["require","exports","module"]:deps,i=0;i{"use strict";return class{constructor(){this.listeners=new Map,this.forwards=new Set}addEventListener(type,callback){const l=this.listeners.get(type);l?l.push(callback):this.listeners.set(type,[callback])}removeEventListener(type,fn){const l=this.listeners.get(type);if(!l)return;const i=l.indexOf(fn);-1!==i&&l.splice(i,1)}countEventListeners(type){return(this.listeners.get(type)||[]).length}removeAllEventListeners(type){type?this.listeners.delete(type):this.listeners.clear()}addEventForwarding(target){this.forwards.add(target)}removeEventForwarding(target){this.forwards.delete(target)}removeAllEventForwardings(){this.forwards.clear()}trigger(type,params=[]){(this.listeners.get(type)||[]).forEach(listener=>listener.apply(null,params)),this.forwards.forEach(fwd=>fwd.trigger(type,params))}}}),define("core/ArrayUtilities",[],()=>{"use strict";function indexOf(list,element,equalityCheck=null){if(null===equalityCheck)return list.indexOf(element);for(let i=0;i=parts.length)return void target.push(current.slice());const choices=parts[position];if(!Array.isArray(choices))return current.push(choices),combineRecur(parts,position+1,current,target),void current.pop();for(let i=0;i{result.push(...fn(item))}),result}}}),define("sequence/CodeMirrorMode",["core/ArrayUtilities"],array=>{"use strict";function cmGetSuggestions(state,token,previous,current){return""===token?function(state,previous,current){return"object"==typeof current.suggest&¤t.suggest.global?[current.suggest]:"string"!=typeof current.suggest||previous.suggest===current.suggest?null:state["known"+current.suggest]}(state,previous,current):!0===current.suggest?[function(token,current){return Object.keys(current.then).length>0?token+" ":token+"\n"}(token,current)]:Array.isArray(current.suggest)?current.suggest:current.suggest?[current.suggest]:null}function cmMakeCompletions(state,path){const comp=[],current=array.last(path);return Object.keys(current.then).forEach(token=>{let next=current.then[token];"number"==typeof next&&(next=path[path.length-next-1]),array.mergeSets(comp,cmGetSuggestions(state,token,current,next))}),comp}function updateSuggestion(state,locals,token,{suggest:suggest,override:override}){locals.type&&suggest!==locals.type&&(override&&(locals.type=override),array.mergeSets(state["known"+locals.type],[locals.value+" "]),locals.type="",locals.value=""),"string"==typeof suggest&&state["known"+suggest]&&(locals.type=suggest,locals.value&&(locals.value+=token.s),locals.value+=token.v)}function cmCheckToken(state,eol,commands){const suggestions={type:"",value:""};let current=commands;const path=[current];return state.line.forEach((token,i)=>{i===state.line.length-1&&(state.completions=cmMakeCompletions(state,path));const keywordToken=token.q?"":token.v,found=current.then[keywordToken]||current.then[""];"number"==typeof found?path.length-=found:path.push(found||CM_ERROR),current=array.last(path),updateSuggestion(state,suggestions,token,current)}),eol&&updateSuggestion(state,suggestions,null,{}),state.nextCompletions=cmMakeCompletions(state,path),state.valid=Boolean(current.then["\n"])||0===Object.keys(current.then).length,current.type}function getInitialToken(block){const baseToken=block.baseToken||{};return{value:baseToken.v||"",quoted:baseToken.q||!1}}const CM_ERROR={type:"error line-error",then:{"":0}},makeCommands=(()=>{function textTo(exit){return{type:"string",then:Object.assign({"":0},exit)}}function agentListTo(exit){return{type:"variable",suggest:"Agent",then:Object.assign({},exit,{"":0,",":{type:"operator",suggest:!0,then:{"":1}}})}}function makeSideNote(side){return{type:"keyword",suggest:[side+" of ",side+": "],then:{of:{type:"keyword",suggest:!0,then:{"":agentListToText}},":":{type:"operator",suggest:!0,then:{"":textToEnd}},"":agentListToText}}}function makeOpBlock(exit){const op={type:"operator",suggest:!0,then:{"+":CM_ERROR,"-":CM_ERROR,"*":CM_ERROR,"!":CM_ERROR,"":exit}};return{"+":{type:"operator",suggest:!0,then:{"+":CM_ERROR,"-":CM_ERROR,"*":op,"!":CM_ERROR,"":exit}},"-":{type:"operator",suggest:!0,then:{"+":CM_ERROR,"-":CM_ERROR,"*":op,"!":{type:"operator",then:{"+":CM_ERROR,"-":CM_ERROR,"*":CM_ERROR,"!":CM_ERROR,"":exit}},"":exit}},"*":{type:"operator",suggest:!0,then:{"+":op,"-":op,"*":CM_ERROR,"!":CM_ERROR,"":exit}},"!":op,"":exit}}const end={type:"",suggest:"\n",then:{}},textToEnd=textTo({"\n":end}),aliasListToEnd={type:"variable",suggest:"Agent",then:{"":0,"\n":end,",":{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":end}}}}}},agentListToText=agentListTo({":":{type:"operator",suggest:!0,then:{"":textToEnd}}}),agentList2ToText={type:"variable",suggest:"Agent",then:{"":0,",":{type:"operator",suggest:!0,then:{"":agentListToText}},":":CM_ERROR}},singleAgentToText={type:"variable",suggest:"Agent",then:{"":0,",":CM_ERROR,":":{type:"operator",suggest:!0,then:{"":textToEnd}}}},agentToOptText={type:"variable",suggest:"Agent",then:{"":0,":":{type:"operator",suggest:!0,then:{"":textToEnd,"\n":{type:"",then:{}}}},"\n":end}},referenceName={":":{type:"operator",suggest:!0,then:{"":textTo({as:{type:"keyword",suggest:!0,then:{"":{type:"variable",suggest:"Agent",then:{"":0,"\n":end}}}}})}}},refDef={type:"keyword",suggest:!0,then:Object.assign({over:{type:"keyword",suggest:!0,then:{"":agentListTo(referenceName)}}},referenceName)},BASE_THEN={title:{type:"keyword",suggest:!0,then:{"":textToEnd}},theme:{type:"keyword",suggest:!0,then:{"":{type:"string",suggest:{global:"themes",suffix:"\n"},then:{"":0,"\n":end}}}},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:{"":aliasListToEnd,as:CM_ERROR}},begin:{type:"keyword",suggest:!0,then:{"":aliasListToEnd,reference:refDef,as:CM_ERROR}},end:{type:"keyword",suggest:!0,then:{"":aliasListToEnd,as:CM_ERROR,"\n":end}},if:{type:"keyword",suggest:!0,then:{"":textToEnd,":":{type:"operator",suggest:!0,then:{"":textToEnd}},"\n":end}},else:{type:"keyword",suggest:["else\n","else if: "],then:{if:{type:"keyword",suggest:"if: ",then:{"":textToEnd,":":{type:"operator",suggest:!0,then:{"":textToEnd}}}},"\n":end}},repeat:{type:"keyword",suggest:!0,then:{"":textToEnd,":":{type:"operator",suggest:!0,then:{"":textToEnd}},"\n":end}},note:{type:"keyword",suggest:!0,then:{over:{type:"keyword",suggest:!0,then:{"":agentListToText}},left:makeSideNote("left"),right:makeSideNote("right"),between:{type:"keyword",suggest:!0,then:{"":agentList2ToText}}}},state:{type:"keyword",suggest:"state over ",then:{over:{type:"keyword",suggest:!0,then:{"":singleAgentToText}}}},text:{type:"keyword",suggest:!0,then:{left:makeSideNote("left"),right:makeSideNote("right")}},autolabel:{type:"keyword",suggest:!0,then:{off:{type:"keyword",suggest:!0,then:{}},"":textToEnd}},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 arrows=>({type:"error line-error",then:Object.assign({},BASE_THEN,function(arrows){const connect={type:"keyword",suggest:!0,then:makeOpBlock(agentToOptText)},then={"":0};return arrows.forEach(arrow=>then[arrow]=connect),then[":"]={type:"operator",suggest:!0,override:"Label",then:{}},makeOpBlock({type:"variable",suggest:"Agent",then:then})}(arrows))})})();return class{constructor(tokenDefinitions,arrows){this.tokenDefinitions=tokenDefinitions,this.commands=makeCommands(arrows),this.lineComment="#"}startState(){return{currentType:-1,current:"",currentSpace:"",currentQuoted:!1,knownAgent:[],knownLabel:[],beginCompletions:cmMakeCompletions({},[this.commands]),completions:[],nextCompletions:[],valid:!0,line:[],indent:0}}_matchPattern(stream,pattern,consume){return pattern?(pattern.lastIndex=0,stream.match(pattern,consume)):null}_tokenBegin(stream,state){state.currentSpace="";let lastChar="";for(;;){if(stream.eol())return!1;state.currentSpace+=lastChar;for(let i=0;i{"use strict";function execAt(str,reg,i){return reg.lastIndex=i,reg.exec(str)}function unescape(match){return"n"===match[1]?"\n":match[1]}function tokAdvance(src,i,block){return block?function(src,i,block){if(block.escape){const match=execAt(src,block.escape,i);if(match)return{newBlock:null,end:!1,appendSpace:"",appendValue:block.escapeWith(match),skip:match[0].length}}const match=execAt(src,block.end,i);return match?{newBlock:null,end:!0,appendSpace:"",appendValue:"",skip:match[0].length}:{newBlock:null,end:!1,appendSpace:"",appendValue:src[i],skip:1}}(src,i,block):function(src,i){for(let j=0;j,])/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 TokenState{constructor(src){this.src=src,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(advance){this.block=advance.newBlock,Object.assign(this.token,this.block.baseToken),this.token.b=copyPos(this.pos)}endToken(){let token=null;return this.block.omit||(this.token.e=copyPos(this.pos),token=this.token),this.reset(),token}advance(){const advance=tokAdvance(this.src,this.pos.i,this.block);return advance.newBlock&&this.beginToken(advance),this.token.s+=advance.appendSpace,this.token.v+=advance.appendValue,function(pos,src,steps){for(let i=0;i{token.q||"\n"!==token.v?line.push(token):line.length>0&&(lines.push(line),line=[])}),line.length>0&&lines.push(line),lines}}}),define("sequence/LabelPatternParser",[],()=>{"use strict";function countDP(value){const match=DP_PATTERN.exec(value);return match&&match[1]?match[1].length:0}function parseToken(token){if("label"===token)return{token:"label"};const p=token.indexOf(" ");let type=null,args=null;return-1===p?(type=token,args=[]):(type=token.substr(0,p),args=token.substr(p+1).split(",")),"inc"===type?function(args){let start=1,inc=1,dp=0;return args[0]&&(start=Number(args[0]),dp=Math.max(dp,countDP(args[0]))),args[1]&&(inc=Number(args[1]),dp=Math.max(dp,countDP(args[1]))),{start:start,inc:inc,dp:dp}}(args):"<"+token+">"}const LABEL_PATTERN=/(.*?)<([^<>]*)>/g,DP_PATTERN=/\.([0-9]*)/;return function(raw){const pattern=[];let match=null,end=0;for(LABEL_PATTERN.lastIndex=0;match=LABEL_PATTERN.exec(raw);)match[1]&&pattern.push(match[1]),match[2]&&pattern.push(parseToken(match[2])),end=LABEL_PATTERN.lastIndex;const remainder=raw.substr(end);return remainder&&pattern.push(remainder),pattern}}),define("sequence/CodeMirrorHints",["core/ArrayUtilities"],array=>{"use strict";function makeHintItem(text,ranges){return{text:text,displayText:"\n"===text?"":text.trim(),className:"\n"===text?"pick-virtual":null,from:SQUASH_START.test(text)?ranges.squashFrom:ranges.wordFrom,to:SQUASH_END.test(text)?ranges.squashTo:ranges.wordTo}}function getGlobals({global:global,prefix:prefix="",suffix:suffix=""},globals){const identified=globals[global];return identified?identified.map(item=>prefix+item+suffix):[]}const TRIMMER=/^([ \t]*)(.*)$/,SQUASH_START=/^[ \t\r\n:,]/,SQUASH_END=/[ \t\r\n]$/;return{getHints:function(cm,options){const cur=cm.getCursor(),token=cm.getTokenAt(cur);let partial=token.string;token.end>cur.ch&&(partial=partial.substr(0,cur.ch-token.start));const parts=TRIMMER.exec(partial);partial=parts[2];const from=token.start+parts[1].length,continuation=cur.ch>0&&token.state.line.length>0;let comp=continuation?token.state.completions:token.state.beginCompletions;continuation||(comp=comp.concat(token.state.knownAgent)),function(suggestions,globals={}){for(let i=0;i0&&" "===ln[chFrom-1]&&ranges.squashFrom.ch--," "===ln[chTo]&&ranges.squashTo.ch++,ranges}(cm,cur.line,from,token.end);let selfValid=!1;const list=comp.filter(opt=>opt.startsWith(partial)).map(opt=>opt!==partial+" "||options.completeSingle?makeHintItem(opt,ranges):(selfValid=!0,null)).filter(opt=>null!==opt);return selfValid&&list.length>0&&list.unshift(makeHintItem(partial+" ",ranges)),{list:list,from:ranges.wordFrom,to:ranges.wordTo}}}}),define("sequence/Parser",["core/ArrayUtilities","./Tokeniser","./LabelPatternParser","./CodeMirrorHints"],(array,Tokeniser,labelPatternParser,CMHints)=>{"use strict";function makeError(message,token=null){let suffix="";return token&&(suffix=" at line "+(token.b.ln+1)+", character "+token.b.ch),new Error(message+suffix)}function joinLabel(line,begin=0,end=null){if(null===end&&(end=line.length),end<=begin)return"";let result=line[begin].v;for(let i=begin+1;i=end)&&(aliasSep=end),start>=aliasSep)throw makeError("Missing agent name",function(line,pos){if(pos{const arrows=array.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(arrow=>0!==arrow[0].type||0!==arrow[2].type),types=new Map;return arrows.forEach(arrow=>{types.set(arrow.map(part=>part.tok).join(""),{line:arrow[1].type,left:arrow[0].type,right:arrow[2].type})}),types})(),CONNECT_AGENT_FLAGS={"*":"begin","+":"start","-":"stop","!":"end"},TERMINATOR_TYPES=["none","box","cross","fade","bar"],NOTE_TYPES={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}}}},AGENT_MANIPULATION_TYPES={define:{type:"agent define"},begin:{type:"agent begin",mode:"box"},end:{type:"agent end",mode:"cross"}},PARSERS=[(line,meta)=>"title"!==tokenKeyword(line[0])?null:(meta.title=joinLabel(line,1),!0),(line,meta)=>"theme"!==tokenKeyword(line[0])?null:(meta.theme=joinLabel(line,1),!0),(line,meta)=>{if("terminators"!==tokenKeyword(line[0]))return null;const type=tokenKeyword(line[1]);if(!type)throw makeError("Unspecified termination",line[0]);if(-1===TERMINATOR_TYPES.indexOf(type))throw makeError('Unknown termination "'+type+'"',line[1]);return meta.terminators=type,!0},(line,meta)=>{if("headers"!==tokenKeyword(line[0]))return null;const type=tokenKeyword(line[1]);if(!type)throw makeError("Unspecified header",line[0]);if(-1===TERMINATOR_TYPES.indexOf(type))throw makeError('Unknown header "'+type+'"',line[1]);return meta.headers=type,!0},line=>{if("autolabel"!==tokenKeyword(line[0]))return null;let raw=null;return raw="off"===tokenKeyword(line[1])?"