bpmn-viewer.development.js 425 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154
  1. /*!
  2. * bpmn-js - bpmn-viewer v6.5.1
  3. *
  4. * Copyright (c) 2014-present, camunda Services GmbH
  5. *
  6. * Released under the bpmn.io license
  7. * http://bpmn.io/license
  8. *
  9. * Source Code: https://github.com/bpmn-io/bpmn-js
  10. *
  11. * Date: 2020-04-28
  12. */
  13. (function (global, factory) {
  14. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  15. typeof define === 'function' && define.amd ? define(factory) :
  16. (global = global || self, global.BpmnJS = factory());
  17. }(this, function () { 'use strict';
  18. function createCommonjsModule(fn, module) {
  19. return module = { exports: {} }, fn(module, module.exports), module.exports;
  20. }
  21. var inherits_browser = createCommonjsModule(function (module) {
  22. if (typeof Object.create === 'function') {
  23. // implementation from standard node.js 'util' module
  24. module.exports = function inherits(ctor, superCtor) {
  25. ctor.super_ = superCtor;
  26. ctor.prototype = Object.create(superCtor.prototype, {
  27. constructor: {
  28. value: ctor,
  29. enumerable: false,
  30. writable: true,
  31. configurable: true
  32. }
  33. });
  34. };
  35. } else {
  36. // old school shim for old browsers
  37. module.exports = function inherits(ctor, superCtor) {
  38. ctor.super_ = superCtor;
  39. var TempCtor = function () {};
  40. TempCtor.prototype = superCtor.prototype;
  41. ctor.prototype = new TempCtor();
  42. ctor.prototype.constructor = ctor;
  43. };
  44. }
  45. });
  46. /**
  47. * Flatten array, one level deep.
  48. *
  49. * @param {Array<?>} arr
  50. *
  51. * @return {Array<?>}
  52. */
  53. var nativeToString = Object.prototype.toString;
  54. var nativeHasOwnProperty = Object.prototype.hasOwnProperty;
  55. function isUndefined(obj) {
  56. return obj === undefined;
  57. }
  58. function isDefined(obj) {
  59. return obj !== undefined;
  60. }
  61. function isArray(obj) {
  62. return nativeToString.call(obj) === '[object Array]';
  63. }
  64. function isObject(obj) {
  65. return nativeToString.call(obj) === '[object Object]';
  66. }
  67. function isNumber(obj) {
  68. return nativeToString.call(obj) === '[object Number]';
  69. }
  70. function isFunction(obj) {
  71. var tag = nativeToString.call(obj);
  72. return tag === '[object Function]' || tag === '[object AsyncFunction]' || tag === '[object GeneratorFunction]' || tag === '[object AsyncGeneratorFunction]' || tag === '[object Proxy]';
  73. }
  74. function isString(obj) {
  75. return nativeToString.call(obj) === '[object String]';
  76. }
  77. /**
  78. * Return true, if target owns a property with the given key.
  79. *
  80. * @param {Object} target
  81. * @param {String} key
  82. *
  83. * @return {Boolean}
  84. */
  85. function has(target, key) {
  86. return nativeHasOwnProperty.call(target, key);
  87. }
  88. /**
  89. * Find element in collection.
  90. *
  91. * @param {Array|Object} collection
  92. * @param {Function|Object} matcher
  93. *
  94. * @return {Object}
  95. */
  96. function find(collection, matcher) {
  97. matcher = toMatcher(matcher);
  98. var match;
  99. forEach(collection, function (val, key) {
  100. if (matcher(val, key)) {
  101. match = val;
  102. return false;
  103. }
  104. });
  105. return match;
  106. }
  107. /**
  108. * Find element in collection.
  109. *
  110. * @param {Array|Object} collection
  111. * @param {Function} matcher
  112. *
  113. * @return {Array} result
  114. */
  115. function filter(collection, matcher) {
  116. var result = [];
  117. forEach(collection, function (val, key) {
  118. if (matcher(val, key)) {
  119. result.push(val);
  120. }
  121. });
  122. return result;
  123. }
  124. /**
  125. * Iterate over collection; returning something
  126. * (non-undefined) will stop iteration.
  127. *
  128. * @param {Array|Object} collection
  129. * @param {Function} iterator
  130. *
  131. * @return {Object} return result that stopped the iteration
  132. */
  133. function forEach(collection, iterator) {
  134. var val, result;
  135. if (isUndefined(collection)) {
  136. return;
  137. }
  138. var convertKey = isArray(collection) ? toNum : identity;
  139. for (var key in collection) {
  140. if (has(collection, key)) {
  141. val = collection[key];
  142. result = iterator(val, convertKey(key));
  143. if (result === false) {
  144. return val;
  145. }
  146. }
  147. }
  148. }
  149. /**
  150. * Reduce collection, returning a single result.
  151. *
  152. * @param {Object|Array} collection
  153. * @param {Function} iterator
  154. * @param {Any} result
  155. *
  156. * @return {Any} result returned from last iterator
  157. */
  158. function reduce(collection, iterator, result) {
  159. forEach(collection, function (value, idx) {
  160. result = iterator(result, value, idx);
  161. });
  162. return result;
  163. }
  164. /**
  165. * Return true if every element in the collection
  166. * matches the criteria.
  167. *
  168. * @param {Object|Array} collection
  169. * @param {Function} matcher
  170. *
  171. * @return {Boolean}
  172. */
  173. function every(collection, matcher) {
  174. return !!reduce(collection, function (matches, val, key) {
  175. return matches && matcher(val, key);
  176. }, true);
  177. }
  178. /**
  179. * Return true if some elements in the collection
  180. * match the criteria.
  181. *
  182. * @param {Object|Array} collection
  183. * @param {Function} matcher
  184. *
  185. * @return {Boolean}
  186. */
  187. function some(collection, matcher) {
  188. return !!find(collection, matcher);
  189. }
  190. /**
  191. * Transform a collection into another collection
  192. * by piping each member through the given fn.
  193. *
  194. * @param {Object|Array} collection
  195. * @param {Function} fn
  196. *
  197. * @return {Array} transformed collection
  198. */
  199. function map(collection, fn) {
  200. var result = [];
  201. forEach(collection, function (val, key) {
  202. result.push(fn(val, key));
  203. });
  204. return result;
  205. }
  206. /**
  207. * Create an object pattern matcher.
  208. *
  209. * @example
  210. *
  211. * const matcher = matchPattern({ id: 1 });
  212. *
  213. * var element = find(elements, matcher);
  214. *
  215. * @param {Object} pattern
  216. *
  217. * @return {Function} matcherFn
  218. */
  219. function matchPattern(pattern) {
  220. return function (el) {
  221. return every(pattern, function (val, key) {
  222. return el[key] === val;
  223. });
  224. };
  225. }
  226. function toMatcher(matcher) {
  227. return isFunction(matcher) ? matcher : function (e) {
  228. return e === matcher;
  229. };
  230. }
  231. function identity(arg) {
  232. return arg;
  233. }
  234. function toNum(arg) {
  235. return Number(arg);
  236. }
  237. /**
  238. * Debounce fn, calling it only once if
  239. * the given time elapsed between calls.
  240. *
  241. * @param {Function} fn
  242. * @param {Number} timeout
  243. *
  244. * @return {Function} debounced function
  245. */
  246. function debounce(fn, timeout) {
  247. var timer;
  248. var lastArgs;
  249. var lastThis;
  250. var lastNow;
  251. function fire() {
  252. var now = Date.now();
  253. var scheduledDiff = lastNow + timeout - now;
  254. if (scheduledDiff > 0) {
  255. return schedule(scheduledDiff);
  256. }
  257. fn.apply(lastThis, lastArgs);
  258. timer = lastNow = lastArgs = lastThis = undefined;
  259. }
  260. function schedule(timeout) {
  261. timer = setTimeout(fire, timeout);
  262. }
  263. return function () {
  264. lastNow = Date.now();
  265. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  266. args[_key] = arguments[_key];
  267. }
  268. lastArgs = args;
  269. lastThis = this; // ensure an execution is scheduled
  270. if (!timer) {
  271. schedule(timeout);
  272. }
  273. };
  274. }
  275. /**
  276. * Bind function against target <this>.
  277. *
  278. * @param {Function} fn
  279. * @param {Object} target
  280. *
  281. * @return {Function} bound function
  282. */
  283. function bind(fn, target) {
  284. return fn.bind(target);
  285. }
  286. function _extends() {
  287. _extends = Object.assign || function (target) {
  288. for (var i = 1; i < arguments.length; i++) {
  289. var source = arguments[i];
  290. for (var key in source) {
  291. if (Object.prototype.hasOwnProperty.call(source, key)) {
  292. target[key] = source[key];
  293. }
  294. }
  295. }
  296. return target;
  297. };
  298. return _extends.apply(this, arguments);
  299. }
  300. /**
  301. * Convenience wrapper for `Object.assign`.
  302. *
  303. * @param {Object} target
  304. * @param {...Object} others
  305. *
  306. * @return {Object} the target
  307. */
  308. function assign(target) {
  309. for (var _len = arguments.length, others = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  310. others[_key - 1] = arguments[_key];
  311. }
  312. return _extends.apply(void 0, [target].concat(others));
  313. }
  314. /**
  315. * Pick given properties from the target object.
  316. *
  317. * @param {Object} target
  318. * @param {Array} properties
  319. *
  320. * @return {Object} target
  321. */
  322. function pick(target, properties) {
  323. var result = {};
  324. var obj = Object(target);
  325. forEach(properties, function (prop) {
  326. if (prop in obj) {
  327. result[prop] = target[prop];
  328. }
  329. });
  330. return result;
  331. }
  332. /**
  333. * Pick all target properties, excluding the given ones.
  334. *
  335. * @param {Object} target
  336. * @param {Array} properties
  337. *
  338. * @return {Object} target
  339. */
  340. function omit(target, properties) {
  341. var result = {};
  342. var obj = Object(target);
  343. forEach(obj, function (prop, key) {
  344. if (properties.indexOf(key) === -1) {
  345. result[key] = prop;
  346. }
  347. });
  348. return result;
  349. }
  350. var DEFAULT_RENDER_PRIORITY = 1000;
  351. /**
  352. * The base implementation of shape and connection renderers.
  353. *
  354. * @param {EventBus} eventBus
  355. * @param {number} [renderPriority=1000]
  356. */
  357. function BaseRenderer(eventBus, renderPriority) {
  358. var self = this;
  359. renderPriority = renderPriority || DEFAULT_RENDER_PRIORITY;
  360. eventBus.on([ 'render.shape', 'render.connection' ], renderPriority, function(evt, context) {
  361. var type = evt.type,
  362. element = context.element,
  363. visuals = context.gfx;
  364. if (self.canRender(element)) {
  365. if (type === 'render.shape') {
  366. return self.drawShape(visuals, element);
  367. } else {
  368. return self.drawConnection(visuals, element);
  369. }
  370. }
  371. });
  372. eventBus.on([ 'render.getShapePath', 'render.getConnectionPath'], renderPriority, function(evt, element) {
  373. if (self.canRender(element)) {
  374. if (evt.type === 'render.getShapePath') {
  375. return self.getShapePath(element);
  376. } else {
  377. return self.getConnectionPath(element);
  378. }
  379. }
  380. });
  381. }
  382. /**
  383. * Should check whether *this* renderer can render
  384. * the element/connection.
  385. *
  386. * @param {element} element
  387. *
  388. * @returns {boolean}
  389. */
  390. BaseRenderer.prototype.canRender = function() {};
  391. /**
  392. * Provides the shape's snap svg element to be drawn on the `canvas`.
  393. *
  394. * @param {djs.Graphics} visuals
  395. * @param {Shape} shape
  396. *
  397. * @returns {Snap.svg} [returns a Snap.svg paper element ]
  398. */
  399. BaseRenderer.prototype.drawShape = function() {};
  400. /**
  401. * Provides the shape's snap svg element to be drawn on the `canvas`.
  402. *
  403. * @param {djs.Graphics} visuals
  404. * @param {Connection} connection
  405. *
  406. * @returns {Snap.svg} [returns a Snap.svg paper element ]
  407. */
  408. BaseRenderer.prototype.drawConnection = function() {};
  409. /**
  410. * Gets the SVG path of a shape that represents it's visual bounds.
  411. *
  412. * @param {Shape} shape
  413. *
  414. * @return {string} svg path
  415. */
  416. BaseRenderer.prototype.getShapePath = function() {};
  417. /**
  418. * Gets the SVG path of a connection that represents it's visual bounds.
  419. *
  420. * @param {Connection} connection
  421. *
  422. * @return {string} svg path
  423. */
  424. BaseRenderer.prototype.getConnectionPath = function() {};
  425. /**
  426. * Is an element of the given BPMN type?
  427. *
  428. * @param {djs.model.Base|ModdleElement} element
  429. * @param {string} type
  430. *
  431. * @return {boolean}
  432. */
  433. function is(element, type) {
  434. var bo = getBusinessObject(element);
  435. return bo && (typeof bo.$instanceOf === 'function') && bo.$instanceOf(type);
  436. }
  437. /**
  438. * Return the business object for a given element.
  439. *
  440. * @param {djs.model.Base|ModdleElement} element
  441. *
  442. * @return {ModdleElement}
  443. */
  444. function getBusinessObject(element) {
  445. return (element && element.businessObject) || element;
  446. }
  447. function isExpanded(element) {
  448. if (is(element, 'bpmn:CallActivity')) {
  449. return false;
  450. }
  451. if (is(element, 'bpmn:SubProcess')) {
  452. return !!getBusinessObject(element).di.isExpanded;
  453. }
  454. if (is(element, 'bpmn:Participant')) {
  455. return !!getBusinessObject(element).processRef;
  456. }
  457. return true;
  458. }
  459. function isEventSubProcess(element) {
  460. return element && !!getBusinessObject(element).triggeredByEvent;
  461. }
  462. function getLabelAttr(semantic) {
  463. if (
  464. is(semantic, 'bpmn:FlowElement') ||
  465. is(semantic, 'bpmn:Participant') ||
  466. is(semantic, 'bpmn:Lane') ||
  467. is(semantic, 'bpmn:SequenceFlow') ||
  468. is(semantic, 'bpmn:MessageFlow') ||
  469. is(semantic, 'bpmn:DataInput') ||
  470. is(semantic, 'bpmn:DataOutput')
  471. ) {
  472. return 'name';
  473. }
  474. if (is(semantic, 'bpmn:TextAnnotation')) {
  475. return 'text';
  476. }
  477. if (is(semantic, 'bpmn:Group')) {
  478. return 'categoryValueRef';
  479. }
  480. }
  481. function getCategoryValue(semantic) {
  482. var categoryValueRef = semantic['categoryValueRef'];
  483. if (!categoryValueRef) {
  484. return '';
  485. }
  486. return categoryValueRef.value || '';
  487. }
  488. function getLabel(element) {
  489. var semantic = element.businessObject,
  490. attr = getLabelAttr(semantic);
  491. if (attr) {
  492. if (attr === 'categoryValueRef') {
  493. return getCategoryValue(semantic);
  494. }
  495. return semantic[attr] || '';
  496. }
  497. }
  498. function ensureImported(element, target) {
  499. if (element.ownerDocument !== target.ownerDocument) {
  500. try {
  501. // may fail on webkit
  502. return target.ownerDocument.importNode(element, true);
  503. } catch (e) {
  504. // ignore
  505. }
  506. }
  507. return element;
  508. }
  509. /**
  510. * appendTo utility
  511. */
  512. /**
  513. * Append a node to a target element and return the appended node.
  514. *
  515. * @param {SVGElement} element
  516. * @param {SVGElement} target
  517. *
  518. * @return {SVGElement} the appended node
  519. */
  520. function appendTo(element, target) {
  521. return target.appendChild(ensureImported(element, target));
  522. }
  523. /**
  524. * append utility
  525. */
  526. /**
  527. * Append a node to an element
  528. *
  529. * @param {SVGElement} element
  530. * @param {SVGElement} node
  531. *
  532. * @return {SVGElement} the element
  533. */
  534. function append(target, node) {
  535. appendTo(node, target);
  536. return target;
  537. }
  538. /**
  539. * attribute accessor utility
  540. */
  541. var LENGTH_ATTR = 2;
  542. var CSS_PROPERTIES = {
  543. 'alignment-baseline': 1,
  544. 'baseline-shift': 1,
  545. 'clip': 1,
  546. 'clip-path': 1,
  547. 'clip-rule': 1,
  548. 'color': 1,
  549. 'color-interpolation': 1,
  550. 'color-interpolation-filters': 1,
  551. 'color-profile': 1,
  552. 'color-rendering': 1,
  553. 'cursor': 1,
  554. 'direction': 1,
  555. 'display': 1,
  556. 'dominant-baseline': 1,
  557. 'enable-background': 1,
  558. 'fill': 1,
  559. 'fill-opacity': 1,
  560. 'fill-rule': 1,
  561. 'filter': 1,
  562. 'flood-color': 1,
  563. 'flood-opacity': 1,
  564. 'font': 1,
  565. 'font-family': 1,
  566. 'font-size': LENGTH_ATTR,
  567. 'font-size-adjust': 1,
  568. 'font-stretch': 1,
  569. 'font-style': 1,
  570. 'font-variant': 1,
  571. 'font-weight': 1,
  572. 'glyph-orientation-horizontal': 1,
  573. 'glyph-orientation-vertical': 1,
  574. 'image-rendering': 1,
  575. 'kerning': 1,
  576. 'letter-spacing': 1,
  577. 'lighting-color': 1,
  578. 'marker': 1,
  579. 'marker-end': 1,
  580. 'marker-mid': 1,
  581. 'marker-start': 1,
  582. 'mask': 1,
  583. 'opacity': 1,
  584. 'overflow': 1,
  585. 'pointer-events': 1,
  586. 'shape-rendering': 1,
  587. 'stop-color': 1,
  588. 'stop-opacity': 1,
  589. 'stroke': 1,
  590. 'stroke-dasharray': 1,
  591. 'stroke-dashoffset': 1,
  592. 'stroke-linecap': 1,
  593. 'stroke-linejoin': 1,
  594. 'stroke-miterlimit': 1,
  595. 'stroke-opacity': 1,
  596. 'stroke-width': LENGTH_ATTR,
  597. 'text-anchor': 1,
  598. 'text-decoration': 1,
  599. 'text-rendering': 1,
  600. 'unicode-bidi': 1,
  601. 'visibility': 1,
  602. 'word-spacing': 1,
  603. 'writing-mode': 1
  604. };
  605. function getAttribute(node, name) {
  606. if (CSS_PROPERTIES[name]) {
  607. return node.style[name];
  608. } else {
  609. return node.getAttributeNS(null, name);
  610. }
  611. }
  612. function setAttribute(node, name, value) {
  613. var hyphenated = name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  614. var type = CSS_PROPERTIES[hyphenated];
  615. if (type) {
  616. // append pixel unit, unless present
  617. if (type === LENGTH_ATTR && typeof value === 'number') {
  618. value = String(value) + 'px';
  619. }
  620. node.style[hyphenated] = value;
  621. } else {
  622. node.setAttributeNS(null, name, value);
  623. }
  624. }
  625. function setAttributes(node, attrs) {
  626. var names = Object.keys(attrs), i, name;
  627. for (i = 0, name; (name = names[i]); i++) {
  628. setAttribute(node, name, attrs[name]);
  629. }
  630. }
  631. /**
  632. * Gets or sets raw attributes on a node.
  633. *
  634. * @param {SVGElement} node
  635. * @param {Object} [attrs]
  636. * @param {String} [name]
  637. * @param {String} [value]
  638. *
  639. * @return {String}
  640. */
  641. function attr(node, name, value) {
  642. if (typeof name === 'string') {
  643. if (value !== undefined) {
  644. setAttribute(node, name, value);
  645. } else {
  646. return getAttribute(node, name);
  647. }
  648. } else {
  649. setAttributes(node, name);
  650. }
  651. return node;
  652. }
  653. /**
  654. * Clear utility
  655. */
  656. function index(arr, obj) {
  657. if (arr.indexOf) {
  658. return arr.indexOf(obj);
  659. }
  660. for (var i = 0; i < arr.length; ++i) {
  661. if (arr[i] === obj) {
  662. return i;
  663. }
  664. }
  665. return -1;
  666. }
  667. var re = /\s+/;
  668. var toString = Object.prototype.toString;
  669. function defined(o) {
  670. return typeof o !== 'undefined';
  671. }
  672. /**
  673. * Wrap `el` in a `ClassList`.
  674. *
  675. * @param {Element} el
  676. * @return {ClassList}
  677. * @api public
  678. */
  679. function classes(el) {
  680. return new ClassList(el);
  681. }
  682. function ClassList(el) {
  683. if (!el || !el.nodeType) {
  684. throw new Error('A DOM element reference is required');
  685. }
  686. this.el = el;
  687. this.list = el.classList;
  688. }
  689. /**
  690. * Add class `name` if not already present.
  691. *
  692. * @param {String} name
  693. * @return {ClassList}
  694. * @api public
  695. */
  696. ClassList.prototype.add = function(name) {
  697. // classList
  698. if (this.list) {
  699. this.list.add(name);
  700. return this;
  701. }
  702. // fallback
  703. var arr = this.array();
  704. var i = index(arr, name);
  705. if (!~i) {
  706. arr.push(name);
  707. }
  708. if (defined(this.el.className.baseVal)) {
  709. this.el.className.baseVal = arr.join(' ');
  710. } else {
  711. this.el.className = arr.join(' ');
  712. }
  713. return this;
  714. };
  715. /**
  716. * Remove class `name` when present, or
  717. * pass a regular expression to remove
  718. * any which match.
  719. *
  720. * @param {String|RegExp} name
  721. * @return {ClassList}
  722. * @api public
  723. */
  724. ClassList.prototype.remove = function(name) {
  725. if ('[object RegExp]' === toString.call(name)) {
  726. return this.removeMatching(name);
  727. }
  728. // classList
  729. if (this.list) {
  730. this.list.remove(name);
  731. return this;
  732. }
  733. // fallback
  734. var arr = this.array();
  735. var i = index(arr, name);
  736. if (~i) {
  737. arr.splice(i, 1);
  738. }
  739. this.el.className.baseVal = arr.join(' ');
  740. return this;
  741. };
  742. /**
  743. * Remove all classes matching `re`.
  744. *
  745. * @param {RegExp} re
  746. * @return {ClassList}
  747. * @api private
  748. */
  749. ClassList.prototype.removeMatching = function(re) {
  750. var arr = this.array();
  751. for (var i = 0; i < arr.length; i++) {
  752. if (re.test(arr[i])) {
  753. this.remove(arr[i]);
  754. }
  755. }
  756. return this;
  757. };
  758. /**
  759. * Toggle class `name`, can force state via `force`.
  760. *
  761. * For browsers that support classList, but do not support `force` yet,
  762. * the mistake will be detected and corrected.
  763. *
  764. * @param {String} name
  765. * @param {Boolean} force
  766. * @return {ClassList}
  767. * @api public
  768. */
  769. ClassList.prototype.toggle = function(name, force) {
  770. // classList
  771. if (this.list) {
  772. if (defined(force)) {
  773. if (force !== this.list.toggle(name, force)) {
  774. this.list.toggle(name); // toggle again to correct
  775. }
  776. } else {
  777. this.list.toggle(name);
  778. }
  779. return this;
  780. }
  781. // fallback
  782. if (defined(force)) {
  783. if (!force) {
  784. this.remove(name);
  785. } else {
  786. this.add(name);
  787. }
  788. } else {
  789. if (this.has(name)) {
  790. this.remove(name);
  791. } else {
  792. this.add(name);
  793. }
  794. }
  795. return this;
  796. };
  797. /**
  798. * Return an array of classes.
  799. *
  800. * @return {Array}
  801. * @api public
  802. */
  803. ClassList.prototype.array = function() {
  804. var className = this.el.getAttribute('class') || '';
  805. var str = className.replace(/^\s+|\s+$/g, '');
  806. var arr = str.split(re);
  807. if ('' === arr[0]) {
  808. arr.shift();
  809. }
  810. return arr;
  811. };
  812. /**
  813. * Check if class `name` is present.
  814. *
  815. * @param {String} name
  816. * @return {ClassList}
  817. * @api public
  818. */
  819. ClassList.prototype.has =
  820. ClassList.prototype.contains = function(name) {
  821. return (
  822. this.list ?
  823. this.list.contains(name) :
  824. !! ~index(this.array(), name)
  825. );
  826. };
  827. function remove(element) {
  828. var parent = element.parentNode;
  829. if (parent) {
  830. parent.removeChild(element);
  831. }
  832. return element;
  833. }
  834. /**
  835. * Clear utility
  836. */
  837. /**
  838. * Removes all children from the given element
  839. *
  840. * @param {DOMElement} element
  841. * @return {DOMElement} the element (for chaining)
  842. */
  843. function clear(element) {
  844. var child;
  845. while ((child = element.firstChild)) {
  846. remove(child);
  847. }
  848. return element;
  849. }
  850. var ns = {
  851. svg: 'http://www.w3.org/2000/svg'
  852. };
  853. /**
  854. * DOM parsing utility
  855. */
  856. var SVG_START = '<svg xmlns="' + ns.svg + '"';
  857. function parse(svg) {
  858. var unwrap = false;
  859. // ensure we import a valid svg document
  860. if (svg.substring(0, 4) === '<svg') {
  861. if (svg.indexOf(ns.svg) === -1) {
  862. svg = SVG_START + svg.substring(4);
  863. }
  864. } else {
  865. // namespace svg
  866. svg = SVG_START + '>' + svg + '</svg>';
  867. unwrap = true;
  868. }
  869. var parsed = parseDocument(svg);
  870. if (!unwrap) {
  871. return parsed;
  872. }
  873. var fragment = document.createDocumentFragment();
  874. var parent = parsed.firstChild;
  875. while (parent.firstChild) {
  876. fragment.appendChild(parent.firstChild);
  877. }
  878. return fragment;
  879. }
  880. function parseDocument(svg) {
  881. var parser;
  882. // parse
  883. parser = new DOMParser();
  884. parser.async = false;
  885. return parser.parseFromString(svg, 'text/xml');
  886. }
  887. /**
  888. * Create utility for SVG elements
  889. */
  890. /**
  891. * Create a specific type from name or SVG markup.
  892. *
  893. * @param {String} name the name or markup of the element
  894. * @param {Object} [attrs] attributes to set on the element
  895. *
  896. * @returns {SVGElement}
  897. */
  898. function create(name, attrs) {
  899. var element;
  900. if (name.charAt(0) === '<') {
  901. element = parse(name).firstChild;
  902. element = document.importNode(element, true);
  903. } else {
  904. element = document.createElementNS(ns.svg, name);
  905. }
  906. if (attrs) {
  907. attr(element, attrs);
  908. }
  909. return element;
  910. }
  911. /**
  912. * Geometry helpers
  913. */
  914. // fake node used to instantiate svg geometry elements
  915. var node = create('svg');
  916. function extend(object, props) {
  917. var i, k, keys = Object.keys(props);
  918. for (i = 0; (k = keys[i]); i++) {
  919. object[k] = props[k];
  920. }
  921. return object;
  922. }
  923. /**
  924. * Create matrix via args.
  925. *
  926. * @example
  927. *
  928. * createMatrix({ a: 1, b: 1 });
  929. * createMatrix();
  930. * createMatrix(1, 2, 0, 0, 30, 20);
  931. *
  932. * @return {SVGMatrix}
  933. */
  934. function createMatrix(a, b, c, d, e, f) {
  935. var matrix = node.createSVGMatrix();
  936. switch (arguments.length) {
  937. case 0:
  938. return matrix;
  939. case 1:
  940. return extend(matrix, a);
  941. case 6:
  942. return extend(matrix, {
  943. a: a,
  944. b: b,
  945. c: c,
  946. d: d,
  947. e: e,
  948. f: f
  949. });
  950. }
  951. }
  952. function createTransform(matrix) {
  953. if (matrix) {
  954. return node.createSVGTransformFromMatrix(matrix);
  955. } else {
  956. return node.createSVGTransform();
  957. }
  958. }
  959. /**
  960. * Serialization util
  961. */
  962. var TEXT_ENTITIES = /([&<>]{1})/g;
  963. var ATTR_ENTITIES = /([\n\r"]{1})/g;
  964. var ENTITY_REPLACEMENT = {
  965. '&': '&amp;',
  966. '<': '&lt;',
  967. '>': '&gt;',
  968. '"': '\''
  969. };
  970. function escape(str, pattern) {
  971. function replaceFn(match, entity) {
  972. return ENTITY_REPLACEMENT[entity] || entity;
  973. }
  974. return str.replace(pattern, replaceFn);
  975. }
  976. function serialize(node, output) {
  977. var i, len, attrMap, attrNode, childNodes;
  978. switch (node.nodeType) {
  979. // TEXT
  980. case 3:
  981. // replace special XML characters
  982. output.push(escape(node.textContent, TEXT_ENTITIES));
  983. break;
  984. // ELEMENT
  985. case 1:
  986. output.push('<', node.tagName);
  987. if (node.hasAttributes()) {
  988. attrMap = node.attributes;
  989. for (i = 0, len = attrMap.length; i < len; ++i) {
  990. attrNode = attrMap.item(i);
  991. output.push(' ', attrNode.name, '="', escape(attrNode.value, ATTR_ENTITIES), '"');
  992. }
  993. }
  994. if (node.hasChildNodes()) {
  995. output.push('>');
  996. childNodes = node.childNodes;
  997. for (i = 0, len = childNodes.length; i < len; ++i) {
  998. serialize(childNodes.item(i), output);
  999. }
  1000. output.push('</', node.tagName, '>');
  1001. } else {
  1002. output.push('/>');
  1003. }
  1004. break;
  1005. // COMMENT
  1006. case 8:
  1007. output.push('<!--', escape(node.nodeValue, TEXT_ENTITIES), '-->');
  1008. break;
  1009. // CDATA
  1010. case 4:
  1011. output.push('<![CDATA[', node.nodeValue, ']]>');
  1012. break;
  1013. default:
  1014. throw new Error('unable to handle node ' + node.nodeType);
  1015. }
  1016. return output;
  1017. }
  1018. /**
  1019. * innerHTML like functionality for SVG elements.
  1020. * based on innerSVG (https://code.google.com/p/innersvg)
  1021. */
  1022. function set(element, svg) {
  1023. var parsed = parse(svg);
  1024. // clear element contents
  1025. clear(element);
  1026. if (!svg) {
  1027. return;
  1028. }
  1029. if (!isFragment(parsed)) {
  1030. // extract <svg> from parsed document
  1031. parsed = parsed.documentElement;
  1032. }
  1033. var nodes = slice(parsed.childNodes);
  1034. // import + append each node
  1035. for (var i = 0; i < nodes.length; i++) {
  1036. appendTo(nodes[i], element);
  1037. }
  1038. }
  1039. function get(element) {
  1040. var child = element.firstChild,
  1041. output = [];
  1042. while (child) {
  1043. serialize(child, output);
  1044. child = child.nextSibling;
  1045. }
  1046. return output.join('');
  1047. }
  1048. function isFragment(node) {
  1049. return node.nodeName === '#document-fragment';
  1050. }
  1051. function innerSVG(element, svg) {
  1052. if (svg !== undefined) {
  1053. try {
  1054. set(element, svg);
  1055. } catch (e) {
  1056. throw new Error('error parsing SVG: ' + e.message);
  1057. }
  1058. return element;
  1059. } else {
  1060. return get(element);
  1061. }
  1062. }
  1063. function slice(arr) {
  1064. return Array.prototype.slice.call(arr);
  1065. }
  1066. /**
  1067. * transform accessor utility
  1068. */
  1069. function wrapMatrix(transformList, transform) {
  1070. if (transform instanceof SVGMatrix) {
  1071. return transformList.createSVGTransformFromMatrix(transform);
  1072. }
  1073. return transform;
  1074. }
  1075. function setTransforms(transformList, transforms) {
  1076. var i, t;
  1077. transformList.clear();
  1078. for (i = 0; (t = transforms[i]); i++) {
  1079. transformList.appendItem(wrapMatrix(transformList, t));
  1080. }
  1081. }
  1082. /**
  1083. * Get or set the transforms on the given node.
  1084. *
  1085. * @param {SVGElement} node
  1086. * @param {SVGTransform|SVGMatrix|Array<SVGTransform|SVGMatrix>} [transforms]
  1087. *
  1088. * @return {SVGTransform} the consolidated transform
  1089. */
  1090. function transform(node, transforms) {
  1091. var transformList = node.transform.baseVal;
  1092. if (transforms) {
  1093. if (!Array.isArray(transforms)) {
  1094. transforms = [ transforms ];
  1095. }
  1096. setTransforms(transformList, transforms);
  1097. }
  1098. return transformList.consolidate();
  1099. }
  1100. function componentsToPath(elements) {
  1101. return elements.join(',').replace(/,?([A-z]),?/g, '$1');
  1102. }
  1103. function toSVGPoints(points) {
  1104. var result = '';
  1105. for (var i = 0, p; (p = points[i]); i++) {
  1106. result += p.x + ',' + p.y + ' ';
  1107. }
  1108. return result;
  1109. }
  1110. function createLine(points, attrs) {
  1111. var line = create('polyline');
  1112. attr(line, { points: toSVGPoints(points) });
  1113. if (attrs) {
  1114. attr(line, attrs);
  1115. }
  1116. return line;
  1117. }
  1118. function updateLine(gfx, points) {
  1119. attr(gfx, { points: toSVGPoints(points) });
  1120. return gfx;
  1121. }
  1122. // element utils //////////////////////
  1123. /**
  1124. * Checks if eventDefinition of the given element matches with semantic type.
  1125. *
  1126. * @return {boolean} true if element is of the given semantic type
  1127. */
  1128. function isTypedEvent(event, eventDefinitionType, filter) {
  1129. function matches(definition, filter) {
  1130. return every(filter, function(val, key) {
  1131. // we want a == conversion here, to be able to catch
  1132. // undefined == false and friends
  1133. /* jshint -W116 */
  1134. return definition[key] == val;
  1135. });
  1136. }
  1137. return some(event.eventDefinitions, function(definition) {
  1138. return definition.$type === eventDefinitionType && matches(event, filter);
  1139. });
  1140. }
  1141. function isThrowEvent(event) {
  1142. return (event.$type === 'bpmn:IntermediateThrowEvent') || (event.$type === 'bpmn:EndEvent');
  1143. }
  1144. function isCollection(element) {
  1145. var dataObject = element.dataObjectRef;
  1146. return element.isCollection || (dataObject && dataObject.isCollection);
  1147. }
  1148. function getDi(element) {
  1149. return element.businessObject.di;
  1150. }
  1151. function getSemantic(element) {
  1152. return element.businessObject;
  1153. }
  1154. // color access //////////////////////
  1155. function getFillColor(element, defaultColor) {
  1156. return getDi(element).get('bioc:fill') || defaultColor || 'white';
  1157. }
  1158. function getStrokeColor(element, defaultColor) {
  1159. return getDi(element).get('bioc:stroke') || defaultColor || 'black';
  1160. }
  1161. // cropping path customizations //////////////////////
  1162. function getCirclePath(shape) {
  1163. var cx = shape.x + shape.width / 2,
  1164. cy = shape.y + shape.height / 2,
  1165. radius = shape.width / 2;
  1166. var circlePath = [
  1167. ['M', cx, cy],
  1168. ['m', 0, -radius],
  1169. ['a', radius, radius, 0, 1, 1, 0, 2 * radius],
  1170. ['a', radius, radius, 0, 1, 1, 0, -2 * radius],
  1171. ['z']
  1172. ];
  1173. return componentsToPath(circlePath);
  1174. }
  1175. function getRoundRectPath(shape, borderRadius) {
  1176. var x = shape.x,
  1177. y = shape.y,
  1178. width = shape.width,
  1179. height = shape.height;
  1180. var roundRectPath = [
  1181. ['M', x + borderRadius, y],
  1182. ['l', width - borderRadius * 2, 0],
  1183. ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, borderRadius],
  1184. ['l', 0, height - borderRadius * 2],
  1185. ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, borderRadius],
  1186. ['l', borderRadius * 2 - width, 0],
  1187. ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, -borderRadius],
  1188. ['l', 0, borderRadius * 2 - height],
  1189. ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, -borderRadius],
  1190. ['z']
  1191. ];
  1192. return componentsToPath(roundRectPath);
  1193. }
  1194. function getDiamondPath(shape) {
  1195. var width = shape.width,
  1196. height = shape.height,
  1197. x = shape.x,
  1198. y = shape.y,
  1199. halfWidth = width / 2,
  1200. halfHeight = height / 2;
  1201. var diamondPath = [
  1202. ['M', x + halfWidth, y],
  1203. ['l', halfWidth, halfHeight],
  1204. ['l', -halfWidth, halfHeight],
  1205. ['l', -halfWidth, -halfHeight],
  1206. ['z']
  1207. ];
  1208. return componentsToPath(diamondPath);
  1209. }
  1210. function getRectPath(shape) {
  1211. var x = shape.x,
  1212. y = shape.y,
  1213. width = shape.width,
  1214. height = shape.height;
  1215. var rectPath = [
  1216. ['M', x, y],
  1217. ['l', width, 0],
  1218. ['l', 0, height],
  1219. ['l', -width, 0],
  1220. ['z']
  1221. ];
  1222. return componentsToPath(rectPath);
  1223. }
  1224. /**
  1225. * Set attribute `name` to `val`, or get attr `name`.
  1226. *
  1227. * @param {Element} el
  1228. * @param {String} name
  1229. * @param {String} [val]
  1230. * @api public
  1231. */
  1232. function attr$1(el, name, val) {
  1233. // get
  1234. if (arguments.length == 2) {
  1235. return el.getAttribute(name);
  1236. }
  1237. // remove
  1238. if (val === null) {
  1239. return el.removeAttribute(name);
  1240. }
  1241. // set
  1242. el.setAttribute(name, val);
  1243. return el;
  1244. }
  1245. var indexOf = [].indexOf;
  1246. var indexof = function(arr, obj){
  1247. if (indexOf) return arr.indexOf(obj);
  1248. for (var i = 0; i < arr.length; ++i) {
  1249. if (arr[i] === obj) return i;
  1250. }
  1251. return -1;
  1252. };
  1253. /**
  1254. * Taken from https://github.com/component/classes
  1255. *
  1256. * Without the component bits.
  1257. */
  1258. /**
  1259. * Whitespace regexp.
  1260. */
  1261. var re$1 = /\s+/;
  1262. /**
  1263. * toString reference.
  1264. */
  1265. var toString$1 = Object.prototype.toString;
  1266. /**
  1267. * Wrap `el` in a `ClassList`.
  1268. *
  1269. * @param {Element} el
  1270. * @return {ClassList}
  1271. * @api public
  1272. */
  1273. function classes$1(el) {
  1274. return new ClassList$1(el);
  1275. }
  1276. /**
  1277. * Initialize a new ClassList for `el`.
  1278. *
  1279. * @param {Element} el
  1280. * @api private
  1281. */
  1282. function ClassList$1(el) {
  1283. if (!el || !el.nodeType) {
  1284. throw new Error('A DOM element reference is required');
  1285. }
  1286. this.el = el;
  1287. this.list = el.classList;
  1288. }
  1289. /**
  1290. * Add class `name` if not already present.
  1291. *
  1292. * @param {String} name
  1293. * @return {ClassList}
  1294. * @api public
  1295. */
  1296. ClassList$1.prototype.add = function (name) {
  1297. // classList
  1298. if (this.list) {
  1299. this.list.add(name);
  1300. return this;
  1301. }
  1302. // fallback
  1303. var arr = this.array();
  1304. var i = indexof(arr, name);
  1305. if (!~i) arr.push(name);
  1306. this.el.className = arr.join(' ');
  1307. return this;
  1308. };
  1309. /**
  1310. * Remove class `name` when present, or
  1311. * pass a regular expression to remove
  1312. * any which match.
  1313. *
  1314. * @param {String|RegExp} name
  1315. * @return {ClassList}
  1316. * @api public
  1317. */
  1318. ClassList$1.prototype.remove = function (name) {
  1319. if ('[object RegExp]' == toString$1.call(name)) {
  1320. return this.removeMatching(name);
  1321. }
  1322. // classList
  1323. if (this.list) {
  1324. this.list.remove(name);
  1325. return this;
  1326. }
  1327. // fallback
  1328. var arr = this.array();
  1329. var i = indexof(arr, name);
  1330. if (~i) arr.splice(i, 1);
  1331. this.el.className = arr.join(' ');
  1332. return this;
  1333. };
  1334. /**
  1335. * Remove all classes matching `re`.
  1336. *
  1337. * @param {RegExp} re
  1338. * @return {ClassList}
  1339. * @api private
  1340. */
  1341. ClassList$1.prototype.removeMatching = function (re) {
  1342. var arr = this.array();
  1343. for (var i = 0; i < arr.length; i++) {
  1344. if (re.test(arr[i])) {
  1345. this.remove(arr[i]);
  1346. }
  1347. }
  1348. return this;
  1349. };
  1350. /**
  1351. * Toggle class `name`, can force state via `force`.
  1352. *
  1353. * For browsers that support classList, but do not support `force` yet,
  1354. * the mistake will be detected and corrected.
  1355. *
  1356. * @param {String} name
  1357. * @param {Boolean} force
  1358. * @return {ClassList}
  1359. * @api public
  1360. */
  1361. ClassList$1.prototype.toggle = function (name, force) {
  1362. // classList
  1363. if (this.list) {
  1364. if ('undefined' !== typeof force) {
  1365. if (force !== this.list.toggle(name, force)) {
  1366. this.list.toggle(name); // toggle again to correct
  1367. }
  1368. } else {
  1369. this.list.toggle(name);
  1370. }
  1371. return this;
  1372. }
  1373. // fallback
  1374. if ('undefined' !== typeof force) {
  1375. if (!force) {
  1376. this.remove(name);
  1377. } else {
  1378. this.add(name);
  1379. }
  1380. } else {
  1381. if (this.has(name)) {
  1382. this.remove(name);
  1383. } else {
  1384. this.add(name);
  1385. }
  1386. }
  1387. return this;
  1388. };
  1389. /**
  1390. * Return an array of classes.
  1391. *
  1392. * @return {Array}
  1393. * @api public
  1394. */
  1395. ClassList$1.prototype.array = function () {
  1396. var className = this.el.getAttribute('class') || '';
  1397. var str = className.replace(/^\s+|\s+$/g, '');
  1398. var arr = str.split(re$1);
  1399. if ('' === arr[0]) arr.shift();
  1400. return arr;
  1401. };
  1402. /**
  1403. * Check if class `name` is present.
  1404. *
  1405. * @param {String} name
  1406. * @return {ClassList}
  1407. * @api public
  1408. */
  1409. ClassList$1.prototype.has = ClassList$1.prototype.contains = function (name) {
  1410. return this.list ? this.list.contains(name) : !!~indexof(this.array(), name);
  1411. };
  1412. /**
  1413. * Remove all children from the given element.
  1414. */
  1415. function clear$1(el) {
  1416. var c;
  1417. while (el.childNodes.length) {
  1418. c = el.childNodes[0];
  1419. el.removeChild(c);
  1420. }
  1421. return el;
  1422. }
  1423. var proto = typeof Element !== 'undefined' ? Element.prototype : {};
  1424. var vendor = proto.matches
  1425. || proto.matchesSelector
  1426. || proto.webkitMatchesSelector
  1427. || proto.mozMatchesSelector
  1428. || proto.msMatchesSelector
  1429. || proto.oMatchesSelector;
  1430. /**
  1431. * Element prototype.
  1432. */
  1433. var proto$1 = Element.prototype;
  1434. /**
  1435. * Vendor function.
  1436. */
  1437. var vendor$1 = proto$1.matchesSelector
  1438. || proto$1.webkitMatchesSelector
  1439. || proto$1.mozMatchesSelector
  1440. || proto$1.msMatchesSelector
  1441. || proto$1.oMatchesSelector;
  1442. /**
  1443. * Expose `match()`.
  1444. */
  1445. var matchesSelector$1 = match$1;
  1446. /**
  1447. * Match `el` to `selector`.
  1448. *
  1449. * @param {Element} el
  1450. * @param {String} selector
  1451. * @return {Boolean}
  1452. * @api public
  1453. */
  1454. function match$1(el, selector) {
  1455. if (vendor$1) return vendor$1.call(el, selector);
  1456. var nodes = el.parentNode.querySelectorAll(selector);
  1457. for (var i = 0; i < nodes.length; ++i) {
  1458. if (nodes[i] == el) return true;
  1459. }
  1460. return false;
  1461. }
  1462. var closest$1 = function (element, selector, checkYoSelf) {
  1463. var parent = checkYoSelf ? element : element.parentNode;
  1464. while (parent && parent !== document) {
  1465. if (matchesSelector$1(parent, selector)) return parent;
  1466. parent = parent.parentNode;
  1467. }
  1468. };
  1469. var bind$1 = window.addEventListener ? 'addEventListener' : 'attachEvent',
  1470. unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
  1471. prefix = bind$1 !== 'addEventListener' ? 'on' : '';
  1472. /**
  1473. * Bind `el` event `type` to `fn`.
  1474. *
  1475. * @param {Element} el
  1476. * @param {String} type
  1477. * @param {Function} fn
  1478. * @param {Boolean} capture
  1479. * @return {Function}
  1480. * @api public
  1481. */
  1482. var bind_1 = function(el, type, fn, capture){
  1483. el[bind$1](prefix + type, fn, capture || false);
  1484. return fn;
  1485. };
  1486. /**
  1487. * Unbind `el` event `type`'s callback `fn`.
  1488. *
  1489. * @param {Element} el
  1490. * @param {String} type
  1491. * @param {Function} fn
  1492. * @param {Boolean} capture
  1493. * @return {Function}
  1494. * @api public
  1495. */
  1496. var unbind_1 = function(el, type, fn, capture){
  1497. el[unbind](prefix + type, fn, capture || false);
  1498. return fn;
  1499. };
  1500. var componentEvent = {
  1501. bind: bind_1,
  1502. unbind: unbind_1
  1503. };
  1504. /**
  1505. * Module dependencies.
  1506. */
  1507. /**
  1508. * Delegate event `type` to `selector`
  1509. * and invoke `fn(e)`. A callback function
  1510. * is returned which may be passed to `.unbind()`.
  1511. *
  1512. * @param {Element} el
  1513. * @param {String} selector
  1514. * @param {String} type
  1515. * @param {Function} fn
  1516. * @param {Boolean} capture
  1517. * @return {Function}
  1518. * @api public
  1519. */
  1520. // Some events don't bubble, so we want to bind to the capture phase instead
  1521. // when delegating.
  1522. var forceCaptureEvents = ['focus', 'blur'];
  1523. var bind$1$1 = function(el, selector, type, fn, capture){
  1524. if (forceCaptureEvents.indexOf(type) !== -1) capture = true;
  1525. return componentEvent.bind(el, type, function(e){
  1526. var target = e.target || e.srcElement;
  1527. e.delegateTarget = closest$1(target, selector, true);
  1528. if (e.delegateTarget) fn.call(el, e);
  1529. }, capture);
  1530. };
  1531. /**
  1532. * Unbind event `type`'s callback `fn`.
  1533. *
  1534. * @param {Element} el
  1535. * @param {String} type
  1536. * @param {Function} fn
  1537. * @param {Boolean} capture
  1538. * @api public
  1539. */
  1540. var unbind$1 = function(el, type, fn, capture){
  1541. if (forceCaptureEvents.indexOf(type) !== -1) capture = true;
  1542. componentEvent.unbind(el, type, fn, capture);
  1543. };
  1544. var delegateEvents = {
  1545. bind: bind$1$1,
  1546. unbind: unbind$1
  1547. };
  1548. /**
  1549. * Expose `parse`.
  1550. */
  1551. var domify = parse$1;
  1552. /**
  1553. * Tests for browser support.
  1554. */
  1555. var innerHTMLBug = false;
  1556. var bugTestDiv;
  1557. if (typeof document !== 'undefined') {
  1558. bugTestDiv = document.createElement('div');
  1559. // Setup
  1560. bugTestDiv.innerHTML = ' <link/><table></table><a href="/a">a</a><input type="checkbox"/>';
  1561. // Make sure that link elements get serialized correctly by innerHTML
  1562. // This requires a wrapper element in IE
  1563. innerHTMLBug = !bugTestDiv.getElementsByTagName('link').length;
  1564. bugTestDiv = undefined;
  1565. }
  1566. /**
  1567. * Wrap map from jquery.
  1568. */
  1569. var map$1 = {
  1570. legend: [1, '<fieldset>', '</fieldset>'],
  1571. tr: [2, '<table><tbody>', '</tbody></table>'],
  1572. col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
  1573. // for script/link/style tags to work in IE6-8, you have to wrap
  1574. // in a div with a non-whitespace character in front, ha!
  1575. _default: innerHTMLBug ? [1, 'X<div>', '</div>'] : [0, '', '']
  1576. };
  1577. map$1.td =
  1578. map$1.th = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
  1579. map$1.option =
  1580. map$1.optgroup = [1, '<select multiple="multiple">', '</select>'];
  1581. map$1.thead =
  1582. map$1.tbody =
  1583. map$1.colgroup =
  1584. map$1.caption =
  1585. map$1.tfoot = [1, '<table>', '</table>'];
  1586. map$1.polyline =
  1587. map$1.ellipse =
  1588. map$1.polygon =
  1589. map$1.circle =
  1590. map$1.text =
  1591. map$1.line =
  1592. map$1.path =
  1593. map$1.rect =
  1594. map$1.g = [1, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">','</svg>'];
  1595. /**
  1596. * Parse `html` and return a DOM Node instance, which could be a TextNode,
  1597. * HTML DOM Node of some kind (<div> for example), or a DocumentFragment
  1598. * instance, depending on the contents of the `html` string.
  1599. *
  1600. * @param {String} html - HTML string to "domify"
  1601. * @param {Document} doc - The `document` instance to create the Node for
  1602. * @return {DOMNode} the TextNode, DOM Node, or DocumentFragment instance
  1603. * @api private
  1604. */
  1605. function parse$1(html, doc) {
  1606. if ('string' != typeof html) throw new TypeError('String expected');
  1607. // default to the global `document` object
  1608. if (!doc) doc = document;
  1609. // tag name
  1610. var m = /<([\w:]+)/.exec(html);
  1611. if (!m) return doc.createTextNode(html);
  1612. html = html.replace(/^\s+|\s+$/g, ''); // Remove leading/trailing whitespace
  1613. var tag = m[1];
  1614. // body support
  1615. if (tag == 'body') {
  1616. var el = doc.createElement('html');
  1617. el.innerHTML = html;
  1618. return el.removeChild(el.lastChild);
  1619. }
  1620. // wrap map
  1621. var wrap = map$1[tag] || map$1._default;
  1622. var depth = wrap[0];
  1623. var prefix = wrap[1];
  1624. var suffix = wrap[2];
  1625. var el = doc.createElement('div');
  1626. el.innerHTML = prefix + html + suffix;
  1627. while (depth--) el = el.lastChild;
  1628. // one element
  1629. if (el.firstChild == el.lastChild) {
  1630. return el.removeChild(el.firstChild);
  1631. }
  1632. // several elements
  1633. var fragment = doc.createDocumentFragment();
  1634. while (el.firstChild) {
  1635. fragment.appendChild(el.removeChild(el.firstChild));
  1636. }
  1637. return fragment;
  1638. }
  1639. function query(selector, el) {
  1640. el = el || document;
  1641. return el.querySelector(selector);
  1642. }
  1643. function all(selector, el) {
  1644. el = el || document;
  1645. return el.querySelectorAll(selector);
  1646. }
  1647. function remove$1(el) {
  1648. el.parentNode && el.parentNode.removeChild(el);
  1649. }
  1650. /**
  1651. * @param {<SVGElement>} element
  1652. * @param {number} x
  1653. * @param {number} y
  1654. * @param {number} angle
  1655. * @param {number} amount
  1656. */
  1657. function transform$1(gfx, x, y, angle, amount) {
  1658. var translate = createTransform();
  1659. translate.setTranslate(x, y);
  1660. var rotate = createTransform();
  1661. rotate.setRotate(angle || 0, 0, 0);
  1662. var scale = createTransform();
  1663. scale.setScale(amount || 1, amount || 1);
  1664. transform(gfx, [ translate, rotate, scale ]);
  1665. }
  1666. /**
  1667. * @param {SVGElement} element
  1668. * @param {number} x
  1669. * @param {number} y
  1670. */
  1671. function translate(gfx, x, y) {
  1672. var translate = createTransform();
  1673. translate.setTranslate(x, y);
  1674. transform(gfx, translate);
  1675. }
  1676. /**
  1677. * @param {SVGElement} element
  1678. * @param {number} angle
  1679. */
  1680. function rotate(gfx, angle) {
  1681. var rotate = createTransform();
  1682. rotate.setRotate(angle, 0, 0);
  1683. transform(gfx, rotate);
  1684. }
  1685. function createCommonjsModule$1(fn, module) {
  1686. return module = { exports: {} }, fn(module, module.exports), module.exports;
  1687. }
  1688. var hat_1 = createCommonjsModule$1(function (module) {
  1689. var hat = module.exports = function (bits, base) {
  1690. if (!base) base = 16;
  1691. if (bits === undefined) bits = 128;
  1692. if (bits <= 0) return '0';
  1693. var digits = Math.log(Math.pow(2, bits)) / Math.log(base);
  1694. for (var i = 2; digits === Infinity; i *= 2) {
  1695. digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i;
  1696. }
  1697. var rem = digits - Math.floor(digits);
  1698. var res = '';
  1699. for (var i = 0; i < Math.floor(digits); i++) {
  1700. var x = Math.floor(Math.random() * base).toString(base);
  1701. res = x + res;
  1702. }
  1703. if (rem) {
  1704. var b = Math.pow(base, rem);
  1705. var x = Math.floor(Math.random() * b).toString(base);
  1706. res = x + res;
  1707. }
  1708. var parsed = parseInt(res, base);
  1709. if (parsed !== Infinity && parsed >= Math.pow(2, bits)) {
  1710. return hat(bits, base)
  1711. }
  1712. else return res;
  1713. };
  1714. hat.rack = function (bits, base, expandBy) {
  1715. var fn = function (data) {
  1716. var iters = 0;
  1717. do {
  1718. if (iters ++ > 10) {
  1719. if (expandBy) bits += expandBy;
  1720. else throw new Error('too many ID collisions, use more bits')
  1721. }
  1722. var id = hat(bits, base);
  1723. } while (Object.hasOwnProperty.call(hats, id));
  1724. hats[id] = data;
  1725. return id;
  1726. };
  1727. var hats = fn.hats = {};
  1728. fn.get = function (id) {
  1729. return fn.hats[id];
  1730. };
  1731. fn.set = function (id, value) {
  1732. fn.hats[id] = value;
  1733. return fn;
  1734. };
  1735. fn.bits = bits || 128;
  1736. fn.base = base || 16;
  1737. return fn;
  1738. };
  1739. });
  1740. /**
  1741. * Create a new id generator / cache instance.
  1742. *
  1743. * You may optionally provide a seed that is used internally.
  1744. *
  1745. * @param {Seed} seed
  1746. */
  1747. function Ids(seed) {
  1748. if (!(this instanceof Ids)) {
  1749. return new Ids(seed);
  1750. }
  1751. seed = seed || [128, 36, 1];
  1752. this._seed = seed.length ? hat_1.rack(seed[0], seed[1], seed[2]) : seed;
  1753. }
  1754. /**
  1755. * Generate a next id.
  1756. *
  1757. * @param {Object} [element] element to bind the id to
  1758. *
  1759. * @return {String} id
  1760. */
  1761. Ids.prototype.next = function (element) {
  1762. return this._seed(element || true);
  1763. };
  1764. /**
  1765. * Generate a next id with a given prefix.
  1766. *
  1767. * @param {Object} [element] element to bind the id to
  1768. *
  1769. * @return {String} id
  1770. */
  1771. Ids.prototype.nextPrefixed = function (prefix, element) {
  1772. var id;
  1773. do {
  1774. id = prefix + this.next(true);
  1775. } while (this.assigned(id)); // claim {prefix}{random}
  1776. this.claim(id, element); // return
  1777. return id;
  1778. };
  1779. /**
  1780. * Manually claim an existing id.
  1781. *
  1782. * @param {String} id
  1783. * @param {String} [element] element the id is claimed by
  1784. */
  1785. Ids.prototype.claim = function (id, element) {
  1786. this._seed.set(id, element || true);
  1787. };
  1788. /**
  1789. * Returns true if the given id has already been assigned.
  1790. *
  1791. * @param {String} id
  1792. * @return {Boolean}
  1793. */
  1794. Ids.prototype.assigned = function (id) {
  1795. return this._seed.get(id) || false;
  1796. };
  1797. /**
  1798. * Unclaim an id.
  1799. *
  1800. * @param {String} id the id to unclaim
  1801. */
  1802. Ids.prototype.unclaim = function (id) {
  1803. delete this._seed.hats[id];
  1804. };
  1805. /**
  1806. * Clear all claimed ids.
  1807. */
  1808. Ids.prototype.clear = function () {
  1809. var hats = this._seed.hats,
  1810. id;
  1811. for (id in hats) {
  1812. this.unclaim(id);
  1813. }
  1814. };
  1815. var RENDERER_IDS = new Ids();
  1816. var TASK_BORDER_RADIUS = 10;
  1817. var INNER_OUTER_DIST = 3;
  1818. var DEFAULT_FILL_OPACITY = .95,
  1819. HIGH_FILL_OPACITY = .35;
  1820. function BpmnRenderer(
  1821. config, eventBus, styles, pathMap,
  1822. canvas, textRenderer, priority) {
  1823. BaseRenderer.call(this, eventBus, priority);
  1824. var defaultFillColor = config && config.defaultFillColor,
  1825. defaultStrokeColor = config && config.defaultStrokeColor;
  1826. var rendererId = RENDERER_IDS.next();
  1827. var markers = {};
  1828. var computeStyle = styles.computeStyle;
  1829. function addMarker(id, options) {
  1830. var attrs = assign({
  1831. fill: 'black',
  1832. strokeWidth: 1,
  1833. strokeLinecap: 'round',
  1834. strokeDasharray: 'none'
  1835. }, options.attrs);
  1836. var ref = options.ref || { x: 0, y: 0 };
  1837. var scale = options.scale || 1;
  1838. // fix for safari / chrome / firefox bug not correctly
  1839. // resetting stroke dash array
  1840. if (attrs.strokeDasharray === 'none') {
  1841. attrs.strokeDasharray = [10000, 1];
  1842. }
  1843. var marker = create('marker');
  1844. attr(options.element, attrs);
  1845. append(marker, options.element);
  1846. attr(marker, {
  1847. id: id,
  1848. viewBox: '0 0 20 20',
  1849. refX: ref.x,
  1850. refY: ref.y,
  1851. markerWidth: 20 * scale,
  1852. markerHeight: 20 * scale,
  1853. orient: 'auto'
  1854. });
  1855. var defs = query('defs', canvas._svg);
  1856. if (!defs) {
  1857. defs = create('defs');
  1858. append(canvas._svg, defs);
  1859. }
  1860. append(defs, marker);
  1861. markers[id] = marker;
  1862. }
  1863. function colorEscape(str) {
  1864. // only allow characters and numbers
  1865. return str.replace(/[^0-9a-zA-z]+/g, '_');
  1866. }
  1867. function marker(type, fill, stroke) {
  1868. var id = type + '-' + colorEscape(fill) + '-' + colorEscape(stroke) + '-' + rendererId;
  1869. if (!markers[id]) {
  1870. createMarker(id, type, fill, stroke);
  1871. }
  1872. return 'url(#' + id + ')';
  1873. }
  1874. function createMarker(id, type, fill, stroke) {
  1875. if (type === 'sequenceflow-end') {
  1876. var sequenceflowEnd = create('path');
  1877. attr(sequenceflowEnd, { d: 'M 1 5 L 11 10 L 1 15 Z' });
  1878. addMarker(id, {
  1879. element: sequenceflowEnd,
  1880. ref: { x: 11, y: 10 },
  1881. scale: 0.5,
  1882. attrs: {
  1883. fill: stroke,
  1884. stroke: stroke
  1885. }
  1886. });
  1887. }
  1888. if (type === 'messageflow-start') {
  1889. var messageflowStart = create('circle');
  1890. attr(messageflowStart, { cx: 6, cy: 6, r: 3.5 });
  1891. addMarker(id, {
  1892. element: messageflowStart,
  1893. attrs: {
  1894. fill: fill,
  1895. stroke: stroke
  1896. },
  1897. ref: { x: 6, y: 6 }
  1898. });
  1899. }
  1900. if (type === 'messageflow-end') {
  1901. var messageflowEnd = create('path');
  1902. attr(messageflowEnd, { d: 'm 1 5 l 0 -3 l 7 3 l -7 3 z' });
  1903. addMarker(id, {
  1904. element: messageflowEnd,
  1905. attrs: {
  1906. fill: fill,
  1907. stroke: stroke,
  1908. strokeLinecap: 'butt'
  1909. },
  1910. ref: { x: 8.5, y: 5 }
  1911. });
  1912. }
  1913. if (type === 'association-start') {
  1914. var associationStart = create('path');
  1915. attr(associationStart, { d: 'M 11 5 L 1 10 L 11 15' });
  1916. addMarker(id, {
  1917. element: associationStart,
  1918. attrs: {
  1919. fill: 'none',
  1920. stroke: stroke,
  1921. strokeWidth: 1.5
  1922. },
  1923. ref: { x: 1, y: 10 },
  1924. scale: 0.5
  1925. });
  1926. }
  1927. if (type === 'association-end') {
  1928. var associationEnd = create('path');
  1929. attr(associationEnd, { d: 'M 1 5 L 11 10 L 1 15' });
  1930. addMarker(id, {
  1931. element: associationEnd,
  1932. attrs: {
  1933. fill: 'none',
  1934. stroke: stroke,
  1935. strokeWidth: 1.5
  1936. },
  1937. ref: { x: 12, y: 10 },
  1938. scale: 0.5
  1939. });
  1940. }
  1941. if (type === 'conditional-flow-marker') {
  1942. var conditionalflowMarker = create('path');
  1943. attr(conditionalflowMarker, { d: 'M 0 10 L 8 6 L 16 10 L 8 14 Z' });
  1944. addMarker(id, {
  1945. element: conditionalflowMarker,
  1946. attrs: {
  1947. fill: fill,
  1948. stroke: stroke
  1949. },
  1950. ref: { x: -1, y: 10 },
  1951. scale: 0.5
  1952. });
  1953. }
  1954. if (type === 'conditional-default-flow-marker') {
  1955. var conditionaldefaultflowMarker = create('path');
  1956. attr(conditionaldefaultflowMarker, { d: 'M 6 4 L 10 16' });
  1957. addMarker(id, {
  1958. element: conditionaldefaultflowMarker,
  1959. attrs: {
  1960. stroke: stroke
  1961. },
  1962. ref: { x: 0, y: 10 },
  1963. scale: 0.5
  1964. });
  1965. }
  1966. }
  1967. function drawCircle(parentGfx, width, height, offset, attrs) {
  1968. if (isObject(offset)) {
  1969. attrs = offset;
  1970. offset = 0;
  1971. }
  1972. offset = offset || 0;
  1973. attrs = computeStyle(attrs, {
  1974. stroke: 'black',
  1975. strokeWidth: 2,
  1976. fill: 'white'
  1977. });
  1978. if (attrs.fill === 'none') {
  1979. delete attrs.fillOpacity;
  1980. }
  1981. var cx = width / 2,
  1982. cy = height / 2;
  1983. var circle = create('circle');
  1984. attr(circle, {
  1985. cx: cx,
  1986. cy: cy,
  1987. r: Math.round((width + height) / 4 - offset)
  1988. });
  1989. attr(circle, attrs);
  1990. append(parentGfx, circle);
  1991. return circle;
  1992. }
  1993. function drawRect(parentGfx, width, height, r, offset, attrs) {
  1994. if (isObject(offset)) {
  1995. attrs = offset;
  1996. offset = 0;
  1997. }
  1998. offset = offset || 0;
  1999. attrs = computeStyle(attrs, {
  2000. stroke: 'black',
  2001. strokeWidth: 2,
  2002. fill: 'white'
  2003. });
  2004. var rect = create('rect');
  2005. attr(rect, {
  2006. x: offset,
  2007. y: offset,
  2008. width: width - offset * 2,
  2009. height: height - offset * 2,
  2010. rx: r,
  2011. ry: r
  2012. });
  2013. attr(rect, attrs);
  2014. append(parentGfx, rect);
  2015. return rect;
  2016. }
  2017. function drawDiamond(parentGfx, width, height, attrs) {
  2018. var x_2 = width / 2;
  2019. var y_2 = height / 2;
  2020. var points = [{ x: x_2, y: 0 }, { x: width, y: y_2 }, { x: x_2, y: height }, { x: 0, y: y_2 }];
  2021. var pointsString = points.map(function(point) {
  2022. return point.x + ',' + point.y;
  2023. }).join(' ');
  2024. attrs = computeStyle(attrs, {
  2025. stroke: 'black',
  2026. strokeWidth: 2,
  2027. fill: 'white'
  2028. });
  2029. var polygon = create('polygon');
  2030. attr(polygon, {
  2031. points: pointsString
  2032. });
  2033. attr(polygon, attrs);
  2034. append(parentGfx, polygon);
  2035. return polygon;
  2036. }
  2037. function drawLine(parentGfx, waypoints, attrs) {
  2038. attrs = computeStyle(attrs, [ 'no-fill' ], {
  2039. stroke: 'black',
  2040. strokeWidth: 2,
  2041. fill: 'none'
  2042. });
  2043. var line = createLine(waypoints, attrs);
  2044. append(parentGfx, line);
  2045. return line;
  2046. }
  2047. function drawPath(parentGfx, d, attrs) {
  2048. attrs = computeStyle(attrs, [ 'no-fill' ], {
  2049. strokeWidth: 2,
  2050. stroke: 'black'
  2051. });
  2052. var path = create('path');
  2053. attr(path, { d: d });
  2054. attr(path, attrs);
  2055. append(parentGfx, path);
  2056. return path;
  2057. }
  2058. function drawMarker(type, parentGfx, path, attrs) {
  2059. return drawPath(parentGfx, path, assign({ 'data-marker': type }, attrs));
  2060. }
  2061. function as(type) {
  2062. return function(parentGfx, element) {
  2063. return handlers[type](parentGfx, element);
  2064. };
  2065. }
  2066. function renderer(type) {
  2067. return handlers[type];
  2068. }
  2069. function renderEventContent(element, parentGfx) {
  2070. var event = getSemantic(element);
  2071. var isThrowing = isThrowEvent(event);
  2072. if (event.eventDefinitions && event.eventDefinitions.length>1) {
  2073. if (event.parallelMultiple) {
  2074. return renderer('bpmn:ParallelMultipleEventDefinition')(parentGfx, element, isThrowing);
  2075. }
  2076. else {
  2077. return renderer('bpmn:MultipleEventDefinition')(parentGfx, element, isThrowing);
  2078. }
  2079. }
  2080. if (isTypedEvent(event, 'bpmn:MessageEventDefinition')) {
  2081. return renderer('bpmn:MessageEventDefinition')(parentGfx, element, isThrowing);
  2082. }
  2083. if (isTypedEvent(event, 'bpmn:TimerEventDefinition')) {
  2084. return renderer('bpmn:TimerEventDefinition')(parentGfx, element, isThrowing);
  2085. }
  2086. if (isTypedEvent(event, 'bpmn:ConditionalEventDefinition')) {
  2087. return renderer('bpmn:ConditionalEventDefinition')(parentGfx, element);
  2088. }
  2089. if (isTypedEvent(event, 'bpmn:SignalEventDefinition')) {
  2090. return renderer('bpmn:SignalEventDefinition')(parentGfx, element, isThrowing);
  2091. }
  2092. if (isTypedEvent(event, 'bpmn:EscalationEventDefinition')) {
  2093. return renderer('bpmn:EscalationEventDefinition')(parentGfx, element, isThrowing);
  2094. }
  2095. if (isTypedEvent(event, 'bpmn:LinkEventDefinition')) {
  2096. return renderer('bpmn:LinkEventDefinition')(parentGfx, element, isThrowing);
  2097. }
  2098. if (isTypedEvent(event, 'bpmn:ErrorEventDefinition')) {
  2099. return renderer('bpmn:ErrorEventDefinition')(parentGfx, element, isThrowing);
  2100. }
  2101. if (isTypedEvent(event, 'bpmn:CancelEventDefinition')) {
  2102. return renderer('bpmn:CancelEventDefinition')(parentGfx, element, isThrowing);
  2103. }
  2104. if (isTypedEvent(event, 'bpmn:CompensateEventDefinition')) {
  2105. return renderer('bpmn:CompensateEventDefinition')(parentGfx, element, isThrowing);
  2106. }
  2107. if (isTypedEvent(event, 'bpmn:TerminateEventDefinition')) {
  2108. return renderer('bpmn:TerminateEventDefinition')(parentGfx, element, isThrowing);
  2109. }
  2110. return null;
  2111. }
  2112. function renderLabel(parentGfx, label, options) {
  2113. options = assign({
  2114. size: {
  2115. width: 100
  2116. }
  2117. }, options);
  2118. var text = textRenderer.createText(label || '', options);
  2119. classes(text).add('djs-label');
  2120. append(parentGfx, text);
  2121. return text;
  2122. }
  2123. function renderEmbeddedLabel(parentGfx, element, align) {
  2124. var semantic = getSemantic(element);
  2125. return renderLabel(parentGfx, semantic.name, {
  2126. box: element,
  2127. align: align,
  2128. padding: 5,
  2129. style: {
  2130. fill: getStrokeColor(element, defaultStrokeColor)
  2131. }
  2132. });
  2133. }
  2134. function renderExternalLabel(parentGfx, element) {
  2135. var box = {
  2136. width: 90,
  2137. height: 30,
  2138. x: element.width / 2 + element.x,
  2139. y: element.height / 2 + element.y
  2140. };
  2141. return renderLabel(parentGfx, getLabel(element), {
  2142. box: box,
  2143. fitBox: true,
  2144. style: assign(
  2145. {},
  2146. textRenderer.getExternalStyle(),
  2147. {
  2148. fill: getStrokeColor(element, defaultStrokeColor)
  2149. }
  2150. )
  2151. });
  2152. }
  2153. function renderLaneLabel(parentGfx, text, element) {
  2154. var textBox = renderLabel(parentGfx, text, {
  2155. box: {
  2156. height: 30,
  2157. width: element.height
  2158. },
  2159. align: 'center-middle',
  2160. style: {
  2161. fill: getStrokeColor(element, defaultStrokeColor)
  2162. }
  2163. });
  2164. var top = -1 * element.height;
  2165. transform$1(textBox, 0, -top, 270);
  2166. }
  2167. function createPathFromConnection(connection) {
  2168. var waypoints = connection.waypoints;
  2169. var pathData = 'm ' + waypoints[0].x + ',' + waypoints[0].y;
  2170. for (var i = 1; i < waypoints.length; i++) {
  2171. pathData += 'L' + waypoints[i].x + ',' + waypoints[i].y + ' ';
  2172. }
  2173. return pathData;
  2174. }
  2175. var handlers = this.handlers = {
  2176. 'bpmn:Event': function(parentGfx, element, attrs) {
  2177. if (!('fillOpacity' in attrs)) {
  2178. attrs.fillOpacity = DEFAULT_FILL_OPACITY;
  2179. }
  2180. return drawCircle(parentGfx, element.width, element.height, attrs);
  2181. },
  2182. 'bpmn:StartEvent': function(parentGfx, element) {
  2183. var attrs = {
  2184. fill: getFillColor(element, defaultFillColor),
  2185. stroke: getStrokeColor(element, defaultStrokeColor)
  2186. };
  2187. var semantic = getSemantic(element);
  2188. if (!semantic.isInterrupting) {
  2189. attrs = {
  2190. strokeDasharray: '6',
  2191. strokeLinecap: 'round',
  2192. fill: getFillColor(element, defaultFillColor),
  2193. stroke: getStrokeColor(element, defaultStrokeColor)
  2194. };
  2195. }
  2196. var circle = renderer('bpmn:Event')(parentGfx, element, attrs);
  2197. renderEventContent(element, parentGfx);
  2198. return circle;
  2199. },
  2200. 'bpmn:MessageEventDefinition': function(parentGfx, element, isThrowing) {
  2201. var pathData = pathMap.getScaledPath('EVENT_MESSAGE', {
  2202. xScaleFactor: 0.9,
  2203. yScaleFactor: 0.9,
  2204. containerWidth: element.width,
  2205. containerHeight: element.height,
  2206. position: {
  2207. mx: 0.235,
  2208. my: 0.315
  2209. }
  2210. });
  2211. var fill = isThrowing ? getStrokeColor(element, defaultStrokeColor) : getFillColor(element, defaultFillColor);
  2212. var stroke = isThrowing ? getFillColor(element, defaultFillColor) : getStrokeColor(element, defaultStrokeColor);
  2213. var messagePath = drawPath(parentGfx, pathData, {
  2214. strokeWidth: 1,
  2215. fill: fill,
  2216. stroke: stroke
  2217. });
  2218. return messagePath;
  2219. },
  2220. 'bpmn:TimerEventDefinition': function(parentGfx, element) {
  2221. var circle = drawCircle(parentGfx, element.width, element.height, 0.2 * element.height, {
  2222. strokeWidth: 2,
  2223. fill: getFillColor(element, defaultFillColor),
  2224. stroke: getStrokeColor(element, defaultStrokeColor)
  2225. });
  2226. var pathData = pathMap.getScaledPath('EVENT_TIMER_WH', {
  2227. xScaleFactor: 0.75,
  2228. yScaleFactor: 0.75,
  2229. containerWidth: element.width,
  2230. containerHeight: element.height,
  2231. position: {
  2232. mx: 0.5,
  2233. my: 0.5
  2234. }
  2235. });
  2236. drawPath(parentGfx, pathData, {
  2237. strokeWidth: 2,
  2238. strokeLinecap: 'square',
  2239. stroke: getStrokeColor(element, defaultStrokeColor)
  2240. });
  2241. for (var i = 0;i < 12; i++) {
  2242. var linePathData = pathMap.getScaledPath('EVENT_TIMER_LINE', {
  2243. xScaleFactor: 0.75,
  2244. yScaleFactor: 0.75,
  2245. containerWidth: element.width,
  2246. containerHeight: element.height,
  2247. position: {
  2248. mx: 0.5,
  2249. my: 0.5
  2250. }
  2251. });
  2252. var width = element.width / 2;
  2253. var height = element.height / 2;
  2254. drawPath(parentGfx, linePathData, {
  2255. strokeWidth: 1,
  2256. strokeLinecap: 'square',
  2257. transform: 'rotate(' + (i * 30) + ',' + height + ',' + width + ')',
  2258. stroke: getStrokeColor(element, defaultStrokeColor)
  2259. });
  2260. }
  2261. return circle;
  2262. },
  2263. 'bpmn:EscalationEventDefinition': function(parentGfx, event, isThrowing) {
  2264. var pathData = pathMap.getScaledPath('EVENT_ESCALATION', {
  2265. xScaleFactor: 1,
  2266. yScaleFactor: 1,
  2267. containerWidth: event.width,
  2268. containerHeight: event.height,
  2269. position: {
  2270. mx: 0.5,
  2271. my: 0.2
  2272. }
  2273. });
  2274. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2275. return drawPath(parentGfx, pathData, {
  2276. strokeWidth: 1,
  2277. fill: fill,
  2278. stroke: getStrokeColor(event, defaultStrokeColor)
  2279. });
  2280. },
  2281. 'bpmn:ConditionalEventDefinition': function(parentGfx, event) {
  2282. var pathData = pathMap.getScaledPath('EVENT_CONDITIONAL', {
  2283. xScaleFactor: 1,
  2284. yScaleFactor: 1,
  2285. containerWidth: event.width,
  2286. containerHeight: event.height,
  2287. position: {
  2288. mx: 0.5,
  2289. my: 0.222
  2290. }
  2291. });
  2292. return drawPath(parentGfx, pathData, {
  2293. strokeWidth: 1,
  2294. stroke: getStrokeColor(event, defaultStrokeColor)
  2295. });
  2296. },
  2297. 'bpmn:LinkEventDefinition': function(parentGfx, event, isThrowing) {
  2298. var pathData = pathMap.getScaledPath('EVENT_LINK', {
  2299. xScaleFactor: 1,
  2300. yScaleFactor: 1,
  2301. containerWidth: event.width,
  2302. containerHeight: event.height,
  2303. position: {
  2304. mx: 0.57,
  2305. my: 0.263
  2306. }
  2307. });
  2308. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2309. return drawPath(parentGfx, pathData, {
  2310. strokeWidth: 1,
  2311. fill: fill,
  2312. stroke: getStrokeColor(event, defaultStrokeColor)
  2313. });
  2314. },
  2315. 'bpmn:ErrorEventDefinition': function(parentGfx, event, isThrowing) {
  2316. var pathData = pathMap.getScaledPath('EVENT_ERROR', {
  2317. xScaleFactor: 1.1,
  2318. yScaleFactor: 1.1,
  2319. containerWidth: event.width,
  2320. containerHeight: event.height,
  2321. position: {
  2322. mx: 0.2,
  2323. my: 0.722
  2324. }
  2325. });
  2326. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2327. return drawPath(parentGfx, pathData, {
  2328. strokeWidth: 1,
  2329. fill: fill,
  2330. stroke: getStrokeColor(event, defaultStrokeColor)
  2331. });
  2332. },
  2333. 'bpmn:CancelEventDefinition': function(parentGfx, event, isThrowing) {
  2334. var pathData = pathMap.getScaledPath('EVENT_CANCEL_45', {
  2335. xScaleFactor: 1.0,
  2336. yScaleFactor: 1.0,
  2337. containerWidth: event.width,
  2338. containerHeight: event.height,
  2339. position: {
  2340. mx: 0.638,
  2341. my: -0.055
  2342. }
  2343. });
  2344. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2345. var path = drawPath(parentGfx, pathData, {
  2346. strokeWidth: 1,
  2347. fill: fill,
  2348. stroke: getStrokeColor(event, defaultStrokeColor)
  2349. });
  2350. rotate(path, 45);
  2351. return path;
  2352. },
  2353. 'bpmn:CompensateEventDefinition': function(parentGfx, event, isThrowing) {
  2354. var pathData = pathMap.getScaledPath('EVENT_COMPENSATION', {
  2355. xScaleFactor: 1,
  2356. yScaleFactor: 1,
  2357. containerWidth: event.width,
  2358. containerHeight: event.height,
  2359. position: {
  2360. mx: 0.22,
  2361. my: 0.5
  2362. }
  2363. });
  2364. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2365. return drawPath(parentGfx, pathData, {
  2366. strokeWidth: 1,
  2367. fill: fill,
  2368. stroke: getStrokeColor(event, defaultStrokeColor)
  2369. });
  2370. },
  2371. 'bpmn:SignalEventDefinition': function(parentGfx, event, isThrowing) {
  2372. var pathData = pathMap.getScaledPath('EVENT_SIGNAL', {
  2373. xScaleFactor: 0.9,
  2374. yScaleFactor: 0.9,
  2375. containerWidth: event.width,
  2376. containerHeight: event.height,
  2377. position: {
  2378. mx: 0.5,
  2379. my: 0.2
  2380. }
  2381. });
  2382. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2383. return drawPath(parentGfx, pathData, {
  2384. strokeWidth: 1,
  2385. fill: fill,
  2386. stroke: getStrokeColor(event, defaultStrokeColor)
  2387. });
  2388. },
  2389. 'bpmn:MultipleEventDefinition': function(parentGfx, event, isThrowing) {
  2390. var pathData = pathMap.getScaledPath('EVENT_MULTIPLE', {
  2391. xScaleFactor: 1.1,
  2392. yScaleFactor: 1.1,
  2393. containerWidth: event.width,
  2394. containerHeight: event.height,
  2395. position: {
  2396. mx: 0.222,
  2397. my: 0.36
  2398. }
  2399. });
  2400. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2401. return drawPath(parentGfx, pathData, {
  2402. strokeWidth: 1,
  2403. fill: fill
  2404. });
  2405. },
  2406. 'bpmn:ParallelMultipleEventDefinition': function(parentGfx, event) {
  2407. var pathData = pathMap.getScaledPath('EVENT_PARALLEL_MULTIPLE', {
  2408. xScaleFactor: 1.2,
  2409. yScaleFactor: 1.2,
  2410. containerWidth: event.width,
  2411. containerHeight: event.height,
  2412. position: {
  2413. mx: 0.458,
  2414. my: 0.194
  2415. }
  2416. });
  2417. return drawPath(parentGfx, pathData, {
  2418. strokeWidth: 1,
  2419. fill: getStrokeColor(event, defaultStrokeColor),
  2420. stroke: getStrokeColor(event, defaultStrokeColor)
  2421. });
  2422. },
  2423. 'bpmn:EndEvent': function(parentGfx, element) {
  2424. var circle = renderer('bpmn:Event')(parentGfx, element, {
  2425. strokeWidth: 4,
  2426. fill: getFillColor(element, defaultFillColor),
  2427. stroke: getStrokeColor(element, defaultStrokeColor)
  2428. });
  2429. renderEventContent(element, parentGfx);
  2430. return circle;
  2431. },
  2432. 'bpmn:TerminateEventDefinition': function(parentGfx, element) {
  2433. var circle = drawCircle(parentGfx, element.width, element.height, 8, {
  2434. strokeWidth: 4,
  2435. fill: getStrokeColor(element, defaultStrokeColor),
  2436. stroke: getStrokeColor(element, defaultStrokeColor)
  2437. });
  2438. return circle;
  2439. },
  2440. 'bpmn:IntermediateEvent': function(parentGfx, element) {
  2441. var outer = renderer('bpmn:Event')(parentGfx, element, {
  2442. strokeWidth: 1,
  2443. fill: getFillColor(element, defaultFillColor),
  2444. stroke: getStrokeColor(element, defaultStrokeColor)
  2445. });
  2446. /* inner */
  2447. drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, {
  2448. strokeWidth: 1,
  2449. fill: getFillColor(element, 'none'),
  2450. stroke: getStrokeColor(element, defaultStrokeColor)
  2451. });
  2452. renderEventContent(element, parentGfx);
  2453. return outer;
  2454. },
  2455. 'bpmn:IntermediateCatchEvent': as('bpmn:IntermediateEvent'),
  2456. 'bpmn:IntermediateThrowEvent': as('bpmn:IntermediateEvent'),
  2457. 'bpmn:Activity': function(parentGfx, element, attrs) {
  2458. attrs = attrs || {};
  2459. if (!('fillOpacity' in attrs)) {
  2460. attrs.fillOpacity = DEFAULT_FILL_OPACITY;
  2461. }
  2462. return drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, attrs);
  2463. },
  2464. 'bpmn:Task': function(parentGfx, element) {
  2465. var attrs = {
  2466. fill: getFillColor(element, defaultFillColor),
  2467. stroke: getStrokeColor(element, defaultStrokeColor)
  2468. };
  2469. var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
  2470. renderEmbeddedLabel(parentGfx, element, 'center-middle');
  2471. attachTaskMarkers(parentGfx, element);
  2472. return rect;
  2473. },
  2474. 'bpmn:ServiceTask': function(parentGfx, element) {
  2475. var task = renderer('bpmn:Task')(parentGfx, element);
  2476. var pathDataBG = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
  2477. abspos: {
  2478. x: 12,
  2479. y: 18
  2480. }
  2481. });
  2482. /* service bg */ drawPath(parentGfx, pathDataBG, {
  2483. strokeWidth: 1,
  2484. fill: getFillColor(element, defaultFillColor),
  2485. stroke: getStrokeColor(element, defaultStrokeColor)
  2486. });
  2487. var fillPathData = pathMap.getScaledPath('TASK_TYPE_SERVICE_FILL', {
  2488. abspos: {
  2489. x: 17.2,
  2490. y: 18
  2491. }
  2492. });
  2493. /* service fill */ drawPath(parentGfx, fillPathData, {
  2494. strokeWidth: 0,
  2495. fill: getFillColor(element, defaultFillColor)
  2496. });
  2497. var pathData = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
  2498. abspos: {
  2499. x: 17,
  2500. y: 22
  2501. }
  2502. });
  2503. /* service */ drawPath(parentGfx, pathData, {
  2504. strokeWidth: 1,
  2505. fill: getFillColor(element, defaultFillColor),
  2506. stroke: getStrokeColor(element, defaultStrokeColor)
  2507. });
  2508. return task;
  2509. },
  2510. 'bpmn:UserTask': function(parentGfx, element) {
  2511. var task = renderer('bpmn:Task')(parentGfx, element);
  2512. var x = 15;
  2513. var y = 12;
  2514. var pathData = pathMap.getScaledPath('TASK_TYPE_USER_1', {
  2515. abspos: {
  2516. x: x,
  2517. y: y
  2518. }
  2519. });
  2520. /* user path */ drawPath(parentGfx, pathData, {
  2521. strokeWidth: 0.5,
  2522. fill: getFillColor(element, defaultFillColor),
  2523. stroke: getStrokeColor(element, defaultStrokeColor)
  2524. });
  2525. var pathData2 = pathMap.getScaledPath('TASK_TYPE_USER_2', {
  2526. abspos: {
  2527. x: x,
  2528. y: y
  2529. }
  2530. });
  2531. /* user2 path */ drawPath(parentGfx, pathData2, {
  2532. strokeWidth: 0.5,
  2533. fill: getFillColor(element, defaultFillColor),
  2534. stroke: getStrokeColor(element, defaultStrokeColor)
  2535. });
  2536. var pathData3 = pathMap.getScaledPath('TASK_TYPE_USER_3', {
  2537. abspos: {
  2538. x: x,
  2539. y: y
  2540. }
  2541. });
  2542. /* user3 path */ drawPath(parentGfx, pathData3, {
  2543. strokeWidth: 0.5,
  2544. fill: getStrokeColor(element, defaultStrokeColor),
  2545. stroke: getStrokeColor(element, defaultStrokeColor)
  2546. });
  2547. return task;
  2548. },
  2549. 'bpmn:ManualTask': function(parentGfx, element) {
  2550. var task = renderer('bpmn:Task')(parentGfx, element);
  2551. var pathData = pathMap.getScaledPath('TASK_TYPE_MANUAL', {
  2552. abspos: {
  2553. x: 17,
  2554. y: 15
  2555. }
  2556. });
  2557. /* manual path */ drawPath(parentGfx, pathData, {
  2558. strokeWidth: 0.5, // 0.25,
  2559. fill: getFillColor(element, defaultFillColor),
  2560. stroke: getStrokeColor(element, defaultStrokeColor)
  2561. });
  2562. return task;
  2563. },
  2564. 'bpmn:SendTask': function(parentGfx, element) {
  2565. var task = renderer('bpmn:Task')(parentGfx, element);
  2566. var pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
  2567. xScaleFactor: 1,
  2568. yScaleFactor: 1,
  2569. containerWidth: 21,
  2570. containerHeight: 14,
  2571. position: {
  2572. mx: 0.285,
  2573. my: 0.357
  2574. }
  2575. });
  2576. /* send path */ drawPath(parentGfx, pathData, {
  2577. strokeWidth: 1,
  2578. fill: getStrokeColor(element, defaultStrokeColor),
  2579. stroke: getFillColor(element, defaultFillColor)
  2580. });
  2581. return task;
  2582. },
  2583. 'bpmn:ReceiveTask' : function(parentGfx, element) {
  2584. var semantic = getSemantic(element);
  2585. var task = renderer('bpmn:Task')(parentGfx, element);
  2586. var pathData;
  2587. if (semantic.instantiate) {
  2588. drawCircle(parentGfx, 28, 28, 20 * 0.22, { strokeWidth: 1 });
  2589. pathData = pathMap.getScaledPath('TASK_TYPE_INSTANTIATING_SEND', {
  2590. abspos: {
  2591. x: 7.77,
  2592. y: 9.52
  2593. }
  2594. });
  2595. } else {
  2596. pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
  2597. xScaleFactor: 0.9,
  2598. yScaleFactor: 0.9,
  2599. containerWidth: 21,
  2600. containerHeight: 14,
  2601. position: {
  2602. mx: 0.3,
  2603. my: 0.4
  2604. }
  2605. });
  2606. }
  2607. /* receive path */ drawPath(parentGfx, pathData, {
  2608. strokeWidth: 1,
  2609. fill: getFillColor(element, defaultFillColor),
  2610. stroke: getStrokeColor(element, defaultStrokeColor)
  2611. });
  2612. return task;
  2613. },
  2614. 'bpmn:ScriptTask': function(parentGfx, element) {
  2615. var task = renderer('bpmn:Task')(parentGfx, element);
  2616. var pathData = pathMap.getScaledPath('TASK_TYPE_SCRIPT', {
  2617. abspos: {
  2618. x: 15,
  2619. y: 20
  2620. }
  2621. });
  2622. /* script path */ drawPath(parentGfx, pathData, {
  2623. strokeWidth: 1,
  2624. stroke: getStrokeColor(element, defaultStrokeColor)
  2625. });
  2626. return task;
  2627. },
  2628. 'bpmn:BusinessRuleTask': function(parentGfx, element) {
  2629. var task = renderer('bpmn:Task')(parentGfx, element);
  2630. var headerPathData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_HEADER', {
  2631. abspos: {
  2632. x: 8,
  2633. y: 8
  2634. }
  2635. });
  2636. var businessHeaderPath = drawPath(parentGfx, headerPathData);
  2637. attr(businessHeaderPath, {
  2638. strokeWidth: 1,
  2639. fill: getFillColor(element, '#aaaaaa'),
  2640. stroke: getStrokeColor(element, defaultStrokeColor)
  2641. });
  2642. var headerData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_MAIN', {
  2643. abspos: {
  2644. x: 8,
  2645. y: 8
  2646. }
  2647. });
  2648. var businessPath = drawPath(parentGfx, headerData);
  2649. attr(businessPath, {
  2650. strokeWidth: 1,
  2651. stroke: getStrokeColor(element, defaultStrokeColor)
  2652. });
  2653. return task;
  2654. },
  2655. 'bpmn:SubProcess': function(parentGfx, element, attrs) {
  2656. attrs = assign({
  2657. fill: getFillColor(element, defaultFillColor),
  2658. stroke: getStrokeColor(element, defaultStrokeColor)
  2659. }, attrs);
  2660. var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
  2661. var expanded = isExpanded(element);
  2662. if (isEventSubProcess(element)) {
  2663. attr(rect, {
  2664. strokeDasharray: '1,2'
  2665. });
  2666. }
  2667. renderEmbeddedLabel(parentGfx, element, expanded ? 'center-top' : 'center-middle');
  2668. if (expanded) {
  2669. attachTaskMarkers(parentGfx, element);
  2670. } else {
  2671. attachTaskMarkers(parentGfx, element, ['SubProcessMarker']);
  2672. }
  2673. return rect;
  2674. },
  2675. 'bpmn:AdHocSubProcess': function(parentGfx, element) {
  2676. return renderer('bpmn:SubProcess')(parentGfx, element);
  2677. },
  2678. 'bpmn:Transaction': function(parentGfx, element) {
  2679. var outer = renderer('bpmn:SubProcess')(parentGfx, element);
  2680. var innerAttrs = styles.style([ 'no-fill', 'no-events' ], {
  2681. stroke: getStrokeColor(element, defaultStrokeColor)
  2682. });
  2683. /* inner path */ drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS - 2, INNER_OUTER_DIST, innerAttrs);
  2684. return outer;
  2685. },
  2686. 'bpmn:CallActivity': function(parentGfx, element) {
  2687. return renderer('bpmn:SubProcess')(parentGfx, element, {
  2688. strokeWidth: 5
  2689. });
  2690. },
  2691. 'bpmn:Participant': function(parentGfx, element) {
  2692. var attrs = {
  2693. fillOpacity: DEFAULT_FILL_OPACITY,
  2694. fill: getFillColor(element, defaultFillColor),
  2695. stroke: getStrokeColor(element, defaultStrokeColor)
  2696. };
  2697. var lane = renderer('bpmn:Lane')(parentGfx, element, attrs);
  2698. var expandedPool = isExpanded(element);
  2699. if (expandedPool) {
  2700. drawLine(parentGfx, [
  2701. { x: 30, y: 0 },
  2702. { x: 30, y: element.height }
  2703. ], {
  2704. stroke: getStrokeColor(element, defaultStrokeColor)
  2705. });
  2706. var text = getSemantic(element).name;
  2707. renderLaneLabel(parentGfx, text, element);
  2708. } else {
  2709. // Collapsed pool draw text inline
  2710. var text2 = getSemantic(element).name;
  2711. renderLabel(parentGfx, text2, {
  2712. box: element, align: 'center-middle',
  2713. style: {
  2714. fill: getStrokeColor(element, defaultStrokeColor)
  2715. }
  2716. });
  2717. }
  2718. var participantMultiplicity = !!(getSemantic(element).participantMultiplicity);
  2719. if (participantMultiplicity) {
  2720. renderer('ParticipantMultiplicityMarker')(parentGfx, element);
  2721. }
  2722. return lane;
  2723. },
  2724. 'bpmn:Lane': function(parentGfx, element, attrs) {
  2725. var rect = drawRect(parentGfx, element.width, element.height, 0, assign({
  2726. fill: getFillColor(element, defaultFillColor),
  2727. fillOpacity: HIGH_FILL_OPACITY,
  2728. stroke: getStrokeColor(element, defaultStrokeColor)
  2729. }, attrs));
  2730. var semantic = getSemantic(element);
  2731. if (semantic.$type === 'bpmn:Lane') {
  2732. var text = semantic.name;
  2733. renderLaneLabel(parentGfx, text, element);
  2734. }
  2735. return rect;
  2736. },
  2737. 'bpmn:InclusiveGateway': function(parentGfx, element) {
  2738. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  2739. /* circle path */
  2740. drawCircle(parentGfx, element.width, element.height, element.height * 0.24, {
  2741. strokeWidth: 2.5,
  2742. fill: getFillColor(element, defaultFillColor),
  2743. stroke: getStrokeColor(element, defaultStrokeColor)
  2744. });
  2745. return diamond;
  2746. },
  2747. 'bpmn:ExclusiveGateway': function(parentGfx, element) {
  2748. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  2749. var pathData = pathMap.getScaledPath('GATEWAY_EXCLUSIVE', {
  2750. xScaleFactor: 0.4,
  2751. yScaleFactor: 0.4,
  2752. containerWidth: element.width,
  2753. containerHeight: element.height,
  2754. position: {
  2755. mx: 0.32,
  2756. my: 0.3
  2757. }
  2758. });
  2759. if ((getDi(element).isMarkerVisible)) {
  2760. drawPath(parentGfx, pathData, {
  2761. strokeWidth: 1,
  2762. fill: getStrokeColor(element, defaultStrokeColor),
  2763. stroke: getStrokeColor(element, defaultStrokeColor)
  2764. });
  2765. }
  2766. return diamond;
  2767. },
  2768. 'bpmn:ComplexGateway': function(parentGfx, element) {
  2769. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  2770. var pathData = pathMap.getScaledPath('GATEWAY_COMPLEX', {
  2771. xScaleFactor: 0.5,
  2772. yScaleFactor:0.5,
  2773. containerWidth: element.width,
  2774. containerHeight: element.height,
  2775. position: {
  2776. mx: 0.46,
  2777. my: 0.26
  2778. }
  2779. });
  2780. /* complex path */ drawPath(parentGfx, pathData, {
  2781. strokeWidth: 1,
  2782. fill: getStrokeColor(element, defaultStrokeColor),
  2783. stroke: getStrokeColor(element, defaultStrokeColor)
  2784. });
  2785. return diamond;
  2786. },
  2787. 'bpmn:ParallelGateway': function(parentGfx, element) {
  2788. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  2789. var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
  2790. xScaleFactor: 0.6,
  2791. yScaleFactor:0.6,
  2792. containerWidth: element.width,
  2793. containerHeight: element.height,
  2794. position: {
  2795. mx: 0.46,
  2796. my: 0.2
  2797. }
  2798. });
  2799. /* parallel path */ drawPath(parentGfx, pathData, {
  2800. strokeWidth: 1,
  2801. fill: getStrokeColor(element, defaultStrokeColor),
  2802. stroke: getStrokeColor(element, defaultStrokeColor)
  2803. });
  2804. return diamond;
  2805. },
  2806. 'bpmn:EventBasedGateway': function(parentGfx, element) {
  2807. var semantic = getSemantic(element);
  2808. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  2809. /* outer circle path */ drawCircle(parentGfx, element.width, element.height, element.height * 0.20, {
  2810. strokeWidth: 1,
  2811. fill: 'none',
  2812. stroke: getStrokeColor(element, defaultStrokeColor)
  2813. });
  2814. var type = semantic.eventGatewayType;
  2815. var instantiate = !!semantic.instantiate;
  2816. function drawEvent() {
  2817. var pathData = pathMap.getScaledPath('GATEWAY_EVENT_BASED', {
  2818. xScaleFactor: 0.18,
  2819. yScaleFactor: 0.18,
  2820. containerWidth: element.width,
  2821. containerHeight: element.height,
  2822. position: {
  2823. mx: 0.36,
  2824. my: 0.44
  2825. }
  2826. });
  2827. var attrs = {
  2828. strokeWidth: 2,
  2829. fill: getFillColor(element, 'none'),
  2830. stroke: getStrokeColor(element, defaultStrokeColor)
  2831. };
  2832. /* event path */ drawPath(parentGfx, pathData, attrs);
  2833. }
  2834. if (type === 'Parallel') {
  2835. var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
  2836. xScaleFactor: 0.4,
  2837. yScaleFactor:0.4,
  2838. containerWidth: element.width,
  2839. containerHeight: element.height,
  2840. position: {
  2841. mx: 0.474,
  2842. my: 0.296
  2843. }
  2844. });
  2845. var parallelPath = drawPath(parentGfx, pathData);
  2846. attr(parallelPath, {
  2847. strokeWidth: 1,
  2848. fill: 'none'
  2849. });
  2850. } else if (type === 'Exclusive') {
  2851. if (!instantiate) {
  2852. var innerCircle = drawCircle(parentGfx, element.width, element.height, element.height * 0.26);
  2853. attr(innerCircle, {
  2854. strokeWidth: 1,
  2855. fill: 'none',
  2856. stroke: getStrokeColor(element, defaultStrokeColor)
  2857. });
  2858. }
  2859. drawEvent();
  2860. }
  2861. return diamond;
  2862. },
  2863. 'bpmn:Gateway': function(parentGfx, element) {
  2864. var attrs = {
  2865. fill: getFillColor(element, defaultFillColor),
  2866. fillOpacity: DEFAULT_FILL_OPACITY,
  2867. stroke: getStrokeColor(element, defaultStrokeColor)
  2868. };
  2869. return drawDiamond(parentGfx, element.width, element.height, attrs);
  2870. },
  2871. 'bpmn:SequenceFlow': function(parentGfx, element) {
  2872. var pathData = createPathFromConnection(element);
  2873. var fill = getFillColor(element, defaultFillColor),
  2874. stroke = getStrokeColor(element, defaultStrokeColor);
  2875. var attrs = {
  2876. strokeLinejoin: 'round',
  2877. markerEnd: marker('sequenceflow-end', fill, stroke),
  2878. stroke: getStrokeColor(element, defaultStrokeColor)
  2879. };
  2880. var path = drawPath(parentGfx, pathData, attrs);
  2881. var sequenceFlow = getSemantic(element);
  2882. var source;
  2883. if (element.source) {
  2884. source = element.source.businessObject;
  2885. // conditional flow marker
  2886. if (sequenceFlow.conditionExpression && source.$instanceOf('bpmn:Activity')) {
  2887. attr(path, {
  2888. markerStart: marker('conditional-flow-marker', fill, stroke)
  2889. });
  2890. }
  2891. // default marker
  2892. if (source.default && (source.$instanceOf('bpmn:Gateway') || source.$instanceOf('bpmn:Activity')) &&
  2893. source.default === sequenceFlow) {
  2894. attr(path, {
  2895. markerStart: marker('conditional-default-flow-marker', fill, stroke)
  2896. });
  2897. }
  2898. }
  2899. return path;
  2900. },
  2901. 'bpmn:Association': function(parentGfx, element, attrs) {
  2902. var semantic = getSemantic(element);
  2903. var fill = getFillColor(element, defaultFillColor),
  2904. stroke = getStrokeColor(element, defaultStrokeColor);
  2905. attrs = assign({
  2906. strokeDasharray: '0.5, 5',
  2907. strokeLinecap: 'round',
  2908. strokeLinejoin: 'round',
  2909. stroke: getStrokeColor(element, defaultStrokeColor)
  2910. }, attrs || {});
  2911. if (semantic.associationDirection === 'One' ||
  2912. semantic.associationDirection === 'Both') {
  2913. attrs.markerEnd = marker('association-end', fill, stroke);
  2914. }
  2915. if (semantic.associationDirection === 'Both') {
  2916. attrs.markerStart = marker('association-start', fill, stroke);
  2917. }
  2918. return drawLine(parentGfx, element.waypoints, attrs);
  2919. },
  2920. 'bpmn:DataInputAssociation': function(parentGfx, element) {
  2921. var fill = getFillColor(element, defaultFillColor),
  2922. stroke = getStrokeColor(element, defaultStrokeColor);
  2923. return renderer('bpmn:Association')(parentGfx, element, {
  2924. markerEnd: marker('association-end', fill, stroke)
  2925. });
  2926. },
  2927. 'bpmn:DataOutputAssociation': function(parentGfx, element) {
  2928. var fill = getFillColor(element, defaultFillColor),
  2929. stroke = getStrokeColor(element, defaultStrokeColor);
  2930. return renderer('bpmn:Association')(parentGfx, element, {
  2931. markerEnd: marker('association-end', fill, stroke)
  2932. });
  2933. },
  2934. 'bpmn:MessageFlow': function(parentGfx, element) {
  2935. var semantic = getSemantic(element),
  2936. di = getDi(element);
  2937. var fill = getFillColor(element, defaultFillColor),
  2938. stroke = getStrokeColor(element, defaultStrokeColor);
  2939. var pathData = createPathFromConnection(element);
  2940. var attrs = {
  2941. markerEnd: marker('messageflow-end', fill, stroke),
  2942. markerStart: marker('messageflow-start', fill, stroke),
  2943. strokeDasharray: '10, 12',
  2944. strokeLinecap: 'round',
  2945. strokeLinejoin: 'round',
  2946. strokeWidth: '1.5px',
  2947. stroke: getStrokeColor(element, defaultStrokeColor)
  2948. };
  2949. var path = drawPath(parentGfx, pathData, attrs);
  2950. if (semantic.messageRef) {
  2951. var midPoint = path.getPointAtLength(path.getTotalLength() / 2);
  2952. var markerPathData = pathMap.getScaledPath('MESSAGE_FLOW_MARKER', {
  2953. abspos: {
  2954. x: midPoint.x,
  2955. y: midPoint.y
  2956. }
  2957. });
  2958. var messageAttrs = { strokeWidth: 1 };
  2959. if (di.messageVisibleKind === 'initiating') {
  2960. messageAttrs.fill = 'white';
  2961. messageAttrs.stroke = 'black';
  2962. } else {
  2963. messageAttrs.fill = '#888';
  2964. messageAttrs.stroke = 'white';
  2965. }
  2966. drawPath(parentGfx, markerPathData, messageAttrs);
  2967. }
  2968. return path;
  2969. },
  2970. 'bpmn:DataObject': function(parentGfx, element) {
  2971. var pathData = pathMap.getScaledPath('DATA_OBJECT_PATH', {
  2972. xScaleFactor: 1,
  2973. yScaleFactor: 1,
  2974. containerWidth: element.width,
  2975. containerHeight: element.height,
  2976. position: {
  2977. mx: 0.474,
  2978. my: 0.296
  2979. }
  2980. });
  2981. var elementObject = drawPath(parentGfx, pathData, {
  2982. fill: getFillColor(element, defaultFillColor),
  2983. fillOpacity: DEFAULT_FILL_OPACITY,
  2984. stroke: getStrokeColor(element, defaultStrokeColor)
  2985. });
  2986. var semantic = getSemantic(element);
  2987. if (isCollection(semantic)) {
  2988. renderDataItemCollection(parentGfx, element);
  2989. }
  2990. return elementObject;
  2991. },
  2992. 'bpmn:DataObjectReference': as('bpmn:DataObject'),
  2993. 'bpmn:DataInput': function(parentGfx, element) {
  2994. var arrowPathData = pathMap.getRawPath('DATA_ARROW');
  2995. // page
  2996. var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
  2997. /* input arrow path */ drawPath(parentGfx, arrowPathData, { strokeWidth: 1 });
  2998. return elementObject;
  2999. },
  3000. 'bpmn:DataOutput': function(parentGfx, element) {
  3001. var arrowPathData = pathMap.getRawPath('DATA_ARROW');
  3002. // page
  3003. var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
  3004. /* output arrow path */ drawPath(parentGfx, arrowPathData, {
  3005. strokeWidth: 1,
  3006. fill: 'black'
  3007. });
  3008. return elementObject;
  3009. },
  3010. 'bpmn:DataStoreReference': function(parentGfx, element) {
  3011. var DATA_STORE_PATH = pathMap.getScaledPath('DATA_STORE', {
  3012. xScaleFactor: 1,
  3013. yScaleFactor: 1,
  3014. containerWidth: element.width,
  3015. containerHeight: element.height,
  3016. position: {
  3017. mx: 0,
  3018. my: 0.133
  3019. }
  3020. });
  3021. var elementStore = drawPath(parentGfx, DATA_STORE_PATH, {
  3022. strokeWidth: 2,
  3023. fill: getFillColor(element, defaultFillColor),
  3024. fillOpacity: DEFAULT_FILL_OPACITY,
  3025. stroke: getStrokeColor(element, defaultStrokeColor)
  3026. });
  3027. return elementStore;
  3028. },
  3029. 'bpmn:BoundaryEvent': function(parentGfx, element) {
  3030. var semantic = getSemantic(element),
  3031. cancel = semantic.cancelActivity;
  3032. var attrs = {
  3033. strokeWidth: 1,
  3034. fill: getFillColor(element, defaultFillColor),
  3035. stroke: getStrokeColor(element, defaultStrokeColor)
  3036. };
  3037. if (!cancel) {
  3038. attrs.strokeDasharray = '6';
  3039. attrs.strokeLinecap = 'round';
  3040. }
  3041. // apply fillOpacity
  3042. var outerAttrs = assign({}, attrs, {
  3043. fillOpacity: 1
  3044. });
  3045. // apply no-fill
  3046. var innerAttrs = assign({}, attrs, {
  3047. fill: 'none'
  3048. });
  3049. var outer = renderer('bpmn:Event')(parentGfx, element, outerAttrs);
  3050. /* inner path */ drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, innerAttrs);
  3051. renderEventContent(element, parentGfx);
  3052. return outer;
  3053. },
  3054. 'bpmn:Group': function(parentGfx, element) {
  3055. var group = drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, {
  3056. stroke: getStrokeColor(element, defaultStrokeColor),
  3057. strokeWidth: 1,
  3058. strokeDasharray: '8,3,1,3',
  3059. fill: 'none',
  3060. pointerEvents: 'none'
  3061. });
  3062. return group;
  3063. },
  3064. 'label': function(parentGfx, element) {
  3065. return renderExternalLabel(parentGfx, element);
  3066. },
  3067. 'bpmn:TextAnnotation': function(parentGfx, element) {
  3068. var style = {
  3069. 'fill': 'none',
  3070. 'stroke': 'none'
  3071. };
  3072. var textElement = drawRect(parentGfx, element.width, element.height, 0, 0, style);
  3073. var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
  3074. xScaleFactor: 1,
  3075. yScaleFactor: 1,
  3076. containerWidth: element.width,
  3077. containerHeight: element.height,
  3078. position: {
  3079. mx: 0.0,
  3080. my: 0.0
  3081. }
  3082. });
  3083. drawPath(parentGfx, textPathData, {
  3084. stroke: getStrokeColor(element, defaultStrokeColor)
  3085. });
  3086. var text = getSemantic(element).text || '';
  3087. renderLabel(parentGfx, text, {
  3088. box: element,
  3089. align: 'left-top',
  3090. padding: 5,
  3091. style: {
  3092. fill: getStrokeColor(element, defaultStrokeColor)
  3093. }
  3094. });
  3095. return textElement;
  3096. },
  3097. 'ParticipantMultiplicityMarker': function(parentGfx, element) {
  3098. var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
  3099. xScaleFactor: 1,
  3100. yScaleFactor: 1,
  3101. containerWidth: element.width,
  3102. containerHeight: element.height,
  3103. position: {
  3104. mx: ((element.width / 2) / element.width),
  3105. my: (element.height - 15) / element.height
  3106. }
  3107. });
  3108. drawMarker('participant-multiplicity', parentGfx, markerPath, {
  3109. strokeWidth: 1,
  3110. fill: getFillColor(element, defaultFillColor),
  3111. stroke: getStrokeColor(element, defaultStrokeColor)
  3112. });
  3113. },
  3114. 'SubProcessMarker': function(parentGfx, element) {
  3115. var markerRect = drawRect(parentGfx, 14, 14, 0, {
  3116. strokeWidth: 1,
  3117. fill: getFillColor(element, defaultFillColor),
  3118. stroke: getStrokeColor(element, defaultStrokeColor)
  3119. });
  3120. // Process marker is placed in the middle of the box
  3121. // therefore fixed values can be used here
  3122. translate(markerRect, element.width / 2 - 7.5, element.height - 20);
  3123. var markerPath = pathMap.getScaledPath('MARKER_SUB_PROCESS', {
  3124. xScaleFactor: 1.5,
  3125. yScaleFactor: 1.5,
  3126. containerWidth: element.width,
  3127. containerHeight: element.height,
  3128. position: {
  3129. mx: (element.width / 2 - 7.5) / element.width,
  3130. my: (element.height - 20) / element.height
  3131. }
  3132. });
  3133. drawMarker('sub-process', parentGfx, markerPath, {
  3134. fill: getFillColor(element, defaultFillColor),
  3135. stroke: getStrokeColor(element, defaultStrokeColor)
  3136. });
  3137. },
  3138. 'ParallelMarker': function(parentGfx, element, position) {
  3139. var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
  3140. xScaleFactor: 1,
  3141. yScaleFactor: 1,
  3142. containerWidth: element.width,
  3143. containerHeight: element.height,
  3144. position: {
  3145. mx: ((element.width / 2 + position.parallel) / element.width),
  3146. my: (element.height - 20) / element.height
  3147. }
  3148. });
  3149. drawMarker('parallel', parentGfx, markerPath, {
  3150. fill: getFillColor(element, defaultFillColor),
  3151. stroke: getStrokeColor(element, defaultStrokeColor)
  3152. });
  3153. },
  3154. 'SequentialMarker': function(parentGfx, element, position) {
  3155. var markerPath = pathMap.getScaledPath('MARKER_SEQUENTIAL', {
  3156. xScaleFactor: 1,
  3157. yScaleFactor: 1,
  3158. containerWidth: element.width,
  3159. containerHeight: element.height,
  3160. position: {
  3161. mx: ((element.width / 2 + position.seq) / element.width),
  3162. my: (element.height - 19) / element.height
  3163. }
  3164. });
  3165. drawMarker('sequential', parentGfx, markerPath, {
  3166. fill: getFillColor(element, defaultFillColor),
  3167. stroke: getStrokeColor(element, defaultStrokeColor)
  3168. });
  3169. },
  3170. 'CompensationMarker': function(parentGfx, element, position) {
  3171. var markerMath = pathMap.getScaledPath('MARKER_COMPENSATION', {
  3172. xScaleFactor: 1,
  3173. yScaleFactor: 1,
  3174. containerWidth: element.width,
  3175. containerHeight: element.height,
  3176. position: {
  3177. mx: ((element.width / 2 + position.compensation) / element.width),
  3178. my: (element.height - 13) / element.height
  3179. }
  3180. });
  3181. drawMarker('compensation', parentGfx, markerMath, {
  3182. strokeWidth: 1,
  3183. fill: getFillColor(element, defaultFillColor),
  3184. stroke: getStrokeColor(element, defaultStrokeColor)
  3185. });
  3186. },
  3187. 'LoopMarker': function(parentGfx, element, position) {
  3188. var markerPath = pathMap.getScaledPath('MARKER_LOOP', {
  3189. xScaleFactor: 1,
  3190. yScaleFactor: 1,
  3191. containerWidth: element.width,
  3192. containerHeight: element.height,
  3193. position: {
  3194. mx: ((element.width / 2 + position.loop) / element.width),
  3195. my: (element.height - 7) / element.height
  3196. }
  3197. });
  3198. drawMarker('loop', parentGfx, markerPath, {
  3199. strokeWidth: 1,
  3200. fill: getFillColor(element, defaultFillColor),
  3201. stroke: getStrokeColor(element, defaultStrokeColor),
  3202. strokeLinecap: 'round',
  3203. strokeMiterlimit: 0.5
  3204. });
  3205. },
  3206. 'AdhocMarker': function(parentGfx, element, position) {
  3207. var markerPath = pathMap.getScaledPath('MARKER_ADHOC', {
  3208. xScaleFactor: 1,
  3209. yScaleFactor: 1,
  3210. containerWidth: element.width,
  3211. containerHeight: element.height,
  3212. position: {
  3213. mx: ((element.width / 2 + position.adhoc) / element.width),
  3214. my: (element.height - 15) / element.height
  3215. }
  3216. });
  3217. drawMarker('adhoc', parentGfx, markerPath, {
  3218. strokeWidth: 1,
  3219. fill: getStrokeColor(element, defaultStrokeColor),
  3220. stroke: getStrokeColor(element, defaultStrokeColor)
  3221. });
  3222. }
  3223. };
  3224. function attachTaskMarkers(parentGfx, element, taskMarkers) {
  3225. var obj = getSemantic(element);
  3226. var subprocess = taskMarkers && taskMarkers.indexOf('SubProcessMarker') !== -1;
  3227. var position;
  3228. if (subprocess) {
  3229. position = {
  3230. seq: -21,
  3231. parallel: -22,
  3232. compensation: -42,
  3233. loop: -18,
  3234. adhoc: 10
  3235. };
  3236. } else {
  3237. position = {
  3238. seq: -3,
  3239. parallel: -6,
  3240. compensation: -27,
  3241. loop: 0,
  3242. adhoc: 10
  3243. };
  3244. }
  3245. forEach(taskMarkers, function(marker) {
  3246. renderer(marker)(parentGfx, element, position);
  3247. });
  3248. if (obj.isForCompensation) {
  3249. renderer('CompensationMarker')(parentGfx, element, position);
  3250. }
  3251. if (obj.$type === 'bpmn:AdHocSubProcess') {
  3252. renderer('AdhocMarker')(parentGfx, element, position);
  3253. }
  3254. var loopCharacteristics = obj.loopCharacteristics,
  3255. isSequential = loopCharacteristics && loopCharacteristics.isSequential;
  3256. if (loopCharacteristics) {
  3257. if (isSequential === undefined) {
  3258. renderer('LoopMarker')(parentGfx, element, position);
  3259. }
  3260. if (isSequential === false) {
  3261. renderer('ParallelMarker')(parentGfx, element, position);
  3262. }
  3263. if (isSequential === true) {
  3264. renderer('SequentialMarker')(parentGfx, element, position);
  3265. }
  3266. }
  3267. }
  3268. function renderDataItemCollection(parentGfx, element) {
  3269. var yPosition = (element.height - 16) / element.height;
  3270. var pathData = pathMap.getScaledPath('DATA_OBJECT_COLLECTION_PATH', {
  3271. xScaleFactor: 1,
  3272. yScaleFactor: 1,
  3273. containerWidth: element.width,
  3274. containerHeight: element.height,
  3275. position: {
  3276. mx: 0.451,
  3277. my: yPosition
  3278. }
  3279. });
  3280. /* collection path */ drawPath(parentGfx, pathData, {
  3281. strokeWidth: 2
  3282. });
  3283. }
  3284. // extension API, use at your own risk
  3285. this._drawPath = drawPath;
  3286. }
  3287. inherits_browser(BpmnRenderer, BaseRenderer);
  3288. BpmnRenderer.$inject = [
  3289. 'config.bpmnRenderer',
  3290. 'eventBus',
  3291. 'styles',
  3292. 'pathMap',
  3293. 'canvas',
  3294. 'textRenderer'
  3295. ];
  3296. BpmnRenderer.prototype.canRender = function(element) {
  3297. return is(element, 'bpmn:BaseElement');
  3298. };
  3299. BpmnRenderer.prototype.drawShape = function(parentGfx, element) {
  3300. var type = element.type;
  3301. var h = this.handlers[type];
  3302. /* jshint -W040 */
  3303. return h(parentGfx, element);
  3304. };
  3305. BpmnRenderer.prototype.drawConnection = function(parentGfx, element) {
  3306. var type = element.type;
  3307. var h = this.handlers[type];
  3308. /* jshint -W040 */
  3309. return h(parentGfx, element);
  3310. };
  3311. BpmnRenderer.prototype.getShapePath = function(element) {
  3312. if (is(element, 'bpmn:Event')) {
  3313. return getCirclePath(element);
  3314. }
  3315. if (is(element, 'bpmn:Activity')) {
  3316. return getRoundRectPath(element, TASK_BORDER_RADIUS);
  3317. }
  3318. if (is(element, 'bpmn:Gateway')) {
  3319. return getDiamondPath(element);
  3320. }
  3321. return getRectPath(element);
  3322. };
  3323. var DEFAULT_BOX_PADDING = 0;
  3324. var DEFAULT_LABEL_SIZE = {
  3325. width: 150,
  3326. height: 50
  3327. };
  3328. function parseAlign(align) {
  3329. var parts = align.split('-');
  3330. return {
  3331. horizontal: parts[0] || 'center',
  3332. vertical: parts[1] || 'top'
  3333. };
  3334. }
  3335. function parsePadding(padding) {
  3336. if (isObject(padding)) {
  3337. return assign({ top: 0, left: 0, right: 0, bottom: 0 }, padding);
  3338. } else {
  3339. return {
  3340. top: padding,
  3341. left: padding,
  3342. right: padding,
  3343. bottom: padding
  3344. };
  3345. }
  3346. }
  3347. function getTextBBox(text, fakeText) {
  3348. fakeText.textContent = text;
  3349. var textBBox;
  3350. try {
  3351. var bbox,
  3352. emptyLine = text === '';
  3353. // add dummy text, when line is empty to
  3354. // determine correct height
  3355. fakeText.textContent = emptyLine ? 'dummy' : text;
  3356. textBBox = fakeText.getBBox();
  3357. // take text rendering related horizontal
  3358. // padding into account
  3359. bbox = {
  3360. width: textBBox.width + textBBox.x * 2,
  3361. height: textBBox.height
  3362. };
  3363. if (emptyLine) {
  3364. // correct width
  3365. bbox.width = 0;
  3366. }
  3367. return bbox;
  3368. } catch (e) {
  3369. return { width: 0, height: 0 };
  3370. }
  3371. }
  3372. /**
  3373. * Layout the next line and return the layouted element.
  3374. *
  3375. * Alters the lines passed.
  3376. *
  3377. * @param {Array<string>} lines
  3378. * @return {Object} the line descriptor, an object { width, height, text }
  3379. */
  3380. function layoutNext(lines, maxWidth, fakeText) {
  3381. var originalLine = lines.shift(),
  3382. fitLine = originalLine;
  3383. var textBBox;
  3384. for (;;) {
  3385. textBBox = getTextBBox(fitLine, fakeText);
  3386. textBBox.width = fitLine ? textBBox.width : 0;
  3387. // try to fit
  3388. if (fitLine === ' ' || fitLine === '' || textBBox.width < Math.round(maxWidth) || fitLine.length < 2) {
  3389. return fit(lines, fitLine, originalLine, textBBox);
  3390. }
  3391. fitLine = shortenLine(fitLine, textBBox.width, maxWidth);
  3392. }
  3393. }
  3394. function fit(lines, fitLine, originalLine, textBBox) {
  3395. if (fitLine.length < originalLine.length) {
  3396. var remainder = originalLine.slice(fitLine.length).trim();
  3397. lines.unshift(remainder);
  3398. }
  3399. return {
  3400. width: textBBox.width,
  3401. height: textBBox.height,
  3402. text: fitLine
  3403. };
  3404. }
  3405. /**
  3406. * Shortens a line based on spacing and hyphens.
  3407. * Returns the shortened result on success.
  3408. *
  3409. * @param {string} line
  3410. * @param {number} maxLength the maximum characters of the string
  3411. * @return {string} the shortened string
  3412. */
  3413. function semanticShorten(line, maxLength) {
  3414. var parts = line.split(/(\s|-)/g),
  3415. part,
  3416. shortenedParts = [],
  3417. length = 0;
  3418. // try to shorten via spaces + hyphens
  3419. if (parts.length > 1) {
  3420. while ((part = parts.shift())) {
  3421. if (part.length + length < maxLength) {
  3422. shortenedParts.push(part);
  3423. length += part.length;
  3424. } else {
  3425. // remove previous part, too if hyphen does not fit anymore
  3426. if (part === '-') {
  3427. shortenedParts.pop();
  3428. }
  3429. break;
  3430. }
  3431. }
  3432. }
  3433. return shortenedParts.join('');
  3434. }
  3435. function shortenLine(line, width, maxWidth) {
  3436. var length = Math.max(line.length * (maxWidth / width), 1);
  3437. // try to shorten semantically (i.e. based on spaces and hyphens)
  3438. var shortenedLine = semanticShorten(line, length);
  3439. if (!shortenedLine) {
  3440. // force shorten by cutting the long word
  3441. shortenedLine = line.slice(0, Math.max(Math.round(length - 1), 1));
  3442. }
  3443. return shortenedLine;
  3444. }
  3445. function getHelperSvg() {
  3446. var helperSvg = document.getElementById('helper-svg');
  3447. if (!helperSvg) {
  3448. helperSvg = create('svg');
  3449. attr(helperSvg, {
  3450. id: 'helper-svg',
  3451. width: 0,
  3452. height: 0,
  3453. style: 'visibility: hidden; position: fixed'
  3454. });
  3455. document.body.appendChild(helperSvg);
  3456. }
  3457. return helperSvg;
  3458. }
  3459. /**
  3460. * Creates a new label utility
  3461. *
  3462. * @param {Object} config
  3463. * @param {Dimensions} config.size
  3464. * @param {number} config.padding
  3465. * @param {Object} config.style
  3466. * @param {string} config.align
  3467. */
  3468. function Text(config) {
  3469. this._config = assign({}, {
  3470. size: DEFAULT_LABEL_SIZE,
  3471. padding: DEFAULT_BOX_PADDING,
  3472. style: {},
  3473. align: 'center-top'
  3474. }, config || {});
  3475. }
  3476. /**
  3477. * Returns the layouted text as an SVG element.
  3478. *
  3479. * @param {string} text
  3480. * @param {Object} options
  3481. *
  3482. * @return {SVGElement}
  3483. */
  3484. Text.prototype.createText = function(text, options) {
  3485. return this.layoutText(text, options).element;
  3486. };
  3487. /**
  3488. * Returns a labels layouted dimensions.
  3489. *
  3490. * @param {string} text to layout
  3491. * @param {Object} options
  3492. *
  3493. * @return {Dimensions}
  3494. */
  3495. Text.prototype.getDimensions = function(text, options) {
  3496. return this.layoutText(text, options).dimensions;
  3497. };
  3498. /**
  3499. * Creates and returns a label and its bounding box.
  3500. *
  3501. * @method Text#createText
  3502. *
  3503. * @param {string} text the text to render on the label
  3504. * @param {Object} options
  3505. * @param {string} options.align how to align in the bounding box.
  3506. * Any of { 'center-middle', 'center-top' },
  3507. * defaults to 'center-top'.
  3508. * @param {string} options.style style to be applied to the text
  3509. * @param {boolean} options.fitBox indicates if box will be recalculated to
  3510. * fit text
  3511. *
  3512. * @return {Object} { element, dimensions }
  3513. */
  3514. Text.prototype.layoutText = function(text, options) {
  3515. var box = assign({}, this._config.size, options.box),
  3516. style = assign({}, this._config.style, options.style),
  3517. align = parseAlign(options.align || this._config.align),
  3518. padding = parsePadding(options.padding !== undefined ? options.padding : this._config.padding),
  3519. fitBox = options.fitBox || false;
  3520. var lineHeight = getLineHeight(style);
  3521. var lines = text.split(/\r?\n/g),
  3522. layouted = [];
  3523. var maxWidth = box.width - padding.left - padding.right;
  3524. // ensure correct rendering by attaching helper text node to invisible SVG
  3525. var helperText = create('text');
  3526. attr(helperText, { x: 0, y: 0 });
  3527. attr(helperText, style);
  3528. var helperSvg = getHelperSvg();
  3529. append(helperSvg, helperText);
  3530. while (lines.length) {
  3531. layouted.push(layoutNext(lines, maxWidth, helperText));
  3532. }
  3533. if (align.vertical === 'middle') {
  3534. padding.top = padding.bottom = 0;
  3535. }
  3536. var totalHeight = reduce(layouted, function(sum, line, idx) {
  3537. return sum + (lineHeight || line.height);
  3538. }, 0) + padding.top + padding.bottom;
  3539. var maxLineWidth = reduce(layouted, function(sum, line, idx) {
  3540. return line.width > sum ? line.width : sum;
  3541. }, 0);
  3542. // the y position of the next line
  3543. var y = padding.top;
  3544. if (align.vertical === 'middle') {
  3545. y += (box.height - totalHeight) / 2;
  3546. }
  3547. // magic number initial offset
  3548. y -= (lineHeight || layouted[0].height) / 4;
  3549. var textElement = create('text');
  3550. attr(textElement, style);
  3551. // layout each line taking into account that parent
  3552. // shape might resize to fit text size
  3553. forEach(layouted, function(line) {
  3554. var x;
  3555. y += (lineHeight || line.height);
  3556. switch (align.horizontal) {
  3557. case 'left':
  3558. x = padding.left;
  3559. break;
  3560. case 'right':
  3561. x = ((fitBox ? maxLineWidth : maxWidth)
  3562. - padding.right - line.width);
  3563. break;
  3564. default:
  3565. // aka center
  3566. x = Math.max((((fitBox ? maxLineWidth : maxWidth)
  3567. - line.width) / 2 + padding.left), 0);
  3568. }
  3569. var tspan = create('tspan');
  3570. attr(tspan, { x: x, y: y });
  3571. tspan.textContent = line.text;
  3572. append(textElement, tspan);
  3573. });
  3574. remove(helperText);
  3575. var dimensions = {
  3576. width: maxLineWidth,
  3577. height: totalHeight
  3578. };
  3579. return {
  3580. dimensions: dimensions,
  3581. element: textElement
  3582. };
  3583. };
  3584. function getLineHeight(style) {
  3585. if ('fontSize' in style && 'lineHeight' in style) {
  3586. return style.lineHeight * parseInt(style.fontSize, 10);
  3587. }
  3588. }
  3589. var DEFAULT_FONT_SIZE = 12;
  3590. var LINE_HEIGHT_RATIO = 1.2;
  3591. var MIN_TEXT_ANNOTATION_HEIGHT = 30;
  3592. function TextRenderer(config) {
  3593. var defaultStyle = assign({
  3594. fontFamily: 'Arial, sans-serif',
  3595. fontSize: DEFAULT_FONT_SIZE,
  3596. fontWeight: 'normal',
  3597. lineHeight: LINE_HEIGHT_RATIO
  3598. }, config && config.defaultStyle || {});
  3599. var fontSize = parseInt(defaultStyle.fontSize, 10) - 1;
  3600. var externalStyle = assign({}, defaultStyle, {
  3601. fontSize: fontSize
  3602. }, config && config.externalStyle || {});
  3603. var textUtil = new Text({
  3604. style: defaultStyle
  3605. });
  3606. /**
  3607. * Get the new bounds of an externally rendered,
  3608. * layouted label.
  3609. *
  3610. * @param {Bounds} bounds
  3611. * @param {string} text
  3612. *
  3613. * @return {Bounds}
  3614. */
  3615. this.getExternalLabelBounds = function(bounds, text) {
  3616. var layoutedDimensions = textUtil.getDimensions(text, {
  3617. box: {
  3618. width: 90,
  3619. height: 30,
  3620. x: bounds.width / 2 + bounds.x,
  3621. y: bounds.height / 2 + bounds.y
  3622. },
  3623. style: externalStyle
  3624. });
  3625. // resize label shape to fit label text
  3626. return {
  3627. x: Math.round(bounds.x + bounds.width / 2 - layoutedDimensions.width / 2),
  3628. y: Math.round(bounds.y),
  3629. width: Math.ceil(layoutedDimensions.width),
  3630. height: Math.ceil(layoutedDimensions.height)
  3631. };
  3632. };
  3633. /**
  3634. * Get the new bounds of text annotation.
  3635. *
  3636. * @param {Bounds} bounds
  3637. * @param {string} text
  3638. *
  3639. * @return {Bounds}
  3640. */
  3641. this.getTextAnnotationBounds = function(bounds, text) {
  3642. var layoutedDimensions = textUtil.getDimensions(text, {
  3643. box: bounds,
  3644. style: defaultStyle,
  3645. align: 'left-top',
  3646. padding: 5
  3647. });
  3648. return {
  3649. x: bounds.x,
  3650. y: bounds.y,
  3651. width: bounds.width,
  3652. height: Math.max(MIN_TEXT_ANNOTATION_HEIGHT, Math.round(layoutedDimensions.height))
  3653. };
  3654. };
  3655. /**
  3656. * Create a layouted text element.
  3657. *
  3658. * @param {string} text
  3659. * @param {Object} [options]
  3660. *
  3661. * @return {SVGElement} rendered text
  3662. */
  3663. this.createText = function(text, options) {
  3664. return textUtil.createText(text, options || {});
  3665. };
  3666. /**
  3667. * Get default text style.
  3668. */
  3669. this.getDefaultStyle = function() {
  3670. return defaultStyle;
  3671. };
  3672. /**
  3673. * Get the external text style.
  3674. */
  3675. this.getExternalStyle = function() {
  3676. return externalStyle;
  3677. };
  3678. }
  3679. TextRenderer.$inject = [
  3680. 'config.textRenderer'
  3681. ];
  3682. /**
  3683. * Map containing SVG paths needed by BpmnRenderer.
  3684. */
  3685. function PathMap() {
  3686. /**
  3687. * Contains a map of path elements
  3688. *
  3689. * <h1>Path definition</h1>
  3690. * A parameterized path is defined like this:
  3691. * <pre>
  3692. * 'GATEWAY_PARALLEL': {
  3693. * d: 'm {mx},{my} {e.x0},0 0,{e.x1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
  3694. '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
  3695. * height: 17.5,
  3696. * width: 17.5,
  3697. * heightElements: [2.5, 7.5],
  3698. * widthElements: [2.5, 7.5]
  3699. * }
  3700. * </pre>
  3701. * <p>It's important to specify a correct <b>height and width</b> for the path as the scaling
  3702. * is based on the ratio between the specified height and width in this object and the
  3703. * height and width that is set as scale target (Note x,y coordinates will be scaled with
  3704. * individual ratios).</p>
  3705. * <p>The '<b>heightElements</b>' and '<b>widthElements</b>' array must contain the values that will be scaled.
  3706. * The scaling is based on the computed ratios.
  3707. * Coordinates on the y axis should be in the <b>heightElement</b>'s array, they will be scaled using
  3708. * the computed ratio coefficient.
  3709. * In the parameterized path the scaled values can be accessed through the 'e' object in {} brackets.
  3710. * <ul>
  3711. * <li>The values for the y axis can be accessed in the path string using {e.y0}, {e.y1}, ....</li>
  3712. * <li>The values for the x axis can be accessed in the path string using {e.x0}, {e.x1}, ....</li>
  3713. * </ul>
  3714. * The numbers x0, x1 respectively y0, y1, ... map to the corresponding array index.
  3715. * </p>
  3716. */
  3717. this.pathMap = {
  3718. 'EVENT_MESSAGE': {
  3719. d: 'm {mx},{my} l 0,{e.y1} l {e.x1},0 l 0,-{e.y1} z l {e.x0},{e.y0} l {e.x0},-{e.y0}',
  3720. height: 36,
  3721. width: 36,
  3722. heightElements: [6, 14],
  3723. widthElements: [10.5, 21]
  3724. },
  3725. 'EVENT_SIGNAL': {
  3726. d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x1},0 Z',
  3727. height: 36,
  3728. width: 36,
  3729. heightElements: [18],
  3730. widthElements: [10, 20]
  3731. },
  3732. 'EVENT_ESCALATION': {
  3733. d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x0},-{e.y1} l -{e.x0},{e.y1} Z',
  3734. height: 36,
  3735. width: 36,
  3736. heightElements: [20, 7],
  3737. widthElements: [8]
  3738. },
  3739. 'EVENT_CONDITIONAL': {
  3740. d: 'M {e.x0},{e.y0} l {e.x1},0 l 0,{e.y2} l -{e.x1},0 Z ' +
  3741. 'M {e.x2},{e.y3} l {e.x0},0 ' +
  3742. 'M {e.x2},{e.y4} l {e.x0},0 ' +
  3743. 'M {e.x2},{e.y5} l {e.x0},0 ' +
  3744. 'M {e.x2},{e.y6} l {e.x0},0 ' +
  3745. 'M {e.x2},{e.y7} l {e.x0},0 ' +
  3746. 'M {e.x2},{e.y8} l {e.x0},0 ',
  3747. height: 36,
  3748. width: 36,
  3749. heightElements: [8.5, 14.5, 18, 11.5, 14.5, 17.5, 20.5, 23.5, 26.5],
  3750. widthElements: [10.5, 14.5, 12.5]
  3751. },
  3752. 'EVENT_LINK': {
  3753. d: 'm {mx},{my} 0,{e.y0} -{e.x1},0 0,{e.y1} {e.x1},0 0,{e.y0} {e.x0},-{e.y2} -{e.x0},-{e.y2} z',
  3754. height: 36,
  3755. width: 36,
  3756. heightElements: [4.4375, 6.75, 7.8125],
  3757. widthElements: [9.84375, 13.5]
  3758. },
  3759. 'EVENT_ERROR': {
  3760. d: 'm {mx},{my} {e.x0},-{e.y0} {e.x1},-{e.y1} {e.x2},{e.y2} {e.x3},-{e.y3} -{e.x4},{e.y4} -{e.x5},-{e.y5} z',
  3761. height: 36,
  3762. width: 36,
  3763. heightElements: [0.023, 8.737, 8.151, 16.564, 10.591, 8.714],
  3764. widthElements: [0.085, 6.672, 6.97, 4.273, 5.337, 6.636]
  3765. },
  3766. 'EVENT_CANCEL_45': {
  3767. d: 'm {mx},{my} -{e.x1},0 0,{e.x0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
  3768. '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
  3769. height: 36,
  3770. width: 36,
  3771. heightElements: [4.75, 8.5],
  3772. widthElements: [4.75, 8.5]
  3773. },
  3774. 'EVENT_COMPENSATION': {
  3775. d: 'm {mx},{my} {e.x0},-{e.y0} 0,{e.y1} z m {e.x1},-{e.y2} {e.x2},-{e.y3} 0,{e.y1} -{e.x2},-{e.y3} z',
  3776. height: 36,
  3777. width: 36,
  3778. heightElements: [6.5, 13, 0.4, 6.1],
  3779. widthElements: [9, 9.3, 8.7]
  3780. },
  3781. 'EVENT_TIMER_WH': {
  3782. d: 'M {mx},{my} l {e.x0},-{e.y0} m -{e.x0},{e.y0} l {e.x1},{e.y1} ',
  3783. height: 36,
  3784. width: 36,
  3785. heightElements: [10, 2],
  3786. widthElements: [3, 7]
  3787. },
  3788. 'EVENT_TIMER_LINE': {
  3789. d: 'M {mx},{my} ' +
  3790. 'm {e.x0},{e.y0} l -{e.x1},{e.y1} ',
  3791. height: 36,
  3792. width: 36,
  3793. heightElements: [10, 3],
  3794. widthElements: [0, 0]
  3795. },
  3796. 'EVENT_MULTIPLE': {
  3797. d:'m {mx},{my} {e.x1},-{e.y0} {e.x1},{e.y0} -{e.x0},{e.y1} -{e.x2},0 z',
  3798. height: 36,
  3799. width: 36,
  3800. heightElements: [6.28099, 12.56199],
  3801. widthElements: [3.1405, 9.42149, 12.56198]
  3802. },
  3803. 'EVENT_PARALLEL_MULTIPLE': {
  3804. d:'m {mx},{my} {e.x0},0 0,{e.y1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
  3805. '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
  3806. height: 36,
  3807. width: 36,
  3808. heightElements: [2.56228, 7.68683],
  3809. widthElements: [2.56228, 7.68683]
  3810. },
  3811. 'GATEWAY_EXCLUSIVE': {
  3812. d:'m {mx},{my} {e.x0},{e.y0} {e.x1},{e.y0} {e.x2},0 {e.x4},{e.y2} ' +
  3813. '{e.x4},{e.y1} {e.x2},0 {e.x1},{e.y3} {e.x0},{e.y3} ' +
  3814. '{e.x3},0 {e.x5},{e.y1} {e.x5},{e.y2} {e.x3},0 z',
  3815. height: 17.5,
  3816. width: 17.5,
  3817. heightElements: [8.5, 6.5312, -6.5312, -8.5],
  3818. widthElements: [6.5, -6.5, 3, -3, 5, -5]
  3819. },
  3820. 'GATEWAY_PARALLEL': {
  3821. d:'m {mx},{my} 0,{e.y1} -{e.x1},0 0,{e.y0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
  3822. '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
  3823. height: 30,
  3824. width: 30,
  3825. heightElements: [5, 12.5],
  3826. widthElements: [5, 12.5]
  3827. },
  3828. 'GATEWAY_EVENT_BASED': {
  3829. d:'m {mx},{my} {e.x0},{e.y0} {e.x0},{e.y1} {e.x1},{e.y2} {e.x2},0 z',
  3830. height: 11,
  3831. width: 11,
  3832. heightElements: [-6, 6, 12, -12],
  3833. widthElements: [9, -3, -12]
  3834. },
  3835. 'GATEWAY_COMPLEX': {
  3836. d:'m {mx},{my} 0,{e.y0} -{e.x0},-{e.y1} -{e.x1},{e.y2} {e.x0},{e.y1} -{e.x2},0 0,{e.y3} ' +
  3837. '{e.x2},0 -{e.x0},{e.y1} l {e.x1},{e.y2} {e.x0},-{e.y1} 0,{e.y0} {e.x3},0 0,-{e.y0} {e.x0},{e.y1} ' +
  3838. '{e.x1},-{e.y2} -{e.x0},-{e.y1} {e.x2},0 0,-{e.y3} -{e.x2},0 {e.x0},-{e.y1} -{e.x1},-{e.y2} ' +
  3839. '-{e.x0},{e.y1} 0,-{e.y0} -{e.x3},0 z',
  3840. height: 17.125,
  3841. width: 17.125,
  3842. heightElements: [4.875, 3.4375, 2.125, 3],
  3843. widthElements: [3.4375, 2.125, 4.875, 3]
  3844. },
  3845. 'DATA_OBJECT_PATH': {
  3846. d:'m 0,0 {e.x1},0 {e.x0},{e.y0} 0,{e.y1} -{e.x2},0 0,-{e.y2} {e.x1},0 0,{e.y0} {e.x0},0',
  3847. height: 61,
  3848. width: 51,
  3849. heightElements: [10, 50, 60],
  3850. widthElements: [10, 40, 50, 60]
  3851. },
  3852. 'DATA_OBJECT_COLLECTION_PATH': {
  3853. d:'m {mx}, {my} ' +
  3854. 'm 0 15 l 0 -15 ' +
  3855. 'm 4 15 l 0 -15 ' +
  3856. 'm 4 15 l 0 -15 ',
  3857. height: 61,
  3858. width: 51,
  3859. heightElements: [12],
  3860. widthElements: [1, 6, 12, 15]
  3861. },
  3862. 'DATA_ARROW': {
  3863. d:'m 5,9 9,0 0,-3 5,5 -5,5 0,-3 -9,0 z',
  3864. height: 61,
  3865. width: 51,
  3866. heightElements: [],
  3867. widthElements: []
  3868. },
  3869. 'DATA_STORE': {
  3870. d:'m {mx},{my} ' +
  3871. 'l 0,{e.y2} ' +
  3872. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
  3873. 'l 0,-{e.y2} ' +
  3874. 'c -{e.x0},-{e.y1} -{e.x1},-{e.y1} -{e.x2},0' +
  3875. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
  3876. 'm -{e.x2},{e.y0}' +
  3877. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0' +
  3878. 'm -{e.x2},{e.y0}' +
  3879. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0',
  3880. height: 61,
  3881. width: 61,
  3882. heightElements: [7, 10, 45],
  3883. widthElements: [2, 58, 60]
  3884. },
  3885. 'TEXT_ANNOTATION': {
  3886. d: 'm {mx}, {my} m 10,0 l -10,0 l 0,{e.y0} l 10,0',
  3887. height: 30,
  3888. width: 10,
  3889. heightElements: [30],
  3890. widthElements: [10]
  3891. },
  3892. 'MARKER_SUB_PROCESS': {
  3893. d: 'm{mx},{my} m 7,2 l 0,10 m -5,-5 l 10,0',
  3894. height: 10,
  3895. width: 10,
  3896. heightElements: [],
  3897. widthElements: []
  3898. },
  3899. 'MARKER_PARALLEL': {
  3900. d: 'm{mx},{my} m 3,2 l 0,10 m 3,-10 l 0,10 m 3,-10 l 0,10',
  3901. height: 10,
  3902. width: 10,
  3903. heightElements: [],
  3904. widthElements: []
  3905. },
  3906. 'MARKER_SEQUENTIAL': {
  3907. d: 'm{mx},{my} m 0,3 l 10,0 m -10,3 l 10,0 m -10,3 l 10,0',
  3908. height: 10,
  3909. width: 10,
  3910. heightElements: [],
  3911. widthElements: []
  3912. },
  3913. 'MARKER_COMPENSATION': {
  3914. d: 'm {mx},{my} 7,-5 0,10 z m 7.1,-0.3 6.9,-4.7 0,10 -6.9,-4.7 z',
  3915. height: 10,
  3916. width: 21,
  3917. heightElements: [],
  3918. widthElements: []
  3919. },
  3920. 'MARKER_LOOP': {
  3921. d: 'm {mx},{my} c 3.526979,0 6.386161,-2.829858 6.386161,-6.320661 0,-3.490806 -2.859182,-6.320661 ' +
  3922. '-6.386161,-6.320661 -3.526978,0 -6.38616,2.829855 -6.38616,6.320661 0,1.745402 ' +
  3923. '0.714797,3.325567 1.870463,4.469381 0.577834,0.571908 1.265885,1.034728 2.029916,1.35457 ' +
  3924. 'l -0.718163,-3.909793 m 0.718163,3.909793 -3.885211,0.802902',
  3925. height: 13.9,
  3926. width: 13.7,
  3927. heightElements: [],
  3928. widthElements: []
  3929. },
  3930. 'MARKER_ADHOC': {
  3931. d: 'm {mx},{my} m 0.84461,2.64411 c 1.05533,-1.23780996 2.64337,-2.07882 4.29653,-1.97997996 2.05163,0.0805 ' +
  3932. '3.85579,1.15803 5.76082,1.79107 1.06385,0.34139996 2.24454,0.1438 3.18759,-0.43767 0.61743,-0.33642 ' +
  3933. '1.2775,-0.64078 1.7542,-1.17511 0,0.56023 0,1.12046 0,1.6807 -0.98706,0.96237996 -2.29792,1.62393996 ' +
  3934. '-3.6918,1.66181996 -1.24459,0.0927 -2.46671,-0.2491 -3.59505,-0.74812 -1.35789,-0.55965 ' +
  3935. '-2.75133,-1.33436996 -4.27027,-1.18121996 -1.37741,0.14601 -2.41842,1.13685996 -3.44288,1.96782996 z',
  3936. height: 4,
  3937. width: 15,
  3938. heightElements: [],
  3939. widthElements: []
  3940. },
  3941. 'TASK_TYPE_SEND': {
  3942. d: 'm {mx},{my} l 0,{e.y1} l {e.x1},0 l 0,-{e.y1} z l {e.x0},{e.y0} l {e.x0},-{e.y0}',
  3943. height: 14,
  3944. width: 21,
  3945. heightElements: [6, 14],
  3946. widthElements: [10.5, 21]
  3947. },
  3948. 'TASK_TYPE_SCRIPT': {
  3949. d: 'm {mx},{my} c 9.966553,-6.27276 -8.000926,-7.91932 2.968968,-14.938 l -8.802728,0 ' +
  3950. 'c -10.969894,7.01868 6.997585,8.66524 -2.968967,14.938 z ' +
  3951. 'm -7,-12 l 5,0 ' +
  3952. 'm -4.5,3 l 4.5,0 ' +
  3953. 'm -3,3 l 5,0' +
  3954. 'm -4,3 l 5,0',
  3955. height: 15,
  3956. width: 12.6,
  3957. heightElements: [6, 14],
  3958. widthElements: [10.5, 21]
  3959. },
  3960. 'TASK_TYPE_USER_1': {
  3961. d: 'm {mx},{my} c 0.909,-0.845 1.594,-2.049 1.594,-3.385 0,-2.554 -1.805,-4.62199999 ' +
  3962. '-4.357,-4.62199999 -2.55199998,0 -4.28799998,2.06799999 -4.28799998,4.62199999 0,1.348 ' +
  3963. '0.974,2.562 1.89599998,3.405 -0.52899998,0.187 -5.669,2.097 -5.794,4.7560005 v 6.718 ' +
  3964. 'h 17 v -6.718 c 0,-2.2980005 -5.5279996,-4.5950005 -6.0509996,-4.7760005 z' +
  3965. 'm -8,6 l 0,5.5 m 11,0 l 0,-5'
  3966. },
  3967. 'TASK_TYPE_USER_2': {
  3968. d: 'm {mx},{my} m 2.162,1.009 c 0,2.4470005 -2.158,4.4310005 -4.821,4.4310005 ' +
  3969. '-2.66499998,0 -4.822,-1.981 -4.822,-4.4310005 '
  3970. },
  3971. 'TASK_TYPE_USER_3': {
  3972. d: 'm {mx},{my} m -6.9,-3.80 c 0,0 2.25099998,-2.358 4.27399998,-1.177 2.024,1.181 4.221,1.537 ' +
  3973. '4.124,0.965 -0.098,-0.57 -0.117,-3.79099999 -4.191,-4.13599999 -3.57499998,0.001 ' +
  3974. '-4.20799998,3.36699999 -4.20699998,4.34799999 z'
  3975. },
  3976. 'TASK_TYPE_MANUAL': {
  3977. d: 'm {mx},{my} c 0.234,-0.01 5.604,0.008 8.029,0.004 0.808,0 1.271,-0.172 1.417,-0.752 0.227,-0.898 ' +
  3978. '-0.334,-1.314 -1.338,-1.316 -2.467,-0.01 -7.886,-0.004 -8.108,-0.004 -0.014,-0.079 0.016,-0.533 0,-0.61 ' +
  3979. '0.195,-0.042 8.507,0.006 9.616,0.002 0.877,-0.007 1.35,-0.438 1.353,-1.208 0.003,-0.768 -0.479,-1.09 ' +
  3980. '-1.35,-1.091 -2.968,-0.002 -9.619,-0.013 -9.619,-0.013 v -0.591 c 0,0 5.052,-0.016 7.225,-0.016 ' +
  3981. '0.888,-0.002 1.354,-0.416 1.351,-1.193 -0.006,-0.761 -0.492,-1.196 -1.361,-1.196 -3.473,-0.005 ' +
  3982. '-10.86,-0.003 -11.0829995,-0.003 -0.022,-0.047 -0.045,-0.094 -0.069,-0.139 0.3939995,-0.319 ' +
  3983. '2.0409995,-1.626 2.4149995,-2.017 0.469,-0.4870005 0.519,-1.1650005 0.162,-1.6040005 -0.414,-0.511 ' +
  3984. '-0.973,-0.5 -1.48,-0.236 -1.4609995,0.764 -6.5999995,3.6430005 -7.7329995,4.2710005 -0.9,0.499 ' +
  3985. '-1.516,1.253 -1.882,2.19 -0.37000002,0.95 -0.17,2.01 -0.166,2.979 0.004,0.718 -0.27300002,1.345 ' +
  3986. '-0.055,2.063 0.629,2.087 2.425,3.312 4.859,3.318 4.6179995,0.014 9.2379995,-0.139 13.8569995,-0.158 ' +
  3987. '0.755,-0.004 1.171,-0.301 1.182,-1.033 0.012,-0.754 -0.423,-0.969 -1.183,-0.973 -1.778,-0.01 ' +
  3988. '-5.824,-0.004 -6.04,-0.004 10e-4,-0.084 0.003,-0.586 10e-4,-0.67 z'
  3989. },
  3990. 'TASK_TYPE_INSTANTIATING_SEND': {
  3991. d: 'm {mx},{my} l 0,8.4 l 12.6,0 l 0,-8.4 z l 6.3,3.6 l 6.3,-3.6'
  3992. },
  3993. 'TASK_TYPE_SERVICE': {
  3994. d: 'm {mx},{my} v -1.71335 c 0.352326,-0.0705 0.703932,-0.17838 1.047628,-0.32133 ' +
  3995. '0.344416,-0.14465 0.665822,-0.32133 0.966377,-0.52145 l 1.19431,1.18005 1.567487,-1.57688 ' +
  3996. '-1.195028,-1.18014 c 0.403376,-0.61394 0.683079,-1.29908 0.825447,-2.01824 l 1.622133,-0.01 ' +
  3997. 'v -2.2196 l -1.636514,0.01 c -0.07333,-0.35153 -0.178319,-0.70024 -0.323564,-1.04372 ' +
  3998. '-0.145244,-0.34406 -0.321407,-0.6644 -0.522735,-0.96217 l 1.131035,-1.13631 -1.583305,-1.56293 ' +
  3999. '-1.129598,1.13589 c -0.614052,-0.40108 -1.302883,-0.68093 -2.022633,-0.82247 l 0.0093,-1.61852 ' +
  4000. 'h -2.241173 l 0.0042,1.63124 c -0.353763,0.0736 -0.705369,0.17977 -1.049785,0.32371 -0.344415,0.14437 ' +
  4001. '-0.665102,0.32092 -0.9635006,0.52046 l -1.1698628,-1.15823 -1.5667691,1.5792 1.1684265,1.15669 ' +
  4002. 'c -0.4026573,0.61283 -0.68308,1.29797 -0.8247287,2.01713 l -1.6588041,0.003 v 2.22174 ' +
  4003. 'l 1.6724648,-0.006 c 0.073327,0.35077 0.1797598,0.70243 0.3242851,1.04472 0.1452428,0.34448 ' +
  4004. '0.3214064,0.6644 0.5227339,0.96066 l -1.1993431,1.19723 1.5840256,1.56011 1.1964668,-1.19348 ' +
  4005. 'c 0.6140517,0.40346 1.3028827,0.68232 2.0233517,0.82331 l 7.19e-4,1.69892 h 2.226848 z ' +
  4006. 'm 0.221462,-3.9957 c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
  4007. '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
  4008. '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
  4009. },
  4010. 'TASK_TYPE_SERVICE_FILL': {
  4011. d: 'm {mx},{my} c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
  4012. '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
  4013. '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
  4014. },
  4015. 'TASK_TYPE_BUSINESS_RULE_HEADER': {
  4016. d: 'm {mx},{my} 0,4 20,0 0,-4 z'
  4017. },
  4018. 'TASK_TYPE_BUSINESS_RULE_MAIN': {
  4019. d: 'm {mx},{my} 0,12 20,0 0,-12 z' +
  4020. 'm 0,8 l 20,0 ' +
  4021. 'm -13,-4 l 0,8'
  4022. },
  4023. 'MESSAGE_FLOW_MARKER': {
  4024. d: 'm {mx},{my} m -10.5 ,-7 l 0,14 l 21,0 l 0,-14 z l 10.5,6 l 10.5,-6'
  4025. }
  4026. };
  4027. this.getRawPath = function getRawPath(pathId) {
  4028. return this.pathMap[pathId].d;
  4029. };
  4030. /**
  4031. * Scales the path to the given height and width.
  4032. * <h1>Use case</h1>
  4033. * <p>Use case is to scale the content of elements (event, gateways) based
  4034. * on the element bounding box's size.
  4035. * </p>
  4036. * <h1>Why not transform</h1>
  4037. * <p>Scaling a path with transform() will also scale the stroke and IE does not support
  4038. * the option 'non-scaling-stroke' to prevent this.
  4039. * Also there are use cases where only some parts of a path should be
  4040. * scaled.</p>
  4041. *
  4042. * @param {string} pathId The ID of the path.
  4043. * @param {Object} param <p>
  4044. * Example param object scales the path to 60% size of the container (data.width, data.height).
  4045. * <pre>
  4046. * {
  4047. * xScaleFactor: 0.6,
  4048. * yScaleFactor:0.6,
  4049. * containerWidth: data.width,
  4050. * containerHeight: data.height,
  4051. * position: {
  4052. * mx: 0.46,
  4053. * my: 0.2,
  4054. * }
  4055. * }
  4056. * </pre>
  4057. * <ul>
  4058. * <li>targetpathwidth = xScaleFactor * containerWidth</li>
  4059. * <li>targetpathheight = yScaleFactor * containerHeight</li>
  4060. * <li>Position is used to set the starting coordinate of the path. M is computed:
  4061. * <ul>
  4062. * <li>position.x * containerWidth</li>
  4063. * <li>position.y * containerHeight</li>
  4064. * </ul>
  4065. * Center of the container <pre> position: {
  4066. * mx: 0.5,
  4067. * my: 0.5,
  4068. * }</pre>
  4069. * Upper left corner of the container
  4070. * <pre> position: {
  4071. * mx: 0.0,
  4072. * my: 0.0,
  4073. * }</pre>
  4074. * </li>
  4075. * </ul>
  4076. * </p>
  4077. *
  4078. */
  4079. this.getScaledPath = function getScaledPath(pathId, param) {
  4080. var rawPath = this.pathMap[pathId];
  4081. // positioning
  4082. // compute the start point of the path
  4083. var mx, my;
  4084. if (param.abspos) {
  4085. mx = param.abspos.x;
  4086. my = param.abspos.y;
  4087. } else {
  4088. mx = param.containerWidth * param.position.mx;
  4089. my = param.containerHeight * param.position.my;
  4090. }
  4091. var coordinates = {}; // map for the scaled coordinates
  4092. if (param.position) {
  4093. // path
  4094. var heightRatio = (param.containerHeight / rawPath.height) * param.yScaleFactor;
  4095. var widthRatio = (param.containerWidth / rawPath.width) * param.xScaleFactor;
  4096. // Apply height ratio
  4097. for (var heightIndex = 0; heightIndex < rawPath.heightElements.length; heightIndex++) {
  4098. coordinates['y' + heightIndex] = rawPath.heightElements[heightIndex] * heightRatio;
  4099. }
  4100. // Apply width ratio
  4101. for (var widthIndex = 0; widthIndex < rawPath.widthElements.length; widthIndex++) {
  4102. coordinates['x' + widthIndex] = rawPath.widthElements[widthIndex] * widthRatio;
  4103. }
  4104. }
  4105. // Apply value to raw path
  4106. var path = format(
  4107. rawPath.d, {
  4108. mx: mx,
  4109. my: my,
  4110. e: coordinates
  4111. }
  4112. );
  4113. return path;
  4114. };
  4115. }
  4116. // helpers //////////////////////
  4117. // copied from https://github.com/adobe-webplatform/Snap.svg/blob/master/src/svg.js
  4118. var tokenRegex = /\{([^}]+)\}/g,
  4119. objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g; // matches .xxxxx or ["xxxxx"] to run over object properties
  4120. function replacer(all, key, obj) {
  4121. var res = obj;
  4122. key.replace(objNotationRegex, function(all, name, quote, quotedName, isFunc) {
  4123. name = name || quotedName;
  4124. if (res) {
  4125. if (name in res) {
  4126. res = res[name];
  4127. }
  4128. typeof res == 'function' && isFunc && (res = res());
  4129. }
  4130. });
  4131. res = (res == null || res == obj ? all : res) + '';
  4132. return res;
  4133. }
  4134. function format(str, obj) {
  4135. return String(str).replace(tokenRegex, function(all, key) {
  4136. return replacer(all, key, obj);
  4137. });
  4138. }
  4139. var DrawModule = {
  4140. __init__: [ 'bpmnRenderer' ],
  4141. bpmnRenderer: [ 'type', BpmnRenderer ],
  4142. textRenderer: [ 'type', TextRenderer ],
  4143. pathMap: [ 'type', PathMap ]
  4144. };
  4145. /**
  4146. * A simple translation stub to be used for multi-language support
  4147. * in diagrams. Can be easily replaced with a more sophisticated
  4148. * solution.
  4149. *
  4150. * @example
  4151. *
  4152. * // use it inside any diagram component by injecting `translate`.
  4153. *
  4154. * function MyService(translate) {
  4155. * alert(translate('HELLO {you}', { you: 'You!' }));
  4156. * }
  4157. *
  4158. * @param {string} template to interpolate
  4159. * @param {Object} [replacements] a map with substitutes
  4160. *
  4161. * @return {string} the translated string
  4162. */
  4163. function translate$1(template, replacements) {
  4164. replacements = replacements || {};
  4165. return template.replace(/{([^}]+)}/g, function(_, key) {
  4166. return replacements[key] || '{' + key + '}';
  4167. });
  4168. }
  4169. var TranslateModule = {
  4170. translate: [ 'value', translate$1 ]
  4171. };
  4172. var DEFAULT_LABEL_SIZE$1 = {
  4173. width: 90,
  4174. height: 20
  4175. };
  4176. var FLOW_LABEL_INDENT = 15;
  4177. /**
  4178. * Returns true if the given semantic has an external label
  4179. *
  4180. * @param {BpmnElement} semantic
  4181. * @return {boolean} true if has label
  4182. */
  4183. function isLabelExternal(semantic) {
  4184. return is(semantic, 'bpmn:Event') ||
  4185. is(semantic, 'bpmn:Gateway') ||
  4186. is(semantic, 'bpmn:DataStoreReference') ||
  4187. is(semantic, 'bpmn:DataObjectReference') ||
  4188. is(semantic, 'bpmn:DataInput') ||
  4189. is(semantic, 'bpmn:DataOutput') ||
  4190. is(semantic, 'bpmn:SequenceFlow') ||
  4191. is(semantic, 'bpmn:MessageFlow') ||
  4192. is(semantic, 'bpmn:Group');
  4193. }
  4194. /**
  4195. * Get the position for sequence flow labels
  4196. *
  4197. * @param {Array<Point>} waypoints
  4198. * @return {Point} the label position
  4199. */
  4200. function getFlowLabelPosition(waypoints) {
  4201. // get the waypoints mid
  4202. var mid = waypoints.length / 2 - 1;
  4203. var first = waypoints[Math.floor(mid)];
  4204. var second = waypoints[Math.ceil(mid + 0.01)];
  4205. // get position
  4206. var position = getWaypointsMid(waypoints);
  4207. // calculate angle
  4208. var angle = Math.atan((second.y - first.y) / (second.x - first.x));
  4209. var x = position.x,
  4210. y = position.y;
  4211. if (Math.abs(angle) < Math.PI / 2) {
  4212. y -= FLOW_LABEL_INDENT;
  4213. } else {
  4214. x += FLOW_LABEL_INDENT;
  4215. }
  4216. return { x: x, y: y };
  4217. }
  4218. /**
  4219. * Get the middle of a number of waypoints
  4220. *
  4221. * @param {Array<Point>} waypoints
  4222. * @return {Point} the mid point
  4223. */
  4224. function getWaypointsMid(waypoints) {
  4225. var mid = waypoints.length / 2 - 1;
  4226. var first = waypoints[Math.floor(mid)];
  4227. var second = waypoints[Math.ceil(mid + 0.01)];
  4228. return {
  4229. x: first.x + (second.x - first.x) / 2,
  4230. y: first.y + (second.y - first.y) / 2
  4231. };
  4232. }
  4233. function getExternalLabelMid(element) {
  4234. if (element.waypoints) {
  4235. return getFlowLabelPosition(element.waypoints);
  4236. } else if (is(element, 'bpmn:Group')) {
  4237. return {
  4238. x: element.x + element.width / 2,
  4239. y: element.y + DEFAULT_LABEL_SIZE$1.height / 2
  4240. };
  4241. } else {
  4242. return {
  4243. x: element.x + element.width / 2,
  4244. y: element.y + element.height + DEFAULT_LABEL_SIZE$1.height / 2
  4245. };
  4246. }
  4247. }
  4248. /**
  4249. * Returns the bounds of an elements label, parsed from the elements DI or
  4250. * generated from its bounds.
  4251. *
  4252. * @param {BpmnElement} semantic
  4253. * @param {djs.model.Base} element
  4254. */
  4255. function getExternalLabelBounds(semantic, element) {
  4256. var mid,
  4257. size,
  4258. bounds,
  4259. di = semantic.di,
  4260. label = di.label;
  4261. if (label && label.bounds) {
  4262. bounds = label.bounds;
  4263. size = {
  4264. width: Math.max(DEFAULT_LABEL_SIZE$1.width, bounds.width),
  4265. height: bounds.height
  4266. };
  4267. mid = {
  4268. x: bounds.x + bounds.width / 2,
  4269. y: bounds.y + bounds.height / 2
  4270. };
  4271. } else {
  4272. mid = getExternalLabelMid(element);
  4273. size = DEFAULT_LABEL_SIZE$1;
  4274. }
  4275. return assign({
  4276. x: mid.x - size.width / 2,
  4277. y: mid.y - size.height / 2
  4278. }, size);
  4279. }
  4280. /**
  4281. * This file contains source code adapted from Snap.svg (licensed Apache-2.0).
  4282. *
  4283. * @see https://github.com/adobe-webplatform/Snap.svg/blob/master/src/path.js
  4284. */
  4285. /* eslint no-fallthrough: "off" */
  4286. var math = Math,
  4287. PI = math.PI;
  4288. function roundPoint(point) {
  4289. return {
  4290. x: Math.round(point.x),
  4291. y: Math.round(point.y)
  4292. };
  4293. }
  4294. /**
  4295. * Get the mid of the given bounds or point.
  4296. *
  4297. * @param {Bounds|Point} bounds
  4298. *
  4299. * @return {Point}
  4300. */
  4301. function getMid(bounds) {
  4302. return roundPoint({
  4303. x: bounds.x + (bounds.width || 0) / 2,
  4304. y: bounds.y + (bounds.height || 0) / 2
  4305. });
  4306. }
  4307. function elementToString(e) {
  4308. if (!e) {
  4309. return '<null>';
  4310. }
  4311. return '<' + e.$type + (e.id ? ' id="' + e.id : '') + '" />';
  4312. }
  4313. function elementData(semantic, attrs) {
  4314. return assign({
  4315. id: semantic.id,
  4316. type: semantic.$type,
  4317. businessObject: semantic
  4318. }, attrs);
  4319. }
  4320. function getWaypoints(bo, source, target) {
  4321. var waypoints = bo.di.waypoint;
  4322. if (!waypoints || waypoints.length < 2) {
  4323. return [ getMid(source), getMid(target) ];
  4324. }
  4325. return waypoints.map(function(p) {
  4326. return { x: p.x, y: p.y };
  4327. });
  4328. }
  4329. function notYetDrawn(translate, semantic, refSemantic, property) {
  4330. return new Error(translate('element {element} referenced by {referenced}#{property} not yet drawn', {
  4331. element: elementToString(refSemantic),
  4332. referenced: elementToString(semantic),
  4333. property: property
  4334. }));
  4335. }
  4336. /**
  4337. * An importer that adds bpmn elements to the canvas
  4338. *
  4339. * @param {EventBus} eventBus
  4340. * @param {Canvas} canvas
  4341. * @param {ElementFactory} elementFactory
  4342. * @param {ElementRegistry} elementRegistry
  4343. * @param {Function} translate
  4344. * @param {TextRenderer} textRenderer
  4345. */
  4346. function BpmnImporter(
  4347. eventBus, canvas, elementFactory,
  4348. elementRegistry, translate, textRenderer) {
  4349. this._eventBus = eventBus;
  4350. this._canvas = canvas;
  4351. this._elementFactory = elementFactory;
  4352. this._elementRegistry = elementRegistry;
  4353. this._translate = translate;
  4354. this._textRenderer = textRenderer;
  4355. }
  4356. BpmnImporter.$inject = [
  4357. 'eventBus',
  4358. 'canvas',
  4359. 'elementFactory',
  4360. 'elementRegistry',
  4361. 'translate',
  4362. 'textRenderer'
  4363. ];
  4364. /**
  4365. * Add bpmn element (semantic) to the canvas onto the
  4366. * specified parent shape.
  4367. */
  4368. BpmnImporter.prototype.add = function(semantic, parentElement) {
  4369. var di = semantic.di,
  4370. element,
  4371. translate = this._translate,
  4372. hidden;
  4373. var parentIndex;
  4374. // ROOT ELEMENT
  4375. // handle the special case that we deal with a
  4376. // invisible root element (process or collaboration)
  4377. if (is(di, 'bpmndi:BPMNPlane')) {
  4378. // add a virtual element (not being drawn)
  4379. element = this._elementFactory.createRoot(elementData(semantic));
  4380. this._canvas.setRootElement(element);
  4381. }
  4382. // SHAPE
  4383. else if (is(di, 'bpmndi:BPMNShape')) {
  4384. var collapsed = !isExpanded(semantic),
  4385. isFrame = isFrameElement(semantic);
  4386. hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
  4387. var bounds = semantic.di.bounds;
  4388. element = this._elementFactory.createShape(elementData(semantic, {
  4389. collapsed: collapsed,
  4390. hidden: hidden,
  4391. x: Math.round(bounds.x),
  4392. y: Math.round(bounds.y),
  4393. width: Math.round(bounds.width),
  4394. height: Math.round(bounds.height),
  4395. isFrame: isFrame
  4396. }));
  4397. if (is(semantic, 'bpmn:BoundaryEvent')) {
  4398. this._attachBoundary(semantic, element);
  4399. }
  4400. // insert lanes behind other flow nodes (cf. #727)
  4401. if (is(semantic, 'bpmn:Lane')) {
  4402. parentIndex = 0;
  4403. }
  4404. if (is(semantic, 'bpmn:DataStoreReference')) {
  4405. // check whether data store is inside our outside of its semantic parent
  4406. if (!isPointInsideBBox(parentElement, getMid(bounds))) {
  4407. parentElement = this._canvas.getRootElement();
  4408. }
  4409. }
  4410. this._canvas.addShape(element, parentElement, parentIndex);
  4411. }
  4412. // CONNECTION
  4413. else if (is(di, 'bpmndi:BPMNEdge')) {
  4414. var source = this._getSource(semantic),
  4415. target = this._getTarget(semantic);
  4416. hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
  4417. element = this._elementFactory.createConnection(elementData(semantic, {
  4418. hidden: hidden,
  4419. source: source,
  4420. target: target,
  4421. waypoints: getWaypoints(semantic, source, target)
  4422. }));
  4423. if (is(semantic, 'bpmn:DataAssociation')) {
  4424. // render always on top; this ensures DataAssociations
  4425. // are rendered correctly across different "hacks" people
  4426. // love to model such as cross participant / sub process
  4427. // associations
  4428. parentElement = null;
  4429. }
  4430. // insert sequence flows behind other flow nodes (cf. #727)
  4431. if (is(semantic, 'bpmn:SequenceFlow')) {
  4432. parentIndex = 0;
  4433. }
  4434. this._canvas.addConnection(element, parentElement, parentIndex);
  4435. } else {
  4436. throw new Error(translate('unknown di {di} for element {semantic}', {
  4437. di: elementToString(di),
  4438. semantic: elementToString(semantic)
  4439. }));
  4440. }
  4441. // (optional) LABEL
  4442. if (isLabelExternal(semantic) && getLabel(element)) {
  4443. this.addLabel(semantic, element);
  4444. }
  4445. this._eventBus.fire('bpmnElement.added', { element: element });
  4446. return element;
  4447. };
  4448. /**
  4449. * Attach the boundary element to the given host
  4450. *
  4451. * @param {ModdleElement} boundarySemantic
  4452. * @param {djs.model.Base} boundaryElement
  4453. */
  4454. BpmnImporter.prototype._attachBoundary = function(boundarySemantic, boundaryElement) {
  4455. var translate = this._translate;
  4456. var hostSemantic = boundarySemantic.attachedToRef;
  4457. if (!hostSemantic) {
  4458. throw new Error(translate('missing {semantic}#attachedToRef', {
  4459. semantic: elementToString(boundarySemantic)
  4460. }));
  4461. }
  4462. var host = this._elementRegistry.get(hostSemantic.id),
  4463. attachers = host && host.attachers;
  4464. if (!host) {
  4465. throw notYetDrawn(translate, boundarySemantic, hostSemantic, 'attachedToRef');
  4466. }
  4467. // wire element.host <> host.attachers
  4468. boundaryElement.host = host;
  4469. if (!attachers) {
  4470. host.attachers = attachers = [];
  4471. }
  4472. if (attachers.indexOf(boundaryElement) === -1) {
  4473. attachers.push(boundaryElement);
  4474. }
  4475. };
  4476. /**
  4477. * add label for an element
  4478. */
  4479. BpmnImporter.prototype.addLabel = function(semantic, element) {
  4480. var bounds,
  4481. text,
  4482. label;
  4483. bounds = getExternalLabelBounds(semantic, element);
  4484. text = getLabel(element);
  4485. if (text) {
  4486. // get corrected bounds from actual layouted text
  4487. bounds = this._textRenderer.getExternalLabelBounds(bounds, text);
  4488. }
  4489. label = this._elementFactory.createLabel(elementData(semantic, {
  4490. id: semantic.id + '_label',
  4491. labelTarget: element,
  4492. type: 'label',
  4493. hidden: element.hidden || !getLabel(element),
  4494. x: Math.round(bounds.x),
  4495. y: Math.round(bounds.y),
  4496. width: Math.round(bounds.width),
  4497. height: Math.round(bounds.height)
  4498. }));
  4499. return this._canvas.addShape(label, element.parent);
  4500. };
  4501. /**
  4502. * Return the drawn connection end based on the given side.
  4503. *
  4504. * @throws {Error} if the end is not yet drawn
  4505. */
  4506. BpmnImporter.prototype._getEnd = function(semantic, side) {
  4507. var element,
  4508. refSemantic,
  4509. type = semantic.$type,
  4510. translate = this._translate;
  4511. refSemantic = semantic[side + 'Ref'];
  4512. // handle mysterious isMany DataAssociation#sourceRef
  4513. if (side === 'source' && type === 'bpmn:DataInputAssociation') {
  4514. refSemantic = refSemantic && refSemantic[0];
  4515. }
  4516. // fix source / target for DataInputAssociation / DataOutputAssociation
  4517. if (side === 'source' && type === 'bpmn:DataOutputAssociation' ||
  4518. side === 'target' && type === 'bpmn:DataInputAssociation') {
  4519. refSemantic = semantic.$parent;
  4520. }
  4521. element = refSemantic && this._getElement(refSemantic);
  4522. if (element) {
  4523. return element;
  4524. }
  4525. if (refSemantic) {
  4526. throw notYetDrawn(translate, semantic, refSemantic, side + 'Ref');
  4527. } else {
  4528. throw new Error(translate('{semantic}#{side} Ref not specified', {
  4529. semantic: elementToString(semantic),
  4530. side: side
  4531. }));
  4532. }
  4533. };
  4534. BpmnImporter.prototype._getSource = function(semantic) {
  4535. return this._getEnd(semantic, 'source');
  4536. };
  4537. BpmnImporter.prototype._getTarget = function(semantic) {
  4538. return this._getEnd(semantic, 'target');
  4539. };
  4540. BpmnImporter.prototype._getElement = function(semantic) {
  4541. return this._elementRegistry.get(semantic.id);
  4542. };
  4543. // helpers ////////////////////
  4544. function isPointInsideBBox(bbox, point) {
  4545. var x = point.x,
  4546. y = point.y;
  4547. return x >= bbox.x &&
  4548. x <= bbox.x + bbox.width &&
  4549. y >= bbox.y &&
  4550. y <= bbox.y + bbox.height;
  4551. }
  4552. function isFrameElement(semantic) {
  4553. return is(semantic, 'bpmn:Group');
  4554. }
  4555. var ImportModule = {
  4556. __depends__: [
  4557. TranslateModule
  4558. ],
  4559. bpmnImporter: [ 'type', BpmnImporter ]
  4560. };
  4561. var CoreModule = {
  4562. __depends__: [
  4563. DrawModule,
  4564. ImportModule
  4565. ]
  4566. };
  4567. function getOriginal(event) {
  4568. return event.originalEvent || event.srcEvent;
  4569. }
  4570. function isMac() {
  4571. return (/mac/i).test(navigator.platform);
  4572. }
  4573. function isPrimaryButton(event) {
  4574. // button === 0 -> left áka primary mouse button
  4575. return !(getOriginal(event) || event).button;
  4576. }
  4577. function hasPrimaryModifier(event) {
  4578. var originalEvent = getOriginal(event) || event;
  4579. if (!isPrimaryButton(event)) {
  4580. return false;
  4581. }
  4582. // Use alt as primary modifier key for mac OS
  4583. if (isMac()) {
  4584. return originalEvent.metaKey;
  4585. } else {
  4586. return originalEvent.ctrlKey;
  4587. }
  4588. }
  4589. function allowAll(e) { return true; }
  4590. var LOW_PRIORITY = 500;
  4591. /**
  4592. * A plugin that provides interaction events for diagram elements.
  4593. *
  4594. * It emits the following events:
  4595. *
  4596. * * element.click
  4597. * * element.contextmenu
  4598. * * element.dblclick
  4599. * * element.hover
  4600. * * element.mousedown
  4601. * * element.mousemove
  4602. * * element.mouseup
  4603. * * element.out
  4604. *
  4605. * Each event is a tuple { element, gfx, originalEvent }.
  4606. *
  4607. * Canceling the event via Event#preventDefault()
  4608. * prevents the original DOM operation.
  4609. *
  4610. * @param {EventBus} eventBus
  4611. */
  4612. function InteractionEvents(eventBus, elementRegistry, styles) {
  4613. var self = this;
  4614. /**
  4615. * Fire an interaction event.
  4616. *
  4617. * @param {string} type local event name, e.g. element.click.
  4618. * @param {DOMEvent} event native event
  4619. * @param {djs.model.Base} [element] the diagram element to emit the event on;
  4620. * defaults to the event target
  4621. */
  4622. function fire(type, event, element) {
  4623. if (isIgnored(type, event)) {
  4624. return;
  4625. }
  4626. var target, gfx, returnValue;
  4627. if (!element) {
  4628. target = event.delegateTarget || event.target;
  4629. if (target) {
  4630. gfx = target;
  4631. element = elementRegistry.get(gfx);
  4632. }
  4633. } else {
  4634. gfx = elementRegistry.getGraphics(element);
  4635. }
  4636. if (!gfx || !element) {
  4637. return;
  4638. }
  4639. returnValue = eventBus.fire(type, {
  4640. element: element,
  4641. gfx: gfx,
  4642. originalEvent: event
  4643. });
  4644. if (returnValue === false) {
  4645. event.stopPropagation();
  4646. event.preventDefault();
  4647. }
  4648. }
  4649. // TODO(nikku): document this
  4650. var handlers = {};
  4651. function mouseHandler(localEventName) {
  4652. return handlers[localEventName];
  4653. }
  4654. function isIgnored(localEventName, event) {
  4655. var filter = ignoredFilters[localEventName] || isPrimaryButton;
  4656. // only react on left mouse button interactions
  4657. // except for interaction events that are enabled
  4658. // for secundary mouse button
  4659. return !filter(event);
  4660. }
  4661. var bindings = {
  4662. click: 'element.click',
  4663. contextmenu: 'element.contextmenu',
  4664. dblclick: 'element.dblclick',
  4665. mousedown: 'element.mousedown',
  4666. mousemove: 'element.mousemove',
  4667. mouseover: 'element.hover',
  4668. mouseout: 'element.out',
  4669. mouseup: 'element.mouseup',
  4670. };
  4671. var ignoredFilters = {
  4672. 'element.contextmenu': allowAll
  4673. };
  4674. // manual event trigger //////////
  4675. /**
  4676. * Trigger an interaction event (based on a native dom event)
  4677. * on the target shape or connection.
  4678. *
  4679. * @param {string} eventName the name of the triggered DOM event
  4680. * @param {MouseEvent} event
  4681. * @param {djs.model.Base} targetElement
  4682. */
  4683. function triggerMouseEvent(eventName, event, targetElement) {
  4684. // i.e. element.mousedown...
  4685. var localEventName = bindings[eventName];
  4686. if (!localEventName) {
  4687. throw new Error('unmapped DOM event name <' + eventName + '>');
  4688. }
  4689. return fire(localEventName, event, targetElement);
  4690. }
  4691. var ELEMENT_SELECTOR = 'svg, .djs-element';
  4692. // event handling ///////
  4693. function registerEvent(node, event, localEvent, ignoredFilter) {
  4694. var handler = handlers[localEvent] = function(event) {
  4695. fire(localEvent, event);
  4696. };
  4697. if (ignoredFilter) {
  4698. ignoredFilters[localEvent] = ignoredFilter;
  4699. }
  4700. handler.$delegate = delegateEvents.bind(node, ELEMENT_SELECTOR, event, handler);
  4701. }
  4702. function unregisterEvent(node, event, localEvent) {
  4703. var handler = mouseHandler(localEvent);
  4704. if (!handler) {
  4705. return;
  4706. }
  4707. delegateEvents.unbind(node, event, handler.$delegate);
  4708. }
  4709. function registerEvents(svg) {
  4710. forEach(bindings, function(val, key) {
  4711. registerEvent(svg, key, val);
  4712. });
  4713. }
  4714. function unregisterEvents(svg) {
  4715. forEach(bindings, function(val, key) {
  4716. unregisterEvent(svg, key, val);
  4717. });
  4718. }
  4719. eventBus.on('canvas.destroy', function(event) {
  4720. unregisterEvents(event.svg);
  4721. });
  4722. eventBus.on('canvas.init', function(event) {
  4723. registerEvents(event.svg);
  4724. });
  4725. // hit box updating ////////////////
  4726. eventBus.on([ 'shape.added', 'connection.added' ], function(event) {
  4727. var element = event.element,
  4728. gfx = event.gfx;
  4729. eventBus.fire('interactionEvents.createHit', { element: element, gfx: gfx });
  4730. });
  4731. // Update djs-hit on change.
  4732. // A low priortity is necessary, because djs-hit of labels has to be updated
  4733. // after the label bounds have been updated in the renderer.
  4734. eventBus.on([
  4735. 'shape.changed',
  4736. 'connection.changed'
  4737. ], LOW_PRIORITY, function(event) {
  4738. var element = event.element,
  4739. gfx = event.gfx;
  4740. eventBus.fire('interactionEvents.updateHit', { element: element, gfx: gfx });
  4741. });
  4742. eventBus.on('interactionEvents.createHit', LOW_PRIORITY, function(event) {
  4743. var element = event.element,
  4744. gfx = event.gfx;
  4745. self.createDefaultHit(element, gfx);
  4746. });
  4747. eventBus.on('interactionEvents.updateHit', function(event) {
  4748. var element = event.element,
  4749. gfx = event.gfx;
  4750. self.updateDefaultHit(element, gfx);
  4751. });
  4752. // hit styles ////////////
  4753. var STROKE_HIT_STYLE = createHitStyle('djs-hit djs-hit-stroke');
  4754. var CLICK_STROKE_HIT_STYLE = createHitStyle('djs-hit djs-hit-click-stroke');
  4755. var ALL_HIT_STYLE = createHitStyle('djs-hit djs-hit-all');
  4756. var HIT_TYPES = {
  4757. 'all': ALL_HIT_STYLE,
  4758. 'click-stroke': CLICK_STROKE_HIT_STYLE,
  4759. 'stroke': STROKE_HIT_STYLE
  4760. };
  4761. function createHitStyle(classNames, attrs) {
  4762. attrs = assign({
  4763. stroke: 'white',
  4764. strokeWidth: 15
  4765. }, attrs || {});
  4766. return styles.cls(classNames, [ 'no-fill', 'no-border' ], attrs);
  4767. }
  4768. // style helpers ///////////////
  4769. function applyStyle(hit, type) {
  4770. var attrs = HIT_TYPES[type];
  4771. if (!attrs) {
  4772. throw new Error('invalid hit type <' + type + '>');
  4773. }
  4774. attr(hit, attrs);
  4775. return hit;
  4776. }
  4777. function appendHit(gfx, hit) {
  4778. append(gfx, hit);
  4779. }
  4780. // API
  4781. /**
  4782. * Remove hints on the given graphics.
  4783. *
  4784. * @param {SVGElement} gfx
  4785. */
  4786. this.removeHits = function(gfx) {
  4787. var hits = all('.djs-hit', gfx);
  4788. forEach(hits, remove);
  4789. };
  4790. /**
  4791. * Create default hit for the given element.
  4792. *
  4793. * @param {djs.model.Base} element
  4794. * @param {SVGElement} gfx
  4795. *
  4796. * @return {SVGElement} created hit
  4797. */
  4798. this.createDefaultHit = function(element, gfx) {
  4799. var waypoints = element.waypoints,
  4800. isFrame = element.isFrame,
  4801. boxType;
  4802. if (waypoints) {
  4803. return this.createWaypointsHit(gfx, waypoints);
  4804. } else {
  4805. boxType = isFrame ? 'stroke' : 'all';
  4806. return this.createBoxHit(gfx, boxType, {
  4807. width: element.width,
  4808. height: element.height
  4809. });
  4810. }
  4811. };
  4812. /**
  4813. * Create hits for the given waypoints.
  4814. *
  4815. * @param {SVGElement} gfx
  4816. * @param {Array<Point>} waypoints
  4817. *
  4818. * @return {SVGElement}
  4819. */
  4820. this.createWaypointsHit = function(gfx, waypoints) {
  4821. var hit = createLine(waypoints);
  4822. applyStyle(hit, 'stroke');
  4823. appendHit(gfx, hit);
  4824. return hit;
  4825. };
  4826. /**
  4827. * Create hits for a box.
  4828. *
  4829. * @param {SVGElement} gfx
  4830. * @param {string} hitType
  4831. * @param {Object} attrs
  4832. *
  4833. * @return {SVGElement}
  4834. */
  4835. this.createBoxHit = function(gfx, type, attrs) {
  4836. attrs = assign({
  4837. x: 0,
  4838. y: 0
  4839. }, attrs);
  4840. var hit = create('rect');
  4841. applyStyle(hit, type);
  4842. attr(hit, attrs);
  4843. appendHit(gfx, hit);
  4844. return hit;
  4845. };
  4846. /**
  4847. * Update default hit of the element.
  4848. *
  4849. * @param {djs.model.Base} element
  4850. * @param {SVGElement} gfx
  4851. *
  4852. * @return {SVGElement} updated hit
  4853. */
  4854. this.updateDefaultHit = function(element, gfx) {
  4855. var hit = query('.djs-hit', gfx);
  4856. if (!hit) {
  4857. return;
  4858. }
  4859. if (element.waypoints) {
  4860. updateLine(hit, element.waypoints);
  4861. } else {
  4862. attr(hit, {
  4863. width: element.width,
  4864. height: element.height
  4865. });
  4866. }
  4867. return hit;
  4868. };
  4869. this.fire = fire;
  4870. this.triggerMouseEvent = triggerMouseEvent;
  4871. this.mouseHandler = mouseHandler;
  4872. this.registerEvent = registerEvent;
  4873. this.unregisterEvent = unregisterEvent;
  4874. }
  4875. InteractionEvents.$inject = [
  4876. 'eventBus',
  4877. 'elementRegistry',
  4878. 'styles'
  4879. ];
  4880. /**
  4881. * An event indicating that the mouse hovered over an element
  4882. *
  4883. * @event element.hover
  4884. *
  4885. * @type {Object}
  4886. * @property {djs.model.Base} element
  4887. * @property {SVGElement} gfx
  4888. * @property {Event} originalEvent
  4889. */
  4890. /**
  4891. * An event indicating that the mouse has left an element
  4892. *
  4893. * @event element.out
  4894. *
  4895. * @type {Object}
  4896. * @property {djs.model.Base} element
  4897. * @property {SVGElement} gfx
  4898. * @property {Event} originalEvent
  4899. */
  4900. /**
  4901. * An event indicating that the mouse has clicked an element
  4902. *
  4903. * @event element.click
  4904. *
  4905. * @type {Object}
  4906. * @property {djs.model.Base} element
  4907. * @property {SVGElement} gfx
  4908. * @property {Event} originalEvent
  4909. */
  4910. /**
  4911. * An event indicating that the mouse has double clicked an element
  4912. *
  4913. * @event element.dblclick
  4914. *
  4915. * @type {Object}
  4916. * @property {djs.model.Base} element
  4917. * @property {SVGElement} gfx
  4918. * @property {Event} originalEvent
  4919. */
  4920. /**
  4921. * An event indicating that the mouse has gone down on an element.
  4922. *
  4923. * @event element.mousedown
  4924. *
  4925. * @type {Object}
  4926. * @property {djs.model.Base} element
  4927. * @property {SVGElement} gfx
  4928. * @property {Event} originalEvent
  4929. */
  4930. /**
  4931. * An event indicating that the mouse has gone up on an element.
  4932. *
  4933. * @event element.mouseup
  4934. *
  4935. * @type {Object}
  4936. * @property {djs.model.Base} element
  4937. * @property {SVGElement} gfx
  4938. * @property {Event} originalEvent
  4939. */
  4940. /**
  4941. * An event indicating that the context menu action is triggered
  4942. * via mouse or touch controls.
  4943. *
  4944. * @event element.contextmenu
  4945. *
  4946. * @type {Object}
  4947. * @property {djs.model.Base} element
  4948. * @property {SVGElement} gfx
  4949. * @property {Event} originalEvent
  4950. */
  4951. var InteractionEventsModule = {
  4952. __init__: [ 'interactionEvents' ],
  4953. interactionEvents: [ 'type', InteractionEvents ]
  4954. };
  4955. /**
  4956. * Returns the surrounding bbox for all elements in
  4957. * the array or the element primitive.
  4958. *
  4959. * @param {Array<djs.model.Shape>|djs.model.Shape} elements
  4960. * @param {boolean} stopRecursion
  4961. */
  4962. function getBBox(elements, stopRecursion) {
  4963. stopRecursion = !!stopRecursion;
  4964. if (!isArray(elements)) {
  4965. elements = [elements];
  4966. }
  4967. var minX,
  4968. minY,
  4969. maxX,
  4970. maxY;
  4971. forEach(elements, function(element) {
  4972. // If element is a connection the bbox must be computed first
  4973. var bbox = element;
  4974. if (element.waypoints && !stopRecursion) {
  4975. bbox = getBBox(element.waypoints, true);
  4976. }
  4977. var x = bbox.x,
  4978. y = bbox.y,
  4979. height = bbox.height || 0,
  4980. width = bbox.width || 0;
  4981. if (x < minX || minX === undefined) {
  4982. minX = x;
  4983. }
  4984. if (y < minY || minY === undefined) {
  4985. minY = y;
  4986. }
  4987. if ((x + width) > maxX || maxX === undefined) {
  4988. maxX = x + width;
  4989. }
  4990. if ((y + height) > maxY || maxY === undefined) {
  4991. maxY = y + height;
  4992. }
  4993. });
  4994. return {
  4995. x: minX,
  4996. y: minY,
  4997. height: maxY - minY,
  4998. width: maxX - minX
  4999. };
  5000. }
  5001. function getType(element) {
  5002. if ('waypoints' in element) {
  5003. return 'connection';
  5004. }
  5005. if ('x' in element) {
  5006. return 'shape';
  5007. }
  5008. return 'root';
  5009. }
  5010. function isFrameElement$1(element) {
  5011. return !!(element && element.isFrame);
  5012. }
  5013. var LOW_PRIORITY$1 = 500;
  5014. /**
  5015. * @class
  5016. *
  5017. * A plugin that adds an outline to shapes and connections that may be activated and styled
  5018. * via CSS classes.
  5019. *
  5020. * @param {EventBus} eventBus
  5021. * @param {Styles} styles
  5022. * @param {ElementRegistry} elementRegistry
  5023. */
  5024. function Outline(eventBus, styles, elementRegistry) {
  5025. this.offset = 6;
  5026. var OUTLINE_STYLE = styles.cls('djs-outline', [ 'no-fill' ]);
  5027. var self = this;
  5028. function createOutline(gfx, bounds) {
  5029. var outline = create('rect');
  5030. attr(outline, assign({
  5031. x: 10,
  5032. y: 10,
  5033. width: 100,
  5034. height: 100
  5035. }, OUTLINE_STYLE));
  5036. append(gfx, outline);
  5037. return outline;
  5038. }
  5039. // A low priortity is necessary, because outlines of labels have to be updated
  5040. // after the label bounds have been updated in the renderer.
  5041. eventBus.on([ 'shape.added', 'shape.changed' ], LOW_PRIORITY$1, function(event) {
  5042. var element = event.element,
  5043. gfx = event.gfx;
  5044. var outline = query('.djs-outline', gfx);
  5045. if (!outline) {
  5046. outline = createOutline(gfx);
  5047. }
  5048. self.updateShapeOutline(outline, element);
  5049. });
  5050. eventBus.on([ 'connection.added', 'connection.changed' ], function(event) {
  5051. var element = event.element,
  5052. gfx = event.gfx;
  5053. var outline = query('.djs-outline', gfx);
  5054. if (!outline) {
  5055. outline = createOutline(gfx);
  5056. }
  5057. self.updateConnectionOutline(outline, element);
  5058. });
  5059. }
  5060. /**
  5061. * Updates the outline of a shape respecting the dimension of the
  5062. * element and an outline offset.
  5063. *
  5064. * @param {SVGElement} outline
  5065. * @param {djs.model.Base} element
  5066. */
  5067. Outline.prototype.updateShapeOutline = function(outline, element) {
  5068. attr(outline, {
  5069. x: -this.offset,
  5070. y: -this.offset,
  5071. width: element.width + this.offset * 2,
  5072. height: element.height + this.offset * 2
  5073. });
  5074. };
  5075. /**
  5076. * Updates the outline of a connection respecting the bounding box of
  5077. * the connection and an outline offset.
  5078. *
  5079. * @param {SVGElement} outline
  5080. * @param {djs.model.Base} element
  5081. */
  5082. Outline.prototype.updateConnectionOutline = function(outline, connection) {
  5083. var bbox = getBBox(connection);
  5084. attr(outline, {
  5085. x: bbox.x - this.offset,
  5086. y: bbox.y - this.offset,
  5087. width: bbox.width + this.offset * 2,
  5088. height: bbox.height + this.offset * 2
  5089. });
  5090. };
  5091. Outline.$inject = ['eventBus', 'styles', 'elementRegistry'];
  5092. var OutlineModule = {
  5093. __init__: [ 'outline' ],
  5094. outline: [ 'type', Outline ]
  5095. };
  5096. /**
  5097. * A service that offers the current selection in a diagram.
  5098. * Offers the api to control the selection, too.
  5099. *
  5100. * @class
  5101. *
  5102. * @param {EventBus} eventBus the event bus
  5103. */
  5104. function Selection(eventBus) {
  5105. this._eventBus = eventBus;
  5106. this._selectedElements = [];
  5107. var self = this;
  5108. eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
  5109. var element = e.element;
  5110. self.deselect(element);
  5111. });
  5112. eventBus.on([ 'diagram.clear' ], function(e) {
  5113. self.select(null);
  5114. });
  5115. }
  5116. Selection.$inject = [ 'eventBus' ];
  5117. Selection.prototype.deselect = function(element) {
  5118. var selectedElements = this._selectedElements;
  5119. var idx = selectedElements.indexOf(element);
  5120. if (idx !== -1) {
  5121. var oldSelection = selectedElements.slice();
  5122. selectedElements.splice(idx, 1);
  5123. this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
  5124. }
  5125. };
  5126. Selection.prototype.get = function() {
  5127. return this._selectedElements;
  5128. };
  5129. Selection.prototype.isSelected = function(element) {
  5130. return this._selectedElements.indexOf(element) !== -1;
  5131. };
  5132. /**
  5133. * This method selects one or more elements on the diagram.
  5134. *
  5135. * By passing an additional add parameter you can decide whether or not the element(s)
  5136. * should be added to the already existing selection or not.
  5137. *
  5138. * @method Selection#select
  5139. *
  5140. * @param {Object|Object[]} elements element or array of elements to be selected
  5141. * @param {boolean} [add] whether the element(s) should be appended to the current selection, defaults to false
  5142. */
  5143. Selection.prototype.select = function(elements, add) {
  5144. var selectedElements = this._selectedElements,
  5145. oldSelection = selectedElements.slice();
  5146. if (!isArray(elements)) {
  5147. elements = elements ? [ elements ] : [];
  5148. }
  5149. // selection may be cleared by passing an empty array or null
  5150. // to the method
  5151. if (add) {
  5152. forEach(elements, function(element) {
  5153. if (selectedElements.indexOf(element) !== -1) {
  5154. // already selected
  5155. return;
  5156. } else {
  5157. selectedElements.push(element);
  5158. }
  5159. });
  5160. } else {
  5161. this._selectedElements = selectedElements = elements.slice();
  5162. }
  5163. this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
  5164. };
  5165. var MARKER_HOVER = 'hover',
  5166. MARKER_SELECTED = 'selected';
  5167. /**
  5168. * A plugin that adds a visible selection UI to shapes and connections
  5169. * by appending the <code>hover</code> and <code>selected</code> classes to them.
  5170. *
  5171. * @class
  5172. *
  5173. * Makes elements selectable, too.
  5174. *
  5175. * @param {EventBus} events
  5176. * @param {SelectionService} selection
  5177. * @param {Canvas} canvas
  5178. */
  5179. function SelectionVisuals(events, canvas, selection, styles) {
  5180. this._multiSelectionBox = null;
  5181. function addMarker(e, cls) {
  5182. canvas.addMarker(e, cls);
  5183. }
  5184. function removeMarker(e, cls) {
  5185. canvas.removeMarker(e, cls);
  5186. }
  5187. events.on('element.hover', function(event) {
  5188. addMarker(event.element, MARKER_HOVER);
  5189. });
  5190. events.on('element.out', function(event) {
  5191. removeMarker(event.element, MARKER_HOVER);
  5192. });
  5193. events.on('selection.changed', function(event) {
  5194. function deselect(s) {
  5195. removeMarker(s, MARKER_SELECTED);
  5196. }
  5197. function select(s) {
  5198. addMarker(s, MARKER_SELECTED);
  5199. }
  5200. var oldSelection = event.oldSelection,
  5201. newSelection = event.newSelection;
  5202. forEach(oldSelection, function(e) {
  5203. if (newSelection.indexOf(e) === -1) {
  5204. deselect(e);
  5205. }
  5206. });
  5207. forEach(newSelection, function(e) {
  5208. if (oldSelection.indexOf(e) === -1) {
  5209. select(e);
  5210. }
  5211. });
  5212. });
  5213. }
  5214. SelectionVisuals.$inject = [
  5215. 'eventBus',
  5216. 'canvas',
  5217. 'selection',
  5218. 'styles'
  5219. ];
  5220. function SelectionBehavior(
  5221. eventBus, selection, canvas,
  5222. elementRegistry) {
  5223. eventBus.on('create.end', 500, function(e) {
  5224. var context = e.context,
  5225. canExecute = context.canExecute,
  5226. elements = context.elements,
  5227. hints = context.hints || {},
  5228. autoSelect = hints.autoSelect;
  5229. // select elements after they have been created
  5230. if (canExecute) {
  5231. if (autoSelect === false) {
  5232. // select no elements
  5233. return;
  5234. }
  5235. if (isArray(autoSelect)) {
  5236. selection.select(autoSelect);
  5237. } else {
  5238. // select all elements by default
  5239. selection.select(elements.filter(isShown));
  5240. }
  5241. }
  5242. });
  5243. eventBus.on('connect.end', 500, function(e) {
  5244. // select the connect end target
  5245. // after a connect operation
  5246. if (e.context.canExecute && e.context.hover) {
  5247. selection.select(e.context.hover);
  5248. }
  5249. });
  5250. eventBus.on('shape.move.end', 500, function(e) {
  5251. var previousSelection = e.previousSelection || [];
  5252. var shape = elementRegistry.get(e.context.shape.id);
  5253. // make sure at least the main moved element is being
  5254. // selected after a move operation
  5255. var inSelection = find(previousSelection, function(selectedShape) {
  5256. return shape.id === selectedShape.id;
  5257. });
  5258. if (!inSelection) {
  5259. selection.select(shape);
  5260. }
  5261. });
  5262. // Shift + click selection
  5263. eventBus.on('element.click', function(event) {
  5264. var element = event.element;
  5265. // do not select the root element
  5266. // or connections
  5267. if (element === canvas.getRootElement()) {
  5268. element = null;
  5269. }
  5270. var isSelected = selection.isSelected(element),
  5271. isMultiSelect = selection.get().length > 1;
  5272. // mouse-event: SELECTION_KEY
  5273. var add = hasPrimaryModifier(event);
  5274. // select OR deselect element in multi selection
  5275. if (isSelected && isMultiSelect) {
  5276. if (add) {
  5277. return selection.deselect(element);
  5278. } else {
  5279. return selection.select(element);
  5280. }
  5281. } else
  5282. if (!isSelected) {
  5283. selection.select(element, add);
  5284. } else {
  5285. selection.deselect(element);
  5286. }
  5287. });
  5288. }
  5289. SelectionBehavior.$inject = [
  5290. 'eventBus',
  5291. 'selection',
  5292. 'canvas',
  5293. 'elementRegistry'
  5294. ];
  5295. function isShown(element) {
  5296. return !element.hidden;
  5297. }
  5298. var SelectionModule = {
  5299. __init__: [ 'selectionVisuals', 'selectionBehavior' ],
  5300. __depends__: [
  5301. InteractionEventsModule,
  5302. OutlineModule
  5303. ],
  5304. selection: [ 'type', Selection ],
  5305. selectionVisuals: [ 'type', SelectionVisuals ],
  5306. selectionBehavior: [ 'type', SelectionBehavior ]
  5307. };
  5308. /**
  5309. * Util that provides unique IDs.
  5310. *
  5311. * @class djs.util.IdGenerator
  5312. * @constructor
  5313. * @memberOf djs.util
  5314. *
  5315. * The ids can be customized via a given prefix and contain a random value to avoid collisions.
  5316. *
  5317. * @param {string} prefix a prefix to prepend to generated ids (for better readability)
  5318. */
  5319. function IdGenerator(prefix) {
  5320. this._counter = 0;
  5321. this._prefix = (prefix ? prefix + '-' : '') + Math.floor(Math.random() * 1000000000) + '-';
  5322. }
  5323. /**
  5324. * Returns a next unique ID.
  5325. *
  5326. * @method djs.util.IdGenerator#next
  5327. *
  5328. * @returns {string} the id
  5329. */
  5330. IdGenerator.prototype.next = function() {
  5331. return this._prefix + (++this._counter);
  5332. };
  5333. // document wide unique overlay ids
  5334. var ids = new IdGenerator('ov');
  5335. var LOW_PRIORITY$2 = 500;
  5336. /**
  5337. * A service that allows users to attach overlays to diagram elements.
  5338. *
  5339. * The overlay service will take care of overlay positioning during updates.
  5340. *
  5341. * @example
  5342. *
  5343. * // add a pink badge on the top left of the shape
  5344. * overlays.add(someShape, {
  5345. * position: {
  5346. * top: -5,
  5347. * left: -5
  5348. * },
  5349. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  5350. * });
  5351. *
  5352. * // or add via shape id
  5353. *
  5354. * overlays.add('some-element-id', {
  5355. * position: {
  5356. * top: -5,
  5357. * left: -5
  5358. * }
  5359. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  5360. * });
  5361. *
  5362. * // or add with optional type
  5363. *
  5364. * overlays.add(someShape, 'badge', {
  5365. * position: {
  5366. * top: -5,
  5367. * left: -5
  5368. * }
  5369. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  5370. * });
  5371. *
  5372. *
  5373. * // remove an overlay
  5374. *
  5375. * var id = overlays.add(...);
  5376. * overlays.remove(id);
  5377. *
  5378. *
  5379. * You may configure overlay defaults during tool by providing a `config` module
  5380. * with `overlays.defaults` as an entry:
  5381. *
  5382. * {
  5383. * overlays: {
  5384. * defaults: {
  5385. * show: {
  5386. * minZoom: 0.7,
  5387. * maxZoom: 5.0
  5388. * },
  5389. * scale: {
  5390. * min: 1
  5391. * }
  5392. * }
  5393. * }
  5394. *
  5395. * @param {Object} config
  5396. * @param {EventBus} eventBus
  5397. * @param {Canvas} canvas
  5398. * @param {ElementRegistry} elementRegistry
  5399. */
  5400. function Overlays(config, eventBus, canvas, elementRegistry) {
  5401. this._eventBus = eventBus;
  5402. this._canvas = canvas;
  5403. this._elementRegistry = elementRegistry;
  5404. this._ids = ids;
  5405. this._overlayDefaults = assign({
  5406. // no show constraints
  5407. show: null,
  5408. // always scale
  5409. scale: true
  5410. }, config && config.defaults);
  5411. /**
  5412. * Mapping overlayId -> overlay
  5413. */
  5414. this._overlays = {};
  5415. /**
  5416. * Mapping elementId -> overlay container
  5417. */
  5418. this._overlayContainers = [];
  5419. // root html element for all overlays
  5420. this._overlayRoot = createRoot(canvas.getContainer());
  5421. this._init();
  5422. }
  5423. Overlays.$inject = [
  5424. 'config.overlays',
  5425. 'eventBus',
  5426. 'canvas',
  5427. 'elementRegistry'
  5428. ];
  5429. /**
  5430. * Returns the overlay with the specified id or a list of overlays
  5431. * for an element with a given type.
  5432. *
  5433. * @example
  5434. *
  5435. * // return the single overlay with the given id
  5436. * overlays.get('some-id');
  5437. *
  5438. * // return all overlays for the shape
  5439. * overlays.get({ element: someShape });
  5440. *
  5441. * // return all overlays on shape with type 'badge'
  5442. * overlays.get({ element: someShape, type: 'badge' });
  5443. *
  5444. * // shape can also be specified as id
  5445. * overlays.get({ element: 'element-id', type: 'badge' });
  5446. *
  5447. *
  5448. * @param {Object} search
  5449. * @param {string} [search.id]
  5450. * @param {string|djs.model.Base} [search.element]
  5451. * @param {string} [search.type]
  5452. *
  5453. * @return {Object|Array<Object>} the overlay(s)
  5454. */
  5455. Overlays.prototype.get = function(search) {
  5456. if (isString(search)) {
  5457. search = { id: search };
  5458. }
  5459. if (isString(search.element)) {
  5460. search.element = this._elementRegistry.get(search.element);
  5461. }
  5462. if (search.element) {
  5463. var container = this._getOverlayContainer(search.element, true);
  5464. // return a list of overlays when searching by element (+type)
  5465. if (container) {
  5466. return search.type ? filter(container.overlays, matchPattern({ type: search.type })) : container.overlays.slice();
  5467. } else {
  5468. return [];
  5469. }
  5470. } else
  5471. if (search.type) {
  5472. return filter(this._overlays, matchPattern({ type: search.type }));
  5473. } else {
  5474. // return single element when searching by id
  5475. return search.id ? this._overlays[search.id] : null;
  5476. }
  5477. };
  5478. /**
  5479. * Adds a HTML overlay to an element.
  5480. *
  5481. * @param {string|djs.model.Base} element attach overlay to this shape
  5482. * @param {string} [type] optional type to assign to the overlay
  5483. * @param {Object} overlay the overlay configuration
  5484. *
  5485. * @param {string|DOMElement} overlay.html html element to use as an overlay
  5486. * @param {Object} [overlay.show] show configuration
  5487. * @param {number} [overlay.show.minZoom] minimal zoom level to show the overlay
  5488. * @param {number} [overlay.show.maxZoom] maximum zoom level to show the overlay
  5489. * @param {Object} overlay.position where to attach the overlay
  5490. * @param {number} [overlay.position.left] relative to element bbox left attachment
  5491. * @param {number} [overlay.position.top] relative to element bbox top attachment
  5492. * @param {number} [overlay.position.bottom] relative to element bbox bottom attachment
  5493. * @param {number} [overlay.position.right] relative to element bbox right attachment
  5494. * @param {boolean|Object} [overlay.scale=true] false to preserve the same size regardless of
  5495. * diagram zoom
  5496. * @param {number} [overlay.scale.min]
  5497. * @param {number} [overlay.scale.max]
  5498. *
  5499. * @return {string} id that may be used to reference the overlay for update or removal
  5500. */
  5501. Overlays.prototype.add = function(element, type, overlay) {
  5502. if (isObject(type)) {
  5503. overlay = type;
  5504. type = null;
  5505. }
  5506. if (!element.id) {
  5507. element = this._elementRegistry.get(element);
  5508. }
  5509. if (!overlay.position) {
  5510. throw new Error('must specifiy overlay position');
  5511. }
  5512. if (!overlay.html) {
  5513. throw new Error('must specifiy overlay html');
  5514. }
  5515. if (!element) {
  5516. throw new Error('invalid element specified');
  5517. }
  5518. var id = this._ids.next();
  5519. overlay = assign({}, this._overlayDefaults, overlay, {
  5520. id: id,
  5521. type: type,
  5522. element: element,
  5523. html: overlay.html
  5524. });
  5525. this._addOverlay(overlay);
  5526. return id;
  5527. };
  5528. /**
  5529. * Remove an overlay with the given id or all overlays matching the given filter.
  5530. *
  5531. * @see Overlays#get for filter options.
  5532. *
  5533. * @param {string} [id]
  5534. * @param {Object} [filter]
  5535. */
  5536. Overlays.prototype.remove = function(filter) {
  5537. var overlays = this.get(filter) || [];
  5538. if (!isArray(overlays)) {
  5539. overlays = [ overlays ];
  5540. }
  5541. var self = this;
  5542. forEach(overlays, function(overlay) {
  5543. var container = self._getOverlayContainer(overlay.element, true);
  5544. if (overlay) {
  5545. remove$1(overlay.html);
  5546. remove$1(overlay.htmlContainer);
  5547. delete overlay.htmlContainer;
  5548. delete overlay.element;
  5549. delete self._overlays[overlay.id];
  5550. }
  5551. if (container) {
  5552. var idx = container.overlays.indexOf(overlay);
  5553. if (idx !== -1) {
  5554. container.overlays.splice(idx, 1);
  5555. }
  5556. }
  5557. });
  5558. };
  5559. Overlays.prototype.show = function() {
  5560. setVisible(this._overlayRoot);
  5561. };
  5562. Overlays.prototype.hide = function() {
  5563. setVisible(this._overlayRoot, false);
  5564. };
  5565. Overlays.prototype.clear = function() {
  5566. this._overlays = {};
  5567. this._overlayContainers = [];
  5568. clear$1(this._overlayRoot);
  5569. };
  5570. Overlays.prototype._updateOverlayContainer = function(container) {
  5571. var element = container.element,
  5572. html = container.html;
  5573. // update container left,top according to the elements x,y coordinates
  5574. // this ensures we can attach child elements relative to this container
  5575. var x = element.x,
  5576. y = element.y;
  5577. if (element.waypoints) {
  5578. var bbox = getBBox(element);
  5579. x = bbox.x;
  5580. y = bbox.y;
  5581. }
  5582. setPosition(html, x, y);
  5583. attr$1(container.html, 'data-container-id', element.id);
  5584. };
  5585. Overlays.prototype._updateOverlay = function(overlay) {
  5586. var position = overlay.position,
  5587. htmlContainer = overlay.htmlContainer,
  5588. element = overlay.element;
  5589. // update overlay html relative to shape because
  5590. // it is already positioned on the element
  5591. // update relative
  5592. var left = position.left,
  5593. top = position.top;
  5594. if (position.right !== undefined) {
  5595. var width;
  5596. if (element.waypoints) {
  5597. width = getBBox(element).width;
  5598. } else {
  5599. width = element.width;
  5600. }
  5601. left = position.right * -1 + width;
  5602. }
  5603. if (position.bottom !== undefined) {
  5604. var height;
  5605. if (element.waypoints) {
  5606. height = getBBox(element).height;
  5607. } else {
  5608. height = element.height;
  5609. }
  5610. top = position.bottom * -1 + height;
  5611. }
  5612. setPosition(htmlContainer, left || 0, top || 0);
  5613. };
  5614. Overlays.prototype._createOverlayContainer = function(element) {
  5615. var html = domify('<div class="djs-overlays" style="position: absolute" />');
  5616. this._overlayRoot.appendChild(html);
  5617. var container = {
  5618. html: html,
  5619. element: element,
  5620. overlays: []
  5621. };
  5622. this._updateOverlayContainer(container);
  5623. this._overlayContainers.push(container);
  5624. return container;
  5625. };
  5626. Overlays.prototype._updateRoot = function(viewbox) {
  5627. var scale = viewbox.scale || 1;
  5628. var matrix = 'matrix(' +
  5629. [
  5630. scale,
  5631. 0,
  5632. 0,
  5633. scale,
  5634. -1 * viewbox.x * scale,
  5635. -1 * viewbox.y * scale
  5636. ].join(',') +
  5637. ')';
  5638. setTransform(this._overlayRoot, matrix);
  5639. };
  5640. Overlays.prototype._getOverlayContainer = function(element, raw) {
  5641. var container = find(this._overlayContainers, function(c) {
  5642. return c.element === element;
  5643. });
  5644. if (!container && !raw) {
  5645. return this._createOverlayContainer(element);
  5646. }
  5647. return container;
  5648. };
  5649. Overlays.prototype._addOverlay = function(overlay) {
  5650. var id = overlay.id,
  5651. element = overlay.element,
  5652. html = overlay.html,
  5653. htmlContainer,
  5654. overlayContainer;
  5655. // unwrap jquery (for those who need it)
  5656. if (html.get && html.constructor.prototype.jquery) {
  5657. html = html.get(0);
  5658. }
  5659. // create proper html elements from
  5660. // overlay HTML strings
  5661. if (isString(html)) {
  5662. html = domify(html);
  5663. }
  5664. overlayContainer = this._getOverlayContainer(element);
  5665. htmlContainer = domify('<div class="djs-overlay" data-overlay-id="' + id + '" style="position: absolute">');
  5666. htmlContainer.appendChild(html);
  5667. if (overlay.type) {
  5668. classes$1(htmlContainer).add('djs-overlay-' + overlay.type);
  5669. }
  5670. overlay.htmlContainer = htmlContainer;
  5671. overlayContainer.overlays.push(overlay);
  5672. overlayContainer.html.appendChild(htmlContainer);
  5673. this._overlays[id] = overlay;
  5674. this._updateOverlay(overlay);
  5675. this._updateOverlayVisibilty(overlay, this._canvas.viewbox());
  5676. };
  5677. Overlays.prototype._updateOverlayVisibilty = function(overlay, viewbox) {
  5678. var show = overlay.show,
  5679. minZoom = show && show.minZoom,
  5680. maxZoom = show && show.maxZoom,
  5681. htmlContainer = overlay.htmlContainer,
  5682. visible = true;
  5683. if (show) {
  5684. if (
  5685. (isDefined(minZoom) && minZoom > viewbox.scale) ||
  5686. (isDefined(maxZoom) && maxZoom < viewbox.scale)
  5687. ) {
  5688. visible = false;
  5689. }
  5690. setVisible(htmlContainer, visible);
  5691. }
  5692. this._updateOverlayScale(overlay, viewbox);
  5693. };
  5694. Overlays.prototype._updateOverlayScale = function(overlay, viewbox) {
  5695. var shouldScale = overlay.scale,
  5696. minScale,
  5697. maxScale,
  5698. htmlContainer = overlay.htmlContainer;
  5699. var scale, transform = '';
  5700. if (shouldScale !== true) {
  5701. if (shouldScale === false) {
  5702. minScale = 1;
  5703. maxScale = 1;
  5704. } else {
  5705. minScale = shouldScale.min;
  5706. maxScale = shouldScale.max;
  5707. }
  5708. if (isDefined(minScale) && viewbox.scale < minScale) {
  5709. scale = (1 / viewbox.scale || 1) * minScale;
  5710. }
  5711. if (isDefined(maxScale) && viewbox.scale > maxScale) {
  5712. scale = (1 / viewbox.scale || 1) * maxScale;
  5713. }
  5714. }
  5715. if (isDefined(scale)) {
  5716. transform = 'scale(' + scale + ',' + scale + ')';
  5717. }
  5718. setTransform(htmlContainer, transform);
  5719. };
  5720. Overlays.prototype._updateOverlaysVisibilty = function(viewbox) {
  5721. var self = this;
  5722. forEach(this._overlays, function(overlay) {
  5723. self._updateOverlayVisibilty(overlay, viewbox);
  5724. });
  5725. };
  5726. Overlays.prototype._init = function() {
  5727. var eventBus = this._eventBus;
  5728. var self = this;
  5729. // scroll/zoom integration
  5730. function updateViewbox(viewbox) {
  5731. self._updateRoot(viewbox);
  5732. self._updateOverlaysVisibilty(viewbox);
  5733. self.show();
  5734. }
  5735. eventBus.on('canvas.viewbox.changing', function(event) {
  5736. self.hide();
  5737. });
  5738. eventBus.on('canvas.viewbox.changed', function(event) {
  5739. updateViewbox(event.viewbox);
  5740. });
  5741. // remove integration
  5742. eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
  5743. var element = e.element;
  5744. var overlays = self.get({ element: element });
  5745. forEach(overlays, function(o) {
  5746. self.remove(o.id);
  5747. });
  5748. var container = self._getOverlayContainer(element);
  5749. if (container) {
  5750. remove$1(container.html);
  5751. var i = self._overlayContainers.indexOf(container);
  5752. if (i !== -1) {
  5753. self._overlayContainers.splice(i, 1);
  5754. }
  5755. }
  5756. });
  5757. // move integration
  5758. eventBus.on('element.changed', LOW_PRIORITY$2, function(e) {
  5759. var element = e.element;
  5760. var container = self._getOverlayContainer(element, true);
  5761. if (container) {
  5762. forEach(container.overlays, function(overlay) {
  5763. self._updateOverlay(overlay);
  5764. });
  5765. self._updateOverlayContainer(container);
  5766. }
  5767. });
  5768. // marker integration, simply add them on the overlays as classes, too.
  5769. eventBus.on('element.marker.update', function(e) {
  5770. var container = self._getOverlayContainer(e.element, true);
  5771. if (container) {
  5772. classes$1(container.html)[e.add ? 'add' : 'remove'](e.marker);
  5773. }
  5774. });
  5775. // clear overlays with diagram
  5776. eventBus.on('diagram.clear', this.clear, this);
  5777. };
  5778. // helpers /////////////////////////////
  5779. function createRoot(parentNode) {
  5780. var root = domify(
  5781. '<div class="djs-overlay-container" style="position: absolute; width: 0; height: 0;" />'
  5782. );
  5783. parentNode.insertBefore(root, parentNode.firstChild);
  5784. return root;
  5785. }
  5786. function setPosition(el, x, y) {
  5787. assign(el.style, { left: x + 'px', top: y + 'px' });
  5788. }
  5789. function setVisible(el, visible) {
  5790. el.style.display = visible === false ? 'none' : '';
  5791. }
  5792. function setTransform(el, transform) {
  5793. el.style['transform-origin'] = 'top left';
  5794. [ '', '-ms-', '-webkit-' ].forEach(function(prefix) {
  5795. el.style[prefix + 'transform'] = transform;
  5796. });
  5797. }
  5798. var OverlaysModule = {
  5799. __init__: [ 'overlays' ],
  5800. overlays: [ 'type', Overlays ]
  5801. };
  5802. var CLASS_PATTERN = /^class /;
  5803. function isClass(fn) {
  5804. return CLASS_PATTERN.test(fn.toString());
  5805. }
  5806. function isArray$1(obj) {
  5807. return Object.prototype.toString.call(obj) === '[object Array]';
  5808. }
  5809. function annotate() {
  5810. var args = Array.prototype.slice.call(arguments);
  5811. if (args.length === 1 && isArray$1(args[0])) {
  5812. args = args[0];
  5813. }
  5814. var fn = args.pop();
  5815. fn.$inject = args;
  5816. return fn;
  5817. }
  5818. // Current limitations:
  5819. // - can't put into "function arg" comments
  5820. // function /* (no parenthesis like this) */ (){}
  5821. // function abc( /* xx (no parenthesis like this) */ a, b) {}
  5822. //
  5823. // Just put the comment before function or inside:
  5824. // /* (((this is fine))) */ function(a, b) {}
  5825. // function abc(a) { /* (((this is fine))) */}
  5826. //
  5827. // - can't reliably auto-annotate constructor; we'll match the
  5828. // first constructor(...) pattern found which may be the one
  5829. // of a nested class, too.
  5830. var CONSTRUCTOR_ARGS = /constructor\s*[^(]*\(\s*([^)]*)\)/m;
  5831. var FN_ARGS = /^function\s*[^(]*\(\s*([^)]*)\)/m;
  5832. var FN_ARG = /\/\*([^*]*)\*\//m;
  5833. function parse$2(fn) {
  5834. if (typeof fn !== 'function') {
  5835. throw new Error('Cannot annotate "' + fn + '". Expected a function!');
  5836. }
  5837. var match = fn.toString().match(isClass(fn) ? CONSTRUCTOR_ARGS : FN_ARGS);
  5838. // may parse class without constructor
  5839. if (!match) {
  5840. return [];
  5841. }
  5842. return match[1] && match[1].split(',').map(function (arg) {
  5843. match = arg.match(FN_ARG);
  5844. return match ? match[1].trim() : arg.trim();
  5845. }) || [];
  5846. }
  5847. function Module() {
  5848. var providers = [];
  5849. this.factory = function (name, factory) {
  5850. providers.push([name, 'factory', factory]);
  5851. return this;
  5852. };
  5853. this.value = function (name, value) {
  5854. providers.push([name, 'value', value]);
  5855. return this;
  5856. };
  5857. this.type = function (name, type) {
  5858. providers.push([name, 'type', type]);
  5859. return this;
  5860. };
  5861. this.forEach = function (iterator) {
  5862. providers.forEach(iterator);
  5863. };
  5864. }
  5865. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  5866. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  5867. function Injector(modules, parent) {
  5868. parent = parent || {
  5869. get: function get(name, strict) {
  5870. currentlyResolving.push(name);
  5871. if (strict === false) {
  5872. return null;
  5873. } else {
  5874. throw error('No provider for "' + name + '"!');
  5875. }
  5876. }
  5877. };
  5878. var currentlyResolving = [];
  5879. var providers = this._providers = Object.create(parent._providers || null);
  5880. var instances = this._instances = Object.create(null);
  5881. var self = instances.injector = this;
  5882. var error = function error(msg) {
  5883. var stack = currentlyResolving.join(' -> ');
  5884. currentlyResolving.length = 0;
  5885. return new Error(stack ? msg + ' (Resolving: ' + stack + ')' : msg);
  5886. };
  5887. /**
  5888. * Return a named service.
  5889. *
  5890. * @param {String} name
  5891. * @param {Boolean} [strict=true] if false, resolve missing services to null
  5892. *
  5893. * @return {Object}
  5894. */
  5895. var get = function get(name, strict) {
  5896. if (!providers[name] && name.indexOf('.') !== -1) {
  5897. var parts = name.split('.');
  5898. var pivot = get(parts.shift());
  5899. while (parts.length) {
  5900. pivot = pivot[parts.shift()];
  5901. }
  5902. return pivot;
  5903. }
  5904. if (hasProp(instances, name)) {
  5905. return instances[name];
  5906. }
  5907. if (hasProp(providers, name)) {
  5908. if (currentlyResolving.indexOf(name) !== -1) {
  5909. currentlyResolving.push(name);
  5910. throw error('Cannot resolve circular dependency!');
  5911. }
  5912. currentlyResolving.push(name);
  5913. instances[name] = providers[name][0](providers[name][1]);
  5914. currentlyResolving.pop();
  5915. return instances[name];
  5916. }
  5917. return parent.get(name, strict);
  5918. };
  5919. var fnDef = function fnDef(fn) {
  5920. var locals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  5921. if (typeof fn !== 'function') {
  5922. if (isArray$1(fn)) {
  5923. fn = annotate(fn.slice());
  5924. } else {
  5925. throw new Error('Cannot invoke "' + fn + '". Expected a function!');
  5926. }
  5927. }
  5928. var inject = fn.$inject || parse$2(fn);
  5929. var dependencies = inject.map(function (dep) {
  5930. if (hasProp(locals, dep)) {
  5931. return locals[dep];
  5932. } else {
  5933. return get(dep);
  5934. }
  5935. });
  5936. return {
  5937. fn: fn,
  5938. dependencies: dependencies
  5939. };
  5940. };
  5941. var instantiate = function instantiate(Type) {
  5942. var _fnDef = fnDef(Type),
  5943. dependencies = _fnDef.dependencies,
  5944. fn = _fnDef.fn;
  5945. return new (Function.prototype.bind.apply(fn, [null].concat(_toConsumableArray(dependencies))))();
  5946. };
  5947. var invoke = function invoke(func, context, locals) {
  5948. var _fnDef2 = fnDef(func, locals),
  5949. dependencies = _fnDef2.dependencies,
  5950. fn = _fnDef2.fn;
  5951. return fn.call.apply(fn, [context].concat(_toConsumableArray(dependencies)));
  5952. };
  5953. var createPrivateInjectorFactory = function createPrivateInjectorFactory(privateChildInjector) {
  5954. return annotate(function (key) {
  5955. return privateChildInjector.get(key);
  5956. });
  5957. };
  5958. var createChild = function createChild(modules, forceNewInstances) {
  5959. if (forceNewInstances && forceNewInstances.length) {
  5960. var fromParentModule = Object.create(null);
  5961. var matchedScopes = Object.create(null);
  5962. var privateInjectorsCache = [];
  5963. var privateChildInjectors = [];
  5964. var privateChildFactories = [];
  5965. var provider;
  5966. var cacheIdx;
  5967. var privateChildInjector;
  5968. var privateChildInjectorFactory;
  5969. for (var name in providers) {
  5970. provider = providers[name];
  5971. if (forceNewInstances.indexOf(name) !== -1) {
  5972. if (provider[2] === 'private') {
  5973. cacheIdx = privateInjectorsCache.indexOf(provider[3]);
  5974. if (cacheIdx === -1) {
  5975. privateChildInjector = provider[3].createChild([], forceNewInstances);
  5976. privateChildInjectorFactory = createPrivateInjectorFactory(privateChildInjector);
  5977. privateInjectorsCache.push(provider[3]);
  5978. privateChildInjectors.push(privateChildInjector);
  5979. privateChildFactories.push(privateChildInjectorFactory);
  5980. fromParentModule[name] = [privateChildInjectorFactory, name, 'private', privateChildInjector];
  5981. } else {
  5982. fromParentModule[name] = [privateChildFactories[cacheIdx], name, 'private', privateChildInjectors[cacheIdx]];
  5983. }
  5984. } else {
  5985. fromParentModule[name] = [provider[2], provider[1]];
  5986. }
  5987. matchedScopes[name] = true;
  5988. }
  5989. if ((provider[2] === 'factory' || provider[2] === 'type') && provider[1].$scope) {
  5990. /* jshint -W083 */
  5991. forceNewInstances.forEach(function (scope) {
  5992. if (provider[1].$scope.indexOf(scope) !== -1) {
  5993. fromParentModule[name] = [provider[2], provider[1]];
  5994. matchedScopes[scope] = true;
  5995. }
  5996. });
  5997. }
  5998. }
  5999. forceNewInstances.forEach(function (scope) {
  6000. if (!matchedScopes[scope]) {
  6001. throw new Error('No provider for "' + scope + '". Cannot use provider from the parent!');
  6002. }
  6003. });
  6004. modules.unshift(fromParentModule);
  6005. }
  6006. return new Injector(modules, self);
  6007. };
  6008. var factoryMap = {
  6009. factory: invoke,
  6010. type: instantiate,
  6011. value: function value(_value) {
  6012. return _value;
  6013. }
  6014. };
  6015. modules.forEach(function (module) {
  6016. function arrayUnwrap(type, value) {
  6017. if (type !== 'value' && isArray$1(value)) {
  6018. value = annotate(value.slice());
  6019. }
  6020. return value;
  6021. }
  6022. // TODO(vojta): handle wrong inputs (modules)
  6023. if (module instanceof Module) {
  6024. module.forEach(function (provider) {
  6025. var name = provider[0];
  6026. var type = provider[1];
  6027. var value = provider[2];
  6028. providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
  6029. });
  6030. } else if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object') {
  6031. if (module.__exports__) {
  6032. var clonedModule = Object.keys(module).reduce(function (m, key) {
  6033. if (key.substring(0, 2) !== '__') {
  6034. m[key] = module[key];
  6035. }
  6036. return m;
  6037. }, Object.create(null));
  6038. var privateInjector = new Injector((module.__modules__ || []).concat([clonedModule]), self);
  6039. var getFromPrivateInjector = annotate(function (key) {
  6040. return privateInjector.get(key);
  6041. });
  6042. module.__exports__.forEach(function (key) {
  6043. providers[key] = [getFromPrivateInjector, key, 'private', privateInjector];
  6044. });
  6045. } else {
  6046. Object.keys(module).forEach(function (name) {
  6047. if (module[name][2] === 'private') {
  6048. providers[name] = module[name];
  6049. return;
  6050. }
  6051. var type = module[name][0];
  6052. var value = module[name][1];
  6053. providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
  6054. });
  6055. }
  6056. }
  6057. });
  6058. // public API
  6059. this.get = get;
  6060. this.invoke = invoke;
  6061. this.instantiate = instantiate;
  6062. this.createChild = createChild;
  6063. }
  6064. // helpers /////////////////
  6065. function hasProp(obj, prop) {
  6066. return Object.hasOwnProperty.call(obj, prop);
  6067. }
  6068. // apply default renderer with lowest possible priority
  6069. // so that it only kicks in if noone else could render
  6070. var DEFAULT_RENDER_PRIORITY$1 = 1;
  6071. /**
  6072. * The default renderer used for shapes and connections.
  6073. *
  6074. * @param {EventBus} eventBus
  6075. * @param {Styles} styles
  6076. */
  6077. function DefaultRenderer(eventBus, styles) {
  6078. //
  6079. BaseRenderer.call(this, eventBus, DEFAULT_RENDER_PRIORITY$1);
  6080. this.CONNECTION_STYLE = styles.style([ 'no-fill' ], { strokeWidth: 5, stroke: 'fuchsia' });
  6081. this.SHAPE_STYLE = styles.style({ fill: 'white', stroke: 'fuchsia', strokeWidth: 2 });
  6082. this.FRAME_STYLE = styles.style([ 'no-fill' ], { stroke: 'fuchsia', strokeDasharray: 4, strokeWidth: 2 });
  6083. }
  6084. inherits_browser(DefaultRenderer, BaseRenderer);
  6085. DefaultRenderer.prototype.canRender = function() {
  6086. return true;
  6087. };
  6088. DefaultRenderer.prototype.drawShape = function drawShape(visuals, element) {
  6089. var rect = create('rect');
  6090. attr(rect, {
  6091. x: 0,
  6092. y: 0,
  6093. width: element.width || 0,
  6094. height: element.height || 0
  6095. });
  6096. if (isFrameElement$1(element)) {
  6097. attr(rect, this.FRAME_STYLE);
  6098. } else {
  6099. attr(rect, this.SHAPE_STYLE);
  6100. }
  6101. append(visuals, rect);
  6102. return rect;
  6103. };
  6104. DefaultRenderer.prototype.drawConnection = function drawConnection(visuals, connection) {
  6105. var line = createLine(connection.waypoints, this.CONNECTION_STYLE);
  6106. append(visuals, line);
  6107. return line;
  6108. };
  6109. DefaultRenderer.prototype.getShapePath = function getShapePath(shape) {
  6110. var x = shape.x,
  6111. y = shape.y,
  6112. width = shape.width,
  6113. height = shape.height;
  6114. var shapePath = [
  6115. ['M', x, y],
  6116. ['l', width, 0],
  6117. ['l', 0, height],
  6118. ['l', -width, 0],
  6119. ['z']
  6120. ];
  6121. return componentsToPath(shapePath);
  6122. };
  6123. DefaultRenderer.prototype.getConnectionPath = function getConnectionPath(connection) {
  6124. var waypoints = connection.waypoints;
  6125. var idx, point, connectionPath = [];
  6126. for (idx = 0; (point = waypoints[idx]); idx++) {
  6127. // take invisible docking into account
  6128. // when creating the path
  6129. point = point.original || point;
  6130. connectionPath.push([ idx === 0 ? 'M' : 'L', point.x, point.y ]);
  6131. }
  6132. return componentsToPath(connectionPath);
  6133. };
  6134. DefaultRenderer.$inject = [ 'eventBus', 'styles' ];
  6135. /**
  6136. * A component that manages shape styles
  6137. */
  6138. function Styles() {
  6139. var defaultTraits = {
  6140. 'no-fill': {
  6141. fill: 'none'
  6142. },
  6143. 'no-border': {
  6144. strokeOpacity: 0.0
  6145. },
  6146. 'no-events': {
  6147. pointerEvents: 'none'
  6148. }
  6149. };
  6150. var self = this;
  6151. /**
  6152. * Builds a style definition from a className, a list of traits and an object of additional attributes.
  6153. *
  6154. * @param {string} className
  6155. * @param {Array<string>} traits
  6156. * @param {Object} additionalAttrs
  6157. *
  6158. * @return {Object} the style defintion
  6159. */
  6160. this.cls = function(className, traits, additionalAttrs) {
  6161. var attrs = this.style(traits, additionalAttrs);
  6162. return assign(attrs, { 'class': className });
  6163. };
  6164. /**
  6165. * Builds a style definition from a list of traits and an object of additional attributes.
  6166. *
  6167. * @param {Array<string>} traits
  6168. * @param {Object} additionalAttrs
  6169. *
  6170. * @return {Object} the style defintion
  6171. */
  6172. this.style = function(traits, additionalAttrs) {
  6173. if (!isArray(traits) && !additionalAttrs) {
  6174. additionalAttrs = traits;
  6175. traits = [];
  6176. }
  6177. var attrs = reduce(traits, function(attrs, t) {
  6178. return assign(attrs, defaultTraits[t] || {});
  6179. }, {});
  6180. return additionalAttrs ? assign(attrs, additionalAttrs) : attrs;
  6181. };
  6182. this.computeStyle = function(custom, traits, defaultStyles) {
  6183. if (!isArray(traits)) {
  6184. defaultStyles = traits;
  6185. traits = [];
  6186. }
  6187. return self.style(traits || [], assign({}, defaultStyles, custom || {}));
  6188. };
  6189. }
  6190. var DrawModule$1 = {
  6191. __init__: [ 'defaultRenderer' ],
  6192. defaultRenderer: [ 'type', DefaultRenderer ],
  6193. styles: [ 'type', Styles ]
  6194. };
  6195. /**
  6196. * Failsafe remove an element from a collection
  6197. *
  6198. * @param {Array<Object>} [collection]
  6199. * @param {Object} [element]
  6200. *
  6201. * @return {number} the previous index of the element
  6202. */
  6203. function remove$2(collection, element) {
  6204. if (!collection || !element) {
  6205. return -1;
  6206. }
  6207. var idx = collection.indexOf(element);
  6208. if (idx !== -1) {
  6209. collection.splice(idx, 1);
  6210. }
  6211. return idx;
  6212. }
  6213. /**
  6214. * Fail save add an element to the given connection, ensuring
  6215. * it does not yet exist.
  6216. *
  6217. * @param {Array<Object>} collection
  6218. * @param {Object} element
  6219. * @param {number} idx
  6220. */
  6221. function add(collection, element, idx) {
  6222. if (!collection || !element) {
  6223. return;
  6224. }
  6225. if (typeof idx !== 'number') {
  6226. idx = -1;
  6227. }
  6228. var currentIdx = collection.indexOf(element);
  6229. if (currentIdx !== -1) {
  6230. if (currentIdx === idx) {
  6231. // nothing to do, position has not changed
  6232. return;
  6233. } else {
  6234. if (idx !== -1) {
  6235. // remove from current position
  6236. collection.splice(currentIdx, 1);
  6237. } else {
  6238. // already exists in collection
  6239. return;
  6240. }
  6241. }
  6242. }
  6243. if (idx !== -1) {
  6244. // insert at specified position
  6245. collection.splice(idx, 0, element);
  6246. } else {
  6247. // push to end
  6248. collection.push(element);
  6249. }
  6250. }
  6251. function round(number, resolution) {
  6252. return Math.round(number * resolution) / resolution;
  6253. }
  6254. function ensurePx(number) {
  6255. return isNumber(number) ? number + 'px' : number;
  6256. }
  6257. /**
  6258. * Creates a HTML container element for a SVG element with
  6259. * the given configuration
  6260. *
  6261. * @param {Object} options
  6262. * @return {HTMLElement} the container element
  6263. */
  6264. function createContainer(options) {
  6265. options = assign({}, { width: '100%', height: '100%' }, options);
  6266. var container = options.container || document.body;
  6267. // create a <div> around the svg element with the respective size
  6268. // this way we can always get the correct container size
  6269. // (this is impossible for <svg> elements at the moment)
  6270. var parent = document.createElement('div');
  6271. parent.setAttribute('class', 'djs-container');
  6272. assign(parent.style, {
  6273. position: 'relative',
  6274. overflow: 'hidden',
  6275. width: ensurePx(options.width),
  6276. height: ensurePx(options.height)
  6277. });
  6278. container.appendChild(parent);
  6279. return parent;
  6280. }
  6281. function createGroup(parent, cls, childIndex) {
  6282. var group = create('g');
  6283. classes(group).add(cls);
  6284. var index = childIndex !== undefined ? childIndex : parent.childNodes.length - 1;
  6285. // must ensure second argument is node or _null_
  6286. // cf. https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
  6287. parent.insertBefore(group, parent.childNodes[index] || null);
  6288. return group;
  6289. }
  6290. var BASE_LAYER = 'base';
  6291. var REQUIRED_MODEL_ATTRS = {
  6292. shape: [ 'x', 'y', 'width', 'height' ],
  6293. connection: [ 'waypoints' ]
  6294. };
  6295. /**
  6296. * The main drawing canvas.
  6297. *
  6298. * @class
  6299. * @constructor
  6300. *
  6301. * @emits Canvas#canvas.init
  6302. *
  6303. * @param {Object} config
  6304. * @param {EventBus} eventBus
  6305. * @param {GraphicsFactory} graphicsFactory
  6306. * @param {ElementRegistry} elementRegistry
  6307. */
  6308. function Canvas(config, eventBus, graphicsFactory, elementRegistry) {
  6309. this._eventBus = eventBus;
  6310. this._elementRegistry = elementRegistry;
  6311. this._graphicsFactory = graphicsFactory;
  6312. this._init(config || {});
  6313. }
  6314. Canvas.$inject = [
  6315. 'config.canvas',
  6316. 'eventBus',
  6317. 'graphicsFactory',
  6318. 'elementRegistry'
  6319. ];
  6320. Canvas.prototype._init = function(config) {
  6321. var eventBus = this._eventBus;
  6322. // Creates a <svg> element that is wrapped into a <div>.
  6323. // This way we are always able to correctly figure out the size of the svg element
  6324. // by querying the parent node.
  6325. //
  6326. // (It is not possible to get the size of a svg element cross browser @ 2014-04-01)
  6327. //
  6328. // <div class="djs-container" style="width: {desired-width}, height: {desired-height}">
  6329. // <svg width="100%" height="100%">
  6330. // ...
  6331. // </svg>
  6332. // </div>
  6333. // html container
  6334. var container = this._container = createContainer(config);
  6335. var svg = this._svg = create('svg');
  6336. attr(svg, { width: '100%', height: '100%' });
  6337. append(container, svg);
  6338. var viewport = this._viewport = createGroup(svg, 'viewport');
  6339. this._layers = {};
  6340. // debounce canvas.viewbox.changed events
  6341. // for smoother diagram interaction
  6342. if (config.deferUpdate !== false) {
  6343. this._viewboxChanged = debounce(bind(this._viewboxChanged, this), 300);
  6344. }
  6345. eventBus.on('diagram.init', function() {
  6346. /**
  6347. * An event indicating that the canvas is ready to be drawn on.
  6348. *
  6349. * @memberOf Canvas
  6350. *
  6351. * @event canvas.init
  6352. *
  6353. * @type {Object}
  6354. * @property {SVGElement} svg the created svg element
  6355. * @property {SVGElement} viewport the direct parent of diagram elements and shapes
  6356. */
  6357. eventBus.fire('canvas.init', {
  6358. svg: svg,
  6359. viewport: viewport
  6360. });
  6361. }, this);
  6362. // reset viewbox on shape changes to
  6363. // recompute the viewbox
  6364. eventBus.on([
  6365. 'shape.added',
  6366. 'connection.added',
  6367. 'shape.removed',
  6368. 'connection.removed',
  6369. 'elements.changed'
  6370. ], function() {
  6371. delete this._cachedViewbox;
  6372. }, this);
  6373. eventBus.on('diagram.destroy', 500, this._destroy, this);
  6374. eventBus.on('diagram.clear', 500, this._clear, this);
  6375. };
  6376. Canvas.prototype._destroy = function(emit) {
  6377. this._eventBus.fire('canvas.destroy', {
  6378. svg: this._svg,
  6379. viewport: this._viewport
  6380. });
  6381. var parent = this._container.parentNode;
  6382. if (parent) {
  6383. parent.removeChild(this._container);
  6384. }
  6385. delete this._svg;
  6386. delete this._container;
  6387. delete this._layers;
  6388. delete this._rootElement;
  6389. delete this._viewport;
  6390. };
  6391. Canvas.prototype._clear = function() {
  6392. var self = this;
  6393. var allElements = this._elementRegistry.getAll();
  6394. // remove all elements
  6395. allElements.forEach(function(element) {
  6396. var type = getType(element);
  6397. if (type === 'root') {
  6398. self.setRootElement(null, true);
  6399. } else {
  6400. self._removeElement(element, type);
  6401. }
  6402. });
  6403. // force recomputation of view box
  6404. delete this._cachedViewbox;
  6405. };
  6406. /**
  6407. * Returns the default layer on which
  6408. * all elements are drawn.
  6409. *
  6410. * @returns {SVGElement}
  6411. */
  6412. Canvas.prototype.getDefaultLayer = function() {
  6413. return this.getLayer(BASE_LAYER, 0);
  6414. };
  6415. /**
  6416. * Returns a layer that is used to draw elements
  6417. * or annotations on it.
  6418. *
  6419. * Non-existing layers retrieved through this method
  6420. * will be created. During creation, the optional index
  6421. * may be used to create layers below or above existing layers.
  6422. * A layer with a certain index is always created above all
  6423. * existing layers with the same index.
  6424. *
  6425. * @param {string} name
  6426. * @param {number} index
  6427. *
  6428. * @returns {SVGElement}
  6429. */
  6430. Canvas.prototype.getLayer = function(name, index) {
  6431. if (!name) {
  6432. throw new Error('must specify a name');
  6433. }
  6434. var layer = this._layers[name];
  6435. if (!layer) {
  6436. layer = this._layers[name] = this._createLayer(name, index);
  6437. }
  6438. // throw an error if layer creation / retrival is
  6439. // requested on different index
  6440. if (typeof index !== 'undefined' && layer.index !== index) {
  6441. throw new Error('layer <' + name + '> already created at index <' + index + '>');
  6442. }
  6443. return layer.group;
  6444. };
  6445. /**
  6446. * Creates a given layer and returns it.
  6447. *
  6448. * @param {string} name
  6449. * @param {number} [index=0]
  6450. *
  6451. * @return {Object} layer descriptor with { index, group: SVGGroup }
  6452. */
  6453. Canvas.prototype._createLayer = function(name, index) {
  6454. if (!index) {
  6455. index = 0;
  6456. }
  6457. var childIndex = reduce(this._layers, function(childIndex, layer) {
  6458. if (index >= layer.index) {
  6459. childIndex++;
  6460. }
  6461. return childIndex;
  6462. }, 0);
  6463. return {
  6464. group: createGroup(this._viewport, 'layer-' + name, childIndex),
  6465. index: index
  6466. };
  6467. };
  6468. /**
  6469. * Returns the html element that encloses the
  6470. * drawing canvas.
  6471. *
  6472. * @return {DOMNode}
  6473. */
  6474. Canvas.prototype.getContainer = function() {
  6475. return this._container;
  6476. };
  6477. // markers //////////////////////
  6478. Canvas.prototype._updateMarker = function(element, marker, add) {
  6479. var container;
  6480. if (!element.id) {
  6481. element = this._elementRegistry.get(element);
  6482. }
  6483. // we need to access all
  6484. container = this._elementRegistry._elements[element.id];
  6485. if (!container) {
  6486. return;
  6487. }
  6488. forEach([ container.gfx, container.secondaryGfx ], function(gfx) {
  6489. if (gfx) {
  6490. // invoke either addClass or removeClass based on mode
  6491. if (add) {
  6492. classes(gfx).add(marker);
  6493. } else {
  6494. classes(gfx).remove(marker);
  6495. }
  6496. }
  6497. });
  6498. /**
  6499. * An event indicating that a marker has been updated for an element
  6500. *
  6501. * @event element.marker.update
  6502. * @type {Object}
  6503. * @property {djs.model.Element} element the shape
  6504. * @property {Object} gfx the graphical representation of the shape
  6505. * @property {string} marker
  6506. * @property {boolean} add true if the marker was added, false if it got removed
  6507. */
  6508. this._eventBus.fire('element.marker.update', { element: element, gfx: container.gfx, marker: marker, add: !!add });
  6509. };
  6510. /**
  6511. * Adds a marker to an element (basically a css class).
  6512. *
  6513. * Fires the element.marker.update event, making it possible to
  6514. * integrate extension into the marker life-cycle, too.
  6515. *
  6516. * @example
  6517. * canvas.addMarker('foo', 'some-marker');
  6518. *
  6519. * var fooGfx = canvas.getGraphics('foo');
  6520. *
  6521. * fooGfx; // <g class="... some-marker"> ... </g>
  6522. *
  6523. * @param {string|djs.model.Base} element
  6524. * @param {string} marker
  6525. */
  6526. Canvas.prototype.addMarker = function(element, marker) {
  6527. this._updateMarker(element, marker, true);
  6528. };
  6529. /**
  6530. * Remove a marker from an element.
  6531. *
  6532. * Fires the element.marker.update event, making it possible to
  6533. * integrate extension into the marker life-cycle, too.
  6534. *
  6535. * @param {string|djs.model.Base} element
  6536. * @param {string} marker
  6537. */
  6538. Canvas.prototype.removeMarker = function(element, marker) {
  6539. this._updateMarker(element, marker, false);
  6540. };
  6541. /**
  6542. * Check the existence of a marker on element.
  6543. *
  6544. * @param {string|djs.model.Base} element
  6545. * @param {string} marker
  6546. */
  6547. Canvas.prototype.hasMarker = function(element, marker) {
  6548. if (!element.id) {
  6549. element = this._elementRegistry.get(element);
  6550. }
  6551. var gfx = this.getGraphics(element);
  6552. return classes(gfx).has(marker);
  6553. };
  6554. /**
  6555. * Toggles a marker on an element.
  6556. *
  6557. * Fires the element.marker.update event, making it possible to
  6558. * integrate extension into the marker life-cycle, too.
  6559. *
  6560. * @param {string|djs.model.Base} element
  6561. * @param {string} marker
  6562. */
  6563. Canvas.prototype.toggleMarker = function(element, marker) {
  6564. if (this.hasMarker(element, marker)) {
  6565. this.removeMarker(element, marker);
  6566. } else {
  6567. this.addMarker(element, marker);
  6568. }
  6569. };
  6570. Canvas.prototype.getRootElement = function() {
  6571. if (!this._rootElement) {
  6572. this.setRootElement({ id: '__implicitroot', children: [] });
  6573. }
  6574. return this._rootElement;
  6575. };
  6576. // root element handling //////////////////////
  6577. /**
  6578. * Sets a given element as the new root element for the canvas
  6579. * and returns the new root element.
  6580. *
  6581. * @param {Object|djs.model.Root} element
  6582. * @param {boolean} [override] whether to override the current root element, if any
  6583. *
  6584. * @return {Object|djs.model.Root} new root element
  6585. */
  6586. Canvas.prototype.setRootElement = function(element, override) {
  6587. if (element) {
  6588. this._ensureValid('root', element);
  6589. }
  6590. var currentRoot = this._rootElement,
  6591. elementRegistry = this._elementRegistry,
  6592. eventBus = this._eventBus;
  6593. if (currentRoot) {
  6594. if (!override) {
  6595. throw new Error('rootElement already set, need to specify override');
  6596. }
  6597. // simulate element remove event sequence
  6598. eventBus.fire('root.remove', { element: currentRoot });
  6599. eventBus.fire('root.removed', { element: currentRoot });
  6600. elementRegistry.remove(currentRoot);
  6601. }
  6602. if (element) {
  6603. var gfx = this.getDefaultLayer();
  6604. // resemble element add event sequence
  6605. eventBus.fire('root.add', { element: element });
  6606. elementRegistry.add(element, gfx, this._svg);
  6607. eventBus.fire('root.added', { element: element, gfx: gfx });
  6608. }
  6609. this._rootElement = element;
  6610. return element;
  6611. };
  6612. // add functionality //////////////////////
  6613. Canvas.prototype._ensureValid = function(type, element) {
  6614. if (!element.id) {
  6615. throw new Error('element must have an id');
  6616. }
  6617. if (this._elementRegistry.get(element.id)) {
  6618. throw new Error('element with id ' + element.id + ' already exists');
  6619. }
  6620. var requiredAttrs = REQUIRED_MODEL_ATTRS[type];
  6621. var valid = every(requiredAttrs, function(attr) {
  6622. return typeof element[attr] !== 'undefined';
  6623. });
  6624. if (!valid) {
  6625. throw new Error(
  6626. 'must supply { ' + requiredAttrs.join(', ') + ' } with ' + type);
  6627. }
  6628. };
  6629. Canvas.prototype._setParent = function(element, parent, parentIndex) {
  6630. add(parent.children, element, parentIndex);
  6631. element.parent = parent;
  6632. };
  6633. /**
  6634. * Adds an element to the canvas.
  6635. *
  6636. * This wires the parent <-> child relationship between the element and
  6637. * a explicitly specified parent or an implicit root element.
  6638. *
  6639. * During add it emits the events
  6640. *
  6641. * * <{type}.add> (element, parent)
  6642. * * <{type}.added> (element, gfx)
  6643. *
  6644. * Extensions may hook into these events to perform their magic.
  6645. *
  6646. * @param {string} type
  6647. * @param {Object|djs.model.Base} element
  6648. * @param {Object|djs.model.Base} [parent]
  6649. * @param {number} [parentIndex]
  6650. *
  6651. * @return {Object|djs.model.Base} the added element
  6652. */
  6653. Canvas.prototype._addElement = function(type, element, parent, parentIndex) {
  6654. parent = parent || this.getRootElement();
  6655. var eventBus = this._eventBus,
  6656. graphicsFactory = this._graphicsFactory;
  6657. this._ensureValid(type, element);
  6658. eventBus.fire(type + '.add', { element: element, parent: parent });
  6659. this._setParent(element, parent, parentIndex);
  6660. // create graphics
  6661. var gfx = graphicsFactory.create(type, element, parentIndex);
  6662. this._elementRegistry.add(element, gfx);
  6663. // update its visual
  6664. graphicsFactory.update(type, element, gfx);
  6665. eventBus.fire(type + '.added', { element: element, gfx: gfx });
  6666. return element;
  6667. };
  6668. /**
  6669. * Adds a shape to the canvas
  6670. *
  6671. * @param {Object|djs.model.Shape} shape to add to the diagram
  6672. * @param {djs.model.Base} [parent]
  6673. * @param {number} [parentIndex]
  6674. *
  6675. * @return {djs.model.Shape} the added shape
  6676. */
  6677. Canvas.prototype.addShape = function(shape, parent, parentIndex) {
  6678. return this._addElement('shape', shape, parent, parentIndex);
  6679. };
  6680. /**
  6681. * Adds a connection to the canvas
  6682. *
  6683. * @param {Object|djs.model.Connection} connection to add to the diagram
  6684. * @param {djs.model.Base} [parent]
  6685. * @param {number} [parentIndex]
  6686. *
  6687. * @return {djs.model.Connection} the added connection
  6688. */
  6689. Canvas.prototype.addConnection = function(connection, parent, parentIndex) {
  6690. return this._addElement('connection', connection, parent, parentIndex);
  6691. };
  6692. /**
  6693. * Internal remove element
  6694. */
  6695. Canvas.prototype._removeElement = function(element, type) {
  6696. var elementRegistry = this._elementRegistry,
  6697. graphicsFactory = this._graphicsFactory,
  6698. eventBus = this._eventBus;
  6699. element = elementRegistry.get(element.id || element);
  6700. if (!element) {
  6701. // element was removed already
  6702. return;
  6703. }
  6704. eventBus.fire(type + '.remove', { element: element });
  6705. graphicsFactory.remove(element);
  6706. // unset parent <-> child relationship
  6707. remove$2(element.parent && element.parent.children, element);
  6708. element.parent = null;
  6709. eventBus.fire(type + '.removed', { element: element });
  6710. elementRegistry.remove(element);
  6711. return element;
  6712. };
  6713. /**
  6714. * Removes a shape from the canvas
  6715. *
  6716. * @param {string|djs.model.Shape} shape or shape id to be removed
  6717. *
  6718. * @return {djs.model.Shape} the removed shape
  6719. */
  6720. Canvas.prototype.removeShape = function(shape) {
  6721. /**
  6722. * An event indicating that a shape is about to be removed from the canvas.
  6723. *
  6724. * @memberOf Canvas
  6725. *
  6726. * @event shape.remove
  6727. * @type {Object}
  6728. * @property {djs.model.Shape} element the shape descriptor
  6729. * @property {Object} gfx the graphical representation of the shape
  6730. */
  6731. /**
  6732. * An event indicating that a shape has been removed from the canvas.
  6733. *
  6734. * @memberOf Canvas
  6735. *
  6736. * @event shape.removed
  6737. * @type {Object}
  6738. * @property {djs.model.Shape} element the shape descriptor
  6739. * @property {Object} gfx the graphical representation of the shape
  6740. */
  6741. return this._removeElement(shape, 'shape');
  6742. };
  6743. /**
  6744. * Removes a connection from the canvas
  6745. *
  6746. * @param {string|djs.model.Connection} connection or connection id to be removed
  6747. *
  6748. * @return {djs.model.Connection} the removed connection
  6749. */
  6750. Canvas.prototype.removeConnection = function(connection) {
  6751. /**
  6752. * An event indicating that a connection is about to be removed from the canvas.
  6753. *
  6754. * @memberOf Canvas
  6755. *
  6756. * @event connection.remove
  6757. * @type {Object}
  6758. * @property {djs.model.Connection} element the connection descriptor
  6759. * @property {Object} gfx the graphical representation of the connection
  6760. */
  6761. /**
  6762. * An event indicating that a connection has been removed from the canvas.
  6763. *
  6764. * @memberOf Canvas
  6765. *
  6766. * @event connection.removed
  6767. * @type {Object}
  6768. * @property {djs.model.Connection} element the connection descriptor
  6769. * @property {Object} gfx the graphical representation of the connection
  6770. */
  6771. return this._removeElement(connection, 'connection');
  6772. };
  6773. /**
  6774. * Return the graphical object underlaying a certain diagram element
  6775. *
  6776. * @param {string|djs.model.Base} element descriptor of the element
  6777. * @param {boolean} [secondary=false] whether to return the secondary connected element
  6778. *
  6779. * @return {SVGElement}
  6780. */
  6781. Canvas.prototype.getGraphics = function(element, secondary) {
  6782. return this._elementRegistry.getGraphics(element, secondary);
  6783. };
  6784. /**
  6785. * Perform a viewbox update via a given change function.
  6786. *
  6787. * @param {Function} changeFn
  6788. */
  6789. Canvas.prototype._changeViewbox = function(changeFn) {
  6790. // notify others of the upcoming viewbox change
  6791. this._eventBus.fire('canvas.viewbox.changing');
  6792. // perform actual change
  6793. changeFn.apply(this);
  6794. // reset the cached viewbox so that
  6795. // a new get operation on viewbox or zoom
  6796. // triggers a viewbox re-computation
  6797. this._cachedViewbox = null;
  6798. // notify others of the change; this step
  6799. // may or may not be debounced
  6800. this._viewboxChanged();
  6801. };
  6802. Canvas.prototype._viewboxChanged = function() {
  6803. this._eventBus.fire('canvas.viewbox.changed', { viewbox: this.viewbox() });
  6804. };
  6805. /**
  6806. * Gets or sets the view box of the canvas, i.e. the
  6807. * area that is currently displayed.
  6808. *
  6809. * The getter may return a cached viewbox (if it is currently
  6810. * changing). To force a recomputation, pass `false` as the first argument.
  6811. *
  6812. * @example
  6813. *
  6814. * canvas.viewbox({ x: 100, y: 100, width: 500, height: 500 })
  6815. *
  6816. * // sets the visible area of the diagram to (100|100) -> (600|100)
  6817. * // and and scales it according to the diagram width
  6818. *
  6819. * var viewbox = canvas.viewbox(); // pass `false` to force recomputing the box.
  6820. *
  6821. * console.log(viewbox);
  6822. * // {
  6823. * // inner: Dimensions,
  6824. * // outer: Dimensions,
  6825. * // scale,
  6826. * // x, y,
  6827. * // width, height
  6828. * // }
  6829. *
  6830. * // if the current diagram is zoomed and scrolled, you may reset it to the
  6831. * // default zoom via this method, too:
  6832. *
  6833. * var zoomedAndScrolledViewbox = canvas.viewbox();
  6834. *
  6835. * canvas.viewbox({
  6836. * x: 0,
  6837. * y: 0,
  6838. * width: zoomedAndScrolledViewbox.outer.width,
  6839. * height: zoomedAndScrolledViewbox.outer.height
  6840. * });
  6841. *
  6842. * @param {Object} [box] the new view box to set
  6843. * @param {number} box.x the top left X coordinate of the canvas visible in view box
  6844. * @param {number} box.y the top left Y coordinate of the canvas visible in view box
  6845. * @param {number} box.width the visible width
  6846. * @param {number} box.height
  6847. *
  6848. * @return {Object} the current view box
  6849. */
  6850. Canvas.prototype.viewbox = function(box) {
  6851. if (box === undefined && this._cachedViewbox) {
  6852. return this._cachedViewbox;
  6853. }
  6854. var viewport = this._viewport,
  6855. innerBox,
  6856. outerBox = this.getSize(),
  6857. matrix,
  6858. transform$1,
  6859. scale,
  6860. x, y;
  6861. if (!box) {
  6862. // compute the inner box based on the
  6863. // diagrams default layer. This allows us to exclude
  6864. // external components, such as overlays
  6865. innerBox = this.getDefaultLayer().getBBox();
  6866. transform$1 = transform(viewport);
  6867. matrix = transform$1 ? transform$1.matrix : createMatrix();
  6868. scale = round(matrix.a, 1000);
  6869. x = round(-matrix.e || 0, 1000);
  6870. y = round(-matrix.f || 0, 1000);
  6871. box = this._cachedViewbox = {
  6872. x: x ? x / scale : 0,
  6873. y: y ? y / scale : 0,
  6874. width: outerBox.width / scale,
  6875. height: outerBox.height / scale,
  6876. scale: scale,
  6877. inner: {
  6878. width: innerBox.width,
  6879. height: innerBox.height,
  6880. x: innerBox.x,
  6881. y: innerBox.y
  6882. },
  6883. outer: outerBox
  6884. };
  6885. return box;
  6886. } else {
  6887. this._changeViewbox(function() {
  6888. scale = Math.min(outerBox.width / box.width, outerBox.height / box.height);
  6889. var matrix = this._svg.createSVGMatrix()
  6890. .scale(scale)
  6891. .translate(-box.x, -box.y);
  6892. transform(viewport, matrix);
  6893. });
  6894. }
  6895. return box;
  6896. };
  6897. /**
  6898. * Gets or sets the scroll of the canvas.
  6899. *
  6900. * @param {Object} [delta] the new scroll to apply.
  6901. *
  6902. * @param {number} [delta.dx]
  6903. * @param {number} [delta.dy]
  6904. */
  6905. Canvas.prototype.scroll = function(delta) {
  6906. var node = this._viewport;
  6907. var matrix = node.getCTM();
  6908. if (delta) {
  6909. this._changeViewbox(function() {
  6910. delta = assign({ dx: 0, dy: 0 }, delta || {});
  6911. matrix = this._svg.createSVGMatrix().translate(delta.dx, delta.dy).multiply(matrix);
  6912. setCTM(node, matrix);
  6913. });
  6914. }
  6915. return { x: matrix.e, y: matrix.f };
  6916. };
  6917. /**
  6918. * Gets or sets the current zoom of the canvas, optionally zooming
  6919. * to the specified position.
  6920. *
  6921. * The getter may return a cached zoom level. Call it with `false` as
  6922. * the first argument to force recomputation of the current level.
  6923. *
  6924. * @param {string|number} [newScale] the new zoom level, either a number, i.e. 0.9,
  6925. * or `fit-viewport` to adjust the size to fit the current viewport
  6926. * @param {string|Point} [center] the reference point { x: .., y: ..} to zoom to, 'auto' to zoom into mid or null
  6927. *
  6928. * @return {number} the current scale
  6929. */
  6930. Canvas.prototype.zoom = function(newScale, center) {
  6931. if (!newScale) {
  6932. return this.viewbox(newScale).scale;
  6933. }
  6934. if (newScale === 'fit-viewport') {
  6935. return this._fitViewport(center);
  6936. }
  6937. var outer,
  6938. matrix;
  6939. this._changeViewbox(function() {
  6940. if (typeof center !== 'object') {
  6941. outer = this.viewbox().outer;
  6942. center = {
  6943. x: outer.width / 2,
  6944. y: outer.height / 2
  6945. };
  6946. }
  6947. matrix = this._setZoom(newScale, center);
  6948. });
  6949. return round(matrix.a, 1000);
  6950. };
  6951. function setCTM(node, m) {
  6952. var mstr = 'matrix(' + m.a + ',' + m.b + ',' + m.c + ',' + m.d + ',' + m.e + ',' + m.f + ')';
  6953. node.setAttribute('transform', mstr);
  6954. }
  6955. Canvas.prototype._fitViewport = function(center) {
  6956. var vbox = this.viewbox(),
  6957. outer = vbox.outer,
  6958. inner = vbox.inner,
  6959. newScale,
  6960. newViewbox;
  6961. // display the complete diagram without zooming in.
  6962. // instead of relying on internal zoom, we perform a
  6963. // hard reset on the canvas viewbox to realize this
  6964. //
  6965. // if diagram does not need to be zoomed in, we focus it around
  6966. // the diagram origin instead
  6967. if (inner.x >= 0 &&
  6968. inner.y >= 0 &&
  6969. inner.x + inner.width <= outer.width &&
  6970. inner.y + inner.height <= outer.height &&
  6971. !center) {
  6972. newViewbox = {
  6973. x: 0,
  6974. y: 0,
  6975. width: Math.max(inner.width + inner.x, outer.width),
  6976. height: Math.max(inner.height + inner.y, outer.height)
  6977. };
  6978. } else {
  6979. newScale = Math.min(1, outer.width / inner.width, outer.height / inner.height);
  6980. newViewbox = {
  6981. x: inner.x + (center ? inner.width / 2 - outer.width / newScale / 2 : 0),
  6982. y: inner.y + (center ? inner.height / 2 - outer.height / newScale / 2 : 0),
  6983. width: outer.width / newScale,
  6984. height: outer.height / newScale
  6985. };
  6986. }
  6987. this.viewbox(newViewbox);
  6988. return this.viewbox(false).scale;
  6989. };
  6990. Canvas.prototype._setZoom = function(scale, center) {
  6991. var svg = this._svg,
  6992. viewport = this._viewport;
  6993. var matrix = svg.createSVGMatrix();
  6994. var point = svg.createSVGPoint();
  6995. var centerPoint,
  6996. originalPoint,
  6997. currentMatrix,
  6998. scaleMatrix,
  6999. newMatrix;
  7000. currentMatrix = viewport.getCTM();
  7001. var currentScale = currentMatrix.a;
  7002. if (center) {
  7003. centerPoint = assign(point, center);
  7004. // revert applied viewport transformations
  7005. originalPoint = centerPoint.matrixTransform(currentMatrix.inverse());
  7006. // create scale matrix
  7007. scaleMatrix = matrix
  7008. .translate(originalPoint.x, originalPoint.y)
  7009. .scale(1 / currentScale * scale)
  7010. .translate(-originalPoint.x, -originalPoint.y);
  7011. newMatrix = currentMatrix.multiply(scaleMatrix);
  7012. } else {
  7013. newMatrix = matrix.scale(scale);
  7014. }
  7015. setCTM(this._viewport, newMatrix);
  7016. return newMatrix;
  7017. };
  7018. /**
  7019. * Returns the size of the canvas
  7020. *
  7021. * @return {Dimensions}
  7022. */
  7023. Canvas.prototype.getSize = function() {
  7024. return {
  7025. width: this._container.clientWidth,
  7026. height: this._container.clientHeight
  7027. };
  7028. };
  7029. /**
  7030. * Return the absolute bounding box for the given element
  7031. *
  7032. * The absolute bounding box may be used to display overlays in the
  7033. * callers (browser) coordinate system rather than the zoomed in/out
  7034. * canvas coordinates.
  7035. *
  7036. * @param {ElementDescriptor} element
  7037. * @return {Bounds} the absolute bounding box
  7038. */
  7039. Canvas.prototype.getAbsoluteBBox = function(element) {
  7040. var vbox = this.viewbox();
  7041. var bbox;
  7042. // connection
  7043. // use svg bbox
  7044. if (element.waypoints) {
  7045. var gfx = this.getGraphics(element);
  7046. bbox = gfx.getBBox();
  7047. }
  7048. // shapes
  7049. // use data
  7050. else {
  7051. bbox = element;
  7052. }
  7053. var x = bbox.x * vbox.scale - vbox.x * vbox.scale;
  7054. var y = bbox.y * vbox.scale - vbox.y * vbox.scale;
  7055. var width = bbox.width * vbox.scale;
  7056. var height = bbox.height * vbox.scale;
  7057. return {
  7058. x: x,
  7059. y: y,
  7060. width: width,
  7061. height: height
  7062. };
  7063. };
  7064. /**
  7065. * Fires an event in order other modules can react to the
  7066. * canvas resizing
  7067. */
  7068. Canvas.prototype.resized = function() {
  7069. // force recomputation of view box
  7070. delete this._cachedViewbox;
  7071. this._eventBus.fire('canvas.resized');
  7072. };
  7073. var ELEMENT_ID = 'data-element-id';
  7074. /**
  7075. * @class
  7076. *
  7077. * A registry that keeps track of all shapes in the diagram.
  7078. */
  7079. function ElementRegistry(eventBus) {
  7080. this._elements = {};
  7081. this._eventBus = eventBus;
  7082. }
  7083. ElementRegistry.$inject = [ 'eventBus' ];
  7084. /**
  7085. * Register a pair of (element, gfx, (secondaryGfx)).
  7086. *
  7087. * @param {djs.model.Base} element
  7088. * @param {SVGElement} gfx
  7089. * @param {SVGElement} [secondaryGfx] optional other element to register, too
  7090. */
  7091. ElementRegistry.prototype.add = function(element, gfx, secondaryGfx) {
  7092. var id = element.id;
  7093. this._validateId(id);
  7094. // associate dom node with element
  7095. attr(gfx, ELEMENT_ID, id);
  7096. if (secondaryGfx) {
  7097. attr(secondaryGfx, ELEMENT_ID, id);
  7098. }
  7099. this._elements[id] = { element: element, gfx: gfx, secondaryGfx: secondaryGfx };
  7100. };
  7101. /**
  7102. * Removes an element from the registry.
  7103. *
  7104. * @param {djs.model.Base} element
  7105. */
  7106. ElementRegistry.prototype.remove = function(element) {
  7107. var elements = this._elements,
  7108. id = element.id || element,
  7109. container = id && elements[id];
  7110. if (container) {
  7111. // unset element id on gfx
  7112. attr(container.gfx, ELEMENT_ID, '');
  7113. if (container.secondaryGfx) {
  7114. attr(container.secondaryGfx, ELEMENT_ID, '');
  7115. }
  7116. delete elements[id];
  7117. }
  7118. };
  7119. /**
  7120. * Update the id of an element
  7121. *
  7122. * @param {djs.model.Base} element
  7123. * @param {string} newId
  7124. */
  7125. ElementRegistry.prototype.updateId = function(element, newId) {
  7126. this._validateId(newId);
  7127. if (typeof element === 'string') {
  7128. element = this.get(element);
  7129. }
  7130. this._eventBus.fire('element.updateId', {
  7131. element: element,
  7132. newId: newId
  7133. });
  7134. var gfx = this.getGraphics(element),
  7135. secondaryGfx = this.getGraphics(element, true);
  7136. this.remove(element);
  7137. element.id = newId;
  7138. this.add(element, gfx, secondaryGfx);
  7139. };
  7140. /**
  7141. * Return the model element for a given id or graphics.
  7142. *
  7143. * @example
  7144. *
  7145. * elementRegistry.get('SomeElementId_1');
  7146. * elementRegistry.get(gfx);
  7147. *
  7148. *
  7149. * @param {string|SVGElement} filter for selecting the element
  7150. *
  7151. * @return {djs.model.Base}
  7152. */
  7153. ElementRegistry.prototype.get = function(filter) {
  7154. var id;
  7155. if (typeof filter === 'string') {
  7156. id = filter;
  7157. } else {
  7158. id = filter && attr(filter, ELEMENT_ID);
  7159. }
  7160. var container = this._elements[id];
  7161. return container && container.element;
  7162. };
  7163. /**
  7164. * Return all elements that match a given filter function.
  7165. *
  7166. * @param {Function} fn
  7167. *
  7168. * @return {Array<djs.model.Base>}
  7169. */
  7170. ElementRegistry.prototype.filter = function(fn) {
  7171. var filtered = [];
  7172. this.forEach(function(element, gfx) {
  7173. if (fn(element, gfx)) {
  7174. filtered.push(element);
  7175. }
  7176. });
  7177. return filtered;
  7178. };
  7179. /**
  7180. * Return all rendered model elements.
  7181. *
  7182. * @return {Array<djs.model.Base>}
  7183. */
  7184. ElementRegistry.prototype.getAll = function() {
  7185. return this.filter(function(e) { return e; });
  7186. };
  7187. /**
  7188. * Iterate over all diagram elements.
  7189. *
  7190. * @param {Function} fn
  7191. */
  7192. ElementRegistry.prototype.forEach = function(fn) {
  7193. var map = this._elements;
  7194. Object.keys(map).forEach(function(id) {
  7195. var container = map[id],
  7196. element = container.element,
  7197. gfx = container.gfx;
  7198. return fn(element, gfx);
  7199. });
  7200. };
  7201. /**
  7202. * Return the graphical representation of an element or its id.
  7203. *
  7204. * @example
  7205. * elementRegistry.getGraphics('SomeElementId_1');
  7206. * elementRegistry.getGraphics(rootElement); // <g ...>
  7207. *
  7208. * elementRegistry.getGraphics(rootElement, true); // <svg ...>
  7209. *
  7210. *
  7211. * @param {string|djs.model.Base} filter
  7212. * @param {boolean} [secondary=false] whether to return the secondary connected element
  7213. *
  7214. * @return {SVGElement}
  7215. */
  7216. ElementRegistry.prototype.getGraphics = function(filter, secondary) {
  7217. var id = filter.id || filter;
  7218. var container = this._elements[id];
  7219. return container && (secondary ? container.secondaryGfx : container.gfx);
  7220. };
  7221. /**
  7222. * Validate the suitability of the given id and signals a problem
  7223. * with an exception.
  7224. *
  7225. * @param {string} id
  7226. *
  7227. * @throws {Error} if id is empty or already assigned
  7228. */
  7229. ElementRegistry.prototype._validateId = function(id) {
  7230. if (!id) {
  7231. throw new Error('element must have an id');
  7232. }
  7233. if (this._elements[id]) {
  7234. throw new Error('element with id ' + id + ' already added');
  7235. }
  7236. };
  7237. /**
  7238. * An empty collection stub. Use {@link RefsCollection.extend} to extend a
  7239. * collection with ref semantics.
  7240. *
  7241. * @class RefsCollection
  7242. */
  7243. /**
  7244. * Extends a collection with {@link Refs} aware methods
  7245. *
  7246. * @memberof RefsCollection
  7247. * @static
  7248. *
  7249. * @param {Array<Object>} collection
  7250. * @param {Refs} refs instance
  7251. * @param {Object} property represented by the collection
  7252. * @param {Object} target object the collection is attached to
  7253. *
  7254. * @return {RefsCollection<Object>} the extended array
  7255. */
  7256. function extend$1(collection, refs, property, target) {
  7257. var inverseProperty = property.inverse;
  7258. /**
  7259. * Removes the given element from the array and returns it.
  7260. *
  7261. * @method RefsCollection#remove
  7262. *
  7263. * @param {Object} element the element to remove
  7264. */
  7265. Object.defineProperty(collection, 'remove', {
  7266. value: function(element) {
  7267. var idx = this.indexOf(element);
  7268. if (idx !== -1) {
  7269. this.splice(idx, 1);
  7270. // unset inverse
  7271. refs.unset(element, inverseProperty, target);
  7272. }
  7273. return element;
  7274. }
  7275. });
  7276. /**
  7277. * Returns true if the collection contains the given element
  7278. *
  7279. * @method RefsCollection#contains
  7280. *
  7281. * @param {Object} element the element to check for
  7282. */
  7283. Object.defineProperty(collection, 'contains', {
  7284. value: function(element) {
  7285. return this.indexOf(element) !== -1;
  7286. }
  7287. });
  7288. /**
  7289. * Adds an element to the array, unless it exists already (set semantics).
  7290. *
  7291. * @method RefsCollection#add
  7292. *
  7293. * @param {Object} element the element to add
  7294. * @param {Number} optional index to add element to
  7295. * (possibly moving other elements around)
  7296. */
  7297. Object.defineProperty(collection, 'add', {
  7298. value: function(element, idx) {
  7299. var currentIdx = this.indexOf(element);
  7300. if (typeof idx === 'undefined') {
  7301. if (currentIdx !== -1) {
  7302. // element already in collection (!)
  7303. return;
  7304. }
  7305. // add to end of array, as no idx is specified
  7306. idx = this.length;
  7307. }
  7308. // handle already in collection
  7309. if (currentIdx !== -1) {
  7310. // remove element from currentIdx
  7311. this.splice(currentIdx, 1);
  7312. }
  7313. // add element at idx
  7314. this.splice(idx, 0, element);
  7315. if (currentIdx === -1) {
  7316. // set inverse, unless element was
  7317. // in collection already
  7318. refs.set(element, inverseProperty, target);
  7319. }
  7320. }
  7321. });
  7322. // a simple marker, identifying this element
  7323. // as being a refs collection
  7324. Object.defineProperty(collection, '__refs_collection', {
  7325. value: true
  7326. });
  7327. return collection;
  7328. }
  7329. function isExtended(collection) {
  7330. return collection.__refs_collection === true;
  7331. }
  7332. var extend_1 = extend$1;
  7333. var isExtended_1 = isExtended;
  7334. var collection = {
  7335. extend: extend_1,
  7336. isExtended: isExtended_1
  7337. };
  7338. function hasOwnProperty(e, property) {
  7339. return Object.prototype.hasOwnProperty.call(e, property.name || property);
  7340. }
  7341. function defineCollectionProperty(ref, property, target) {
  7342. var collection$1 = collection.extend(target[property.name] || [], ref, property, target);
  7343. Object.defineProperty(target, property.name, {
  7344. enumerable: property.enumerable,
  7345. value: collection$1
  7346. });
  7347. if (collection$1.length) {
  7348. collection$1.forEach(function(o) {
  7349. ref.set(o, property.inverse, target);
  7350. });
  7351. }
  7352. }
  7353. function defineProperty(ref, property, target) {
  7354. var inverseProperty = property.inverse;
  7355. var _value = target[property.name];
  7356. Object.defineProperty(target, property.name, {
  7357. configurable: property.configurable,
  7358. enumerable: property.enumerable,
  7359. get: function() {
  7360. return _value;
  7361. },
  7362. set: function(value) {
  7363. // return if we already performed all changes
  7364. if (value === _value) {
  7365. return;
  7366. }
  7367. var old = _value;
  7368. // temporary set null
  7369. _value = null;
  7370. if (old) {
  7371. ref.unset(old, inverseProperty, target);
  7372. }
  7373. // set new value
  7374. _value = value;
  7375. // set inverse value
  7376. ref.set(_value, inverseProperty, target);
  7377. }
  7378. });
  7379. }
  7380. /**
  7381. * Creates a new references object defining two inversly related
  7382. * attribute descriptors a and b.
  7383. *
  7384. * <p>
  7385. * When bound to an object using {@link Refs#bind} the references
  7386. * get activated and ensure that add and remove operations are applied
  7387. * reversely, too.
  7388. * </p>
  7389. *
  7390. * <p>
  7391. * For attributes represented as collections {@link Refs} provides the
  7392. * {@link RefsCollection#add}, {@link RefsCollection#remove} and {@link RefsCollection#contains} extensions
  7393. * that must be used to properly hook into the inverse change mechanism.
  7394. * </p>
  7395. *
  7396. * @class Refs
  7397. *
  7398. * @classdesc A bi-directional reference between two attributes.
  7399. *
  7400. * @param {Refs.AttributeDescriptor} a property descriptor
  7401. * @param {Refs.AttributeDescriptor} b property descriptor
  7402. *
  7403. * @example
  7404. *
  7405. * var refs = Refs({ name: 'wheels', collection: true, enumerable: true }, { name: 'car' });
  7406. *
  7407. * var car = { name: 'toyota' };
  7408. * var wheels = [{ pos: 'front-left' }, { pos: 'front-right' }];
  7409. *
  7410. * refs.bind(car, 'wheels');
  7411. *
  7412. * car.wheels // []
  7413. * car.wheels.add(wheels[0]);
  7414. * car.wheels.add(wheels[1]);
  7415. *
  7416. * car.wheels // [{ pos: 'front-left' }, { pos: 'front-right' }]
  7417. *
  7418. * wheels[0].car // { name: 'toyota' };
  7419. * car.wheels.remove(wheels[0]);
  7420. *
  7421. * wheels[0].car // undefined
  7422. */
  7423. function Refs(a, b) {
  7424. if (!(this instanceof Refs)) {
  7425. return new Refs(a, b);
  7426. }
  7427. // link
  7428. a.inverse = b;
  7429. b.inverse = a;
  7430. this.props = {};
  7431. this.props[a.name] = a;
  7432. this.props[b.name] = b;
  7433. }
  7434. /**
  7435. * Binds one side of a bi-directional reference to a
  7436. * target object.
  7437. *
  7438. * @memberOf Refs
  7439. *
  7440. * @param {Object} target
  7441. * @param {String} property
  7442. */
  7443. Refs.prototype.bind = function(target, property) {
  7444. if (typeof property === 'string') {
  7445. if (!this.props[property]) {
  7446. throw new Error('no property <' + property + '> in ref');
  7447. }
  7448. property = this.props[property];
  7449. }
  7450. if (property.collection) {
  7451. defineCollectionProperty(this, property, target);
  7452. } else {
  7453. defineProperty(this, property, target);
  7454. }
  7455. };
  7456. Refs.prototype.ensureRefsCollection = function(target, property) {
  7457. var collection$1 = target[property.name];
  7458. if (!collection.isExtended(collection$1)) {
  7459. defineCollectionProperty(this, property, target);
  7460. }
  7461. return collection$1;
  7462. };
  7463. Refs.prototype.ensureBound = function(target, property) {
  7464. if (!hasOwnProperty(target, property)) {
  7465. this.bind(target, property);
  7466. }
  7467. };
  7468. Refs.prototype.unset = function(target, property, value) {
  7469. if (target) {
  7470. this.ensureBound(target, property);
  7471. if (property.collection) {
  7472. this.ensureRefsCollection(target, property).remove(value);
  7473. } else {
  7474. target[property.name] = undefined;
  7475. }
  7476. }
  7477. };
  7478. Refs.prototype.set = function(target, property, value) {
  7479. if (target) {
  7480. this.ensureBound(target, property);
  7481. if (property.collection) {
  7482. this.ensureRefsCollection(target, property).add(value);
  7483. } else {
  7484. target[property.name] = value;
  7485. }
  7486. }
  7487. };
  7488. var refs = Refs;
  7489. var objectRefs = refs;
  7490. var Collection = collection;
  7491. objectRefs.Collection = Collection;
  7492. var parentRefs = new objectRefs({ name: 'children', enumerable: true, collection: true }, { name: 'parent' }),
  7493. labelRefs = new objectRefs({ name: 'labels', enumerable: true, collection: true }, { name: 'labelTarget' }),
  7494. attacherRefs = new objectRefs({ name: 'attachers', collection: true }, { name: 'host' }),
  7495. outgoingRefs = new objectRefs({ name: 'outgoing', collection: true }, { name: 'source' }),
  7496. incomingRefs = new objectRefs({ name: 'incoming', collection: true }, { name: 'target' });
  7497. /**
  7498. * @namespace djs.model
  7499. */
  7500. /**
  7501. * @memberOf djs.model
  7502. */
  7503. /**
  7504. * The basic graphical representation
  7505. *
  7506. * @class
  7507. *
  7508. * @abstract
  7509. */
  7510. function Base() {
  7511. /**
  7512. * The object that backs up the shape
  7513. *
  7514. * @name Base#businessObject
  7515. * @type Object
  7516. */
  7517. Object.defineProperty(this, 'businessObject', {
  7518. writable: true
  7519. });
  7520. /**
  7521. * Single label support, will mapped to multi label array
  7522. *
  7523. * @name Base#label
  7524. * @type Object
  7525. */
  7526. Object.defineProperty(this, 'label', {
  7527. get: function() {
  7528. return this.labels[0];
  7529. },
  7530. set: function(newLabel) {
  7531. var label = this.label,
  7532. labels = this.labels;
  7533. if (!newLabel && label) {
  7534. labels.remove(label);
  7535. } else {
  7536. labels.add(newLabel, 0);
  7537. }
  7538. }
  7539. });
  7540. /**
  7541. * The parent shape
  7542. *
  7543. * @name Base#parent
  7544. * @type Shape
  7545. */
  7546. parentRefs.bind(this, 'parent');
  7547. /**
  7548. * The list of labels
  7549. *
  7550. * @name Base#labels
  7551. * @type Label
  7552. */
  7553. labelRefs.bind(this, 'labels');
  7554. /**
  7555. * The list of outgoing connections
  7556. *
  7557. * @name Base#outgoing
  7558. * @type Array<Connection>
  7559. */
  7560. outgoingRefs.bind(this, 'outgoing');
  7561. /**
  7562. * The list of incoming connections
  7563. *
  7564. * @name Base#incoming
  7565. * @type Array<Connection>
  7566. */
  7567. incomingRefs.bind(this, 'incoming');
  7568. }
  7569. /**
  7570. * A graphical object
  7571. *
  7572. * @class
  7573. * @constructor
  7574. *
  7575. * @extends Base
  7576. */
  7577. function Shape() {
  7578. Base.call(this);
  7579. /**
  7580. * Indicates frame shapes
  7581. *
  7582. * @name Shape#isFrame
  7583. * @type boolean
  7584. */
  7585. /**
  7586. * The list of children
  7587. *
  7588. * @name Shape#children
  7589. * @type Array<Base>
  7590. */
  7591. parentRefs.bind(this, 'children');
  7592. /**
  7593. * @name Shape#host
  7594. * @type Shape
  7595. */
  7596. attacherRefs.bind(this, 'host');
  7597. /**
  7598. * @name Shape#attachers
  7599. * @type Shape
  7600. */
  7601. attacherRefs.bind(this, 'attachers');
  7602. }
  7603. inherits_browser(Shape, Base);
  7604. /**
  7605. * A root graphical object
  7606. *
  7607. * @class
  7608. * @constructor
  7609. *
  7610. * @extends Shape
  7611. */
  7612. function Root() {
  7613. Shape.call(this);
  7614. }
  7615. inherits_browser(Root, Shape);
  7616. /**
  7617. * A label for an element
  7618. *
  7619. * @class
  7620. * @constructor
  7621. *
  7622. * @extends Shape
  7623. */
  7624. function Label() {
  7625. Shape.call(this);
  7626. /**
  7627. * The labeled element
  7628. *
  7629. * @name Label#labelTarget
  7630. * @type Base
  7631. */
  7632. labelRefs.bind(this, 'labelTarget');
  7633. }
  7634. inherits_browser(Label, Shape);
  7635. /**
  7636. * A connection between two elements
  7637. *
  7638. * @class
  7639. * @constructor
  7640. *
  7641. * @extends Base
  7642. */
  7643. function Connection() {
  7644. Base.call(this);
  7645. /**
  7646. * The element this connection originates from
  7647. *
  7648. * @name Connection#source
  7649. * @type Base
  7650. */
  7651. outgoingRefs.bind(this, 'source');
  7652. /**
  7653. * The element this connection points to
  7654. *
  7655. * @name Connection#target
  7656. * @type Base
  7657. */
  7658. incomingRefs.bind(this, 'target');
  7659. }
  7660. inherits_browser(Connection, Base);
  7661. var types = {
  7662. connection: Connection,
  7663. shape: Shape,
  7664. label: Label,
  7665. root: Root
  7666. };
  7667. /**
  7668. * Creates a new model element of the specified type
  7669. *
  7670. * @method create
  7671. *
  7672. * @example
  7673. *
  7674. * var shape1 = Model.create('shape', { x: 10, y: 10, width: 100, height: 100 });
  7675. * var shape2 = Model.create('shape', { x: 210, y: 210, width: 100, height: 100 });
  7676. *
  7677. * var connection = Model.create('connection', { waypoints: [ { x: 110, y: 55 }, {x: 210, y: 55 } ] });
  7678. *
  7679. * @param {string} type lower-cased model name
  7680. * @param {Object} attrs attributes to initialize the new model instance with
  7681. *
  7682. * @return {Base} the new model instance
  7683. */
  7684. function create$1(type, attrs) {
  7685. var Type = types[type];
  7686. if (!Type) {
  7687. throw new Error('unknown type: <' + type + '>');
  7688. }
  7689. return assign(new Type(), attrs);
  7690. }
  7691. /**
  7692. * A factory for diagram-js shapes
  7693. */
  7694. function ElementFactory() {
  7695. this._uid = 12;
  7696. }
  7697. ElementFactory.prototype.createRoot = function(attrs) {
  7698. return this.create('root', attrs);
  7699. };
  7700. ElementFactory.prototype.createLabel = function(attrs) {
  7701. return this.create('label', attrs);
  7702. };
  7703. ElementFactory.prototype.createShape = function(attrs) {
  7704. return this.create('shape', attrs);
  7705. };
  7706. ElementFactory.prototype.createConnection = function(attrs) {
  7707. return this.create('connection', attrs);
  7708. };
  7709. /**
  7710. * Create a model element with the given type and
  7711. * a number of pre-set attributes.
  7712. *
  7713. * @param {string} type
  7714. * @param {Object} attrs
  7715. * @return {djs.model.Base} the newly created model instance
  7716. */
  7717. ElementFactory.prototype.create = function(type, attrs) {
  7718. attrs = assign({}, attrs || {});
  7719. if (!attrs.id) {
  7720. attrs.id = type + '_' + (this._uid++);
  7721. }
  7722. return create$1(type, attrs);
  7723. };
  7724. var FN_REF = '__fn';
  7725. var DEFAULT_PRIORITY = 1000;
  7726. var slice$1 = Array.prototype.slice;
  7727. /**
  7728. * A general purpose event bus.
  7729. *
  7730. * This component is used to communicate across a diagram instance.
  7731. * Other parts of a diagram can use it to listen to and broadcast events.
  7732. *
  7733. *
  7734. * ## Registering for Events
  7735. *
  7736. * The event bus provides the {@link EventBus#on} and {@link EventBus#once}
  7737. * methods to register for events. {@link EventBus#off} can be used to
  7738. * remove event registrations. Listeners receive an instance of {@link Event}
  7739. * as the first argument. It allows them to hook into the event execution.
  7740. *
  7741. * ```javascript
  7742. *
  7743. * // listen for event
  7744. * eventBus.on('foo', function(event) {
  7745. *
  7746. * // access event type
  7747. * event.type; // 'foo'
  7748. *
  7749. * // stop propagation to other listeners
  7750. * event.stopPropagation();
  7751. *
  7752. * // prevent event default
  7753. * event.preventDefault();
  7754. * });
  7755. *
  7756. * // listen for event with custom payload
  7757. * eventBus.on('bar', function(event, payload) {
  7758. * console.log(payload);
  7759. * });
  7760. *
  7761. * // listen for event returning value
  7762. * eventBus.on('foobar', function(event) {
  7763. *
  7764. * // stop event propagation + prevent default
  7765. * return false;
  7766. *
  7767. * // stop event propagation + return custom result
  7768. * return {
  7769. * complex: 'listening result'
  7770. * };
  7771. * });
  7772. *
  7773. *
  7774. * // listen with custom priority (default=1000, higher is better)
  7775. * eventBus.on('priorityfoo', 1500, function(event) {
  7776. * console.log('invoked first!');
  7777. * });
  7778. *
  7779. *
  7780. * // listen for event and pass the context (`this`)
  7781. * eventBus.on('foobar', function(event) {
  7782. * this.foo();
  7783. * }, this);
  7784. * ```
  7785. *
  7786. *
  7787. * ## Emitting Events
  7788. *
  7789. * Events can be emitted via the event bus using {@link EventBus#fire}.
  7790. *
  7791. * ```javascript
  7792. *
  7793. * // false indicates that the default action
  7794. * // was prevented by listeners
  7795. * if (eventBus.fire('foo') === false) {
  7796. * console.log('default has been prevented!');
  7797. * };
  7798. *
  7799. *
  7800. * // custom args + return value listener
  7801. * eventBus.on('sum', function(event, a, b) {
  7802. * return a + b;
  7803. * });
  7804. *
  7805. * // you can pass custom arguments + retrieve result values.
  7806. * var sum = eventBus.fire('sum', 1, 2);
  7807. * console.log(sum); // 3
  7808. * ```
  7809. */
  7810. function EventBus() {
  7811. this._listeners = {};
  7812. // cleanup on destroy on lowest priority to allow
  7813. // message passing until the bitter end
  7814. this.on('diagram.destroy', 1, this._destroy, this);
  7815. }
  7816. /**
  7817. * Register an event listener for events with the given name.
  7818. *
  7819. * The callback will be invoked with `event, ...additionalArguments`
  7820. * that have been passed to {@link EventBus#fire}.
  7821. *
  7822. * Returning false from a listener will prevent the events default action
  7823. * (if any is specified). To stop an event from being processed further in
  7824. * other listeners execute {@link Event#stopPropagation}.
  7825. *
  7826. * Returning anything but `undefined` from a listener will stop the listener propagation.
  7827. *
  7828. * @param {string|Array<string>} events
  7829. * @param {number} [priority=1000] the priority in which this listener is called, larger is higher
  7830. * @param {Function} callback
  7831. * @param {Object} [that] Pass context (`this`) to the callback
  7832. */
  7833. EventBus.prototype.on = function(events, priority, callback, that) {
  7834. events = isArray(events) ? events : [ events ];
  7835. if (isFunction(priority)) {
  7836. that = callback;
  7837. callback = priority;
  7838. priority = DEFAULT_PRIORITY;
  7839. }
  7840. if (!isNumber(priority)) {
  7841. throw new Error('priority must be a number');
  7842. }
  7843. var actualCallback = callback;
  7844. if (that) {
  7845. actualCallback = bind(callback, that);
  7846. // make sure we remember and are able to remove
  7847. // bound callbacks via {@link #off} using the original
  7848. // callback
  7849. actualCallback[FN_REF] = callback[FN_REF] || callback;
  7850. }
  7851. var self = this;
  7852. events.forEach(function(e) {
  7853. self._addListener(e, {
  7854. priority: priority,
  7855. callback: actualCallback,
  7856. next: null
  7857. });
  7858. });
  7859. };
  7860. /**
  7861. * Register an event listener that is executed only once.
  7862. *
  7863. * @param {string} event the event name to register for
  7864. * @param {number} [priority=1000] the priority in which this listener is called, larger is higher
  7865. * @param {Function} callback the callback to execute
  7866. * @param {Object} [that] Pass context (`this`) to the callback
  7867. */
  7868. EventBus.prototype.once = function(event, priority, callback, that) {
  7869. var self = this;
  7870. if (isFunction(priority)) {
  7871. that = callback;
  7872. callback = priority;
  7873. priority = DEFAULT_PRIORITY;
  7874. }
  7875. if (!isNumber(priority)) {
  7876. throw new Error('priority must be a number');
  7877. }
  7878. function wrappedCallback() {
  7879. var result = callback.apply(that, arguments);
  7880. self.off(event, wrappedCallback);
  7881. return result;
  7882. }
  7883. // make sure we remember and are able to remove
  7884. // bound callbacks via {@link #off} using the original
  7885. // callback
  7886. wrappedCallback[FN_REF] = callback;
  7887. this.on(event, priority, wrappedCallback);
  7888. };
  7889. /**
  7890. * Removes event listeners by event and callback.
  7891. *
  7892. * If no callback is given, all listeners for a given event name are being removed.
  7893. *
  7894. * @param {string|Array<string>} events
  7895. * @param {Function} [callback]
  7896. */
  7897. EventBus.prototype.off = function(events, callback) {
  7898. events = isArray(events) ? events : [ events ];
  7899. var self = this;
  7900. events.forEach(function(event) {
  7901. self._removeListener(event, callback);
  7902. });
  7903. };
  7904. /**
  7905. * Create an EventBus event.
  7906. *
  7907. * @param {Object} data
  7908. *
  7909. * @return {Object} event, recognized by the eventBus
  7910. */
  7911. EventBus.prototype.createEvent = function(data) {
  7912. var event = new InternalEvent();
  7913. event.init(data);
  7914. return event;
  7915. };
  7916. /**
  7917. * Fires a named event.
  7918. *
  7919. * @example
  7920. *
  7921. * // fire event by name
  7922. * events.fire('foo');
  7923. *
  7924. * // fire event object with nested type
  7925. * var event = { type: 'foo' };
  7926. * events.fire(event);
  7927. *
  7928. * // fire event with explicit type
  7929. * var event = { x: 10, y: 20 };
  7930. * events.fire('element.moved', event);
  7931. *
  7932. * // pass additional arguments to the event
  7933. * events.on('foo', function(event, bar) {
  7934. * alert(bar);
  7935. * });
  7936. *
  7937. * events.fire({ type: 'foo' }, 'I am bar!');
  7938. *
  7939. * @param {string} [name] the optional event name
  7940. * @param {Object} [event] the event object
  7941. * @param {...Object} additional arguments to be passed to the callback functions
  7942. *
  7943. * @return {boolean} the events return value, if specified or false if the
  7944. * default action was prevented by listeners
  7945. */
  7946. EventBus.prototype.fire = function(type, data) {
  7947. var event,
  7948. firstListener,
  7949. returnValue,
  7950. args;
  7951. args = slice$1.call(arguments);
  7952. if (typeof type === 'object') {
  7953. data = type;
  7954. type = data.type;
  7955. }
  7956. if (!type) {
  7957. throw new Error('no event type specified');
  7958. }
  7959. firstListener = this._listeners[type];
  7960. if (!firstListener) {
  7961. return;
  7962. }
  7963. // we make sure we fire instances of our home made
  7964. // events here. We wrap them only once, though
  7965. if (data instanceof InternalEvent) {
  7966. // we are fine, we alread have an event
  7967. event = data;
  7968. } else {
  7969. event = this.createEvent(data);
  7970. }
  7971. // ensure we pass the event as the first parameter
  7972. args[0] = event;
  7973. // original event type (in case we delegate)
  7974. var originalType = event.type;
  7975. // update event type before delegation
  7976. if (type !== originalType) {
  7977. event.type = type;
  7978. }
  7979. try {
  7980. returnValue = this._invokeListeners(event, args, firstListener);
  7981. } finally {
  7982. // reset event type after delegation
  7983. if (type !== originalType) {
  7984. event.type = originalType;
  7985. }
  7986. }
  7987. // set the return value to false if the event default
  7988. // got prevented and no other return value exists
  7989. if (returnValue === undefined && event.defaultPrevented) {
  7990. returnValue = false;
  7991. }
  7992. return returnValue;
  7993. };
  7994. EventBus.prototype.handleError = function(error) {
  7995. return this.fire('error', { error: error }) === false;
  7996. };
  7997. EventBus.prototype._destroy = function() {
  7998. this._listeners = {};
  7999. };
  8000. EventBus.prototype._invokeListeners = function(event, args, listener) {
  8001. var returnValue;
  8002. while (listener) {
  8003. // handle stopped propagation
  8004. if (event.cancelBubble) {
  8005. break;
  8006. }
  8007. returnValue = this._invokeListener(event, args, listener);
  8008. listener = listener.next;
  8009. }
  8010. return returnValue;
  8011. };
  8012. EventBus.prototype._invokeListener = function(event, args, listener) {
  8013. var returnValue;
  8014. try {
  8015. // returning false prevents the default action
  8016. returnValue = invokeFunction(listener.callback, args);
  8017. // stop propagation on return value
  8018. if (returnValue !== undefined) {
  8019. event.returnValue = returnValue;
  8020. event.stopPropagation();
  8021. }
  8022. // prevent default on return false
  8023. if (returnValue === false) {
  8024. event.preventDefault();
  8025. }
  8026. } catch (e) {
  8027. if (!this.handleError(e)) {
  8028. console.error('unhandled error in event listener');
  8029. console.error(e.stack);
  8030. throw e;
  8031. }
  8032. }
  8033. return returnValue;
  8034. };
  8035. /*
  8036. * Add new listener with a certain priority to the list
  8037. * of listeners (for the given event).
  8038. *
  8039. * The semantics of listener registration / listener execution are
  8040. * first register, first serve: New listeners will always be inserted
  8041. * after existing listeners with the same priority.
  8042. *
  8043. * Example: Inserting two listeners with priority 1000 and 1300
  8044. *
  8045. * * before: [ 1500, 1500, 1000, 1000 ]
  8046. * * after: [ 1500, 1500, (new=1300), 1000, 1000, (new=1000) ]
  8047. *
  8048. * @param {string} event
  8049. * @param {Object} listener { priority, callback }
  8050. */
  8051. EventBus.prototype._addListener = function(event, newListener) {
  8052. var listener = this._getListeners(event),
  8053. previousListener;
  8054. // no prior listeners
  8055. if (!listener) {
  8056. this._setListeners(event, newListener);
  8057. return;
  8058. }
  8059. // ensure we order listeners by priority from
  8060. // 0 (high) to n > 0 (low)
  8061. while (listener) {
  8062. if (listener.priority < newListener.priority) {
  8063. newListener.next = listener;
  8064. if (previousListener) {
  8065. previousListener.next = newListener;
  8066. } else {
  8067. this._setListeners(event, newListener);
  8068. }
  8069. return;
  8070. }
  8071. previousListener = listener;
  8072. listener = listener.next;
  8073. }
  8074. // add new listener to back
  8075. previousListener.next = newListener;
  8076. };
  8077. EventBus.prototype._getListeners = function(name) {
  8078. return this._listeners[name];
  8079. };
  8080. EventBus.prototype._setListeners = function(name, listener) {
  8081. this._listeners[name] = listener;
  8082. };
  8083. EventBus.prototype._removeListener = function(event, callback) {
  8084. var listener = this._getListeners(event),
  8085. nextListener,
  8086. previousListener,
  8087. listenerCallback;
  8088. if (!callback) {
  8089. // clear listeners
  8090. this._setListeners(event, null);
  8091. return;
  8092. }
  8093. while (listener) {
  8094. nextListener = listener.next;
  8095. listenerCallback = listener.callback;
  8096. if (listenerCallback === callback || listenerCallback[FN_REF] === callback) {
  8097. if (previousListener) {
  8098. previousListener.next = nextListener;
  8099. } else {
  8100. // new first listener
  8101. this._setListeners(event, nextListener);
  8102. }
  8103. }
  8104. previousListener = listener;
  8105. listener = nextListener;
  8106. }
  8107. };
  8108. /**
  8109. * A event that is emitted via the event bus.
  8110. */
  8111. function InternalEvent() { }
  8112. InternalEvent.prototype.stopPropagation = function() {
  8113. this.cancelBubble = true;
  8114. };
  8115. InternalEvent.prototype.preventDefault = function() {
  8116. this.defaultPrevented = true;
  8117. };
  8118. InternalEvent.prototype.init = function(data) {
  8119. assign(this, data || {});
  8120. };
  8121. /**
  8122. * Invoke function. Be fast...
  8123. *
  8124. * @param {Function} fn
  8125. * @param {Array<Object>} args
  8126. *
  8127. * @return {Any}
  8128. */
  8129. function invokeFunction(fn, args) {
  8130. return fn.apply(null, args);
  8131. }
  8132. /**
  8133. * SVGs for elements are generated by the {@link GraphicsFactory}.
  8134. *
  8135. * This utility gives quick access to the important semantic
  8136. * parts of an element.
  8137. */
  8138. /**
  8139. * Returns the visual part of a diagram element
  8140. *
  8141. * @param {Snap<SVGElement>} gfx
  8142. *
  8143. * @return {Snap<SVGElement>}
  8144. */
  8145. function getVisual(gfx) {
  8146. return gfx.childNodes[0];
  8147. }
  8148. /**
  8149. * Returns the children for a given diagram element.
  8150. *
  8151. * @param {Snap<SVGElement>} gfx
  8152. * @return {Snap<SVGElement>}
  8153. */
  8154. function getChildren(gfx) {
  8155. return gfx.parentNode.childNodes[1];
  8156. }
  8157. /**
  8158. * A factory that creates graphical elements
  8159. *
  8160. * @param {EventBus} eventBus
  8161. * @param {ElementRegistry} elementRegistry
  8162. */
  8163. function GraphicsFactory(eventBus, elementRegistry) {
  8164. this._eventBus = eventBus;
  8165. this._elementRegistry = elementRegistry;
  8166. }
  8167. GraphicsFactory.$inject = [ 'eventBus' , 'elementRegistry' ];
  8168. GraphicsFactory.prototype._getChildrenContainer = function(element) {
  8169. var gfx = this._elementRegistry.getGraphics(element);
  8170. var childrenGfx;
  8171. // root element
  8172. if (!element.parent) {
  8173. childrenGfx = gfx;
  8174. } else {
  8175. childrenGfx = getChildren(gfx);
  8176. if (!childrenGfx) {
  8177. childrenGfx = create('g');
  8178. classes(childrenGfx).add('djs-children');
  8179. append(gfx.parentNode, childrenGfx);
  8180. }
  8181. }
  8182. return childrenGfx;
  8183. };
  8184. /**
  8185. * Clears the graphical representation of the element and returns the
  8186. * cleared visual (the <g class="djs-visual" /> element).
  8187. */
  8188. GraphicsFactory.prototype._clear = function(gfx) {
  8189. var visual = getVisual(gfx);
  8190. clear$1(visual);
  8191. return visual;
  8192. };
  8193. /**
  8194. * Creates a gfx container for shapes and connections
  8195. *
  8196. * The layout is as follows:
  8197. *
  8198. * <g class="djs-group">
  8199. *
  8200. * <!-- the gfx -->
  8201. * <g class="djs-element djs-(shape|connection|frame)">
  8202. * <g class="djs-visual">
  8203. * <!-- the renderer draws in here -->
  8204. * </g>
  8205. *
  8206. * <!-- extensions (overlays, click box, ...) goes here
  8207. * </g>
  8208. *
  8209. * <!-- the gfx child nodes -->
  8210. * <g class="djs-children"></g>
  8211. * </g>
  8212. *
  8213. * @param {string} type the type of the element, i.e. shape | connection
  8214. * @param {SVGElement} [childrenGfx]
  8215. * @param {number} [parentIndex] position to create container in parent
  8216. * @param {boolean} [isFrame] is frame element
  8217. *
  8218. * @return {SVGElement}
  8219. */
  8220. GraphicsFactory.prototype._createContainer = function(
  8221. type, childrenGfx, parentIndex, isFrame
  8222. ) {
  8223. var outerGfx = create('g');
  8224. classes(outerGfx).add('djs-group');
  8225. // insert node at position
  8226. if (typeof parentIndex !== 'undefined') {
  8227. prependTo(outerGfx, childrenGfx, childrenGfx.childNodes[parentIndex]);
  8228. } else {
  8229. append(childrenGfx, outerGfx);
  8230. }
  8231. var gfx = create('g');
  8232. classes(gfx).add('djs-element');
  8233. classes(gfx).add('djs-' + type);
  8234. if (isFrame) {
  8235. classes(gfx).add('djs-frame');
  8236. }
  8237. append(outerGfx, gfx);
  8238. // create visual
  8239. var visual = create('g');
  8240. classes(visual).add('djs-visual');
  8241. append(gfx, visual);
  8242. return gfx;
  8243. };
  8244. GraphicsFactory.prototype.create = function(type, element, parentIndex) {
  8245. var childrenGfx = this._getChildrenContainer(element.parent);
  8246. return this._createContainer(type, childrenGfx, parentIndex, isFrameElement$1(element));
  8247. };
  8248. GraphicsFactory.prototype.updateContainments = function(elements) {
  8249. var self = this,
  8250. elementRegistry = this._elementRegistry,
  8251. parents;
  8252. parents = reduce(elements, function(map, e) {
  8253. if (e.parent) {
  8254. map[e.parent.id] = e.parent;
  8255. }
  8256. return map;
  8257. }, {});
  8258. // update all parents of changed and reorganized their children
  8259. // in the correct order (as indicated in our model)
  8260. forEach(parents, function(parent) {
  8261. var children = parent.children;
  8262. if (!children) {
  8263. return;
  8264. }
  8265. var childrenGfx = self._getChildrenContainer(parent);
  8266. forEach(children.slice().reverse(), function(child) {
  8267. var childGfx = elementRegistry.getGraphics(child);
  8268. prependTo(childGfx.parentNode, childrenGfx);
  8269. });
  8270. });
  8271. };
  8272. GraphicsFactory.prototype.drawShape = function(visual, element) {
  8273. var eventBus = this._eventBus;
  8274. return eventBus.fire('render.shape', { gfx: visual, element: element });
  8275. };
  8276. GraphicsFactory.prototype.getShapePath = function(element) {
  8277. var eventBus = this._eventBus;
  8278. return eventBus.fire('render.getShapePath', element);
  8279. };
  8280. GraphicsFactory.prototype.drawConnection = function(visual, element) {
  8281. var eventBus = this._eventBus;
  8282. return eventBus.fire('render.connection', { gfx: visual, element: element });
  8283. };
  8284. GraphicsFactory.prototype.getConnectionPath = function(waypoints) {
  8285. var eventBus = this._eventBus;
  8286. return eventBus.fire('render.getConnectionPath', waypoints);
  8287. };
  8288. GraphicsFactory.prototype.update = function(type, element, gfx) {
  8289. // do NOT update root element
  8290. if (!element.parent) {
  8291. return;
  8292. }
  8293. var visual = this._clear(gfx);
  8294. // redraw
  8295. if (type === 'shape') {
  8296. this.drawShape(visual, element);
  8297. // update positioning
  8298. translate(gfx, element.x, element.y);
  8299. } else
  8300. if (type === 'connection') {
  8301. this.drawConnection(visual, element);
  8302. } else {
  8303. throw new Error('unknown type: ' + type);
  8304. }
  8305. if (element.hidden) {
  8306. attr(gfx, 'display', 'none');
  8307. } else {
  8308. attr(gfx, 'display', 'block');
  8309. }
  8310. };
  8311. GraphicsFactory.prototype.remove = function(element) {
  8312. var gfx = this._elementRegistry.getGraphics(element);
  8313. // remove
  8314. remove(gfx.parentNode);
  8315. };
  8316. // helpers //////////
  8317. function prependTo(newNode, parentNode, siblingNode) {
  8318. var node = siblingNode || parentNode.firstChild;
  8319. // do not prepend node to itself to prevent IE from crashing
  8320. // https://github.com/bpmn-io/bpmn-js/issues/746
  8321. if (newNode === node) {
  8322. return;
  8323. }
  8324. parentNode.insertBefore(newNode, node);
  8325. }
  8326. var CoreModule$1 = {
  8327. __depends__: [ DrawModule$1 ],
  8328. __init__: [ 'canvas' ],
  8329. canvas: [ 'type', Canvas ],
  8330. elementRegistry: [ 'type', ElementRegistry ],
  8331. elementFactory: [ 'type', ElementFactory ],
  8332. eventBus: [ 'type', EventBus ],
  8333. graphicsFactory: [ 'type', GraphicsFactory ]
  8334. };
  8335. /**
  8336. * Bootstrap an injector from a list of modules, instantiating a number of default components
  8337. *
  8338. * @ignore
  8339. * @param {Array<didi.Module>} bootstrapModules
  8340. *
  8341. * @return {didi.Injector} a injector to use to access the components
  8342. */
  8343. function bootstrap(bootstrapModules) {
  8344. var modules = [],
  8345. components = [];
  8346. function hasModule(m) {
  8347. return modules.indexOf(m) >= 0;
  8348. }
  8349. function addModule(m) {
  8350. modules.push(m);
  8351. }
  8352. function visit(m) {
  8353. if (hasModule(m)) {
  8354. return;
  8355. }
  8356. (m.__depends__ || []).forEach(visit);
  8357. if (hasModule(m)) {
  8358. return;
  8359. }
  8360. addModule(m);
  8361. (m.__init__ || []).forEach(function(c) {
  8362. components.push(c);
  8363. });
  8364. }
  8365. bootstrapModules.forEach(visit);
  8366. var injector = new Injector(modules);
  8367. components.forEach(function(c) {
  8368. try {
  8369. // eagerly resolve component (fn or string)
  8370. injector[typeof c === 'string' ? 'get' : 'invoke'](c);
  8371. } catch (e) {
  8372. console.error('Failed to instantiate component');
  8373. console.error(e.stack);
  8374. throw e;
  8375. }
  8376. });
  8377. return injector;
  8378. }
  8379. /**
  8380. * Creates an injector from passed options.
  8381. *
  8382. * @ignore
  8383. * @param {Object} options
  8384. * @return {didi.Injector}
  8385. */
  8386. function createInjector(options) {
  8387. options = options || {};
  8388. var configModule = {
  8389. 'config': ['value', options]
  8390. };
  8391. var modules = [ configModule, CoreModule$1 ].concat(options.modules || []);
  8392. return bootstrap(modules);
  8393. }
  8394. /**
  8395. * The main diagram-js entry point that bootstraps the diagram with the given
  8396. * configuration.
  8397. *
  8398. * To register extensions with the diagram, pass them as Array<didi.Module> to the constructor.
  8399. *
  8400. * @class djs.Diagram
  8401. * @memberOf djs
  8402. * @constructor
  8403. *
  8404. * @example
  8405. *
  8406. * <caption>Creating a plug-in that logs whenever a shape is added to the canvas.</caption>
  8407. *
  8408. * // plug-in implemenentation
  8409. * function MyLoggingPlugin(eventBus) {
  8410. * eventBus.on('shape.added', function(event) {
  8411. * console.log('shape ', event.shape, ' was added to the diagram');
  8412. * });
  8413. * }
  8414. *
  8415. * // export as module
  8416. * export default {
  8417. * __init__: [ 'myLoggingPlugin' ],
  8418. * myLoggingPlugin: [ 'type', MyLoggingPlugin ]
  8419. * };
  8420. *
  8421. *
  8422. * // instantiate the diagram with the new plug-in
  8423. *
  8424. * import MyLoggingModule from 'path-to-my-logging-plugin';
  8425. *
  8426. * var diagram = new Diagram({
  8427. * modules: [
  8428. * MyLoggingModule
  8429. * ]
  8430. * });
  8431. *
  8432. * diagram.invoke([ 'canvas', function(canvas) {
  8433. * // add shape to drawing canvas
  8434. * canvas.addShape({ x: 10, y: 10 });
  8435. * });
  8436. *
  8437. * // 'shape ... was added to the diagram' logged to console
  8438. *
  8439. * @param {Object} options
  8440. * @param {Array<didi.Module>} [options.modules] external modules to instantiate with the diagram
  8441. * @param {didi.Injector} [injector] an (optional) injector to bootstrap the diagram with
  8442. */
  8443. function Diagram(options, injector) {
  8444. // create injector unless explicitly specified
  8445. this.injector = injector = injector || createInjector(options);
  8446. // API
  8447. /**
  8448. * Resolves a diagram service
  8449. *
  8450. * @method Diagram#get
  8451. *
  8452. * @param {string} name the name of the diagram service to be retrieved
  8453. * @param {boolean} [strict=true] if false, resolve missing services to null
  8454. */
  8455. this.get = injector.get;
  8456. /**
  8457. * Executes a function into which diagram services are injected
  8458. *
  8459. * @method Diagram#invoke
  8460. *
  8461. * @param {Function|Object[]} fn the function to resolve
  8462. * @param {Object} locals a number of locals to use to resolve certain dependencies
  8463. */
  8464. this.invoke = injector.invoke;
  8465. // init
  8466. // indicate via event
  8467. /**
  8468. * An event indicating that all plug-ins are loaded.
  8469. *
  8470. * Use this event to fire other events to interested plug-ins
  8471. *
  8472. * @memberOf Diagram
  8473. *
  8474. * @event diagram.init
  8475. *
  8476. * @example
  8477. *
  8478. * eventBus.on('diagram.init', function() {
  8479. * eventBus.fire('my-custom-event', { foo: 'BAR' });
  8480. * });
  8481. *
  8482. * @type {Object}
  8483. */
  8484. this.get('eventBus').fire('diagram.init');
  8485. }
  8486. /**
  8487. * Destroys the diagram
  8488. *
  8489. * @method Diagram#destroy
  8490. */
  8491. Diagram.prototype.destroy = function() {
  8492. this.get('eventBus').fire('diagram.destroy');
  8493. };
  8494. /**
  8495. * Clear the diagram, removing all contents.
  8496. */
  8497. Diagram.prototype.clear = function() {
  8498. this.get('eventBus').fire('diagram.clear');
  8499. };
  8500. /**
  8501. * Moddle base element.
  8502. */
  8503. function Base$1() { }
  8504. Base$1.prototype.get = function(name) {
  8505. return this.$model.properties.get(this, name);
  8506. };
  8507. Base$1.prototype.set = function(name, value) {
  8508. this.$model.properties.set(this, name, value);
  8509. };
  8510. /**
  8511. * A model element factory.
  8512. *
  8513. * @param {Moddle} model
  8514. * @param {Properties} properties
  8515. */
  8516. function Factory(model, properties) {
  8517. this.model = model;
  8518. this.properties = properties;
  8519. }
  8520. Factory.prototype.createType = function(descriptor) {
  8521. var model = this.model;
  8522. var props = this.properties,
  8523. prototype = Object.create(Base$1.prototype);
  8524. // initialize default values
  8525. forEach(descriptor.properties, function(p) {
  8526. if (!p.isMany && p.default !== undefined) {
  8527. prototype[p.name] = p.default;
  8528. }
  8529. });
  8530. props.defineModel(prototype, model);
  8531. props.defineDescriptor(prototype, descriptor);
  8532. var name = descriptor.ns.name;
  8533. /**
  8534. * The new type constructor
  8535. */
  8536. function ModdleElement(attrs) {
  8537. props.define(this, '$type', { value: name, enumerable: true });
  8538. props.define(this, '$attrs', { value: {} });
  8539. props.define(this, '$parent', { writable: true });
  8540. forEach(attrs, bind(function(val, key) {
  8541. this.set(key, val);
  8542. }, this));
  8543. }
  8544. ModdleElement.prototype = prototype;
  8545. ModdleElement.hasType = prototype.$instanceOf = this.model.hasType;
  8546. // static links
  8547. props.defineModel(ModdleElement, model);
  8548. props.defineDescriptor(ModdleElement, descriptor);
  8549. return ModdleElement;
  8550. };
  8551. /**
  8552. * Built-in moddle types
  8553. */
  8554. var BUILTINS = {
  8555. String: true,
  8556. Boolean: true,
  8557. Integer: true,
  8558. Real: true,
  8559. Element: true
  8560. };
  8561. /**
  8562. * Converters for built in types from string representations
  8563. */
  8564. var TYPE_CONVERTERS = {
  8565. String: function(s) { return s; },
  8566. Boolean: function(s) { return s === 'true'; },
  8567. Integer: function(s) { return parseInt(s, 10); },
  8568. Real: function(s) { return parseFloat(s, 10); }
  8569. };
  8570. /**
  8571. * Convert a type to its real representation
  8572. */
  8573. function coerceType(type, value) {
  8574. var converter = TYPE_CONVERTERS[type];
  8575. if (converter) {
  8576. return converter(value);
  8577. } else {
  8578. return value;
  8579. }
  8580. }
  8581. /**
  8582. * Return whether the given type is built-in
  8583. */
  8584. function isBuiltIn(type) {
  8585. return !!BUILTINS[type];
  8586. }
  8587. /**
  8588. * Return whether the given type is simple
  8589. */
  8590. function isSimple(type) {
  8591. return !!TYPE_CONVERTERS[type];
  8592. }
  8593. /**
  8594. * Parses a namespaced attribute name of the form (ns:)localName to an object,
  8595. * given a default prefix to assume in case no explicit namespace is given.
  8596. *
  8597. * @param {String} name
  8598. * @param {String} [defaultPrefix] the default prefix to take, if none is present.
  8599. *
  8600. * @return {Object} the parsed name
  8601. */
  8602. function parseName(name, defaultPrefix) {
  8603. var parts = name.split(/:/),
  8604. localName, prefix;
  8605. // no prefix (i.e. only local name)
  8606. if (parts.length === 1) {
  8607. localName = name;
  8608. prefix = defaultPrefix;
  8609. } else
  8610. // prefix + local name
  8611. if (parts.length === 2) {
  8612. localName = parts[1];
  8613. prefix = parts[0];
  8614. } else {
  8615. throw new Error('expected <prefix:localName> or <localName>, got ' + name);
  8616. }
  8617. name = (prefix ? prefix + ':' : '') + localName;
  8618. return {
  8619. name: name,
  8620. prefix: prefix,
  8621. localName: localName
  8622. };
  8623. }
  8624. /**
  8625. * A utility to build element descriptors.
  8626. */
  8627. function DescriptorBuilder(nameNs) {
  8628. this.ns = nameNs;
  8629. this.name = nameNs.name;
  8630. this.allTypes = [];
  8631. this.allTypesByName = {};
  8632. this.properties = [];
  8633. this.propertiesByName = {};
  8634. }
  8635. DescriptorBuilder.prototype.build = function() {
  8636. return pick(this, [
  8637. 'ns',
  8638. 'name',
  8639. 'allTypes',
  8640. 'allTypesByName',
  8641. 'properties',
  8642. 'propertiesByName',
  8643. 'bodyProperty',
  8644. 'idProperty'
  8645. ]);
  8646. };
  8647. /**
  8648. * Add property at given index.
  8649. *
  8650. * @param {Object} p
  8651. * @param {Number} [idx]
  8652. * @param {Boolean} [validate=true]
  8653. */
  8654. DescriptorBuilder.prototype.addProperty = function(p, idx, validate) {
  8655. if (typeof idx === 'boolean') {
  8656. validate = idx;
  8657. idx = undefined;
  8658. }
  8659. this.addNamedProperty(p, validate !== false);
  8660. var properties = this.properties;
  8661. if (idx !== undefined) {
  8662. properties.splice(idx, 0, p);
  8663. } else {
  8664. properties.push(p);
  8665. }
  8666. };
  8667. DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty, replace) {
  8668. var oldNameNs = oldProperty.ns;
  8669. var props = this.properties,
  8670. propertiesByName = this.propertiesByName,
  8671. rename = oldProperty.name !== newProperty.name;
  8672. if (oldProperty.isId) {
  8673. if (!newProperty.isId) {
  8674. throw new Error(
  8675. 'property <' + newProperty.ns.name + '> must be id property ' +
  8676. 'to refine <' + oldProperty.ns.name + '>');
  8677. }
  8678. this.setIdProperty(newProperty, false);
  8679. }
  8680. if (oldProperty.isBody) {
  8681. if (!newProperty.isBody) {
  8682. throw new Error(
  8683. 'property <' + newProperty.ns.name + '> must be body property ' +
  8684. 'to refine <' + oldProperty.ns.name + '>');
  8685. }
  8686. // TODO: Check compatibility
  8687. this.setBodyProperty(newProperty, false);
  8688. }
  8689. // validate existence and get location of old property
  8690. var idx = props.indexOf(oldProperty);
  8691. if (idx === -1) {
  8692. throw new Error('property <' + oldNameNs.name + '> not found in property list');
  8693. }
  8694. // remove old property
  8695. props.splice(idx, 1);
  8696. // replacing the named property is intentional
  8697. //
  8698. // * validate only if this is a "rename" operation
  8699. // * add at specific index unless we "replace"
  8700. //
  8701. this.addProperty(newProperty, replace ? undefined : idx, rename);
  8702. // make new property available under old name
  8703. propertiesByName[oldNameNs.name] = propertiesByName[oldNameNs.localName] = newProperty;
  8704. };
  8705. DescriptorBuilder.prototype.redefineProperty = function(p, targetPropertyName, replace) {
  8706. var nsPrefix = p.ns.prefix;
  8707. var parts = targetPropertyName.split('#');
  8708. var name = parseName(parts[0], nsPrefix);
  8709. var attrName = parseName(parts[1], name.prefix).name;
  8710. var redefinedProperty = this.propertiesByName[attrName];
  8711. if (!redefinedProperty) {
  8712. throw new Error('refined property <' + attrName + '> not found');
  8713. } else {
  8714. this.replaceProperty(redefinedProperty, p, replace);
  8715. }
  8716. delete p.redefines;
  8717. };
  8718. DescriptorBuilder.prototype.addNamedProperty = function(p, validate) {
  8719. var ns = p.ns,
  8720. propsByName = this.propertiesByName;
  8721. if (validate) {
  8722. this.assertNotDefined(p, ns.name);
  8723. this.assertNotDefined(p, ns.localName);
  8724. }
  8725. propsByName[ns.name] = propsByName[ns.localName] = p;
  8726. };
  8727. DescriptorBuilder.prototype.removeNamedProperty = function(p) {
  8728. var ns = p.ns,
  8729. propsByName = this.propertiesByName;
  8730. delete propsByName[ns.name];
  8731. delete propsByName[ns.localName];
  8732. };
  8733. DescriptorBuilder.prototype.setBodyProperty = function(p, validate) {
  8734. if (validate && this.bodyProperty) {
  8735. throw new Error(
  8736. 'body property defined multiple times ' +
  8737. '(<' + this.bodyProperty.ns.name + '>, <' + p.ns.name + '>)');
  8738. }
  8739. this.bodyProperty = p;
  8740. };
  8741. DescriptorBuilder.prototype.setIdProperty = function(p, validate) {
  8742. if (validate && this.idProperty) {
  8743. throw new Error(
  8744. 'id property defined multiple times ' +
  8745. '(<' + this.idProperty.ns.name + '>, <' + p.ns.name + '>)');
  8746. }
  8747. this.idProperty = p;
  8748. };
  8749. DescriptorBuilder.prototype.assertNotDefined = function(p, name) {
  8750. var propertyName = p.name,
  8751. definedProperty = this.propertiesByName[propertyName];
  8752. if (definedProperty) {
  8753. throw new Error(
  8754. 'property <' + propertyName + '> already defined; ' +
  8755. 'override of <' + definedProperty.definedBy.ns.name + '#' + definedProperty.ns.name + '> by ' +
  8756. '<' + p.definedBy.ns.name + '#' + p.ns.name + '> not allowed without redefines');
  8757. }
  8758. };
  8759. DescriptorBuilder.prototype.hasProperty = function(name) {
  8760. return this.propertiesByName[name];
  8761. };
  8762. DescriptorBuilder.prototype.addTrait = function(t, inherited) {
  8763. var typesByName = this.allTypesByName,
  8764. types = this.allTypes;
  8765. var typeName = t.name;
  8766. if (typeName in typesByName) {
  8767. return;
  8768. }
  8769. forEach(t.properties, bind(function(p) {
  8770. // clone property to allow extensions
  8771. p = assign({}, p, {
  8772. name: p.ns.localName,
  8773. inherited: inherited
  8774. });
  8775. Object.defineProperty(p, 'definedBy', {
  8776. value: t
  8777. });
  8778. var replaces = p.replaces,
  8779. redefines = p.redefines;
  8780. // add replace/redefine support
  8781. if (replaces || redefines) {
  8782. this.redefineProperty(p, replaces || redefines, replaces);
  8783. } else {
  8784. if (p.isBody) {
  8785. this.setBodyProperty(p);
  8786. }
  8787. if (p.isId) {
  8788. this.setIdProperty(p);
  8789. }
  8790. this.addProperty(p);
  8791. }
  8792. }, this));
  8793. types.push(t);
  8794. typesByName[typeName] = t;
  8795. };
  8796. /**
  8797. * A registry of Moddle packages.
  8798. *
  8799. * @param {Array<Package>} packages
  8800. * @param {Properties} properties
  8801. */
  8802. function Registry(packages, properties) {
  8803. this.packageMap = {};
  8804. this.typeMap = {};
  8805. this.packages = [];
  8806. this.properties = properties;
  8807. forEach(packages, bind(this.registerPackage, this));
  8808. }
  8809. Registry.prototype.getPackage = function(uriOrPrefix) {
  8810. return this.packageMap[uriOrPrefix];
  8811. };
  8812. Registry.prototype.getPackages = function() {
  8813. return this.packages;
  8814. };
  8815. Registry.prototype.registerPackage = function(pkg) {
  8816. // copy package
  8817. pkg = assign({}, pkg);
  8818. var pkgMap = this.packageMap;
  8819. ensureAvailable(pkgMap, pkg, 'prefix');
  8820. ensureAvailable(pkgMap, pkg, 'uri');
  8821. // register types
  8822. forEach(pkg.types, bind(function(descriptor) {
  8823. this.registerType(descriptor, pkg);
  8824. }, this));
  8825. pkgMap[pkg.uri] = pkgMap[pkg.prefix] = pkg;
  8826. this.packages.push(pkg);
  8827. };
  8828. /**
  8829. * Register a type from a specific package with us
  8830. */
  8831. Registry.prototype.registerType = function(type, pkg) {
  8832. type = assign({}, type, {
  8833. superClass: (type.superClass || []).slice(),
  8834. extends: (type.extends || []).slice(),
  8835. properties: (type.properties || []).slice(),
  8836. meta: assign((type.meta || {}))
  8837. });
  8838. var ns = parseName(type.name, pkg.prefix),
  8839. name = ns.name,
  8840. propertiesByName = {};
  8841. // parse properties
  8842. forEach(type.properties, bind(function(p) {
  8843. // namespace property names
  8844. var propertyNs = parseName(p.name, ns.prefix),
  8845. propertyName = propertyNs.name;
  8846. // namespace property types
  8847. if (!isBuiltIn(p.type)) {
  8848. p.type = parseName(p.type, propertyNs.prefix).name;
  8849. }
  8850. assign(p, {
  8851. ns: propertyNs,
  8852. name: propertyName
  8853. });
  8854. propertiesByName[propertyName] = p;
  8855. }, this));
  8856. // update ns + name
  8857. assign(type, {
  8858. ns: ns,
  8859. name: name,
  8860. propertiesByName: propertiesByName
  8861. });
  8862. forEach(type.extends, bind(function(extendsName) {
  8863. var extended = this.typeMap[extendsName];
  8864. extended.traits = extended.traits || [];
  8865. extended.traits.push(name);
  8866. }, this));
  8867. // link to package
  8868. this.definePackage(type, pkg);
  8869. // register
  8870. this.typeMap[name] = type;
  8871. };
  8872. /**
  8873. * Traverse the type hierarchy from bottom to top,
  8874. * calling iterator with (type, inherited) for all elements in
  8875. * the inheritance chain.
  8876. *
  8877. * @param {Object} nsName
  8878. * @param {Function} iterator
  8879. * @param {Boolean} [trait=false]
  8880. */
  8881. Registry.prototype.mapTypes = function(nsName, iterator, trait) {
  8882. var type = isBuiltIn(nsName.name) ? { name: nsName.name } : this.typeMap[nsName.name];
  8883. var self = this;
  8884. /**
  8885. * Traverse the selected trait.
  8886. *
  8887. * @param {String} cls
  8888. */
  8889. function traverseTrait(cls) {
  8890. return traverseSuper(cls, true);
  8891. }
  8892. /**
  8893. * Traverse the selected super type or trait
  8894. *
  8895. * @param {String} cls
  8896. * @param {Boolean} [trait=false]
  8897. */
  8898. function traverseSuper(cls, trait) {
  8899. var parentNs = parseName(cls, isBuiltIn(cls) ? '' : nsName.prefix);
  8900. self.mapTypes(parentNs, iterator, trait);
  8901. }
  8902. if (!type) {
  8903. throw new Error('unknown type <' + nsName.name + '>');
  8904. }
  8905. forEach(type.superClass, trait ? traverseTrait : traverseSuper);
  8906. // call iterator with (type, inherited=!trait)
  8907. iterator(type, !trait);
  8908. forEach(type.traits, traverseTrait);
  8909. };
  8910. /**
  8911. * Returns the effective descriptor for a type.
  8912. *
  8913. * @param {String} type the namespaced name (ns:localName) of the type
  8914. *
  8915. * @return {Descriptor} the resulting effective descriptor
  8916. */
  8917. Registry.prototype.getEffectiveDescriptor = function(name) {
  8918. var nsName = parseName(name);
  8919. var builder = new DescriptorBuilder(nsName);
  8920. this.mapTypes(nsName, function(type, inherited) {
  8921. builder.addTrait(type, inherited);
  8922. });
  8923. var descriptor = builder.build();
  8924. // define package link
  8925. this.definePackage(descriptor, descriptor.allTypes[descriptor.allTypes.length - 1].$pkg);
  8926. return descriptor;
  8927. };
  8928. Registry.prototype.definePackage = function(target, pkg) {
  8929. this.properties.define(target, '$pkg', { value: pkg });
  8930. };
  8931. ///////// helpers ////////////////////////////
  8932. function ensureAvailable(packageMap, pkg, identifierKey) {
  8933. var value = pkg[identifierKey];
  8934. if (value in packageMap) {
  8935. throw new Error('package with ' + identifierKey + ' <' + value + '> already defined');
  8936. }
  8937. }
  8938. /**
  8939. * A utility that gets and sets properties of model elements.
  8940. *
  8941. * @param {Model} model
  8942. */
  8943. function Properties(model) {
  8944. this.model = model;
  8945. }
  8946. /**
  8947. * Sets a named property on the target element.
  8948. * If the value is undefined, the property gets deleted.
  8949. *
  8950. * @param {Object} target
  8951. * @param {String} name
  8952. * @param {Object} value
  8953. */
  8954. Properties.prototype.set = function(target, name, value) {
  8955. var property = this.model.getPropertyDescriptor(target, name);
  8956. var propertyName = property && property.name;
  8957. if (isUndefined$1(value)) {
  8958. // unset the property, if the specified value is undefined;
  8959. // delete from $attrs (for extensions) or the target itself
  8960. if (property) {
  8961. delete target[propertyName];
  8962. } else {
  8963. delete target.$attrs[name];
  8964. }
  8965. } else {
  8966. // set the property, defining well defined properties on the fly
  8967. // or simply updating them in target.$attrs (for extensions)
  8968. if (property) {
  8969. if (propertyName in target) {
  8970. target[propertyName] = value;
  8971. } else {
  8972. defineProperty$1(target, property, value);
  8973. }
  8974. } else {
  8975. target.$attrs[name] = value;
  8976. }
  8977. }
  8978. };
  8979. /**
  8980. * Returns the named property of the given element
  8981. *
  8982. * @param {Object} target
  8983. * @param {String} name
  8984. *
  8985. * @return {Object}
  8986. */
  8987. Properties.prototype.get = function(target, name) {
  8988. var property = this.model.getPropertyDescriptor(target, name);
  8989. if (!property) {
  8990. return target.$attrs[name];
  8991. }
  8992. var propertyName = property.name;
  8993. // check if access to collection property and lazily initialize it
  8994. if (!target[propertyName] && property.isMany) {
  8995. defineProperty$1(target, property, []);
  8996. }
  8997. return target[propertyName];
  8998. };
  8999. /**
  9000. * Define a property on the target element
  9001. *
  9002. * @param {Object} target
  9003. * @param {String} name
  9004. * @param {Object} options
  9005. */
  9006. Properties.prototype.define = function(target, name, options) {
  9007. Object.defineProperty(target, name, options);
  9008. };
  9009. /**
  9010. * Define the descriptor for an element
  9011. */
  9012. Properties.prototype.defineDescriptor = function(target, descriptor) {
  9013. this.define(target, '$descriptor', { value: descriptor });
  9014. };
  9015. /**
  9016. * Define the model for an element
  9017. */
  9018. Properties.prototype.defineModel = function(target, model) {
  9019. this.define(target, '$model', { value: model });
  9020. };
  9021. function isUndefined$1(val) {
  9022. return typeof val === 'undefined';
  9023. }
  9024. function defineProperty$1(target, property, value) {
  9025. Object.defineProperty(target, property.name, {
  9026. enumerable: !property.isReference,
  9027. writable: true,
  9028. value: value,
  9029. configurable: true
  9030. });
  9031. }
  9032. //// Moddle implementation /////////////////////////////////////////////////
  9033. /**
  9034. * @class Moddle
  9035. *
  9036. * A model that can be used to create elements of a specific type.
  9037. *
  9038. * @example
  9039. *
  9040. * var Moddle = require('moddle');
  9041. *
  9042. * var pkg = {
  9043. * name: 'mypackage',
  9044. * prefix: 'my',
  9045. * types: [
  9046. * { name: 'Root' }
  9047. * ]
  9048. * };
  9049. *
  9050. * var moddle = new Moddle([pkg]);
  9051. *
  9052. * @param {Array<Package>} packages the packages to contain
  9053. */
  9054. function Moddle(packages) {
  9055. this.properties = new Properties(this);
  9056. this.factory = new Factory(this, this.properties);
  9057. this.registry = new Registry(packages, this.properties);
  9058. this.typeCache = {};
  9059. }
  9060. /**
  9061. * Create an instance of the specified type.
  9062. *
  9063. * @method Moddle#create
  9064. *
  9065. * @example
  9066. *
  9067. * var foo = moddle.create('my:Foo');
  9068. * var bar = moddle.create('my:Bar', { id: 'BAR_1' });
  9069. *
  9070. * @param {String|Object} descriptor the type descriptor or name know to the model
  9071. * @param {Object} attrs a number of attributes to initialize the model instance with
  9072. * @return {Object} model instance
  9073. */
  9074. Moddle.prototype.create = function(descriptor, attrs) {
  9075. var Type = this.getType(descriptor);
  9076. if (!Type) {
  9077. throw new Error('unknown type <' + descriptor + '>');
  9078. }
  9079. return new Type(attrs);
  9080. };
  9081. /**
  9082. * Returns the type representing a given descriptor
  9083. *
  9084. * @method Moddle#getType
  9085. *
  9086. * @example
  9087. *
  9088. * var Foo = moddle.getType('my:Foo');
  9089. * var foo = new Foo({ 'id' : 'FOO_1' });
  9090. *
  9091. * @param {String|Object} descriptor the type descriptor or name know to the model
  9092. * @return {Object} the type representing the descriptor
  9093. */
  9094. Moddle.prototype.getType = function(descriptor) {
  9095. var cache = this.typeCache;
  9096. var name = isString(descriptor) ? descriptor : descriptor.ns.name;
  9097. var type = cache[name];
  9098. if (!type) {
  9099. descriptor = this.registry.getEffectiveDescriptor(name);
  9100. type = cache[name] = this.factory.createType(descriptor);
  9101. }
  9102. return type;
  9103. };
  9104. /**
  9105. * Creates an any-element type to be used within model instances.
  9106. *
  9107. * This can be used to create custom elements that lie outside the meta-model.
  9108. * The created element contains all the meta-data required to serialize it
  9109. * as part of meta-model elements.
  9110. *
  9111. * @method Moddle#createAny
  9112. *
  9113. * @example
  9114. *
  9115. * var foo = moddle.createAny('vendor:Foo', 'http://vendor', {
  9116. * value: 'bar'
  9117. * });
  9118. *
  9119. * var container = moddle.create('my:Container', 'http://my', {
  9120. * any: [ foo ]
  9121. * });
  9122. *
  9123. * // go ahead and serialize the stuff
  9124. *
  9125. *
  9126. * @param {String} name the name of the element
  9127. * @param {String} nsUri the namespace uri of the element
  9128. * @param {Object} [properties] a map of properties to initialize the instance with
  9129. * @return {Object} the any type instance
  9130. */
  9131. Moddle.prototype.createAny = function(name, nsUri, properties) {
  9132. var nameNs = parseName(name);
  9133. var element = {
  9134. $type: name,
  9135. $instanceOf: function(type) {
  9136. return type === this.$type;
  9137. }
  9138. };
  9139. var descriptor = {
  9140. name: name,
  9141. isGeneric: true,
  9142. ns: {
  9143. prefix: nameNs.prefix,
  9144. localName: nameNs.localName,
  9145. uri: nsUri
  9146. }
  9147. };
  9148. this.properties.defineDescriptor(element, descriptor);
  9149. this.properties.defineModel(element, this);
  9150. this.properties.define(element, '$parent', { enumerable: false, writable: true });
  9151. forEach(properties, function(a, key) {
  9152. if (isObject(a) && a.value !== undefined) {
  9153. element[a.name] = a.value;
  9154. } else {
  9155. element[key] = a;
  9156. }
  9157. });
  9158. return element;
  9159. };
  9160. /**
  9161. * Returns a registered package by uri or prefix
  9162. *
  9163. * @return {Object} the package
  9164. */
  9165. Moddle.prototype.getPackage = function(uriOrPrefix) {
  9166. return this.registry.getPackage(uriOrPrefix);
  9167. };
  9168. /**
  9169. * Returns a snapshot of all known packages
  9170. *
  9171. * @return {Object} the package
  9172. */
  9173. Moddle.prototype.getPackages = function() {
  9174. return this.registry.getPackages();
  9175. };
  9176. /**
  9177. * Returns the descriptor for an element
  9178. */
  9179. Moddle.prototype.getElementDescriptor = function(element) {
  9180. return element.$descriptor;
  9181. };
  9182. /**
  9183. * Returns true if the given descriptor or instance
  9184. * represents the given type.
  9185. *
  9186. * May be applied to this, if element is omitted.
  9187. */
  9188. Moddle.prototype.hasType = function(element, type) {
  9189. if (type === undefined) {
  9190. type = element;
  9191. element = this;
  9192. }
  9193. var descriptor = element.$model.getElementDescriptor(element);
  9194. return (type in descriptor.allTypesByName);
  9195. };
  9196. /**
  9197. * Returns the descriptor of an elements named property
  9198. */
  9199. Moddle.prototype.getPropertyDescriptor = function(element, property) {
  9200. return this.getElementDescriptor(element).propertiesByName[property];
  9201. };
  9202. /**
  9203. * Returns a mapped type's descriptor
  9204. */
  9205. Moddle.prototype.getTypeDescriptor = function(type) {
  9206. return this.registry.typeMap[type];
  9207. };
  9208. var fromCharCode = String.fromCharCode;
  9209. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  9210. var ENTITY_PATTERN = /&#(\d+);|&#x([0-9a-f]+);|&(\w+);/ig;
  9211. var ENTITY_MAPPING = {
  9212. 'amp': '&',
  9213. 'apos': '\'',
  9214. 'gt': '>',
  9215. 'lt': '<',
  9216. 'quot': '"'
  9217. };
  9218. // map UPPERCASE variants of supported special chars
  9219. Object.keys(ENTITY_MAPPING).forEach(function(k) {
  9220. ENTITY_MAPPING[k.toUpperCase()] = ENTITY_MAPPING[k];
  9221. });
  9222. function replaceEntities(_, d, x, z) {
  9223. // reserved names, i.e. &nbsp;
  9224. if (z) {
  9225. if (hasOwnProperty$1.call(ENTITY_MAPPING, z)) {
  9226. return ENTITY_MAPPING[z];
  9227. } else {
  9228. // fall back to original value
  9229. return '&' + z + ';';
  9230. }
  9231. }
  9232. // decimal encoded char
  9233. if (d) {
  9234. return fromCharCode(d);
  9235. }
  9236. // hex encoded char
  9237. return fromCharCode(parseInt(x, 16));
  9238. }
  9239. /**
  9240. * A basic entity decoder that can decode a minimal
  9241. * sub-set of reserved names (&amp;) as well as
  9242. * hex (&#xaaf;) and decimal (&#1231;) encoded characters.
  9243. *
  9244. * @param {string} str
  9245. *
  9246. * @return {string} decoded string
  9247. */
  9248. function decodeEntities(s) {
  9249. if (s.length > 3 && s.indexOf('&') !== -1) {
  9250. return s.replace(ENTITY_PATTERN, replaceEntities);
  9251. }
  9252. return s;
  9253. }
  9254. var XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance';
  9255. var XSI_PREFIX = 'xsi';
  9256. var XSI_TYPE = 'xsi:type';
  9257. var NON_WHITESPACE_OUTSIDE_ROOT_NODE = 'non-whitespace outside of root node';
  9258. function error(msg) {
  9259. return new Error(msg);
  9260. }
  9261. function missingNamespaceForPrefix(prefix) {
  9262. return 'missing namespace for prefix <' + prefix + '>';
  9263. }
  9264. function getter(getFn) {
  9265. return {
  9266. 'get': getFn,
  9267. 'enumerable': true
  9268. };
  9269. }
  9270. function cloneNsMatrix(nsMatrix) {
  9271. var clone = {}, key;
  9272. for (key in nsMatrix) {
  9273. clone[key] = nsMatrix[key];
  9274. }
  9275. return clone;
  9276. }
  9277. function uriPrefix(prefix) {
  9278. return prefix + '$uri';
  9279. }
  9280. function buildNsMatrix(nsUriToPrefix) {
  9281. var nsMatrix = {},
  9282. uri,
  9283. prefix;
  9284. for (uri in nsUriToPrefix) {
  9285. prefix = nsUriToPrefix[uri];
  9286. nsMatrix[prefix] = prefix;
  9287. nsMatrix[uriPrefix(prefix)] = uri;
  9288. }
  9289. return nsMatrix;
  9290. }
  9291. function noopGetContext() {
  9292. return { 'line': 0, 'column': 0 };
  9293. }
  9294. function throwFunc(err) {
  9295. throw err;
  9296. }
  9297. /**
  9298. * Creates a new parser with the given options.
  9299. *
  9300. * @constructor
  9301. *
  9302. * @param {!Object<string, ?>=} options
  9303. */
  9304. function Parser(options) {
  9305. if (!this) {
  9306. return new Parser(options);
  9307. }
  9308. var proxy = options && options['proxy'];
  9309. var onText,
  9310. onOpenTag,
  9311. onCloseTag,
  9312. onCDATA,
  9313. onError = throwFunc,
  9314. onWarning,
  9315. onComment,
  9316. onQuestion,
  9317. onAttention;
  9318. var getContext = noopGetContext;
  9319. /**
  9320. * Do we need to parse the current elements attributes for namespaces?
  9321. *
  9322. * @type {boolean}
  9323. */
  9324. var maybeNS = false;
  9325. /**
  9326. * Do we process namespaces at all?
  9327. *
  9328. * @type {boolean}
  9329. */
  9330. var isNamespace = false;
  9331. /**
  9332. * The caught error returned on parse end
  9333. *
  9334. * @type {Error}
  9335. */
  9336. var returnError = null;
  9337. /**
  9338. * Should we stop parsing?
  9339. *
  9340. * @type {boolean}
  9341. */
  9342. var parseStop = false;
  9343. /**
  9344. * A map of { uri: prefix } used by the parser.
  9345. *
  9346. * This map will ensure we can normalize prefixes during processing;
  9347. * for each uri, only one prefix will be exposed to the handlers.
  9348. *
  9349. * @type {!Object<string, string>}}
  9350. */
  9351. var nsUriToPrefix;
  9352. /**
  9353. * Handle parse error.
  9354. *
  9355. * @param {string|Error} err
  9356. */
  9357. function handleError(err) {
  9358. if (!(err instanceof Error)) {
  9359. err = error(err);
  9360. }
  9361. returnError = err;
  9362. onError(err, getContext);
  9363. }
  9364. /**
  9365. * Handle parse error.
  9366. *
  9367. * @param {string|Error} err
  9368. */
  9369. function handleWarning(err) {
  9370. if (!onWarning) {
  9371. return;
  9372. }
  9373. if (!(err instanceof Error)) {
  9374. err = error(err);
  9375. }
  9376. onWarning(err, getContext);
  9377. }
  9378. /**
  9379. * Register parse listener.
  9380. *
  9381. * @param {string} name
  9382. * @param {Function} cb
  9383. *
  9384. * @return {Parser}
  9385. */
  9386. this['on'] = function(name, cb) {
  9387. if (typeof cb !== 'function') {
  9388. throw error('required args <name, cb>');
  9389. }
  9390. switch (name) {
  9391. case 'openTag': onOpenTag = cb; break;
  9392. case 'text': onText = cb; break;
  9393. case 'closeTag': onCloseTag = cb; break;
  9394. case 'error': onError = cb; break;
  9395. case 'warn': onWarning = cb; break;
  9396. case 'cdata': onCDATA = cb; break;
  9397. case 'attention': onAttention = cb; break; // <!XXXXX zzzz="eeee">
  9398. case 'question': onQuestion = cb; break; // <? .... ?>
  9399. case 'comment': onComment = cb; break;
  9400. default:
  9401. throw error('unsupported event: ' + name);
  9402. }
  9403. return this;
  9404. };
  9405. /**
  9406. * Set the namespace to prefix mapping.
  9407. *
  9408. * @example
  9409. *
  9410. * parser.ns({
  9411. * 'http://foo': 'foo',
  9412. * 'http://bar': 'bar'
  9413. * });
  9414. *
  9415. * @param {!Object<string, string>} nsMap
  9416. *
  9417. * @return {Parser}
  9418. */
  9419. this['ns'] = function(nsMap) {
  9420. if (typeof nsMap === 'undefined') {
  9421. nsMap = {};
  9422. }
  9423. if (typeof nsMap !== 'object') {
  9424. throw error('required args <nsMap={}>');
  9425. }
  9426. var _nsUriToPrefix = {}, k;
  9427. for (k in nsMap) {
  9428. _nsUriToPrefix[k] = nsMap[k];
  9429. }
  9430. // FORCE default mapping for schema instance
  9431. _nsUriToPrefix[XSI_URI] = XSI_PREFIX;
  9432. isNamespace = true;
  9433. nsUriToPrefix = _nsUriToPrefix;
  9434. return this;
  9435. };
  9436. /**
  9437. * Parse xml string.
  9438. *
  9439. * @param {string} xml
  9440. *
  9441. * @return {Error} returnError, if not thrown
  9442. */
  9443. this['parse'] = function(xml) {
  9444. if (typeof xml !== 'string') {
  9445. throw error('required args <xml=string>');
  9446. }
  9447. returnError = null;
  9448. parse(xml);
  9449. getContext = noopGetContext;
  9450. parseStop = false;
  9451. return returnError;
  9452. };
  9453. /**
  9454. * Stop parsing.
  9455. */
  9456. this['stop'] = function() {
  9457. parseStop = true;
  9458. };
  9459. /**
  9460. * Parse string, invoking configured listeners on element.
  9461. *
  9462. * @param {string} xml
  9463. */
  9464. function parse(xml) {
  9465. var nsMatrixStack = isNamespace ? [] : null,
  9466. nsMatrix = isNamespace ? buildNsMatrix(nsUriToPrefix) : null,
  9467. _nsMatrix,
  9468. nodeStack = [],
  9469. anonymousNsCount = 0,
  9470. tagStart = false,
  9471. tagEnd = false,
  9472. i = 0, j = 0,
  9473. x, y, q, w, v,
  9474. xmlns,
  9475. elementName,
  9476. _elementName,
  9477. elementProxy
  9478. ;
  9479. var attrsString = '',
  9480. attrsStart = 0,
  9481. cachedAttrs // false = parsed with errors, null = needs parsing
  9482. ;
  9483. /**
  9484. * Parse attributes on demand and returns the parsed attributes.
  9485. *
  9486. * Return semantics: (1) `false` on attribute parse error,
  9487. * (2) object hash on extracted attrs.
  9488. *
  9489. * @return {boolean|Object}
  9490. */
  9491. function getAttrs() {
  9492. if (cachedAttrs !== null) {
  9493. return cachedAttrs;
  9494. }
  9495. var nsUri,
  9496. nsUriPrefix,
  9497. nsName,
  9498. defaultAlias = isNamespace && nsMatrix['xmlns'],
  9499. attrList = isNamespace && maybeNS ? [] : null,
  9500. i = attrsStart,
  9501. s = attrsString,
  9502. l = s.length,
  9503. hasNewMatrix,
  9504. newalias,
  9505. value,
  9506. alias,
  9507. name,
  9508. attrs = {},
  9509. seenAttrs = {},
  9510. skipAttr,
  9511. w,
  9512. j;
  9513. parseAttr:
  9514. for (; i < l; i++) {
  9515. skipAttr = false;
  9516. w = s.charCodeAt(i);
  9517. if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE={ \f\n\r\t\v}
  9518. continue;
  9519. }
  9520. // wait for non whitespace character
  9521. if (w < 65 || w > 122 || (w > 90 && w < 97)) {
  9522. if (w !== 95 && w !== 58) { // char 95"_" 58":"
  9523. handleWarning('illegal first char attribute name');
  9524. skipAttr = true;
  9525. }
  9526. }
  9527. // parse attribute name
  9528. for (j = i + 1; j < l; j++) {
  9529. w = s.charCodeAt(j);
  9530. if (
  9531. w > 96 && w < 123 ||
  9532. w > 64 && w < 91 ||
  9533. w > 47 && w < 59 ||
  9534. w === 46 || // '.'
  9535. w === 45 || // '-'
  9536. w === 95 // '_'
  9537. ) {
  9538. continue;
  9539. }
  9540. // unexpected whitespace
  9541. if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
  9542. handleWarning('missing attribute value');
  9543. i = j;
  9544. continue parseAttr;
  9545. }
  9546. // expected "="
  9547. if (w === 61) { // "=" == 61
  9548. break;
  9549. }
  9550. handleWarning('illegal attribute name char');
  9551. skipAttr = true;
  9552. }
  9553. name = s.substring(i, j);
  9554. if (name === 'xmlns:xmlns') {
  9555. handleWarning('illegal declaration of xmlns');
  9556. skipAttr = true;
  9557. }
  9558. w = s.charCodeAt(j + 1);
  9559. if (w === 34) { // '"'
  9560. j = s.indexOf('"', i = j + 2);
  9561. if (j === -1) {
  9562. j = s.indexOf('\'', i);
  9563. if (j !== -1) {
  9564. handleWarning('attribute value quote missmatch');
  9565. skipAttr = true;
  9566. }
  9567. }
  9568. } else if (w === 39) { // "'"
  9569. j = s.indexOf('\'', i = j + 2);
  9570. if (j === -1) {
  9571. j = s.indexOf('"', i);
  9572. if (j !== -1) {
  9573. handleWarning('attribute value quote missmatch');
  9574. skipAttr = true;
  9575. }
  9576. }
  9577. } else {
  9578. handleWarning('missing attribute value quotes');
  9579. skipAttr = true;
  9580. // skip to next space
  9581. for (j = j + 1; j < l; j++) {
  9582. w = s.charCodeAt(j + 1);
  9583. if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
  9584. break;
  9585. }
  9586. }
  9587. }
  9588. if (j === -1) {
  9589. handleWarning('missing closing quotes');
  9590. j = l;
  9591. skipAttr = true;
  9592. }
  9593. if (!skipAttr) {
  9594. value = s.substring(i, j);
  9595. }
  9596. i = j;
  9597. // ensure SPACE follows attribute
  9598. // skip illegal content otherwise
  9599. // example a="b"c
  9600. for (; j + 1 < l; j++) {
  9601. w = s.charCodeAt(j + 1);
  9602. if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
  9603. break;
  9604. }
  9605. // FIRST ILLEGAL CHAR
  9606. if (i === j) {
  9607. handleWarning('illegal character after attribute end');
  9608. skipAttr = true;
  9609. }
  9610. }
  9611. // advance cursor to next attribute
  9612. i = j + 1;
  9613. if (skipAttr) {
  9614. continue parseAttr;
  9615. }
  9616. // check attribute re-declaration
  9617. if (name in seenAttrs) {
  9618. handleWarning('attribute <' + name + '> already defined');
  9619. continue;
  9620. }
  9621. seenAttrs[name] = true;
  9622. if (!isNamespace) {
  9623. attrs[name] = value;
  9624. continue;
  9625. }
  9626. // try to extract namespace information
  9627. if (maybeNS) {
  9628. newalias = (
  9629. name === 'xmlns'
  9630. ? 'xmlns'
  9631. : (name.charCodeAt(0) === 120 && name.substr(0, 6) === 'xmlns:')
  9632. ? name.substr(6)
  9633. : null
  9634. );
  9635. // handle xmlns(:alias) assignment
  9636. if (newalias !== null) {
  9637. nsUri = decodeEntities(value);
  9638. nsUriPrefix = uriPrefix(newalias);
  9639. alias = nsUriToPrefix[nsUri];
  9640. if (!alias) {
  9641. // no prefix defined or prefix collision
  9642. if (
  9643. (newalias === 'xmlns') ||
  9644. (nsUriPrefix in nsMatrix && nsMatrix[nsUriPrefix] !== nsUri)
  9645. ) {
  9646. // alocate free ns prefix
  9647. do {
  9648. alias = 'ns' + (anonymousNsCount++);
  9649. } while (typeof nsMatrix[alias] !== 'undefined');
  9650. } else {
  9651. alias = newalias;
  9652. }
  9653. nsUriToPrefix[nsUri] = alias;
  9654. }
  9655. if (nsMatrix[newalias] !== alias) {
  9656. if (!hasNewMatrix) {
  9657. nsMatrix = cloneNsMatrix(nsMatrix);
  9658. hasNewMatrix = true;
  9659. }
  9660. nsMatrix[newalias] = alias;
  9661. if (newalias === 'xmlns') {
  9662. nsMatrix[uriPrefix(alias)] = nsUri;
  9663. defaultAlias = alias;
  9664. }
  9665. nsMatrix[nsUriPrefix] = nsUri;
  9666. }
  9667. // expose xmlns(:asd)="..." in attributes
  9668. attrs[name] = value;
  9669. continue;
  9670. }
  9671. // collect attributes until all namespace
  9672. // declarations are processed
  9673. attrList.push(name, value);
  9674. continue;
  9675. } /** end if (maybeNs) */
  9676. // handle attributes on element without
  9677. // namespace declarations
  9678. w = name.indexOf(':');
  9679. if (w === -1) {
  9680. attrs[name] = value;
  9681. continue;
  9682. }
  9683. // normalize ns attribute name
  9684. if (!(nsName = nsMatrix[name.substring(0, w)])) {
  9685. handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
  9686. continue;
  9687. }
  9688. name = defaultAlias === nsName
  9689. ? name.substr(w + 1)
  9690. : nsName + name.substr(w);
  9691. // end: normalize ns attribute name
  9692. // normalize xsi:type ns attribute value
  9693. if (name === XSI_TYPE) {
  9694. w = value.indexOf(':');
  9695. if (w !== -1) {
  9696. nsName = value.substring(0, w);
  9697. // handle default prefixes, i.e. xs:String gracefully
  9698. nsName = nsMatrix[nsName] || nsName;
  9699. value = nsName + value.substring(w);
  9700. } else {
  9701. value = defaultAlias + ':' + value;
  9702. }
  9703. }
  9704. // end: normalize xsi:type ns attribute value
  9705. attrs[name] = value;
  9706. }
  9707. // handle deferred, possibly namespaced attributes
  9708. if (maybeNS) {
  9709. // normalize captured attributes
  9710. for (i = 0, l = attrList.length; i < l; i++) {
  9711. name = attrList[i++];
  9712. value = attrList[i];
  9713. w = name.indexOf(':');
  9714. if (w !== -1) {
  9715. // normalize ns attribute name
  9716. if (!(nsName = nsMatrix[name.substring(0, w)])) {
  9717. handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
  9718. continue;
  9719. }
  9720. name = defaultAlias === nsName
  9721. ? name.substr(w + 1)
  9722. : nsName + name.substr(w);
  9723. // end: normalize ns attribute name
  9724. // normalize xsi:type ns attribute value
  9725. if (name === XSI_TYPE) {
  9726. w = value.indexOf(':');
  9727. if (w !== -1) {
  9728. nsName = value.substring(0, w);
  9729. // handle default prefixes, i.e. xs:String gracefully
  9730. nsName = nsMatrix[nsName] || nsName;
  9731. value = nsName + value.substring(w);
  9732. } else {
  9733. value = defaultAlias + ':' + value;
  9734. }
  9735. }
  9736. // end: normalize xsi:type ns attribute value
  9737. }
  9738. attrs[name] = value;
  9739. }
  9740. // end: normalize captured attributes
  9741. }
  9742. return cachedAttrs = attrs;
  9743. }
  9744. /**
  9745. * Extract the parse context { line, column, part }
  9746. * from the current parser position.
  9747. *
  9748. * @return {Object} parse context
  9749. */
  9750. function getParseContext() {
  9751. var splitsRe = /(\r\n|\r|\n)/g;
  9752. var line = 0;
  9753. var column = 0;
  9754. var startOfLine = 0;
  9755. var endOfLine = j;
  9756. var match;
  9757. var data;
  9758. while (i >= startOfLine) {
  9759. match = splitsRe.exec(xml);
  9760. if (!match) {
  9761. break;
  9762. }
  9763. // end of line = (break idx + break chars)
  9764. endOfLine = match[0].length + match.index;
  9765. if (endOfLine > i) {
  9766. break;
  9767. }
  9768. // advance to next line
  9769. line += 1;
  9770. startOfLine = endOfLine;
  9771. }
  9772. // EOF errors
  9773. if (i == -1) {
  9774. column = endOfLine;
  9775. data = xml.substring(j);
  9776. } else
  9777. // start errors
  9778. if (j === 0) {
  9779. data = xml.substring(j, i);
  9780. }
  9781. // other errors
  9782. else {
  9783. column = i - startOfLine;
  9784. data = (j == -1 ? xml.substring(i) : xml.substring(i, j + 1));
  9785. }
  9786. return {
  9787. 'data': data,
  9788. 'line': line,
  9789. 'column': column
  9790. };
  9791. }
  9792. getContext = getParseContext;
  9793. if (proxy) {
  9794. elementProxy = Object.create({}, {
  9795. 'name': getter(function() {
  9796. return elementName;
  9797. }),
  9798. 'originalName': getter(function() {
  9799. return _elementName;
  9800. }),
  9801. 'attrs': getter(getAttrs),
  9802. 'ns': getter(function() {
  9803. return nsMatrix;
  9804. })
  9805. });
  9806. }
  9807. // actual parse logic
  9808. while (j !== -1) {
  9809. if (xml.charCodeAt(j) === 60) { // "<"
  9810. i = j;
  9811. } else {
  9812. i = xml.indexOf('<', j);
  9813. }
  9814. // parse end
  9815. if (i === -1) {
  9816. if (nodeStack.length) {
  9817. return handleError('unexpected end of file');
  9818. }
  9819. if (j === 0) {
  9820. return handleError('missing start tag');
  9821. }
  9822. if (j < xml.length) {
  9823. if (xml.substring(j).trim()) {
  9824. handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
  9825. }
  9826. }
  9827. return;
  9828. }
  9829. // parse text
  9830. if (j !== i) {
  9831. if (nodeStack.length) {
  9832. if (onText) {
  9833. onText(xml.substring(j, i), decodeEntities, getContext);
  9834. if (parseStop) {
  9835. return;
  9836. }
  9837. }
  9838. } else {
  9839. if (xml.substring(j, i).trim()) {
  9840. handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
  9841. if (parseStop) {
  9842. return;
  9843. }
  9844. }
  9845. }
  9846. }
  9847. w = xml.charCodeAt(i+1);
  9848. // parse comments + CDATA
  9849. if (w === 33) { // "!"
  9850. q = xml.charCodeAt(i+2);
  9851. // CDATA section
  9852. if (q === 91 && xml.substr(i + 3, 6) === 'CDATA[') { // 91 == "["
  9853. j = xml.indexOf(']]>', i);
  9854. if (j === -1) {
  9855. return handleError('unclosed cdata');
  9856. }
  9857. if (onCDATA) {
  9858. onCDATA(xml.substring(i + 9, j), getContext);
  9859. if (parseStop) {
  9860. return;
  9861. }
  9862. }
  9863. j += 3;
  9864. continue;
  9865. }
  9866. // comment
  9867. if (q === 45 && xml.charCodeAt(i + 3) === 45) { // 45 == "-"
  9868. j = xml.indexOf('-->', i);
  9869. if (j === -1) {
  9870. return handleError('unclosed comment');
  9871. }
  9872. if (onComment) {
  9873. onComment(xml.substring(i + 4, j), decodeEntities, getContext);
  9874. if (parseStop) {
  9875. return;
  9876. }
  9877. }
  9878. j += 3;
  9879. continue;
  9880. }
  9881. }
  9882. // parse question <? ... ?>
  9883. if (w === 63) { // "?"
  9884. j = xml.indexOf('?>', i);
  9885. if (j === -1) {
  9886. return handleError('unclosed question');
  9887. }
  9888. if (onQuestion) {
  9889. onQuestion(xml.substring(i, j + 2), getContext);
  9890. if (parseStop) {
  9891. return;
  9892. }
  9893. }
  9894. j += 2;
  9895. continue;
  9896. }
  9897. // find matching closing tag for attention or standard tags
  9898. // for that we must skip through attribute values
  9899. // (enclosed in single or double quotes)
  9900. for (x = i + 1; ; x++) {
  9901. v = xml.charCodeAt(x);
  9902. if (isNaN(v)) {
  9903. j = -1;
  9904. return handleError('unclosed tag');
  9905. }
  9906. // [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
  9907. // skips the quoted string
  9908. // (double quotes) does not appear in a literal enclosed by (double quotes)
  9909. // (single quote) does not appear in a literal enclosed by (single quote)
  9910. if (v === 34) { // '"'
  9911. q = xml.indexOf('"', x + 1);
  9912. x = q !== -1 ? q : x;
  9913. } else if (v === 39) { // "'"
  9914. q = xml.indexOf("'", x + 1);
  9915. x = q !== -1 ? q : x;
  9916. } else if (v === 62) { // '>'
  9917. j = x;
  9918. break;
  9919. }
  9920. }
  9921. // parse attention <! ...>
  9922. // previously comment and CDATA have already been parsed
  9923. if (w === 33) { // "!"
  9924. if (onAttention) {
  9925. onAttention(xml.substring(i, j + 1), decodeEntities, getContext);
  9926. if (parseStop) {
  9927. return;
  9928. }
  9929. }
  9930. j += 1;
  9931. continue;
  9932. }
  9933. // don't process attributes;
  9934. // there are none
  9935. cachedAttrs = {};
  9936. // if (xml.charCodeAt(i+1) === 47) { // </...
  9937. if (w === 47) { // </...
  9938. tagStart = false;
  9939. tagEnd = true;
  9940. if (!nodeStack.length) {
  9941. return handleError('missing open tag');
  9942. }
  9943. // verify open <-> close tag match
  9944. x = elementName = nodeStack.pop();
  9945. q = i + 2 + x.length;
  9946. if (xml.substring(i + 2, q) !== x) {
  9947. return handleError('closing tag mismatch');
  9948. }
  9949. // verify chars in close tag
  9950. for (; q < j; q++) {
  9951. w = xml.charCodeAt(q);
  9952. if (w === 32 || (w > 8 && w < 14)) { // \f\n\r\t\v space
  9953. continue;
  9954. }
  9955. return handleError('close tag');
  9956. }
  9957. } else {
  9958. if (xml.charCodeAt(j - 1) === 47) { // .../>
  9959. x = elementName = xml.substring(i + 1, j - 1);
  9960. tagStart = true;
  9961. tagEnd = true;
  9962. } else {
  9963. x = elementName = xml.substring(i + 1, j);
  9964. tagStart = true;
  9965. tagEnd = false;
  9966. }
  9967. if (!(w > 96 && w < 123 || w > 64 && w < 91 || w === 95 || w === 58)) { // char 95"_" 58":"
  9968. return handleError('illegal first char nodeName');
  9969. }
  9970. for (q = 1, y = x.length; q < y; q++) {
  9971. w = x.charCodeAt(q);
  9972. if (w > 96 && w < 123 || w > 64 && w < 91 || w > 47 && w < 59 || w === 45 || w === 95 || w == 46) {
  9973. continue;
  9974. }
  9975. if (w === 32 || (w < 14 && w > 8)) { // \f\n\r\t\v space
  9976. elementName = x.substring(0, q);
  9977. // maybe there are attributes
  9978. cachedAttrs = null;
  9979. break;
  9980. }
  9981. return handleError('invalid nodeName');
  9982. }
  9983. if (!tagEnd) {
  9984. nodeStack.push(elementName);
  9985. }
  9986. }
  9987. if (isNamespace) {
  9988. _nsMatrix = nsMatrix;
  9989. if (tagStart) {
  9990. // remember old namespace
  9991. // unless we're self-closing
  9992. if (!tagEnd) {
  9993. nsMatrixStack.push(_nsMatrix);
  9994. }
  9995. if (cachedAttrs === null) {
  9996. // quick check, whether there may be namespace
  9997. // declarations on the node; if that is the case
  9998. // we need to eagerly parse the node attributes
  9999. if ((maybeNS = x.indexOf('xmlns', q) !== -1)) {
  10000. attrsStart = q;
  10001. attrsString = x;
  10002. getAttrs();
  10003. maybeNS = false;
  10004. }
  10005. }
  10006. }
  10007. _elementName = elementName;
  10008. w = elementName.indexOf(':');
  10009. if (w !== -1) {
  10010. xmlns = nsMatrix[elementName.substring(0, w)];
  10011. // prefix given; namespace must exist
  10012. if (!xmlns) {
  10013. return handleError('missing namespace on <' + _elementName + '>');
  10014. }
  10015. elementName = elementName.substr(w + 1);
  10016. } else {
  10017. xmlns = nsMatrix['xmlns'];
  10018. // if no default namespace is defined,
  10019. // we'll import the element as anonymous.
  10020. //
  10021. // it is up to users to correct that to the document defined
  10022. // targetNamespace, or whatever their undersanding of the
  10023. // XML spec mandates.
  10024. }
  10025. // adjust namespace prefixs as configured
  10026. if (xmlns) {
  10027. elementName = xmlns + ':' + elementName;
  10028. }
  10029. }
  10030. if (tagStart) {
  10031. attrsStart = q;
  10032. attrsString = x;
  10033. if (onOpenTag) {
  10034. if (proxy) {
  10035. onOpenTag(elementProxy, decodeEntities, tagEnd, getContext);
  10036. } else {
  10037. onOpenTag(elementName, getAttrs, decodeEntities, tagEnd, getContext);
  10038. }
  10039. if (parseStop) {
  10040. return;
  10041. }
  10042. }
  10043. }
  10044. if (tagEnd) {
  10045. if (onCloseTag) {
  10046. onCloseTag(proxy ? elementProxy : elementName, decodeEntities, tagStart, getContext);
  10047. if (parseStop) {
  10048. return;
  10049. }
  10050. }
  10051. // restore old namespace
  10052. if (isNamespace) {
  10053. if (!tagStart) {
  10054. nsMatrix = nsMatrixStack.pop();
  10055. } else {
  10056. nsMatrix = _nsMatrix;
  10057. }
  10058. }
  10059. }
  10060. j += 1;
  10061. }
  10062. } /** end parse */
  10063. }
  10064. function hasLowerCaseAlias(pkg) {
  10065. return pkg.xml && pkg.xml.tagAlias === 'lowerCase';
  10066. }
  10067. var DEFAULT_NS_MAP = {
  10068. 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'
  10069. };
  10070. var XSI_TYPE$1 = 'xsi:type';
  10071. function serializeFormat(element) {
  10072. return element.xml && element.xml.serialize;
  10073. }
  10074. function serializeAsType(element) {
  10075. return serializeFormat(element) === XSI_TYPE$1;
  10076. }
  10077. function serializeAsProperty(element) {
  10078. return serializeFormat(element) === 'property';
  10079. }
  10080. function capitalize(str) {
  10081. return str.charAt(0).toUpperCase() + str.slice(1);
  10082. }
  10083. function aliasToName(aliasNs, pkg) {
  10084. if (!hasLowerCaseAlias(pkg)) {
  10085. return aliasNs.name;
  10086. }
  10087. return aliasNs.prefix + ':' + capitalize(aliasNs.localName);
  10088. }
  10089. function prefixedToName(nameNs, pkg) {
  10090. var name = nameNs.name,
  10091. localName = nameNs.localName;
  10092. var typePrefix = pkg.xml && pkg.xml.typePrefix;
  10093. if (typePrefix && localName.indexOf(typePrefix) === 0) {
  10094. return nameNs.prefix + ':' + localName.slice(typePrefix.length);
  10095. } else {
  10096. return name;
  10097. }
  10098. }
  10099. function normalizeXsiTypeName(name, model) {
  10100. var nameNs = parseName(name);
  10101. var pkg = model.getPackage(nameNs.prefix);
  10102. return prefixedToName(nameNs, pkg);
  10103. }
  10104. function error$1(message) {
  10105. return new Error(message);
  10106. }
  10107. /**
  10108. * Get the moddle descriptor for a given instance or type.
  10109. *
  10110. * @param {ModdleElement|Function} element
  10111. *
  10112. * @return {Object} the moddle descriptor
  10113. */
  10114. function getModdleDescriptor(element) {
  10115. return element.$descriptor;
  10116. }
  10117. function defer(fn) {
  10118. setTimeout(fn, 0);
  10119. }
  10120. /**
  10121. * A parse context.
  10122. *
  10123. * @class
  10124. *
  10125. * @param {Object} options
  10126. * @param {ElementHandler} options.rootHandler the root handler for parsing a document
  10127. * @param {boolean} [options.lax=false] whether or not to ignore invalid elements
  10128. */
  10129. function Context(options) {
  10130. /**
  10131. * @property {ElementHandler} rootHandler
  10132. */
  10133. /**
  10134. * @property {Boolean} lax
  10135. */
  10136. assign(this, options);
  10137. this.elementsById = {};
  10138. this.references = [];
  10139. this.warnings = [];
  10140. /**
  10141. * Add an unresolved reference.
  10142. *
  10143. * @param {Object} reference
  10144. */
  10145. this.addReference = function(reference) {
  10146. this.references.push(reference);
  10147. };
  10148. /**
  10149. * Add a processed element.
  10150. *
  10151. * @param {ModdleElement} element
  10152. */
  10153. this.addElement = function(element) {
  10154. if (!element) {
  10155. throw error$1('expected element');
  10156. }
  10157. var elementsById = this.elementsById;
  10158. var descriptor = getModdleDescriptor(element);
  10159. var idProperty = descriptor.idProperty,
  10160. id;
  10161. if (idProperty) {
  10162. id = element.get(idProperty.name);
  10163. if (id) {
  10164. // for QName validation as per http://www.w3.org/TR/REC-xml/#NT-NameChar
  10165. if (!/^([a-z][\w-.]*:)?[a-z_][\w-.]*$/i.test(id)) {
  10166. throw new Error('illegal ID <' + id + '>');
  10167. }
  10168. if (elementsById[id]) {
  10169. throw error$1('duplicate ID <' + id + '>');
  10170. }
  10171. elementsById[id] = element;
  10172. }
  10173. }
  10174. };
  10175. /**
  10176. * Add an import warning.
  10177. *
  10178. * @param {Object} warning
  10179. * @param {String} warning.message
  10180. * @param {Error} [warning.error]
  10181. */
  10182. this.addWarning = function(warning) {
  10183. this.warnings.push(warning);
  10184. };
  10185. }
  10186. function BaseHandler() {}
  10187. BaseHandler.prototype.handleEnd = function() {};
  10188. BaseHandler.prototype.handleText = function() {};
  10189. BaseHandler.prototype.handleNode = function() {};
  10190. /**
  10191. * A simple pass through handler that does nothing except for
  10192. * ignoring all input it receives.
  10193. *
  10194. * This is used to ignore unknown elements and
  10195. * attributes.
  10196. */
  10197. function NoopHandler() { }
  10198. NoopHandler.prototype = Object.create(BaseHandler.prototype);
  10199. NoopHandler.prototype.handleNode = function() {
  10200. return this;
  10201. };
  10202. function BodyHandler() {}
  10203. BodyHandler.prototype = Object.create(BaseHandler.prototype);
  10204. BodyHandler.prototype.handleText = function(text) {
  10205. this.body = (this.body || '') + text;
  10206. };
  10207. function ReferenceHandler(property, context) {
  10208. this.property = property;
  10209. this.context = context;
  10210. }
  10211. ReferenceHandler.prototype = Object.create(BodyHandler.prototype);
  10212. ReferenceHandler.prototype.handleNode = function(node) {
  10213. if (this.element) {
  10214. throw error$1('expected no sub nodes');
  10215. } else {
  10216. this.element = this.createReference(node);
  10217. }
  10218. return this;
  10219. };
  10220. ReferenceHandler.prototype.handleEnd = function() {
  10221. this.element.id = this.body;
  10222. };
  10223. ReferenceHandler.prototype.createReference = function(node) {
  10224. return {
  10225. property: this.property.ns.name,
  10226. id: ''
  10227. };
  10228. };
  10229. function ValueHandler(propertyDesc, element) {
  10230. this.element = element;
  10231. this.propertyDesc = propertyDesc;
  10232. }
  10233. ValueHandler.prototype = Object.create(BodyHandler.prototype);
  10234. ValueHandler.prototype.handleEnd = function() {
  10235. var value = this.body || '',
  10236. element = this.element,
  10237. propertyDesc = this.propertyDesc;
  10238. value = coerceType(propertyDesc.type, value);
  10239. if (propertyDesc.isMany) {
  10240. element.get(propertyDesc.name).push(value);
  10241. } else {
  10242. element.set(propertyDesc.name, value);
  10243. }
  10244. };
  10245. function BaseElementHandler() {}
  10246. BaseElementHandler.prototype = Object.create(BodyHandler.prototype);
  10247. BaseElementHandler.prototype.handleNode = function(node) {
  10248. var parser = this,
  10249. element = this.element;
  10250. if (!element) {
  10251. element = this.element = this.createElement(node);
  10252. this.context.addElement(element);
  10253. } else {
  10254. parser = this.handleChild(node);
  10255. }
  10256. return parser;
  10257. };
  10258. /**
  10259. * @class Reader.ElementHandler
  10260. *
  10261. */
  10262. function ElementHandler(model, typeName, context) {
  10263. this.model = model;
  10264. this.type = model.getType(typeName);
  10265. this.context = context;
  10266. }
  10267. ElementHandler.prototype = Object.create(BaseElementHandler.prototype);
  10268. ElementHandler.prototype.addReference = function(reference) {
  10269. this.context.addReference(reference);
  10270. };
  10271. ElementHandler.prototype.handleText = function(text) {
  10272. var element = this.element,
  10273. descriptor = getModdleDescriptor(element),
  10274. bodyProperty = descriptor.bodyProperty;
  10275. if (!bodyProperty) {
  10276. throw error$1('unexpected body text <' + text + '>');
  10277. }
  10278. BodyHandler.prototype.handleText.call(this, text);
  10279. };
  10280. ElementHandler.prototype.handleEnd = function() {
  10281. var value = this.body,
  10282. element = this.element,
  10283. descriptor = getModdleDescriptor(element),
  10284. bodyProperty = descriptor.bodyProperty;
  10285. if (bodyProperty && value !== undefined) {
  10286. value = coerceType(bodyProperty.type, value);
  10287. element.set(bodyProperty.name, value);
  10288. }
  10289. };
  10290. /**
  10291. * Create an instance of the model from the given node.
  10292. *
  10293. * @param {Element} node the xml node
  10294. */
  10295. ElementHandler.prototype.createElement = function(node) {
  10296. var attributes = node.attributes,
  10297. Type = this.type,
  10298. descriptor = getModdleDescriptor(Type),
  10299. context = this.context,
  10300. instance = new Type({}),
  10301. model = this.model,
  10302. propNameNs;
  10303. forEach(attributes, function(value, name) {
  10304. var prop = descriptor.propertiesByName[name],
  10305. values;
  10306. if (prop && prop.isReference) {
  10307. if (!prop.isMany) {
  10308. context.addReference({
  10309. element: instance,
  10310. property: prop.ns.name,
  10311. id: value
  10312. });
  10313. } else {
  10314. // IDREFS: parse references as whitespace-separated list
  10315. values = value.split(' ');
  10316. forEach(values, function(v) {
  10317. context.addReference({
  10318. element: instance,
  10319. property: prop.ns.name,
  10320. id: v
  10321. });
  10322. });
  10323. }
  10324. } else {
  10325. if (prop) {
  10326. value = coerceType(prop.type, value);
  10327. } else
  10328. if (name !== 'xmlns') {
  10329. propNameNs = parseName(name, descriptor.ns.prefix);
  10330. // check whether attribute is defined in a well-known namespace
  10331. // if that is the case we emit a warning to indicate potential misuse
  10332. if (model.getPackage(propNameNs.prefix)) {
  10333. context.addWarning({
  10334. message: 'unknown attribute <' + name + '>',
  10335. element: instance,
  10336. property: name,
  10337. value: value
  10338. });
  10339. }
  10340. }
  10341. instance.set(name, value);
  10342. }
  10343. });
  10344. return instance;
  10345. };
  10346. ElementHandler.prototype.getPropertyForNode = function(node) {
  10347. var name = node.name;
  10348. var nameNs = parseName(name);
  10349. var type = this.type,
  10350. model = this.model,
  10351. descriptor = getModdleDescriptor(type);
  10352. var propertyName = nameNs.name,
  10353. property = descriptor.propertiesByName[propertyName],
  10354. elementTypeName,
  10355. elementType;
  10356. // search for properties by name first
  10357. if (property && !property.isAttr) {
  10358. if (serializeAsType(property)) {
  10359. elementTypeName = node.attributes[XSI_TYPE$1];
  10360. // xsi type is optional, if it does not exists the
  10361. // default type is assumed
  10362. if (elementTypeName) {
  10363. // take possible type prefixes from XML
  10364. // into account, i.e.: xsi:type="t{ActualType}"
  10365. elementTypeName = normalizeXsiTypeName(elementTypeName, model);
  10366. elementType = model.getType(elementTypeName);
  10367. return assign({}, property, {
  10368. effectiveType: getModdleDescriptor(elementType).name
  10369. });
  10370. }
  10371. }
  10372. // search for properties by name first
  10373. return property;
  10374. }
  10375. var pkg = model.getPackage(nameNs.prefix);
  10376. if (pkg) {
  10377. elementTypeName = aliasToName(nameNs, pkg);
  10378. elementType = model.getType(elementTypeName);
  10379. // search for collection members later
  10380. property = find(descriptor.properties, function(p) {
  10381. return !p.isVirtual && !p.isReference && !p.isAttribute && elementType.hasType(p.type);
  10382. });
  10383. if (property) {
  10384. return assign({}, property, {
  10385. effectiveType: getModdleDescriptor(elementType).name
  10386. });
  10387. }
  10388. } else {
  10389. // parse unknown element (maybe extension)
  10390. property = find(descriptor.properties, function(p) {
  10391. return !p.isReference && !p.isAttribute && p.type === 'Element';
  10392. });
  10393. if (property) {
  10394. return property;
  10395. }
  10396. }
  10397. throw error$1('unrecognized element <' + nameNs.name + '>');
  10398. };
  10399. ElementHandler.prototype.toString = function() {
  10400. return 'ElementDescriptor[' + getModdleDescriptor(this.type).name + ']';
  10401. };
  10402. ElementHandler.prototype.valueHandler = function(propertyDesc, element) {
  10403. return new ValueHandler(propertyDesc, element);
  10404. };
  10405. ElementHandler.prototype.referenceHandler = function(propertyDesc) {
  10406. return new ReferenceHandler(propertyDesc, this.context);
  10407. };
  10408. ElementHandler.prototype.handler = function(type) {
  10409. if (type === 'Element') {
  10410. return new GenericElementHandler(this.model, type, this.context);
  10411. } else {
  10412. return new ElementHandler(this.model, type, this.context);
  10413. }
  10414. };
  10415. /**
  10416. * Handle the child element parsing
  10417. *
  10418. * @param {Element} node the xml node
  10419. */
  10420. ElementHandler.prototype.handleChild = function(node) {
  10421. var propertyDesc, type, element, childHandler;
  10422. propertyDesc = this.getPropertyForNode(node);
  10423. element = this.element;
  10424. type = propertyDesc.effectiveType || propertyDesc.type;
  10425. if (isSimple(type)) {
  10426. return this.valueHandler(propertyDesc, element);
  10427. }
  10428. if (propertyDesc.isReference) {
  10429. childHandler = this.referenceHandler(propertyDesc).handleNode(node);
  10430. } else {
  10431. childHandler = this.handler(type).handleNode(node);
  10432. }
  10433. var newElement = childHandler.element;
  10434. // child handles may decide to skip elements
  10435. // by not returning anything
  10436. if (newElement !== undefined) {
  10437. if (propertyDesc.isMany) {
  10438. element.get(propertyDesc.name).push(newElement);
  10439. } else {
  10440. element.set(propertyDesc.name, newElement);
  10441. }
  10442. if (propertyDesc.isReference) {
  10443. assign(newElement, {
  10444. element: element
  10445. });
  10446. this.context.addReference(newElement);
  10447. } else {
  10448. // establish child -> parent relationship
  10449. newElement.$parent = element;
  10450. }
  10451. }
  10452. return childHandler;
  10453. };
  10454. /**
  10455. * An element handler that performs special validation
  10456. * to ensure the node it gets initialized with matches
  10457. * the handlers type (namespace wise).
  10458. *
  10459. * @param {Moddle} model
  10460. * @param {String} typeName
  10461. * @param {Context} context
  10462. */
  10463. function RootElementHandler(model, typeName, context) {
  10464. ElementHandler.call(this, model, typeName, context);
  10465. }
  10466. RootElementHandler.prototype = Object.create(ElementHandler.prototype);
  10467. RootElementHandler.prototype.createElement = function(node) {
  10468. var name = node.name,
  10469. nameNs = parseName(name),
  10470. model = this.model,
  10471. type = this.type,
  10472. pkg = model.getPackage(nameNs.prefix),
  10473. typeName = pkg && aliasToName(nameNs, pkg) || name;
  10474. // verify the correct namespace if we parse
  10475. // the first element in the handler tree
  10476. //
  10477. // this ensures we don't mistakenly import wrong namespace elements
  10478. if (!type.hasType(typeName)) {
  10479. throw error$1('unexpected element <' + node.originalName + '>');
  10480. }
  10481. return ElementHandler.prototype.createElement.call(this, node);
  10482. };
  10483. function GenericElementHandler(model, typeName, context) {
  10484. this.model = model;
  10485. this.context = context;
  10486. }
  10487. GenericElementHandler.prototype = Object.create(BaseElementHandler.prototype);
  10488. GenericElementHandler.prototype.createElement = function(node) {
  10489. var name = node.name,
  10490. ns = parseName(name),
  10491. prefix = ns.prefix,
  10492. uri = node.ns[prefix + '$uri'],
  10493. attributes = node.attributes;
  10494. return this.model.createAny(name, uri, attributes);
  10495. };
  10496. GenericElementHandler.prototype.handleChild = function(node) {
  10497. var handler = new GenericElementHandler(this.model, 'Element', this.context).handleNode(node),
  10498. element = this.element;
  10499. var newElement = handler.element,
  10500. children;
  10501. if (newElement !== undefined) {
  10502. children = element.$children = element.$children || [];
  10503. children.push(newElement);
  10504. // establish child -> parent relationship
  10505. newElement.$parent = element;
  10506. }
  10507. return handler;
  10508. };
  10509. GenericElementHandler.prototype.handleEnd = function() {
  10510. if (this.body) {
  10511. this.element.$body = this.body;
  10512. }
  10513. };
  10514. /**
  10515. * A reader for a meta-model
  10516. *
  10517. * @param {Object} options
  10518. * @param {Model} options.model used to read xml files
  10519. * @param {Boolean} options.lax whether to make parse errors warnings
  10520. */
  10521. function Reader(options) {
  10522. if (options instanceof Moddle) {
  10523. options = {
  10524. model: options
  10525. };
  10526. }
  10527. assign(this, { lax: false }, options);
  10528. }
  10529. /**
  10530. * Parse the given XML into a moddle document tree.
  10531. *
  10532. * @param {String} xml
  10533. * @param {ElementHandler|Object} options or rootHandler
  10534. * @param {Function} done
  10535. */
  10536. Reader.prototype.fromXML = function(xml, options, done) {
  10537. var rootHandler = options.rootHandler;
  10538. if (options instanceof ElementHandler) {
  10539. // root handler passed via (xml, { rootHandler: ElementHandler }, ...)
  10540. rootHandler = options;
  10541. options = {};
  10542. } else {
  10543. if (typeof options === 'string') {
  10544. // rootHandler passed via (xml, 'someString', ...)
  10545. rootHandler = this.handler(options);
  10546. options = {};
  10547. } else if (typeof rootHandler === 'string') {
  10548. // rootHandler passed via (xml, { rootHandler: 'someString' }, ...)
  10549. rootHandler = this.handler(rootHandler);
  10550. }
  10551. }
  10552. var model = this.model,
  10553. lax = this.lax;
  10554. var context = new Context(assign({}, options, { rootHandler: rootHandler })),
  10555. parser = new Parser({ proxy: true }),
  10556. stack = createStack();
  10557. rootHandler.context = context;
  10558. // push root handler
  10559. stack.push(rootHandler);
  10560. /**
  10561. * Handle error.
  10562. *
  10563. * @param {Error} err
  10564. * @param {Function} getContext
  10565. * @param {boolean} lax
  10566. *
  10567. * @return {boolean} true if handled
  10568. */
  10569. function handleError(err, getContext, lax) {
  10570. var ctx = getContext();
  10571. var line = ctx.line,
  10572. column = ctx.column,
  10573. data = ctx.data;
  10574. // we receive the full context data here,
  10575. // for elements trim down the information
  10576. // to the tag name, only
  10577. if (data.charAt(0) === '<' && data.indexOf(' ') !== -1) {
  10578. data = data.slice(0, data.indexOf(' ')) + '>';
  10579. }
  10580. var message =
  10581. 'unparsable content ' + (data ? data + ' ' : '') + 'detected\n\t' +
  10582. 'line: ' + line + '\n\t' +
  10583. 'column: ' + column + '\n\t' +
  10584. 'nested error: ' + err.message;
  10585. if (lax) {
  10586. context.addWarning({
  10587. message: message,
  10588. error: err
  10589. });
  10590. return true;
  10591. } else {
  10592. throw error$1(message);
  10593. }
  10594. }
  10595. function handleWarning(err, getContext) {
  10596. // just like handling errors in <lax=true> mode
  10597. return handleError(err, getContext, true);
  10598. }
  10599. /**
  10600. * Resolve collected references on parse end.
  10601. */
  10602. function resolveReferences() {
  10603. var elementsById = context.elementsById;
  10604. var references = context.references;
  10605. var i, r;
  10606. for (i = 0; (r = references[i]); i++) {
  10607. var element = r.element;
  10608. var reference = elementsById[r.id];
  10609. var property = getModdleDescriptor(element).propertiesByName[r.property];
  10610. if (!reference) {
  10611. context.addWarning({
  10612. message: 'unresolved reference <' + r.id + '>',
  10613. element: r.element,
  10614. property: r.property,
  10615. value: r.id
  10616. });
  10617. }
  10618. if (property.isMany) {
  10619. var collection = element.get(property.name),
  10620. idx = collection.indexOf(r);
  10621. // we replace an existing place holder (idx != -1) or
  10622. // append to the collection instead
  10623. if (idx === -1) {
  10624. idx = collection.length;
  10625. }
  10626. if (!reference) {
  10627. // remove unresolvable reference
  10628. collection.splice(idx, 1);
  10629. } else {
  10630. // add or update reference in collection
  10631. collection[idx] = reference;
  10632. }
  10633. } else {
  10634. element.set(property.name, reference);
  10635. }
  10636. }
  10637. }
  10638. function handleClose() {
  10639. stack.pop().handleEnd();
  10640. }
  10641. var PREAMBLE_START_PATTERN = /^<\?xml /i;
  10642. var ENCODING_PATTERN = / encoding="([^"]+)"/i;
  10643. var UTF_8_PATTERN = /^utf-8$/i;
  10644. function handleQuestion(question) {
  10645. if (!PREAMBLE_START_PATTERN.test(question)) {
  10646. return;
  10647. }
  10648. var match = ENCODING_PATTERN.exec(question);
  10649. var encoding = match && match[1];
  10650. if (!encoding || UTF_8_PATTERN.test(encoding)) {
  10651. return;
  10652. }
  10653. context.addWarning({
  10654. message:
  10655. 'unsupported document encoding <' + encoding + '>, ' +
  10656. 'falling back to UTF-8'
  10657. });
  10658. }
  10659. function handleOpen(node, getContext) {
  10660. var handler = stack.peek();
  10661. try {
  10662. stack.push(handler.handleNode(node));
  10663. } catch (err) {
  10664. if (handleError(err, getContext, lax)) {
  10665. stack.push(new NoopHandler());
  10666. }
  10667. }
  10668. }
  10669. function handleCData(text, getContext) {
  10670. try {
  10671. stack.peek().handleText(text);
  10672. } catch (err) {
  10673. handleWarning(err, getContext);
  10674. }
  10675. }
  10676. function handleText(text, getContext) {
  10677. // strip whitespace only nodes, i.e. before
  10678. // <!CDATA[ ... ]> sections and in between tags
  10679. text = text.trim();
  10680. if (!text) {
  10681. return;
  10682. }
  10683. handleCData(text, getContext);
  10684. }
  10685. var uriMap = model.getPackages().reduce(function(uriMap, p) {
  10686. uriMap[p.uri] = p.prefix;
  10687. return uriMap;
  10688. }, {});
  10689. parser
  10690. .ns(uriMap)
  10691. .on('openTag', function(obj, decodeStr, selfClosing, getContext) {
  10692. // gracefully handle unparsable attributes (attrs=false)
  10693. var attrs = obj.attrs || {};
  10694. var decodedAttrs = Object.keys(attrs).reduce(function(d, key) {
  10695. var value = decodeStr(attrs[key]);
  10696. d[key] = value;
  10697. return d;
  10698. }, {});
  10699. var node = {
  10700. name: obj.name,
  10701. originalName: obj.originalName,
  10702. attributes: decodedAttrs,
  10703. ns: obj.ns
  10704. };
  10705. handleOpen(node, getContext);
  10706. })
  10707. .on('question', handleQuestion)
  10708. .on('closeTag', handleClose)
  10709. .on('cdata', handleCData)
  10710. .on('text', function(text, decodeEntities, getContext) {
  10711. handleText(decodeEntities(text), getContext);
  10712. })
  10713. .on('error', handleError)
  10714. .on('warn', handleWarning);
  10715. // deferred parse XML to make loading really ascnchronous
  10716. // this ensures the execution environment (node or browser)
  10717. // is kept responsive and that certain optimization strategies
  10718. // can kick in
  10719. defer(function() {
  10720. var err;
  10721. try {
  10722. parser.parse(xml);
  10723. resolveReferences();
  10724. } catch (e) {
  10725. err = e;
  10726. }
  10727. var element = rootHandler.element;
  10728. // handle the situation that we could not extract
  10729. // the desired root element from the document
  10730. if (!err && !element) {
  10731. err = error$1('failed to parse document as <' + rootHandler.type.$descriptor.name + '>');
  10732. }
  10733. done(err, err ? undefined : element, context);
  10734. });
  10735. };
  10736. Reader.prototype.handler = function(name) {
  10737. return new RootElementHandler(this.model, name);
  10738. };
  10739. // helpers //////////////////////////
  10740. function createStack() {
  10741. var stack = [];
  10742. Object.defineProperty(stack, 'peek', {
  10743. value: function() {
  10744. return this[this.length - 1];
  10745. }
  10746. });
  10747. return stack;
  10748. }
  10749. var XML_PREAMBLE = '<?xml version="1.0" encoding="UTF-8"?>\n';
  10750. var ESCAPE_ATTR_CHARS = /<|>|'|"|&|\n\r|\n/g;
  10751. var ESCAPE_CHARS = /<|>|&/g;
  10752. function Namespaces(parent) {
  10753. var prefixMap = {};
  10754. var uriMap = {};
  10755. var used = {};
  10756. var wellknown = [];
  10757. var custom = [];
  10758. // API
  10759. this.byUri = function(uri) {
  10760. return uriMap[uri] || (
  10761. parent && parent.byUri(uri)
  10762. );
  10763. };
  10764. this.add = function(ns, isWellknown) {
  10765. uriMap[ns.uri] = ns;
  10766. if (isWellknown) {
  10767. wellknown.push(ns);
  10768. } else {
  10769. custom.push(ns);
  10770. }
  10771. this.mapPrefix(ns.prefix, ns.uri);
  10772. };
  10773. this.uriByPrefix = function(prefix) {
  10774. return prefixMap[prefix || 'xmlns'];
  10775. };
  10776. this.mapPrefix = function(prefix, uri) {
  10777. prefixMap[prefix || 'xmlns'] = uri;
  10778. };
  10779. this.getNSKey = function(ns) {
  10780. return (ns.prefix !== undefined) ? (ns.uri + '|' + ns.prefix) : ns.uri;
  10781. };
  10782. this.logUsed = function(ns) {
  10783. var uri = ns.uri;
  10784. var nsKey = this.getNSKey(ns);
  10785. used[nsKey] = this.byUri(uri);
  10786. // Inform parent recursively about the usage of this NS
  10787. if (parent) {
  10788. parent.logUsed(ns);
  10789. }
  10790. };
  10791. this.getUsed = function(ns) {
  10792. function isUsed(ns) {
  10793. var nsKey = self.getNSKey(ns);
  10794. return used[nsKey];
  10795. }
  10796. var self = this;
  10797. var allNs = [].concat(wellknown, custom);
  10798. return allNs.filter(isUsed);
  10799. };
  10800. }
  10801. function lower(string) {
  10802. return string.charAt(0).toLowerCase() + string.slice(1);
  10803. }
  10804. function nameToAlias(name, pkg) {
  10805. if (hasLowerCaseAlias(pkg)) {
  10806. return lower(name);
  10807. } else {
  10808. return name;
  10809. }
  10810. }
  10811. function inherits(ctor, superCtor) {
  10812. ctor.super_ = superCtor;
  10813. ctor.prototype = Object.create(superCtor.prototype, {
  10814. constructor: {
  10815. value: ctor,
  10816. enumerable: false,
  10817. writable: true,
  10818. configurable: true
  10819. }
  10820. });
  10821. }
  10822. function nsName(ns) {
  10823. if (isString(ns)) {
  10824. return ns;
  10825. } else {
  10826. return (ns.prefix ? ns.prefix + ':' : '') + ns.localName;
  10827. }
  10828. }
  10829. function getNsAttrs(namespaces) {
  10830. return map(namespaces.getUsed(), function(ns) {
  10831. var name = 'xmlns' + (ns.prefix ? ':' + ns.prefix : '');
  10832. return { name: name, value: ns.uri };
  10833. });
  10834. }
  10835. function getElementNs(ns, descriptor) {
  10836. if (descriptor.isGeneric) {
  10837. return assign({ localName: descriptor.ns.localName }, ns);
  10838. } else {
  10839. return assign({ localName: nameToAlias(descriptor.ns.localName, descriptor.$pkg) }, ns);
  10840. }
  10841. }
  10842. function getPropertyNs(ns, descriptor) {
  10843. return assign({ localName: descriptor.ns.localName }, ns);
  10844. }
  10845. function getSerializableProperties(element) {
  10846. var descriptor = element.$descriptor;
  10847. return filter(descriptor.properties, function(p) {
  10848. var name = p.name;
  10849. if (p.isVirtual) {
  10850. return false;
  10851. }
  10852. // do not serialize defaults
  10853. if (!element.hasOwnProperty(name)) {
  10854. return false;
  10855. }
  10856. var value = element[name];
  10857. // do not serialize default equals
  10858. if (value === p.default) {
  10859. return false;
  10860. }
  10861. // do not serialize null properties
  10862. if (value === null) {
  10863. return false;
  10864. }
  10865. return p.isMany ? value.length : true;
  10866. });
  10867. }
  10868. var ESCAPE_ATTR_MAP = {
  10869. '\n': '#10',
  10870. '\n\r': '#10',
  10871. '"': '#34',
  10872. '\'': '#39',
  10873. '<': '#60',
  10874. '>': '#62',
  10875. '&': '#38'
  10876. };
  10877. var ESCAPE_MAP = {
  10878. '<': 'lt',
  10879. '>': 'gt',
  10880. '&': 'amp'
  10881. };
  10882. function escape$1(str, charPattern, replaceMap) {
  10883. // ensure we are handling strings here
  10884. str = isString(str) ? str : '' + str;
  10885. return str.replace(charPattern, function(s) {
  10886. return '&' + replaceMap[s] + ';';
  10887. });
  10888. }
  10889. /**
  10890. * Escape a string attribute to not contain any bad values (line breaks, '"', ...)
  10891. *
  10892. * @param {String} str the string to escape
  10893. * @return {String} the escaped string
  10894. */
  10895. function escapeAttr(str) {
  10896. return escape$1(str, ESCAPE_ATTR_CHARS, ESCAPE_ATTR_MAP);
  10897. }
  10898. function escapeBody(str) {
  10899. return escape$1(str, ESCAPE_CHARS, ESCAPE_MAP);
  10900. }
  10901. function filterAttributes(props) {
  10902. return filter(props, function(p) { return p.isAttr; });
  10903. }
  10904. function filterContained(props) {
  10905. return filter(props, function(p) { return !p.isAttr; });
  10906. }
  10907. function ReferenceSerializer(tagName) {
  10908. this.tagName = tagName;
  10909. }
  10910. ReferenceSerializer.prototype.build = function(element) {
  10911. this.element = element;
  10912. return this;
  10913. };
  10914. ReferenceSerializer.prototype.serializeTo = function(writer) {
  10915. writer
  10916. .appendIndent()
  10917. .append('<' + this.tagName + '>' + this.element.id + '</' + this.tagName + '>')
  10918. .appendNewLine();
  10919. };
  10920. function BodySerializer() {}
  10921. BodySerializer.prototype.serializeValue =
  10922. BodySerializer.prototype.serializeTo = function(writer) {
  10923. writer.append(
  10924. this.escape
  10925. ? escapeBody(this.value)
  10926. : this.value
  10927. );
  10928. };
  10929. BodySerializer.prototype.build = function(prop, value) {
  10930. this.value = value;
  10931. if (prop.type === 'String' && value.search(ESCAPE_CHARS) !== -1) {
  10932. this.escape = true;
  10933. }
  10934. return this;
  10935. };
  10936. function ValueSerializer(tagName) {
  10937. this.tagName = tagName;
  10938. }
  10939. inherits(ValueSerializer, BodySerializer);
  10940. ValueSerializer.prototype.serializeTo = function(writer) {
  10941. writer
  10942. .appendIndent()
  10943. .append('<' + this.tagName + '>');
  10944. this.serializeValue(writer);
  10945. writer
  10946. .append('</' + this.tagName + '>')
  10947. .appendNewLine();
  10948. };
  10949. function ElementSerializer(parent, propertyDescriptor) {
  10950. this.body = [];
  10951. this.attrs = [];
  10952. this.parent = parent;
  10953. this.propertyDescriptor = propertyDescriptor;
  10954. }
  10955. ElementSerializer.prototype.build = function(element) {
  10956. this.element = element;
  10957. var elementDescriptor = element.$descriptor,
  10958. propertyDescriptor = this.propertyDescriptor;
  10959. var otherAttrs,
  10960. properties;
  10961. var isGeneric = elementDescriptor.isGeneric;
  10962. if (isGeneric) {
  10963. otherAttrs = this.parseGeneric(element);
  10964. } else {
  10965. otherAttrs = this.parseNsAttributes(element);
  10966. }
  10967. if (propertyDescriptor) {
  10968. this.ns = this.nsPropertyTagName(propertyDescriptor);
  10969. } else {
  10970. this.ns = this.nsTagName(elementDescriptor);
  10971. }
  10972. // compute tag name
  10973. this.tagName = this.addTagName(this.ns);
  10974. if (!isGeneric) {
  10975. properties = getSerializableProperties(element);
  10976. this.parseAttributes(filterAttributes(properties));
  10977. this.parseContainments(filterContained(properties));
  10978. }
  10979. this.parseGenericAttributes(element, otherAttrs);
  10980. return this;
  10981. };
  10982. ElementSerializer.prototype.nsTagName = function(descriptor) {
  10983. var effectiveNs = this.logNamespaceUsed(descriptor.ns);
  10984. return getElementNs(effectiveNs, descriptor);
  10985. };
  10986. ElementSerializer.prototype.nsPropertyTagName = function(descriptor) {
  10987. var effectiveNs = this.logNamespaceUsed(descriptor.ns);
  10988. return getPropertyNs(effectiveNs, descriptor);
  10989. };
  10990. ElementSerializer.prototype.isLocalNs = function(ns) {
  10991. return ns.uri === this.ns.uri;
  10992. };
  10993. /**
  10994. * Get the actual ns attribute name for the given element.
  10995. *
  10996. * @param {Object} element
  10997. * @param {Boolean} [element.inherited=false]
  10998. *
  10999. * @return {Object} nsName
  11000. */
  11001. ElementSerializer.prototype.nsAttributeName = function(element) {
  11002. var ns;
  11003. if (isString(element)) {
  11004. ns = parseName(element);
  11005. } else {
  11006. ns = element.ns;
  11007. }
  11008. // return just local name for inherited attributes
  11009. if (element.inherited) {
  11010. return { localName: ns.localName };
  11011. }
  11012. // parse + log effective ns
  11013. var effectiveNs = this.logNamespaceUsed(ns);
  11014. // LOG ACTUAL namespace use
  11015. this.getNamespaces().logUsed(effectiveNs);
  11016. // strip prefix if same namespace like parent
  11017. if (this.isLocalNs(effectiveNs)) {
  11018. return { localName: ns.localName };
  11019. } else {
  11020. return assign({ localName: ns.localName }, effectiveNs);
  11021. }
  11022. };
  11023. ElementSerializer.prototype.parseGeneric = function(element) {
  11024. var self = this,
  11025. body = this.body;
  11026. var attributes = [];
  11027. forEach(element, function(val, key) {
  11028. var nonNsAttr;
  11029. if (key === '$body') {
  11030. body.push(new BodySerializer().build({ type: 'String' }, val));
  11031. } else
  11032. if (key === '$children') {
  11033. forEach(val, function(child) {
  11034. body.push(new ElementSerializer(self).build(child));
  11035. });
  11036. } else
  11037. if (key.indexOf('$') !== 0) {
  11038. nonNsAttr = self.parseNsAttribute(element, key, val);
  11039. if (nonNsAttr) {
  11040. attributes.push({ name: key, value: val });
  11041. }
  11042. }
  11043. });
  11044. return attributes;
  11045. };
  11046. ElementSerializer.prototype.parseNsAttribute = function(element, name, value) {
  11047. var model = element.$model;
  11048. var nameNs = parseName(name);
  11049. var ns;
  11050. // parse xmlns:foo="http://foo.bar"
  11051. if (nameNs.prefix === 'xmlns') {
  11052. ns = { prefix: nameNs.localName, uri: value };
  11053. }
  11054. // parse xmlns="http://foo.bar"
  11055. if (!nameNs.prefix && nameNs.localName === 'xmlns') {
  11056. ns = { uri: value };
  11057. }
  11058. if (!ns) {
  11059. return {
  11060. name: name,
  11061. value: value
  11062. };
  11063. }
  11064. if (model && model.getPackage(value)) {
  11065. // register well known namespace
  11066. this.logNamespace(ns, true, true);
  11067. } else {
  11068. // log custom namespace directly as used
  11069. var actualNs = this.logNamespaceUsed(ns, true);
  11070. this.getNamespaces().logUsed(actualNs);
  11071. }
  11072. };
  11073. /**
  11074. * Parse namespaces and return a list of left over generic attributes
  11075. *
  11076. * @param {Object} element
  11077. * @return {Array<Object>}
  11078. */
  11079. ElementSerializer.prototype.parseNsAttributes = function(element, attrs) {
  11080. var self = this;
  11081. var genericAttrs = element.$attrs;
  11082. var attributes = [];
  11083. // parse namespace attributes first
  11084. // and log them. push non namespace attributes to a list
  11085. // and process them later
  11086. forEach(genericAttrs, function(value, name) {
  11087. var nonNsAttr = self.parseNsAttribute(element, name, value);
  11088. if (nonNsAttr) {
  11089. attributes.push(nonNsAttr);
  11090. }
  11091. });
  11092. return attributes;
  11093. };
  11094. ElementSerializer.prototype.parseGenericAttributes = function(element, attributes) {
  11095. var self = this;
  11096. forEach(attributes, function(attr) {
  11097. // do not serialize xsi:type attribute
  11098. // it is set manually based on the actual implementation type
  11099. if (attr.name === XSI_TYPE$1) {
  11100. return;
  11101. }
  11102. try {
  11103. self.addAttribute(self.nsAttributeName(attr.name), attr.value);
  11104. } catch (e) {
  11105. console.warn(
  11106. 'missing namespace information for ',
  11107. attr.name, '=', attr.value, 'on', element,
  11108. e);
  11109. }
  11110. });
  11111. };
  11112. ElementSerializer.prototype.parseContainments = function(properties) {
  11113. var self = this,
  11114. body = this.body,
  11115. element = this.element;
  11116. forEach(properties, function(p) {
  11117. var value = element.get(p.name),
  11118. isReference = p.isReference,
  11119. isMany = p.isMany;
  11120. if (!isMany) {
  11121. value = [ value ];
  11122. }
  11123. if (p.isBody) {
  11124. body.push(new BodySerializer().build(p, value[0]));
  11125. } else
  11126. if (isSimple(p.type)) {
  11127. forEach(value, function(v) {
  11128. body.push(new ValueSerializer(self.addTagName(self.nsPropertyTagName(p))).build(p, v));
  11129. });
  11130. } else
  11131. if (isReference) {
  11132. forEach(value, function(v) {
  11133. body.push(new ReferenceSerializer(self.addTagName(self.nsPropertyTagName(p))).build(v));
  11134. });
  11135. } else {
  11136. // allow serialization via type
  11137. // rather than element name
  11138. var asType = serializeAsType(p),
  11139. asProperty = serializeAsProperty(p);
  11140. forEach(value, function(v) {
  11141. var serializer;
  11142. if (asType) {
  11143. serializer = new TypeSerializer(self, p);
  11144. } else
  11145. if (asProperty) {
  11146. serializer = new ElementSerializer(self, p);
  11147. } else {
  11148. serializer = new ElementSerializer(self);
  11149. }
  11150. body.push(serializer.build(v));
  11151. });
  11152. }
  11153. });
  11154. };
  11155. ElementSerializer.prototype.getNamespaces = function(local) {
  11156. var namespaces = this.namespaces,
  11157. parent = this.parent,
  11158. parentNamespaces;
  11159. if (!namespaces) {
  11160. parentNamespaces = parent && parent.getNamespaces();
  11161. if (local || !parentNamespaces) {
  11162. this.namespaces = namespaces = new Namespaces(parentNamespaces);
  11163. } else {
  11164. namespaces = parentNamespaces;
  11165. }
  11166. }
  11167. return namespaces;
  11168. };
  11169. ElementSerializer.prototype.logNamespace = function(ns, wellknown, local) {
  11170. var namespaces = this.getNamespaces(local);
  11171. var nsUri = ns.uri,
  11172. nsPrefix = ns.prefix;
  11173. var existing = namespaces.byUri(nsUri);
  11174. if (!existing || local) {
  11175. namespaces.add(ns, wellknown);
  11176. }
  11177. namespaces.mapPrefix(nsPrefix, nsUri);
  11178. return ns;
  11179. };
  11180. ElementSerializer.prototype.logNamespaceUsed = function(ns, local) {
  11181. var element = this.element,
  11182. model = element.$model,
  11183. namespaces = this.getNamespaces(local);
  11184. // ns may be
  11185. //
  11186. // * prefix only
  11187. // * prefix:uri
  11188. // * localName only
  11189. var prefix = ns.prefix,
  11190. uri = ns.uri,
  11191. newPrefix, idx,
  11192. wellknownUri;
  11193. // handle anonymous namespaces (elementForm=unqualified), cf. #23
  11194. if (!prefix && !uri) {
  11195. return { localName: ns.localName };
  11196. }
  11197. wellknownUri = DEFAULT_NS_MAP[prefix] || model && (model.getPackage(prefix) || {}).uri;
  11198. uri = uri || wellknownUri || namespaces.uriByPrefix(prefix);
  11199. if (!uri) {
  11200. throw new Error('no namespace uri given for prefix <' + prefix + '>');
  11201. }
  11202. ns = namespaces.byUri(uri);
  11203. if (!ns) {
  11204. newPrefix = prefix;
  11205. idx = 1;
  11206. // find a prefix that is not mapped yet
  11207. while (namespaces.uriByPrefix(newPrefix)) {
  11208. newPrefix = prefix + '_' + idx++;
  11209. }
  11210. ns = this.logNamespace({ prefix: newPrefix, uri: uri }, wellknownUri === uri);
  11211. }
  11212. if (prefix) {
  11213. namespaces.mapPrefix(prefix, uri);
  11214. }
  11215. return ns;
  11216. };
  11217. ElementSerializer.prototype.parseAttributes = function(properties) {
  11218. var self = this,
  11219. element = this.element;
  11220. forEach(properties, function(p) {
  11221. var value = element.get(p.name);
  11222. if (p.isReference) {
  11223. if (!p.isMany) {
  11224. value = value.id;
  11225. }
  11226. else {
  11227. var values = [];
  11228. forEach(value, function(v) {
  11229. values.push(v.id);
  11230. });
  11231. // IDREFS is a whitespace-separated list of references.
  11232. value = values.join(' ');
  11233. }
  11234. }
  11235. self.addAttribute(self.nsAttributeName(p), value);
  11236. });
  11237. };
  11238. ElementSerializer.prototype.addTagName = function(nsTagName) {
  11239. var actualNs = this.logNamespaceUsed(nsTagName);
  11240. this.getNamespaces().logUsed(actualNs);
  11241. return nsName(nsTagName);
  11242. };
  11243. ElementSerializer.prototype.addAttribute = function(name, value) {
  11244. var attrs = this.attrs;
  11245. if (isString(value)) {
  11246. value = escapeAttr(value);
  11247. }
  11248. attrs.push({ name: name, value: value });
  11249. };
  11250. ElementSerializer.prototype.serializeAttributes = function(writer) {
  11251. var attrs = this.attrs,
  11252. namespaces = this.namespaces;
  11253. if (namespaces) {
  11254. attrs = getNsAttrs(namespaces).concat(attrs);
  11255. }
  11256. forEach(attrs, function(a) {
  11257. writer
  11258. .append(' ')
  11259. .append(nsName(a.name)).append('="').append(a.value).append('"');
  11260. });
  11261. };
  11262. ElementSerializer.prototype.serializeTo = function(writer) {
  11263. var firstBody = this.body[0],
  11264. indent = firstBody && firstBody.constructor !== BodySerializer;
  11265. writer
  11266. .appendIndent()
  11267. .append('<' + this.tagName);
  11268. this.serializeAttributes(writer);
  11269. writer.append(firstBody ? '>' : ' />');
  11270. if (firstBody) {
  11271. if (indent) {
  11272. writer
  11273. .appendNewLine()
  11274. .indent();
  11275. }
  11276. forEach(this.body, function(b) {
  11277. b.serializeTo(writer);
  11278. });
  11279. if (indent) {
  11280. writer
  11281. .unindent()
  11282. .appendIndent();
  11283. }
  11284. writer.append('</' + this.tagName + '>');
  11285. }
  11286. writer.appendNewLine();
  11287. };
  11288. /**
  11289. * A serializer for types that handles serialization of data types
  11290. */
  11291. function TypeSerializer(parent, propertyDescriptor) {
  11292. ElementSerializer.call(this, parent, propertyDescriptor);
  11293. }
  11294. inherits(TypeSerializer, ElementSerializer);
  11295. TypeSerializer.prototype.parseNsAttributes = function(element) {
  11296. // extracted attributes
  11297. var attributes = ElementSerializer.prototype.parseNsAttributes.call(this, element);
  11298. var descriptor = element.$descriptor;
  11299. // only serialize xsi:type if necessary
  11300. if (descriptor.name === this.propertyDescriptor.type) {
  11301. return attributes;
  11302. }
  11303. var typeNs = this.typeNs = this.nsTagName(descriptor);
  11304. this.getNamespaces().logUsed(this.typeNs);
  11305. // add xsi:type attribute to represent the elements
  11306. // actual type
  11307. var pkg = element.$model.getPackage(typeNs.uri),
  11308. typePrefix = (pkg.xml && pkg.xml.typePrefix) || '';
  11309. this.addAttribute(
  11310. this.nsAttributeName(XSI_TYPE$1),
  11311. (typeNs.prefix ? typeNs.prefix + ':' : '') + typePrefix + descriptor.ns.localName
  11312. );
  11313. return attributes;
  11314. };
  11315. TypeSerializer.prototype.isLocalNs = function(ns) {
  11316. return ns.uri === (this.typeNs || this.ns).uri;
  11317. };
  11318. function SavingWriter() {
  11319. this.value = '';
  11320. this.write = function(str) {
  11321. this.value += str;
  11322. };
  11323. }
  11324. function FormatingWriter(out, format) {
  11325. var indent = [''];
  11326. this.append = function(str) {
  11327. out.write(str);
  11328. return this;
  11329. };
  11330. this.appendNewLine = function() {
  11331. if (format) {
  11332. out.write('\n');
  11333. }
  11334. return this;
  11335. };
  11336. this.appendIndent = function() {
  11337. if (format) {
  11338. out.write(indent.join(' '));
  11339. }
  11340. return this;
  11341. };
  11342. this.indent = function() {
  11343. indent.push('');
  11344. return this;
  11345. };
  11346. this.unindent = function() {
  11347. indent.pop();
  11348. return this;
  11349. };
  11350. }
  11351. /**
  11352. * A writer for meta-model backed document trees
  11353. *
  11354. * @param {Object} options output options to pass into the writer
  11355. */
  11356. function Writer(options) {
  11357. options = assign({ format: false, preamble: true }, options || {});
  11358. function toXML(tree, writer) {
  11359. var internalWriter = writer || new SavingWriter();
  11360. var formatingWriter = new FormatingWriter(internalWriter, options.format);
  11361. if (options.preamble) {
  11362. formatingWriter.append(XML_PREAMBLE);
  11363. }
  11364. new ElementSerializer().build(tree).serializeTo(formatingWriter);
  11365. if (!writer) {
  11366. return internalWriter.value;
  11367. }
  11368. }
  11369. return {
  11370. toXML: toXML
  11371. };
  11372. }
  11373. /**
  11374. * A sub class of {@link Moddle} with support for import and export of BPMN 2.0 xml files.
  11375. *
  11376. * @class BpmnModdle
  11377. * @extends Moddle
  11378. *
  11379. * @param {Object|Array} packages to use for instantiating the model
  11380. * @param {Object} [options] additional options to pass over
  11381. */
  11382. function BpmnModdle(packages, options) {
  11383. Moddle.call(this, packages, options);
  11384. }
  11385. BpmnModdle.prototype = Object.create(Moddle.prototype);
  11386. /**
  11387. * Instantiates a BPMN model tree from a given xml string.
  11388. *
  11389. * @param {String} xmlStr
  11390. * @param {String} [typeName='bpmn:Definitions'] name of the root element
  11391. * @param {Object} [options] options to pass to the underlying reader
  11392. * @param {Function} done callback that is invoked with (err, result, parseContext)
  11393. * once the import completes
  11394. */
  11395. BpmnModdle.prototype.fromXML = function(xmlStr, typeName, options, done) {
  11396. if (!isString(typeName)) {
  11397. done = options;
  11398. options = typeName;
  11399. typeName = 'bpmn:Definitions';
  11400. }
  11401. if (isFunction(options)) {
  11402. done = options;
  11403. options = {};
  11404. }
  11405. var reader = new Reader(assign({ model: this, lax: true }, options));
  11406. var rootHandler = reader.handler(typeName);
  11407. reader.fromXML(xmlStr, rootHandler, done);
  11408. };
  11409. /**
  11410. * Serializes a BPMN 2.0 object tree to XML.
  11411. *
  11412. * @param {String} element the root element, typically an instance of `bpmn:Definitions`
  11413. * @param {Object} [options] to pass to the underlying writer
  11414. * @param {Function} done callback invoked with (err, xmlStr) once the import completes
  11415. */
  11416. BpmnModdle.prototype.toXML = function(element, options, done) {
  11417. if (isFunction(options)) {
  11418. done = options;
  11419. options = {};
  11420. }
  11421. var writer = new Writer(options);
  11422. var result;
  11423. var err;
  11424. try {
  11425. result = writer.toXML(element);
  11426. } catch (e) {
  11427. err = e;
  11428. }
  11429. return done(err, result);
  11430. };
  11431. var name = "BPMN20";
  11432. var uri = "http://www.omg.org/spec/BPMN/20100524/MODEL";
  11433. var prefix$1 = "bpmn";
  11434. var associations = [
  11435. ];
  11436. var types$1 = [
  11437. {
  11438. name: "Interface",
  11439. superClass: [
  11440. "RootElement"
  11441. ],
  11442. properties: [
  11443. {
  11444. name: "name",
  11445. isAttr: true,
  11446. type: "String"
  11447. },
  11448. {
  11449. name: "operations",
  11450. type: "Operation",
  11451. isMany: true
  11452. },
  11453. {
  11454. name: "implementationRef",
  11455. isAttr: true,
  11456. type: "String"
  11457. }
  11458. ]
  11459. },
  11460. {
  11461. name: "Operation",
  11462. superClass: [
  11463. "BaseElement"
  11464. ],
  11465. properties: [
  11466. {
  11467. name: "name",
  11468. isAttr: true,
  11469. type: "String"
  11470. },
  11471. {
  11472. name: "inMessageRef",
  11473. type: "Message",
  11474. isReference: true
  11475. },
  11476. {
  11477. name: "outMessageRef",
  11478. type: "Message",
  11479. isReference: true
  11480. },
  11481. {
  11482. name: "errorRef",
  11483. type: "Error",
  11484. isMany: true,
  11485. isReference: true
  11486. },
  11487. {
  11488. name: "implementationRef",
  11489. isAttr: true,
  11490. type: "String"
  11491. }
  11492. ]
  11493. },
  11494. {
  11495. name: "EndPoint",
  11496. superClass: [
  11497. "RootElement"
  11498. ]
  11499. },
  11500. {
  11501. name: "Auditing",
  11502. superClass: [
  11503. "BaseElement"
  11504. ]
  11505. },
  11506. {
  11507. name: "GlobalTask",
  11508. superClass: [
  11509. "CallableElement"
  11510. ],
  11511. properties: [
  11512. {
  11513. name: "resources",
  11514. type: "ResourceRole",
  11515. isMany: true
  11516. }
  11517. ]
  11518. },
  11519. {
  11520. name: "Monitoring",
  11521. superClass: [
  11522. "BaseElement"
  11523. ]
  11524. },
  11525. {
  11526. name: "Performer",
  11527. superClass: [
  11528. "ResourceRole"
  11529. ]
  11530. },
  11531. {
  11532. name: "Process",
  11533. superClass: [
  11534. "FlowElementsContainer",
  11535. "CallableElement"
  11536. ],
  11537. properties: [
  11538. {
  11539. name: "processType",
  11540. type: "ProcessType",
  11541. isAttr: true
  11542. },
  11543. {
  11544. name: "isClosed",
  11545. isAttr: true,
  11546. type: "Boolean"
  11547. },
  11548. {
  11549. name: "auditing",
  11550. type: "Auditing"
  11551. },
  11552. {
  11553. name: "monitoring",
  11554. type: "Monitoring"
  11555. },
  11556. {
  11557. name: "properties",
  11558. type: "Property",
  11559. isMany: true
  11560. },
  11561. {
  11562. name: "laneSets",
  11563. isMany: true,
  11564. replaces: "FlowElementsContainer#laneSets",
  11565. type: "LaneSet"
  11566. },
  11567. {
  11568. name: "flowElements",
  11569. isMany: true,
  11570. replaces: "FlowElementsContainer#flowElements",
  11571. type: "FlowElement"
  11572. },
  11573. {
  11574. name: "artifacts",
  11575. type: "Artifact",
  11576. isMany: true
  11577. },
  11578. {
  11579. name: "resources",
  11580. type: "ResourceRole",
  11581. isMany: true
  11582. },
  11583. {
  11584. name: "correlationSubscriptions",
  11585. type: "CorrelationSubscription",
  11586. isMany: true
  11587. },
  11588. {
  11589. name: "supports",
  11590. type: "Process",
  11591. isMany: true,
  11592. isReference: true
  11593. },
  11594. {
  11595. name: "definitionalCollaborationRef",
  11596. type: "Collaboration",
  11597. isAttr: true,
  11598. isReference: true
  11599. },
  11600. {
  11601. name: "isExecutable",
  11602. isAttr: true,
  11603. type: "Boolean"
  11604. }
  11605. ]
  11606. },
  11607. {
  11608. name: "LaneSet",
  11609. superClass: [
  11610. "BaseElement"
  11611. ],
  11612. properties: [
  11613. {
  11614. name: "lanes",
  11615. type: "Lane",
  11616. isMany: true
  11617. },
  11618. {
  11619. name: "name",
  11620. isAttr: true,
  11621. type: "String"
  11622. }
  11623. ]
  11624. },
  11625. {
  11626. name: "Lane",
  11627. superClass: [
  11628. "BaseElement"
  11629. ],
  11630. properties: [
  11631. {
  11632. name: "name",
  11633. isAttr: true,
  11634. type: "String"
  11635. },
  11636. {
  11637. name: "partitionElementRef",
  11638. type: "BaseElement",
  11639. isAttr: true,
  11640. isReference: true
  11641. },
  11642. {
  11643. name: "partitionElement",
  11644. type: "BaseElement"
  11645. },
  11646. {
  11647. name: "flowNodeRef",
  11648. type: "FlowNode",
  11649. isMany: true,
  11650. isReference: true
  11651. },
  11652. {
  11653. name: "childLaneSet",
  11654. type: "LaneSet",
  11655. xml: {
  11656. serialize: "xsi:type"
  11657. }
  11658. }
  11659. ]
  11660. },
  11661. {
  11662. name: "GlobalManualTask",
  11663. superClass: [
  11664. "GlobalTask"
  11665. ]
  11666. },
  11667. {
  11668. name: "ManualTask",
  11669. superClass: [
  11670. "Task"
  11671. ]
  11672. },
  11673. {
  11674. name: "UserTask",
  11675. superClass: [
  11676. "Task"
  11677. ],
  11678. properties: [
  11679. {
  11680. name: "renderings",
  11681. type: "Rendering",
  11682. isMany: true
  11683. },
  11684. {
  11685. name: "implementation",
  11686. isAttr: true,
  11687. type: "String"
  11688. }
  11689. ]
  11690. },
  11691. {
  11692. name: "Rendering",
  11693. superClass: [
  11694. "BaseElement"
  11695. ]
  11696. },
  11697. {
  11698. name: "HumanPerformer",
  11699. superClass: [
  11700. "Performer"
  11701. ]
  11702. },
  11703. {
  11704. name: "PotentialOwner",
  11705. superClass: [
  11706. "HumanPerformer"
  11707. ]
  11708. },
  11709. {
  11710. name: "GlobalUserTask",
  11711. superClass: [
  11712. "GlobalTask"
  11713. ],
  11714. properties: [
  11715. {
  11716. name: "implementation",
  11717. isAttr: true,
  11718. type: "String"
  11719. },
  11720. {
  11721. name: "renderings",
  11722. type: "Rendering",
  11723. isMany: true
  11724. }
  11725. ]
  11726. },
  11727. {
  11728. name: "Gateway",
  11729. isAbstract: true,
  11730. superClass: [
  11731. "FlowNode"
  11732. ],
  11733. properties: [
  11734. {
  11735. name: "gatewayDirection",
  11736. type: "GatewayDirection",
  11737. "default": "Unspecified",
  11738. isAttr: true
  11739. }
  11740. ]
  11741. },
  11742. {
  11743. name: "EventBasedGateway",
  11744. superClass: [
  11745. "Gateway"
  11746. ],
  11747. properties: [
  11748. {
  11749. name: "instantiate",
  11750. "default": false,
  11751. isAttr: true,
  11752. type: "Boolean"
  11753. },
  11754. {
  11755. name: "eventGatewayType",
  11756. type: "EventBasedGatewayType",
  11757. isAttr: true,
  11758. "default": "Exclusive"
  11759. }
  11760. ]
  11761. },
  11762. {
  11763. name: "ComplexGateway",
  11764. superClass: [
  11765. "Gateway"
  11766. ],
  11767. properties: [
  11768. {
  11769. name: "activationCondition",
  11770. type: "Expression",
  11771. xml: {
  11772. serialize: "xsi:type"
  11773. }
  11774. },
  11775. {
  11776. name: "default",
  11777. type: "SequenceFlow",
  11778. isAttr: true,
  11779. isReference: true
  11780. }
  11781. ]
  11782. },
  11783. {
  11784. name: "ExclusiveGateway",
  11785. superClass: [
  11786. "Gateway"
  11787. ],
  11788. properties: [
  11789. {
  11790. name: "default",
  11791. type: "SequenceFlow",
  11792. isAttr: true,
  11793. isReference: true
  11794. }
  11795. ]
  11796. },
  11797. {
  11798. name: "InclusiveGateway",
  11799. superClass: [
  11800. "Gateway"
  11801. ],
  11802. properties: [
  11803. {
  11804. name: "default",
  11805. type: "SequenceFlow",
  11806. isAttr: true,
  11807. isReference: true
  11808. }
  11809. ]
  11810. },
  11811. {
  11812. name: "ParallelGateway",
  11813. superClass: [
  11814. "Gateway"
  11815. ]
  11816. },
  11817. {
  11818. name: "RootElement",
  11819. isAbstract: true,
  11820. superClass: [
  11821. "BaseElement"
  11822. ]
  11823. },
  11824. {
  11825. name: "Relationship",
  11826. superClass: [
  11827. "BaseElement"
  11828. ],
  11829. properties: [
  11830. {
  11831. name: "type",
  11832. isAttr: true,
  11833. type: "String"
  11834. },
  11835. {
  11836. name: "direction",
  11837. type: "RelationshipDirection",
  11838. isAttr: true
  11839. },
  11840. {
  11841. name: "source",
  11842. isMany: true,
  11843. isReference: true,
  11844. type: "Element"
  11845. },
  11846. {
  11847. name: "target",
  11848. isMany: true,
  11849. isReference: true,
  11850. type: "Element"
  11851. }
  11852. ]
  11853. },
  11854. {
  11855. name: "BaseElement",
  11856. isAbstract: true,
  11857. properties: [
  11858. {
  11859. name: "id",
  11860. isAttr: true,
  11861. type: "String",
  11862. isId: true
  11863. },
  11864. {
  11865. name: "documentation",
  11866. type: "Documentation",
  11867. isMany: true
  11868. },
  11869. {
  11870. name: "extensionDefinitions",
  11871. type: "ExtensionDefinition",
  11872. isMany: true,
  11873. isReference: true
  11874. },
  11875. {
  11876. name: "extensionElements",
  11877. type: "ExtensionElements"
  11878. }
  11879. ]
  11880. },
  11881. {
  11882. name: "Extension",
  11883. properties: [
  11884. {
  11885. name: "mustUnderstand",
  11886. "default": false,
  11887. isAttr: true,
  11888. type: "Boolean"
  11889. },
  11890. {
  11891. name: "definition",
  11892. type: "ExtensionDefinition",
  11893. isAttr: true,
  11894. isReference: true
  11895. }
  11896. ]
  11897. },
  11898. {
  11899. name: "ExtensionDefinition",
  11900. properties: [
  11901. {
  11902. name: "name",
  11903. isAttr: true,
  11904. type: "String"
  11905. },
  11906. {
  11907. name: "extensionAttributeDefinitions",
  11908. type: "ExtensionAttributeDefinition",
  11909. isMany: true
  11910. }
  11911. ]
  11912. },
  11913. {
  11914. name: "ExtensionAttributeDefinition",
  11915. properties: [
  11916. {
  11917. name: "name",
  11918. isAttr: true,
  11919. type: "String"
  11920. },
  11921. {
  11922. name: "type",
  11923. isAttr: true,
  11924. type: "String"
  11925. },
  11926. {
  11927. name: "isReference",
  11928. "default": false,
  11929. isAttr: true,
  11930. type: "Boolean"
  11931. },
  11932. {
  11933. name: "extensionDefinition",
  11934. type: "ExtensionDefinition",
  11935. isAttr: true,
  11936. isReference: true
  11937. }
  11938. ]
  11939. },
  11940. {
  11941. name: "ExtensionElements",
  11942. properties: [
  11943. {
  11944. name: "valueRef",
  11945. isAttr: true,
  11946. isReference: true,
  11947. type: "Element"
  11948. },
  11949. {
  11950. name: "values",
  11951. type: "Element",
  11952. isMany: true
  11953. },
  11954. {
  11955. name: "extensionAttributeDefinition",
  11956. type: "ExtensionAttributeDefinition",
  11957. isAttr: true,
  11958. isReference: true
  11959. }
  11960. ]
  11961. },
  11962. {
  11963. name: "Documentation",
  11964. superClass: [
  11965. "BaseElement"
  11966. ],
  11967. properties: [
  11968. {
  11969. name: "text",
  11970. type: "String",
  11971. isBody: true
  11972. },
  11973. {
  11974. name: "textFormat",
  11975. "default": "text/plain",
  11976. isAttr: true,
  11977. type: "String"
  11978. }
  11979. ]
  11980. },
  11981. {
  11982. name: "Event",
  11983. isAbstract: true,
  11984. superClass: [
  11985. "FlowNode",
  11986. "InteractionNode"
  11987. ],
  11988. properties: [
  11989. {
  11990. name: "properties",
  11991. type: "Property",
  11992. isMany: true
  11993. }
  11994. ]
  11995. },
  11996. {
  11997. name: "IntermediateCatchEvent",
  11998. superClass: [
  11999. "CatchEvent"
  12000. ]
  12001. },
  12002. {
  12003. name: "IntermediateThrowEvent",
  12004. superClass: [
  12005. "ThrowEvent"
  12006. ]
  12007. },
  12008. {
  12009. name: "EndEvent",
  12010. superClass: [
  12011. "ThrowEvent"
  12012. ]
  12013. },
  12014. {
  12015. name: "StartEvent",
  12016. superClass: [
  12017. "CatchEvent"
  12018. ],
  12019. properties: [
  12020. {
  12021. name: "isInterrupting",
  12022. "default": true,
  12023. isAttr: true,
  12024. type: "Boolean"
  12025. }
  12026. ]
  12027. },
  12028. {
  12029. name: "ThrowEvent",
  12030. isAbstract: true,
  12031. superClass: [
  12032. "Event"
  12033. ],
  12034. properties: [
  12035. {
  12036. name: "dataInputs",
  12037. type: "DataInput",
  12038. isMany: true
  12039. },
  12040. {
  12041. name: "dataInputAssociations",
  12042. type: "DataInputAssociation",
  12043. isMany: true
  12044. },
  12045. {
  12046. name: "inputSet",
  12047. type: "InputSet"
  12048. },
  12049. {
  12050. name: "eventDefinitions",
  12051. type: "EventDefinition",
  12052. isMany: true
  12053. },
  12054. {
  12055. name: "eventDefinitionRef",
  12056. type: "EventDefinition",
  12057. isMany: true,
  12058. isReference: true
  12059. }
  12060. ]
  12061. },
  12062. {
  12063. name: "CatchEvent",
  12064. isAbstract: true,
  12065. superClass: [
  12066. "Event"
  12067. ],
  12068. properties: [
  12069. {
  12070. name: "parallelMultiple",
  12071. isAttr: true,
  12072. type: "Boolean",
  12073. "default": false
  12074. },
  12075. {
  12076. name: "dataOutputs",
  12077. type: "DataOutput",
  12078. isMany: true
  12079. },
  12080. {
  12081. name: "dataOutputAssociations",
  12082. type: "DataOutputAssociation",
  12083. isMany: true
  12084. },
  12085. {
  12086. name: "outputSet",
  12087. type: "OutputSet"
  12088. },
  12089. {
  12090. name: "eventDefinitions",
  12091. type: "EventDefinition",
  12092. isMany: true
  12093. },
  12094. {
  12095. name: "eventDefinitionRef",
  12096. type: "EventDefinition",
  12097. isMany: true,
  12098. isReference: true
  12099. }
  12100. ]
  12101. },
  12102. {
  12103. name: "BoundaryEvent",
  12104. superClass: [
  12105. "CatchEvent"
  12106. ],
  12107. properties: [
  12108. {
  12109. name: "cancelActivity",
  12110. "default": true,
  12111. isAttr: true,
  12112. type: "Boolean"
  12113. },
  12114. {
  12115. name: "attachedToRef",
  12116. type: "Activity",
  12117. isAttr: true,
  12118. isReference: true
  12119. }
  12120. ]
  12121. },
  12122. {
  12123. name: "EventDefinition",
  12124. isAbstract: true,
  12125. superClass: [
  12126. "RootElement"
  12127. ]
  12128. },
  12129. {
  12130. name: "CancelEventDefinition",
  12131. superClass: [
  12132. "EventDefinition"
  12133. ]
  12134. },
  12135. {
  12136. name: "ErrorEventDefinition",
  12137. superClass: [
  12138. "EventDefinition"
  12139. ],
  12140. properties: [
  12141. {
  12142. name: "errorRef",
  12143. type: "Error",
  12144. isAttr: true,
  12145. isReference: true
  12146. }
  12147. ]
  12148. },
  12149. {
  12150. name: "TerminateEventDefinition",
  12151. superClass: [
  12152. "EventDefinition"
  12153. ]
  12154. },
  12155. {
  12156. name: "EscalationEventDefinition",
  12157. superClass: [
  12158. "EventDefinition"
  12159. ],
  12160. properties: [
  12161. {
  12162. name: "escalationRef",
  12163. type: "Escalation",
  12164. isAttr: true,
  12165. isReference: true
  12166. }
  12167. ]
  12168. },
  12169. {
  12170. name: "Escalation",
  12171. properties: [
  12172. {
  12173. name: "structureRef",
  12174. type: "ItemDefinition",
  12175. isAttr: true,
  12176. isReference: true
  12177. },
  12178. {
  12179. name: "name",
  12180. isAttr: true,
  12181. type: "String"
  12182. },
  12183. {
  12184. name: "escalationCode",
  12185. isAttr: true,
  12186. type: "String"
  12187. }
  12188. ],
  12189. superClass: [
  12190. "RootElement"
  12191. ]
  12192. },
  12193. {
  12194. name: "CompensateEventDefinition",
  12195. superClass: [
  12196. "EventDefinition"
  12197. ],
  12198. properties: [
  12199. {
  12200. name: "waitForCompletion",
  12201. isAttr: true,
  12202. type: "Boolean",
  12203. "default": true
  12204. },
  12205. {
  12206. name: "activityRef",
  12207. type: "Activity",
  12208. isAttr: true,
  12209. isReference: true
  12210. }
  12211. ]
  12212. },
  12213. {
  12214. name: "TimerEventDefinition",
  12215. superClass: [
  12216. "EventDefinition"
  12217. ],
  12218. properties: [
  12219. {
  12220. name: "timeDate",
  12221. type: "Expression",
  12222. xml: {
  12223. serialize: "xsi:type"
  12224. }
  12225. },
  12226. {
  12227. name: "timeCycle",
  12228. type: "Expression",
  12229. xml: {
  12230. serialize: "xsi:type"
  12231. }
  12232. },
  12233. {
  12234. name: "timeDuration",
  12235. type: "Expression",
  12236. xml: {
  12237. serialize: "xsi:type"
  12238. }
  12239. }
  12240. ]
  12241. },
  12242. {
  12243. name: "LinkEventDefinition",
  12244. superClass: [
  12245. "EventDefinition"
  12246. ],
  12247. properties: [
  12248. {
  12249. name: "name",
  12250. isAttr: true,
  12251. type: "String"
  12252. },
  12253. {
  12254. name: "target",
  12255. type: "LinkEventDefinition",
  12256. isAttr: true,
  12257. isReference: true
  12258. },
  12259. {
  12260. name: "source",
  12261. type: "LinkEventDefinition",
  12262. isMany: true,
  12263. isReference: true
  12264. }
  12265. ]
  12266. },
  12267. {
  12268. name: "MessageEventDefinition",
  12269. superClass: [
  12270. "EventDefinition"
  12271. ],
  12272. properties: [
  12273. {
  12274. name: "messageRef",
  12275. type: "Message",
  12276. isAttr: true,
  12277. isReference: true
  12278. },
  12279. {
  12280. name: "operationRef",
  12281. type: "Operation",
  12282. isAttr: true,
  12283. isReference: true
  12284. }
  12285. ]
  12286. },
  12287. {
  12288. name: "ConditionalEventDefinition",
  12289. superClass: [
  12290. "EventDefinition"
  12291. ],
  12292. properties: [
  12293. {
  12294. name: "condition",
  12295. type: "Expression",
  12296. xml: {
  12297. serialize: "xsi:type"
  12298. }
  12299. }
  12300. ]
  12301. },
  12302. {
  12303. name: "SignalEventDefinition",
  12304. superClass: [
  12305. "EventDefinition"
  12306. ],
  12307. properties: [
  12308. {
  12309. name: "signalRef",
  12310. type: "Signal",
  12311. isAttr: true,
  12312. isReference: true
  12313. }
  12314. ]
  12315. },
  12316. {
  12317. name: "Signal",
  12318. superClass: [
  12319. "RootElement"
  12320. ],
  12321. properties: [
  12322. {
  12323. name: "structureRef",
  12324. type: "ItemDefinition",
  12325. isAttr: true,
  12326. isReference: true
  12327. },
  12328. {
  12329. name: "name",
  12330. isAttr: true,
  12331. type: "String"
  12332. }
  12333. ]
  12334. },
  12335. {
  12336. name: "ImplicitThrowEvent",
  12337. superClass: [
  12338. "ThrowEvent"
  12339. ]
  12340. },
  12341. {
  12342. name: "DataState",
  12343. superClass: [
  12344. "BaseElement"
  12345. ],
  12346. properties: [
  12347. {
  12348. name: "name",
  12349. isAttr: true,
  12350. type: "String"
  12351. }
  12352. ]
  12353. },
  12354. {
  12355. name: "ItemAwareElement",
  12356. superClass: [
  12357. "BaseElement"
  12358. ],
  12359. properties: [
  12360. {
  12361. name: "itemSubjectRef",
  12362. type: "ItemDefinition",
  12363. isAttr: true,
  12364. isReference: true
  12365. },
  12366. {
  12367. name: "dataState",
  12368. type: "DataState"
  12369. }
  12370. ]
  12371. },
  12372. {
  12373. name: "DataAssociation",
  12374. superClass: [
  12375. "BaseElement"
  12376. ],
  12377. properties: [
  12378. {
  12379. name: "sourceRef",
  12380. type: "ItemAwareElement",
  12381. isMany: true,
  12382. isReference: true
  12383. },
  12384. {
  12385. name: "targetRef",
  12386. type: "ItemAwareElement",
  12387. isReference: true
  12388. },
  12389. {
  12390. name: "transformation",
  12391. type: "FormalExpression",
  12392. xml: {
  12393. serialize: "property"
  12394. }
  12395. },
  12396. {
  12397. name: "assignment",
  12398. type: "Assignment",
  12399. isMany: true
  12400. }
  12401. ]
  12402. },
  12403. {
  12404. name: "DataInput",
  12405. superClass: [
  12406. "ItemAwareElement"
  12407. ],
  12408. properties: [
  12409. {
  12410. name: "name",
  12411. isAttr: true,
  12412. type: "String"
  12413. },
  12414. {
  12415. name: "isCollection",
  12416. "default": false,
  12417. isAttr: true,
  12418. type: "Boolean"
  12419. },
  12420. {
  12421. name: "inputSetRef",
  12422. type: "InputSet",
  12423. isMany: true,
  12424. isVirtual: true,
  12425. isReference: true
  12426. },
  12427. {
  12428. name: "inputSetWithOptional",
  12429. type: "InputSet",
  12430. isMany: true,
  12431. isVirtual: true,
  12432. isReference: true
  12433. },
  12434. {
  12435. name: "inputSetWithWhileExecuting",
  12436. type: "InputSet",
  12437. isMany: true,
  12438. isVirtual: true,
  12439. isReference: true
  12440. }
  12441. ]
  12442. },
  12443. {
  12444. name: "DataOutput",
  12445. superClass: [
  12446. "ItemAwareElement"
  12447. ],
  12448. properties: [
  12449. {
  12450. name: "name",
  12451. isAttr: true,
  12452. type: "String"
  12453. },
  12454. {
  12455. name: "isCollection",
  12456. "default": false,
  12457. isAttr: true,
  12458. type: "Boolean"
  12459. },
  12460. {
  12461. name: "outputSetRef",
  12462. type: "OutputSet",
  12463. isMany: true,
  12464. isVirtual: true,
  12465. isReference: true
  12466. },
  12467. {
  12468. name: "outputSetWithOptional",
  12469. type: "OutputSet",
  12470. isMany: true,
  12471. isVirtual: true,
  12472. isReference: true
  12473. },
  12474. {
  12475. name: "outputSetWithWhileExecuting",
  12476. type: "OutputSet",
  12477. isMany: true,
  12478. isVirtual: true,
  12479. isReference: true
  12480. }
  12481. ]
  12482. },
  12483. {
  12484. name: "InputSet",
  12485. superClass: [
  12486. "BaseElement"
  12487. ],
  12488. properties: [
  12489. {
  12490. name: "name",
  12491. isAttr: true,
  12492. type: "String"
  12493. },
  12494. {
  12495. name: "dataInputRefs",
  12496. type: "DataInput",
  12497. isMany: true,
  12498. isReference: true
  12499. },
  12500. {
  12501. name: "optionalInputRefs",
  12502. type: "DataInput",
  12503. isMany: true,
  12504. isReference: true
  12505. },
  12506. {
  12507. name: "whileExecutingInputRefs",
  12508. type: "DataInput",
  12509. isMany: true,
  12510. isReference: true
  12511. },
  12512. {
  12513. name: "outputSetRefs",
  12514. type: "OutputSet",
  12515. isMany: true,
  12516. isReference: true
  12517. }
  12518. ]
  12519. },
  12520. {
  12521. name: "OutputSet",
  12522. superClass: [
  12523. "BaseElement"
  12524. ],
  12525. properties: [
  12526. {
  12527. name: "dataOutputRefs",
  12528. type: "DataOutput",
  12529. isMany: true,
  12530. isReference: true
  12531. },
  12532. {
  12533. name: "name",
  12534. isAttr: true,
  12535. type: "String"
  12536. },
  12537. {
  12538. name: "inputSetRefs",
  12539. type: "InputSet",
  12540. isMany: true,
  12541. isReference: true
  12542. },
  12543. {
  12544. name: "optionalOutputRefs",
  12545. type: "DataOutput",
  12546. isMany: true,
  12547. isReference: true
  12548. },
  12549. {
  12550. name: "whileExecutingOutputRefs",
  12551. type: "DataOutput",
  12552. isMany: true,
  12553. isReference: true
  12554. }
  12555. ]
  12556. },
  12557. {
  12558. name: "Property",
  12559. superClass: [
  12560. "ItemAwareElement"
  12561. ],
  12562. properties: [
  12563. {
  12564. name: "name",
  12565. isAttr: true,
  12566. type: "String"
  12567. }
  12568. ]
  12569. },
  12570. {
  12571. name: "DataInputAssociation",
  12572. superClass: [
  12573. "DataAssociation"
  12574. ]
  12575. },
  12576. {
  12577. name: "DataOutputAssociation",
  12578. superClass: [
  12579. "DataAssociation"
  12580. ]
  12581. },
  12582. {
  12583. name: "InputOutputSpecification",
  12584. superClass: [
  12585. "BaseElement"
  12586. ],
  12587. properties: [
  12588. {
  12589. name: "dataInputs",
  12590. type: "DataInput",
  12591. isMany: true
  12592. },
  12593. {
  12594. name: "dataOutputs",
  12595. type: "DataOutput",
  12596. isMany: true
  12597. },
  12598. {
  12599. name: "inputSets",
  12600. type: "InputSet",
  12601. isMany: true
  12602. },
  12603. {
  12604. name: "outputSets",
  12605. type: "OutputSet",
  12606. isMany: true
  12607. }
  12608. ]
  12609. },
  12610. {
  12611. name: "DataObject",
  12612. superClass: [
  12613. "FlowElement",
  12614. "ItemAwareElement"
  12615. ],
  12616. properties: [
  12617. {
  12618. name: "isCollection",
  12619. "default": false,
  12620. isAttr: true,
  12621. type: "Boolean"
  12622. }
  12623. ]
  12624. },
  12625. {
  12626. name: "InputOutputBinding",
  12627. properties: [
  12628. {
  12629. name: "inputDataRef",
  12630. type: "InputSet",
  12631. isAttr: true,
  12632. isReference: true
  12633. },
  12634. {
  12635. name: "outputDataRef",
  12636. type: "OutputSet",
  12637. isAttr: true,
  12638. isReference: true
  12639. },
  12640. {
  12641. name: "operationRef",
  12642. type: "Operation",
  12643. isAttr: true,
  12644. isReference: true
  12645. }
  12646. ]
  12647. },
  12648. {
  12649. name: "Assignment",
  12650. superClass: [
  12651. "BaseElement"
  12652. ],
  12653. properties: [
  12654. {
  12655. name: "from",
  12656. type: "Expression",
  12657. xml: {
  12658. serialize: "xsi:type"
  12659. }
  12660. },
  12661. {
  12662. name: "to",
  12663. type: "Expression",
  12664. xml: {
  12665. serialize: "xsi:type"
  12666. }
  12667. }
  12668. ]
  12669. },
  12670. {
  12671. name: "DataStore",
  12672. superClass: [
  12673. "RootElement",
  12674. "ItemAwareElement"
  12675. ],
  12676. properties: [
  12677. {
  12678. name: "name",
  12679. isAttr: true,
  12680. type: "String"
  12681. },
  12682. {
  12683. name: "capacity",
  12684. isAttr: true,
  12685. type: "Integer"
  12686. },
  12687. {
  12688. name: "isUnlimited",
  12689. "default": true,
  12690. isAttr: true,
  12691. type: "Boolean"
  12692. }
  12693. ]
  12694. },
  12695. {
  12696. name: "DataStoreReference",
  12697. superClass: [
  12698. "ItemAwareElement",
  12699. "FlowElement"
  12700. ],
  12701. properties: [
  12702. {
  12703. name: "dataStoreRef",
  12704. type: "DataStore",
  12705. isAttr: true,
  12706. isReference: true
  12707. }
  12708. ]
  12709. },
  12710. {
  12711. name: "DataObjectReference",
  12712. superClass: [
  12713. "ItemAwareElement",
  12714. "FlowElement"
  12715. ],
  12716. properties: [
  12717. {
  12718. name: "dataObjectRef",
  12719. type: "DataObject",
  12720. isAttr: true,
  12721. isReference: true
  12722. }
  12723. ]
  12724. },
  12725. {
  12726. name: "ConversationLink",
  12727. superClass: [
  12728. "BaseElement"
  12729. ],
  12730. properties: [
  12731. {
  12732. name: "sourceRef",
  12733. type: "InteractionNode",
  12734. isAttr: true,
  12735. isReference: true
  12736. },
  12737. {
  12738. name: "targetRef",
  12739. type: "InteractionNode",
  12740. isAttr: true,
  12741. isReference: true
  12742. },
  12743. {
  12744. name: "name",
  12745. isAttr: true,
  12746. type: "String"
  12747. }
  12748. ]
  12749. },
  12750. {
  12751. name: "ConversationAssociation",
  12752. superClass: [
  12753. "BaseElement"
  12754. ],
  12755. properties: [
  12756. {
  12757. name: "innerConversationNodeRef",
  12758. type: "ConversationNode",
  12759. isAttr: true,
  12760. isReference: true
  12761. },
  12762. {
  12763. name: "outerConversationNodeRef",
  12764. type: "ConversationNode",
  12765. isAttr: true,
  12766. isReference: true
  12767. }
  12768. ]
  12769. },
  12770. {
  12771. name: "CallConversation",
  12772. superClass: [
  12773. "ConversationNode"
  12774. ],
  12775. properties: [
  12776. {
  12777. name: "calledCollaborationRef",
  12778. type: "Collaboration",
  12779. isAttr: true,
  12780. isReference: true
  12781. },
  12782. {
  12783. name: "participantAssociations",
  12784. type: "ParticipantAssociation",
  12785. isMany: true
  12786. }
  12787. ]
  12788. },
  12789. {
  12790. name: "Conversation",
  12791. superClass: [
  12792. "ConversationNode"
  12793. ]
  12794. },
  12795. {
  12796. name: "SubConversation",
  12797. superClass: [
  12798. "ConversationNode"
  12799. ],
  12800. properties: [
  12801. {
  12802. name: "conversationNodes",
  12803. type: "ConversationNode",
  12804. isMany: true
  12805. }
  12806. ]
  12807. },
  12808. {
  12809. name: "ConversationNode",
  12810. isAbstract: true,
  12811. superClass: [
  12812. "InteractionNode",
  12813. "BaseElement"
  12814. ],
  12815. properties: [
  12816. {
  12817. name: "name",
  12818. isAttr: true,
  12819. type: "String"
  12820. },
  12821. {
  12822. name: "participantRef",
  12823. type: "Participant",
  12824. isMany: true,
  12825. isReference: true
  12826. },
  12827. {
  12828. name: "messageFlowRefs",
  12829. type: "MessageFlow",
  12830. isMany: true,
  12831. isReference: true
  12832. },
  12833. {
  12834. name: "correlationKeys",
  12835. type: "CorrelationKey",
  12836. isMany: true
  12837. }
  12838. ]
  12839. },
  12840. {
  12841. name: "GlobalConversation",
  12842. superClass: [
  12843. "Collaboration"
  12844. ]
  12845. },
  12846. {
  12847. name: "PartnerEntity",
  12848. superClass: [
  12849. "RootElement"
  12850. ],
  12851. properties: [
  12852. {
  12853. name: "name",
  12854. isAttr: true,
  12855. type: "String"
  12856. },
  12857. {
  12858. name: "participantRef",
  12859. type: "Participant",
  12860. isMany: true,
  12861. isReference: true
  12862. }
  12863. ]
  12864. },
  12865. {
  12866. name: "PartnerRole",
  12867. superClass: [
  12868. "RootElement"
  12869. ],
  12870. properties: [
  12871. {
  12872. name: "name",
  12873. isAttr: true,
  12874. type: "String"
  12875. },
  12876. {
  12877. name: "participantRef",
  12878. type: "Participant",
  12879. isMany: true,
  12880. isReference: true
  12881. }
  12882. ]
  12883. },
  12884. {
  12885. name: "CorrelationProperty",
  12886. superClass: [
  12887. "RootElement"
  12888. ],
  12889. properties: [
  12890. {
  12891. name: "correlationPropertyRetrievalExpression",
  12892. type: "CorrelationPropertyRetrievalExpression",
  12893. isMany: true
  12894. },
  12895. {
  12896. name: "name",
  12897. isAttr: true,
  12898. type: "String"
  12899. },
  12900. {
  12901. name: "type",
  12902. type: "ItemDefinition",
  12903. isAttr: true,
  12904. isReference: true
  12905. }
  12906. ]
  12907. },
  12908. {
  12909. name: "Error",
  12910. superClass: [
  12911. "RootElement"
  12912. ],
  12913. properties: [
  12914. {
  12915. name: "structureRef",
  12916. type: "ItemDefinition",
  12917. isAttr: true,
  12918. isReference: true
  12919. },
  12920. {
  12921. name: "name",
  12922. isAttr: true,
  12923. type: "String"
  12924. },
  12925. {
  12926. name: "errorCode",
  12927. isAttr: true,
  12928. type: "String"
  12929. }
  12930. ]
  12931. },
  12932. {
  12933. name: "CorrelationKey",
  12934. superClass: [
  12935. "BaseElement"
  12936. ],
  12937. properties: [
  12938. {
  12939. name: "correlationPropertyRef",
  12940. type: "CorrelationProperty",
  12941. isMany: true,
  12942. isReference: true
  12943. },
  12944. {
  12945. name: "name",
  12946. isAttr: true,
  12947. type: "String"
  12948. }
  12949. ]
  12950. },
  12951. {
  12952. name: "Expression",
  12953. superClass: [
  12954. "BaseElement"
  12955. ],
  12956. isAbstract: false,
  12957. properties: [
  12958. {
  12959. name: "body",
  12960. isBody: true,
  12961. type: "String"
  12962. }
  12963. ]
  12964. },
  12965. {
  12966. name: "FormalExpression",
  12967. superClass: [
  12968. "Expression"
  12969. ],
  12970. properties: [
  12971. {
  12972. name: "language",
  12973. isAttr: true,
  12974. type: "String"
  12975. },
  12976. {
  12977. name: "evaluatesToTypeRef",
  12978. type: "ItemDefinition",
  12979. isAttr: true,
  12980. isReference: true
  12981. }
  12982. ]
  12983. },
  12984. {
  12985. name: "Message",
  12986. superClass: [
  12987. "RootElement"
  12988. ],
  12989. properties: [
  12990. {
  12991. name: "name",
  12992. isAttr: true,
  12993. type: "String"
  12994. },
  12995. {
  12996. name: "itemRef",
  12997. type: "ItemDefinition",
  12998. isAttr: true,
  12999. isReference: true
  13000. }
  13001. ]
  13002. },
  13003. {
  13004. name: "ItemDefinition",
  13005. superClass: [
  13006. "RootElement"
  13007. ],
  13008. properties: [
  13009. {
  13010. name: "itemKind",
  13011. type: "ItemKind",
  13012. isAttr: true
  13013. },
  13014. {
  13015. name: "structureRef",
  13016. isAttr: true,
  13017. type: "String"
  13018. },
  13019. {
  13020. name: "isCollection",
  13021. "default": false,
  13022. isAttr: true,
  13023. type: "Boolean"
  13024. },
  13025. {
  13026. name: "import",
  13027. type: "Import",
  13028. isAttr: true,
  13029. isReference: true
  13030. }
  13031. ]
  13032. },
  13033. {
  13034. name: "FlowElement",
  13035. isAbstract: true,
  13036. superClass: [
  13037. "BaseElement"
  13038. ],
  13039. properties: [
  13040. {
  13041. name: "name",
  13042. isAttr: true,
  13043. type: "String"
  13044. },
  13045. {
  13046. name: "auditing",
  13047. type: "Auditing"
  13048. },
  13049. {
  13050. name: "monitoring",
  13051. type: "Monitoring"
  13052. },
  13053. {
  13054. name: "categoryValueRef",
  13055. type: "CategoryValue",
  13056. isMany: true,
  13057. isReference: true
  13058. }
  13059. ]
  13060. },
  13061. {
  13062. name: "SequenceFlow",
  13063. superClass: [
  13064. "FlowElement"
  13065. ],
  13066. properties: [
  13067. {
  13068. name: "isImmediate",
  13069. isAttr: true,
  13070. type: "Boolean"
  13071. },
  13072. {
  13073. name: "conditionExpression",
  13074. type: "Expression",
  13075. xml: {
  13076. serialize: "xsi:type"
  13077. }
  13078. },
  13079. {
  13080. name: "sourceRef",
  13081. type: "FlowNode",
  13082. isAttr: true,
  13083. isReference: true
  13084. },
  13085. {
  13086. name: "targetRef",
  13087. type: "FlowNode",
  13088. isAttr: true,
  13089. isReference: true
  13090. }
  13091. ]
  13092. },
  13093. {
  13094. name: "FlowElementsContainer",
  13095. isAbstract: true,
  13096. superClass: [
  13097. "BaseElement"
  13098. ],
  13099. properties: [
  13100. {
  13101. name: "laneSets",
  13102. type: "LaneSet",
  13103. isMany: true
  13104. },
  13105. {
  13106. name: "flowElements",
  13107. type: "FlowElement",
  13108. isMany: true
  13109. }
  13110. ]
  13111. },
  13112. {
  13113. name: "CallableElement",
  13114. isAbstract: true,
  13115. superClass: [
  13116. "RootElement"
  13117. ],
  13118. properties: [
  13119. {
  13120. name: "name",
  13121. isAttr: true,
  13122. type: "String"
  13123. },
  13124. {
  13125. name: "ioSpecification",
  13126. type: "InputOutputSpecification",
  13127. xml: {
  13128. serialize: "property"
  13129. }
  13130. },
  13131. {
  13132. name: "supportedInterfaceRef",
  13133. type: "Interface",
  13134. isMany: true,
  13135. isReference: true
  13136. },
  13137. {
  13138. name: "ioBinding",
  13139. type: "InputOutputBinding",
  13140. isMany: true,
  13141. xml: {
  13142. serialize: "property"
  13143. }
  13144. }
  13145. ]
  13146. },
  13147. {
  13148. name: "FlowNode",
  13149. isAbstract: true,
  13150. superClass: [
  13151. "FlowElement"
  13152. ],
  13153. properties: [
  13154. {
  13155. name: "incoming",
  13156. type: "SequenceFlow",
  13157. isMany: true,
  13158. isReference: true
  13159. },
  13160. {
  13161. name: "outgoing",
  13162. type: "SequenceFlow",
  13163. isMany: true,
  13164. isReference: true
  13165. },
  13166. {
  13167. name: "lanes",
  13168. type: "Lane",
  13169. isMany: true,
  13170. isVirtual: true,
  13171. isReference: true
  13172. }
  13173. ]
  13174. },
  13175. {
  13176. name: "CorrelationPropertyRetrievalExpression",
  13177. superClass: [
  13178. "BaseElement"
  13179. ],
  13180. properties: [
  13181. {
  13182. name: "messagePath",
  13183. type: "FormalExpression"
  13184. },
  13185. {
  13186. name: "messageRef",
  13187. type: "Message",
  13188. isAttr: true,
  13189. isReference: true
  13190. }
  13191. ]
  13192. },
  13193. {
  13194. name: "CorrelationPropertyBinding",
  13195. superClass: [
  13196. "BaseElement"
  13197. ],
  13198. properties: [
  13199. {
  13200. name: "dataPath",
  13201. type: "FormalExpression"
  13202. },
  13203. {
  13204. name: "correlationPropertyRef",
  13205. type: "CorrelationProperty",
  13206. isAttr: true,
  13207. isReference: true
  13208. }
  13209. ]
  13210. },
  13211. {
  13212. name: "Resource",
  13213. superClass: [
  13214. "RootElement"
  13215. ],
  13216. properties: [
  13217. {
  13218. name: "name",
  13219. isAttr: true,
  13220. type: "String"
  13221. },
  13222. {
  13223. name: "resourceParameters",
  13224. type: "ResourceParameter",
  13225. isMany: true
  13226. }
  13227. ]
  13228. },
  13229. {
  13230. name: "ResourceParameter",
  13231. superClass: [
  13232. "BaseElement"
  13233. ],
  13234. properties: [
  13235. {
  13236. name: "name",
  13237. isAttr: true,
  13238. type: "String"
  13239. },
  13240. {
  13241. name: "isRequired",
  13242. isAttr: true,
  13243. type: "Boolean"
  13244. },
  13245. {
  13246. name: "type",
  13247. type: "ItemDefinition",
  13248. isAttr: true,
  13249. isReference: true
  13250. }
  13251. ]
  13252. },
  13253. {
  13254. name: "CorrelationSubscription",
  13255. superClass: [
  13256. "BaseElement"
  13257. ],
  13258. properties: [
  13259. {
  13260. name: "correlationKeyRef",
  13261. type: "CorrelationKey",
  13262. isAttr: true,
  13263. isReference: true
  13264. },
  13265. {
  13266. name: "correlationPropertyBinding",
  13267. type: "CorrelationPropertyBinding",
  13268. isMany: true
  13269. }
  13270. ]
  13271. },
  13272. {
  13273. name: "MessageFlow",
  13274. superClass: [
  13275. "BaseElement"
  13276. ],
  13277. properties: [
  13278. {
  13279. name: "name",
  13280. isAttr: true,
  13281. type: "String"
  13282. },
  13283. {
  13284. name: "sourceRef",
  13285. type: "InteractionNode",
  13286. isAttr: true,
  13287. isReference: true
  13288. },
  13289. {
  13290. name: "targetRef",
  13291. type: "InteractionNode",
  13292. isAttr: true,
  13293. isReference: true
  13294. },
  13295. {
  13296. name: "messageRef",
  13297. type: "Message",
  13298. isAttr: true,
  13299. isReference: true
  13300. }
  13301. ]
  13302. },
  13303. {
  13304. name: "MessageFlowAssociation",
  13305. superClass: [
  13306. "BaseElement"
  13307. ],
  13308. properties: [
  13309. {
  13310. name: "innerMessageFlowRef",
  13311. type: "MessageFlow",
  13312. isAttr: true,
  13313. isReference: true
  13314. },
  13315. {
  13316. name: "outerMessageFlowRef",
  13317. type: "MessageFlow",
  13318. isAttr: true,
  13319. isReference: true
  13320. }
  13321. ]
  13322. },
  13323. {
  13324. name: "InteractionNode",
  13325. isAbstract: true,
  13326. properties: [
  13327. {
  13328. name: "incomingConversationLinks",
  13329. type: "ConversationLink",
  13330. isMany: true,
  13331. isVirtual: true,
  13332. isReference: true
  13333. },
  13334. {
  13335. name: "outgoingConversationLinks",
  13336. type: "ConversationLink",
  13337. isMany: true,
  13338. isVirtual: true,
  13339. isReference: true
  13340. }
  13341. ]
  13342. },
  13343. {
  13344. name: "Participant",
  13345. superClass: [
  13346. "InteractionNode",
  13347. "BaseElement"
  13348. ],
  13349. properties: [
  13350. {
  13351. name: "name",
  13352. isAttr: true,
  13353. type: "String"
  13354. },
  13355. {
  13356. name: "interfaceRef",
  13357. type: "Interface",
  13358. isMany: true,
  13359. isReference: true
  13360. },
  13361. {
  13362. name: "participantMultiplicity",
  13363. type: "ParticipantMultiplicity"
  13364. },
  13365. {
  13366. name: "endPointRefs",
  13367. type: "EndPoint",
  13368. isMany: true,
  13369. isReference: true
  13370. },
  13371. {
  13372. name: "processRef",
  13373. type: "Process",
  13374. isAttr: true,
  13375. isReference: true
  13376. }
  13377. ]
  13378. },
  13379. {
  13380. name: "ParticipantAssociation",
  13381. superClass: [
  13382. "BaseElement"
  13383. ],
  13384. properties: [
  13385. {
  13386. name: "innerParticipantRef",
  13387. type: "Participant",
  13388. isAttr: true,
  13389. isReference: true
  13390. },
  13391. {
  13392. name: "outerParticipantRef",
  13393. type: "Participant",
  13394. isAttr: true,
  13395. isReference: true
  13396. }
  13397. ]
  13398. },
  13399. {
  13400. name: "ParticipantMultiplicity",
  13401. properties: [
  13402. {
  13403. name: "minimum",
  13404. "default": 0,
  13405. isAttr: true,
  13406. type: "Integer"
  13407. },
  13408. {
  13409. name: "maximum",
  13410. "default": 1,
  13411. isAttr: true,
  13412. type: "Integer"
  13413. }
  13414. ],
  13415. superClass: [
  13416. "BaseElement"
  13417. ]
  13418. },
  13419. {
  13420. name: "Collaboration",
  13421. superClass: [
  13422. "RootElement"
  13423. ],
  13424. properties: [
  13425. {
  13426. name: "name",
  13427. isAttr: true,
  13428. type: "String"
  13429. },
  13430. {
  13431. name: "isClosed",
  13432. isAttr: true,
  13433. type: "Boolean"
  13434. },
  13435. {
  13436. name: "participants",
  13437. type: "Participant",
  13438. isMany: true
  13439. },
  13440. {
  13441. name: "messageFlows",
  13442. type: "MessageFlow",
  13443. isMany: true
  13444. },
  13445. {
  13446. name: "artifacts",
  13447. type: "Artifact",
  13448. isMany: true
  13449. },
  13450. {
  13451. name: "conversations",
  13452. type: "ConversationNode",
  13453. isMany: true
  13454. },
  13455. {
  13456. name: "conversationAssociations",
  13457. type: "ConversationAssociation"
  13458. },
  13459. {
  13460. name: "participantAssociations",
  13461. type: "ParticipantAssociation",
  13462. isMany: true
  13463. },
  13464. {
  13465. name: "messageFlowAssociations",
  13466. type: "MessageFlowAssociation",
  13467. isMany: true
  13468. },
  13469. {
  13470. name: "correlationKeys",
  13471. type: "CorrelationKey",
  13472. isMany: true
  13473. },
  13474. {
  13475. name: "choreographyRef",
  13476. type: "Choreography",
  13477. isMany: true,
  13478. isReference: true
  13479. },
  13480. {
  13481. name: "conversationLinks",
  13482. type: "ConversationLink",
  13483. isMany: true
  13484. }
  13485. ]
  13486. },
  13487. {
  13488. name: "ChoreographyActivity",
  13489. isAbstract: true,
  13490. superClass: [
  13491. "FlowNode"
  13492. ],
  13493. properties: [
  13494. {
  13495. name: "participantRef",
  13496. type: "Participant",
  13497. isMany: true,
  13498. isReference: true
  13499. },
  13500. {
  13501. name: "initiatingParticipantRef",
  13502. type: "Participant",
  13503. isAttr: true,
  13504. isReference: true
  13505. },
  13506. {
  13507. name: "correlationKeys",
  13508. type: "CorrelationKey",
  13509. isMany: true
  13510. },
  13511. {
  13512. name: "loopType",
  13513. type: "ChoreographyLoopType",
  13514. "default": "None",
  13515. isAttr: true
  13516. }
  13517. ]
  13518. },
  13519. {
  13520. name: "CallChoreography",
  13521. superClass: [
  13522. "ChoreographyActivity"
  13523. ],
  13524. properties: [
  13525. {
  13526. name: "calledChoreographyRef",
  13527. type: "Choreography",
  13528. isAttr: true,
  13529. isReference: true
  13530. },
  13531. {
  13532. name: "participantAssociations",
  13533. type: "ParticipantAssociation",
  13534. isMany: true
  13535. }
  13536. ]
  13537. },
  13538. {
  13539. name: "SubChoreography",
  13540. superClass: [
  13541. "ChoreographyActivity",
  13542. "FlowElementsContainer"
  13543. ],
  13544. properties: [
  13545. {
  13546. name: "artifacts",
  13547. type: "Artifact",
  13548. isMany: true
  13549. }
  13550. ]
  13551. },
  13552. {
  13553. name: "ChoreographyTask",
  13554. superClass: [
  13555. "ChoreographyActivity"
  13556. ],
  13557. properties: [
  13558. {
  13559. name: "messageFlowRef",
  13560. type: "MessageFlow",
  13561. isMany: true,
  13562. isReference: true
  13563. }
  13564. ]
  13565. },
  13566. {
  13567. name: "Choreography",
  13568. superClass: [
  13569. "Collaboration",
  13570. "FlowElementsContainer"
  13571. ]
  13572. },
  13573. {
  13574. name: "GlobalChoreographyTask",
  13575. superClass: [
  13576. "Choreography"
  13577. ],
  13578. properties: [
  13579. {
  13580. name: "initiatingParticipantRef",
  13581. type: "Participant",
  13582. isAttr: true,
  13583. isReference: true
  13584. }
  13585. ]
  13586. },
  13587. {
  13588. name: "TextAnnotation",
  13589. superClass: [
  13590. "Artifact"
  13591. ],
  13592. properties: [
  13593. {
  13594. name: "text",
  13595. type: "String"
  13596. },
  13597. {
  13598. name: "textFormat",
  13599. "default": "text/plain",
  13600. isAttr: true,
  13601. type: "String"
  13602. }
  13603. ]
  13604. },
  13605. {
  13606. name: "Group",
  13607. superClass: [
  13608. "Artifact"
  13609. ],
  13610. properties: [
  13611. {
  13612. name: "categoryValueRef",
  13613. type: "CategoryValue",
  13614. isAttr: true,
  13615. isReference: true
  13616. }
  13617. ]
  13618. },
  13619. {
  13620. name: "Association",
  13621. superClass: [
  13622. "Artifact"
  13623. ],
  13624. properties: [
  13625. {
  13626. name: "associationDirection",
  13627. type: "AssociationDirection",
  13628. isAttr: true
  13629. },
  13630. {
  13631. name: "sourceRef",
  13632. type: "BaseElement",
  13633. isAttr: true,
  13634. isReference: true
  13635. },
  13636. {
  13637. name: "targetRef",
  13638. type: "BaseElement",
  13639. isAttr: true,
  13640. isReference: true
  13641. }
  13642. ]
  13643. },
  13644. {
  13645. name: "Category",
  13646. superClass: [
  13647. "RootElement"
  13648. ],
  13649. properties: [
  13650. {
  13651. name: "categoryValue",
  13652. type: "CategoryValue",
  13653. isMany: true
  13654. },
  13655. {
  13656. name: "name",
  13657. isAttr: true,
  13658. type: "String"
  13659. }
  13660. ]
  13661. },
  13662. {
  13663. name: "Artifact",
  13664. isAbstract: true,
  13665. superClass: [
  13666. "BaseElement"
  13667. ]
  13668. },
  13669. {
  13670. name: "CategoryValue",
  13671. superClass: [
  13672. "BaseElement"
  13673. ],
  13674. properties: [
  13675. {
  13676. name: "categorizedFlowElements",
  13677. type: "FlowElement",
  13678. isMany: true,
  13679. isVirtual: true,
  13680. isReference: true
  13681. },
  13682. {
  13683. name: "value",
  13684. isAttr: true,
  13685. type: "String"
  13686. }
  13687. ]
  13688. },
  13689. {
  13690. name: "Activity",
  13691. isAbstract: true,
  13692. superClass: [
  13693. "FlowNode"
  13694. ],
  13695. properties: [
  13696. {
  13697. name: "isForCompensation",
  13698. "default": false,
  13699. isAttr: true,
  13700. type: "Boolean"
  13701. },
  13702. {
  13703. name: "default",
  13704. type: "SequenceFlow",
  13705. isAttr: true,
  13706. isReference: true
  13707. },
  13708. {
  13709. name: "ioSpecification",
  13710. type: "InputOutputSpecification",
  13711. xml: {
  13712. serialize: "property"
  13713. }
  13714. },
  13715. {
  13716. name: "boundaryEventRefs",
  13717. type: "BoundaryEvent",
  13718. isMany: true,
  13719. isReference: true
  13720. },
  13721. {
  13722. name: "properties",
  13723. type: "Property",
  13724. isMany: true
  13725. },
  13726. {
  13727. name: "dataInputAssociations",
  13728. type: "DataInputAssociation",
  13729. isMany: true
  13730. },
  13731. {
  13732. name: "dataOutputAssociations",
  13733. type: "DataOutputAssociation",
  13734. isMany: true
  13735. },
  13736. {
  13737. name: "startQuantity",
  13738. "default": 1,
  13739. isAttr: true,
  13740. type: "Integer"
  13741. },
  13742. {
  13743. name: "resources",
  13744. type: "ResourceRole",
  13745. isMany: true
  13746. },
  13747. {
  13748. name: "completionQuantity",
  13749. "default": 1,
  13750. isAttr: true,
  13751. type: "Integer"
  13752. },
  13753. {
  13754. name: "loopCharacteristics",
  13755. type: "LoopCharacteristics"
  13756. }
  13757. ]
  13758. },
  13759. {
  13760. name: "ServiceTask",
  13761. superClass: [
  13762. "Task"
  13763. ],
  13764. properties: [
  13765. {
  13766. name: "implementation",
  13767. isAttr: true,
  13768. type: "String"
  13769. },
  13770. {
  13771. name: "operationRef",
  13772. type: "Operation",
  13773. isAttr: true,
  13774. isReference: true
  13775. }
  13776. ]
  13777. },
  13778. {
  13779. name: "SubProcess",
  13780. superClass: [
  13781. "Activity",
  13782. "FlowElementsContainer",
  13783. "InteractionNode"
  13784. ],
  13785. properties: [
  13786. {
  13787. name: "triggeredByEvent",
  13788. "default": false,
  13789. isAttr: true,
  13790. type: "Boolean"
  13791. },
  13792. {
  13793. name: "artifacts",
  13794. type: "Artifact",
  13795. isMany: true
  13796. }
  13797. ]
  13798. },
  13799. {
  13800. name: "LoopCharacteristics",
  13801. isAbstract: true,
  13802. superClass: [
  13803. "BaseElement"
  13804. ]
  13805. },
  13806. {
  13807. name: "MultiInstanceLoopCharacteristics",
  13808. superClass: [
  13809. "LoopCharacteristics"
  13810. ],
  13811. properties: [
  13812. {
  13813. name: "isSequential",
  13814. "default": false,
  13815. isAttr: true,
  13816. type: "Boolean"
  13817. },
  13818. {
  13819. name: "behavior",
  13820. type: "MultiInstanceBehavior",
  13821. "default": "All",
  13822. isAttr: true
  13823. },
  13824. {
  13825. name: "loopCardinality",
  13826. type: "Expression",
  13827. xml: {
  13828. serialize: "xsi:type"
  13829. }
  13830. },
  13831. {
  13832. name: "loopDataInputRef",
  13833. type: "ItemAwareElement",
  13834. isReference: true
  13835. },
  13836. {
  13837. name: "loopDataOutputRef",
  13838. type: "ItemAwareElement",
  13839. isReference: true
  13840. },
  13841. {
  13842. name: "inputDataItem",
  13843. type: "DataInput",
  13844. xml: {
  13845. serialize: "property"
  13846. }
  13847. },
  13848. {
  13849. name: "outputDataItem",
  13850. type: "DataOutput",
  13851. xml: {
  13852. serialize: "property"
  13853. }
  13854. },
  13855. {
  13856. name: "complexBehaviorDefinition",
  13857. type: "ComplexBehaviorDefinition",
  13858. isMany: true
  13859. },
  13860. {
  13861. name: "completionCondition",
  13862. type: "Expression",
  13863. xml: {
  13864. serialize: "xsi:type"
  13865. }
  13866. },
  13867. {
  13868. name: "oneBehaviorEventRef",
  13869. type: "EventDefinition",
  13870. isAttr: true,
  13871. isReference: true
  13872. },
  13873. {
  13874. name: "noneBehaviorEventRef",
  13875. type: "EventDefinition",
  13876. isAttr: true,
  13877. isReference: true
  13878. }
  13879. ]
  13880. },
  13881. {
  13882. name: "StandardLoopCharacteristics",
  13883. superClass: [
  13884. "LoopCharacteristics"
  13885. ],
  13886. properties: [
  13887. {
  13888. name: "testBefore",
  13889. "default": false,
  13890. isAttr: true,
  13891. type: "Boolean"
  13892. },
  13893. {
  13894. name: "loopCondition",
  13895. type: "Expression",
  13896. xml: {
  13897. serialize: "xsi:type"
  13898. }
  13899. },
  13900. {
  13901. name: "loopMaximum",
  13902. type: "Integer",
  13903. isAttr: true
  13904. }
  13905. ]
  13906. },
  13907. {
  13908. name: "CallActivity",
  13909. superClass: [
  13910. "Activity"
  13911. ],
  13912. properties: [
  13913. {
  13914. name: "calledElement",
  13915. type: "String",
  13916. isAttr: true
  13917. }
  13918. ]
  13919. },
  13920. {
  13921. name: "Task",
  13922. superClass: [
  13923. "Activity",
  13924. "InteractionNode"
  13925. ]
  13926. },
  13927. {
  13928. name: "SendTask",
  13929. superClass: [
  13930. "Task"
  13931. ],
  13932. properties: [
  13933. {
  13934. name: "implementation",
  13935. isAttr: true,
  13936. type: "String"
  13937. },
  13938. {
  13939. name: "operationRef",
  13940. type: "Operation",
  13941. isAttr: true,
  13942. isReference: true
  13943. },
  13944. {
  13945. name: "messageRef",
  13946. type: "Message",
  13947. isAttr: true,
  13948. isReference: true
  13949. }
  13950. ]
  13951. },
  13952. {
  13953. name: "ReceiveTask",
  13954. superClass: [
  13955. "Task"
  13956. ],
  13957. properties: [
  13958. {
  13959. name: "implementation",
  13960. isAttr: true,
  13961. type: "String"
  13962. },
  13963. {
  13964. name: "instantiate",
  13965. "default": false,
  13966. isAttr: true,
  13967. type: "Boolean"
  13968. },
  13969. {
  13970. name: "operationRef",
  13971. type: "Operation",
  13972. isAttr: true,
  13973. isReference: true
  13974. },
  13975. {
  13976. name: "messageRef",
  13977. type: "Message",
  13978. isAttr: true,
  13979. isReference: true
  13980. }
  13981. ]
  13982. },
  13983. {
  13984. name: "ScriptTask",
  13985. superClass: [
  13986. "Task"
  13987. ],
  13988. properties: [
  13989. {
  13990. name: "scriptFormat",
  13991. isAttr: true,
  13992. type: "String"
  13993. },
  13994. {
  13995. name: "script",
  13996. type: "String"
  13997. }
  13998. ]
  13999. },
  14000. {
  14001. name: "BusinessRuleTask",
  14002. superClass: [
  14003. "Task"
  14004. ],
  14005. properties: [
  14006. {
  14007. name: "implementation",
  14008. isAttr: true,
  14009. type: "String"
  14010. }
  14011. ]
  14012. },
  14013. {
  14014. name: "AdHocSubProcess",
  14015. superClass: [
  14016. "SubProcess"
  14017. ],
  14018. properties: [
  14019. {
  14020. name: "completionCondition",
  14021. type: "Expression",
  14022. xml: {
  14023. serialize: "xsi:type"
  14024. }
  14025. },
  14026. {
  14027. name: "ordering",
  14028. type: "AdHocOrdering",
  14029. isAttr: true
  14030. },
  14031. {
  14032. name: "cancelRemainingInstances",
  14033. "default": true,
  14034. isAttr: true,
  14035. type: "Boolean"
  14036. }
  14037. ]
  14038. },
  14039. {
  14040. name: "Transaction",
  14041. superClass: [
  14042. "SubProcess"
  14043. ],
  14044. properties: [
  14045. {
  14046. name: "protocol",
  14047. isAttr: true,
  14048. type: "String"
  14049. },
  14050. {
  14051. name: "method",
  14052. isAttr: true,
  14053. type: "String"
  14054. }
  14055. ]
  14056. },
  14057. {
  14058. name: "GlobalScriptTask",
  14059. superClass: [
  14060. "GlobalTask"
  14061. ],
  14062. properties: [
  14063. {
  14064. name: "scriptLanguage",
  14065. isAttr: true,
  14066. type: "String"
  14067. },
  14068. {
  14069. name: "script",
  14070. isAttr: true,
  14071. type: "String"
  14072. }
  14073. ]
  14074. },
  14075. {
  14076. name: "GlobalBusinessRuleTask",
  14077. superClass: [
  14078. "GlobalTask"
  14079. ],
  14080. properties: [
  14081. {
  14082. name: "implementation",
  14083. isAttr: true,
  14084. type: "String"
  14085. }
  14086. ]
  14087. },
  14088. {
  14089. name: "ComplexBehaviorDefinition",
  14090. superClass: [
  14091. "BaseElement"
  14092. ],
  14093. properties: [
  14094. {
  14095. name: "condition",
  14096. type: "FormalExpression"
  14097. },
  14098. {
  14099. name: "event",
  14100. type: "ImplicitThrowEvent"
  14101. }
  14102. ]
  14103. },
  14104. {
  14105. name: "ResourceRole",
  14106. superClass: [
  14107. "BaseElement"
  14108. ],
  14109. properties: [
  14110. {
  14111. name: "resourceRef",
  14112. type: "Resource",
  14113. isReference: true
  14114. },
  14115. {
  14116. name: "resourceParameterBindings",
  14117. type: "ResourceParameterBinding",
  14118. isMany: true
  14119. },
  14120. {
  14121. name: "resourceAssignmentExpression",
  14122. type: "ResourceAssignmentExpression"
  14123. },
  14124. {
  14125. name: "name",
  14126. isAttr: true,
  14127. type: "String"
  14128. }
  14129. ]
  14130. },
  14131. {
  14132. name: "ResourceParameterBinding",
  14133. properties: [
  14134. {
  14135. name: "expression",
  14136. type: "Expression",
  14137. xml: {
  14138. serialize: "xsi:type"
  14139. }
  14140. },
  14141. {
  14142. name: "parameterRef",
  14143. type: "ResourceParameter",
  14144. isAttr: true,
  14145. isReference: true
  14146. }
  14147. ],
  14148. superClass: [
  14149. "BaseElement"
  14150. ]
  14151. },
  14152. {
  14153. name: "ResourceAssignmentExpression",
  14154. properties: [
  14155. {
  14156. name: "expression",
  14157. type: "Expression",
  14158. xml: {
  14159. serialize: "xsi:type"
  14160. }
  14161. }
  14162. ],
  14163. superClass: [
  14164. "BaseElement"
  14165. ]
  14166. },
  14167. {
  14168. name: "Import",
  14169. properties: [
  14170. {
  14171. name: "importType",
  14172. isAttr: true,
  14173. type: "String"
  14174. },
  14175. {
  14176. name: "location",
  14177. isAttr: true,
  14178. type: "String"
  14179. },
  14180. {
  14181. name: "namespace",
  14182. isAttr: true,
  14183. type: "String"
  14184. }
  14185. ]
  14186. },
  14187. {
  14188. name: "Definitions",
  14189. superClass: [
  14190. "BaseElement"
  14191. ],
  14192. properties: [
  14193. {
  14194. name: "name",
  14195. isAttr: true,
  14196. type: "String"
  14197. },
  14198. {
  14199. name: "targetNamespace",
  14200. isAttr: true,
  14201. type: "String"
  14202. },
  14203. {
  14204. name: "expressionLanguage",
  14205. "default": "http://www.w3.org/1999/XPath",
  14206. isAttr: true,
  14207. type: "String"
  14208. },
  14209. {
  14210. name: "typeLanguage",
  14211. "default": "http://www.w3.org/2001/XMLSchema",
  14212. isAttr: true,
  14213. type: "String"
  14214. },
  14215. {
  14216. name: "imports",
  14217. type: "Import",
  14218. isMany: true
  14219. },
  14220. {
  14221. name: "extensions",
  14222. type: "Extension",
  14223. isMany: true
  14224. },
  14225. {
  14226. name: "rootElements",
  14227. type: "RootElement",
  14228. isMany: true
  14229. },
  14230. {
  14231. name: "diagrams",
  14232. isMany: true,
  14233. type: "bpmndi:BPMNDiagram"
  14234. },
  14235. {
  14236. name: "exporter",
  14237. isAttr: true,
  14238. type: "String"
  14239. },
  14240. {
  14241. name: "relationships",
  14242. type: "Relationship",
  14243. isMany: true
  14244. },
  14245. {
  14246. name: "exporterVersion",
  14247. isAttr: true,
  14248. type: "String"
  14249. }
  14250. ]
  14251. }
  14252. ];
  14253. var enumerations = [
  14254. {
  14255. name: "ProcessType",
  14256. literalValues: [
  14257. {
  14258. name: "None"
  14259. },
  14260. {
  14261. name: "Public"
  14262. },
  14263. {
  14264. name: "Private"
  14265. }
  14266. ]
  14267. },
  14268. {
  14269. name: "GatewayDirection",
  14270. literalValues: [
  14271. {
  14272. name: "Unspecified"
  14273. },
  14274. {
  14275. name: "Converging"
  14276. },
  14277. {
  14278. name: "Diverging"
  14279. },
  14280. {
  14281. name: "Mixed"
  14282. }
  14283. ]
  14284. },
  14285. {
  14286. name: "EventBasedGatewayType",
  14287. literalValues: [
  14288. {
  14289. name: "Parallel"
  14290. },
  14291. {
  14292. name: "Exclusive"
  14293. }
  14294. ]
  14295. },
  14296. {
  14297. name: "RelationshipDirection",
  14298. literalValues: [
  14299. {
  14300. name: "None"
  14301. },
  14302. {
  14303. name: "Forward"
  14304. },
  14305. {
  14306. name: "Backward"
  14307. },
  14308. {
  14309. name: "Both"
  14310. }
  14311. ]
  14312. },
  14313. {
  14314. name: "ItemKind",
  14315. literalValues: [
  14316. {
  14317. name: "Physical"
  14318. },
  14319. {
  14320. name: "Information"
  14321. }
  14322. ]
  14323. },
  14324. {
  14325. name: "ChoreographyLoopType",
  14326. literalValues: [
  14327. {
  14328. name: "None"
  14329. },
  14330. {
  14331. name: "Standard"
  14332. },
  14333. {
  14334. name: "MultiInstanceSequential"
  14335. },
  14336. {
  14337. name: "MultiInstanceParallel"
  14338. }
  14339. ]
  14340. },
  14341. {
  14342. name: "AssociationDirection",
  14343. literalValues: [
  14344. {
  14345. name: "None"
  14346. },
  14347. {
  14348. name: "One"
  14349. },
  14350. {
  14351. name: "Both"
  14352. }
  14353. ]
  14354. },
  14355. {
  14356. name: "MultiInstanceBehavior",
  14357. literalValues: [
  14358. {
  14359. name: "None"
  14360. },
  14361. {
  14362. name: "One"
  14363. },
  14364. {
  14365. name: "All"
  14366. },
  14367. {
  14368. name: "Complex"
  14369. }
  14370. ]
  14371. },
  14372. {
  14373. name: "AdHocOrdering",
  14374. literalValues: [
  14375. {
  14376. name: "Parallel"
  14377. },
  14378. {
  14379. name: "Sequential"
  14380. }
  14381. ]
  14382. }
  14383. ];
  14384. var xml = {
  14385. tagAlias: "lowerCase",
  14386. typePrefix: "t"
  14387. };
  14388. var BpmnPackage = {
  14389. name: name,
  14390. uri: uri,
  14391. prefix: prefix$1,
  14392. associations: associations,
  14393. types: types$1,
  14394. enumerations: enumerations,
  14395. xml: xml
  14396. };
  14397. var name$1 = "BPMNDI";
  14398. var uri$1 = "http://www.omg.org/spec/BPMN/20100524/DI";
  14399. var prefix$1$1 = "bpmndi";
  14400. var types$1$1 = [
  14401. {
  14402. name: "BPMNDiagram",
  14403. properties: [
  14404. {
  14405. name: "plane",
  14406. type: "BPMNPlane",
  14407. redefines: "di:Diagram#rootElement"
  14408. },
  14409. {
  14410. name: "labelStyle",
  14411. type: "BPMNLabelStyle",
  14412. isMany: true
  14413. }
  14414. ],
  14415. superClass: [
  14416. "di:Diagram"
  14417. ]
  14418. },
  14419. {
  14420. name: "BPMNPlane",
  14421. properties: [
  14422. {
  14423. name: "bpmnElement",
  14424. isAttr: true,
  14425. isReference: true,
  14426. type: "bpmn:BaseElement",
  14427. redefines: "di:DiagramElement#modelElement"
  14428. }
  14429. ],
  14430. superClass: [
  14431. "di:Plane"
  14432. ]
  14433. },
  14434. {
  14435. name: "BPMNShape",
  14436. properties: [
  14437. {
  14438. name: "bpmnElement",
  14439. isAttr: true,
  14440. isReference: true,
  14441. type: "bpmn:BaseElement",
  14442. redefines: "di:DiagramElement#modelElement"
  14443. },
  14444. {
  14445. name: "isHorizontal",
  14446. isAttr: true,
  14447. type: "Boolean"
  14448. },
  14449. {
  14450. name: "isExpanded",
  14451. isAttr: true,
  14452. type: "Boolean"
  14453. },
  14454. {
  14455. name: "isMarkerVisible",
  14456. isAttr: true,
  14457. type: "Boolean"
  14458. },
  14459. {
  14460. name: "label",
  14461. type: "BPMNLabel"
  14462. },
  14463. {
  14464. name: "isMessageVisible",
  14465. isAttr: true,
  14466. type: "Boolean"
  14467. },
  14468. {
  14469. name: "participantBandKind",
  14470. type: "ParticipantBandKind",
  14471. isAttr: true
  14472. },
  14473. {
  14474. name: "choreographyActivityShape",
  14475. type: "BPMNShape",
  14476. isAttr: true,
  14477. isReference: true
  14478. }
  14479. ],
  14480. superClass: [
  14481. "di:LabeledShape"
  14482. ]
  14483. },
  14484. {
  14485. name: "BPMNEdge",
  14486. properties: [
  14487. {
  14488. name: "label",
  14489. type: "BPMNLabel"
  14490. },
  14491. {
  14492. name: "bpmnElement",
  14493. isAttr: true,
  14494. isReference: true,
  14495. type: "bpmn:BaseElement",
  14496. redefines: "di:DiagramElement#modelElement"
  14497. },
  14498. {
  14499. name: "sourceElement",
  14500. isAttr: true,
  14501. isReference: true,
  14502. type: "di:DiagramElement",
  14503. redefines: "di:Edge#source"
  14504. },
  14505. {
  14506. name: "targetElement",
  14507. isAttr: true,
  14508. isReference: true,
  14509. type: "di:DiagramElement",
  14510. redefines: "di:Edge#target"
  14511. },
  14512. {
  14513. name: "messageVisibleKind",
  14514. type: "MessageVisibleKind",
  14515. isAttr: true,
  14516. "default": "initiating"
  14517. }
  14518. ],
  14519. superClass: [
  14520. "di:LabeledEdge"
  14521. ]
  14522. },
  14523. {
  14524. name: "BPMNLabel",
  14525. properties: [
  14526. {
  14527. name: "labelStyle",
  14528. type: "BPMNLabelStyle",
  14529. isAttr: true,
  14530. isReference: true,
  14531. redefines: "di:DiagramElement#style"
  14532. }
  14533. ],
  14534. superClass: [
  14535. "di:Label"
  14536. ]
  14537. },
  14538. {
  14539. name: "BPMNLabelStyle",
  14540. properties: [
  14541. {
  14542. name: "font",
  14543. type: "dc:Font"
  14544. }
  14545. ],
  14546. superClass: [
  14547. "di:Style"
  14548. ]
  14549. }
  14550. ];
  14551. var enumerations$1 = [
  14552. {
  14553. name: "ParticipantBandKind",
  14554. literalValues: [
  14555. {
  14556. name: "top_initiating"
  14557. },
  14558. {
  14559. name: "middle_initiating"
  14560. },
  14561. {
  14562. name: "bottom_initiating"
  14563. },
  14564. {
  14565. name: "top_non_initiating"
  14566. },
  14567. {
  14568. name: "middle_non_initiating"
  14569. },
  14570. {
  14571. name: "bottom_non_initiating"
  14572. }
  14573. ]
  14574. },
  14575. {
  14576. name: "MessageVisibleKind",
  14577. literalValues: [
  14578. {
  14579. name: "initiating"
  14580. },
  14581. {
  14582. name: "non_initiating"
  14583. }
  14584. ]
  14585. }
  14586. ];
  14587. var associations$1 = [
  14588. ];
  14589. var BpmnDiPackage = {
  14590. name: name$1,
  14591. uri: uri$1,
  14592. prefix: prefix$1$1,
  14593. types: types$1$1,
  14594. enumerations: enumerations$1,
  14595. associations: associations$1
  14596. };
  14597. var name$2 = "DC";
  14598. var uri$2 = "http://www.omg.org/spec/DD/20100524/DC";
  14599. var prefix$2 = "dc";
  14600. var types$2 = [
  14601. {
  14602. name: "Boolean"
  14603. },
  14604. {
  14605. name: "Integer"
  14606. },
  14607. {
  14608. name: "Real"
  14609. },
  14610. {
  14611. name: "String"
  14612. },
  14613. {
  14614. name: "Font",
  14615. properties: [
  14616. {
  14617. name: "name",
  14618. type: "String",
  14619. isAttr: true
  14620. },
  14621. {
  14622. name: "size",
  14623. type: "Real",
  14624. isAttr: true
  14625. },
  14626. {
  14627. name: "isBold",
  14628. type: "Boolean",
  14629. isAttr: true
  14630. },
  14631. {
  14632. name: "isItalic",
  14633. type: "Boolean",
  14634. isAttr: true
  14635. },
  14636. {
  14637. name: "isUnderline",
  14638. type: "Boolean",
  14639. isAttr: true
  14640. },
  14641. {
  14642. name: "isStrikeThrough",
  14643. type: "Boolean",
  14644. isAttr: true
  14645. }
  14646. ]
  14647. },
  14648. {
  14649. name: "Point",
  14650. properties: [
  14651. {
  14652. name: "x",
  14653. type: "Real",
  14654. "default": "0",
  14655. isAttr: true
  14656. },
  14657. {
  14658. name: "y",
  14659. type: "Real",
  14660. "default": "0",
  14661. isAttr: true
  14662. }
  14663. ]
  14664. },
  14665. {
  14666. name: "Bounds",
  14667. properties: [
  14668. {
  14669. name: "x",
  14670. type: "Real",
  14671. "default": "0",
  14672. isAttr: true
  14673. },
  14674. {
  14675. name: "y",
  14676. type: "Real",
  14677. "default": "0",
  14678. isAttr: true
  14679. },
  14680. {
  14681. name: "width",
  14682. type: "Real",
  14683. isAttr: true
  14684. },
  14685. {
  14686. name: "height",
  14687. type: "Real",
  14688. isAttr: true
  14689. }
  14690. ]
  14691. }
  14692. ];
  14693. var associations$2 = [
  14694. ];
  14695. var DcPackage = {
  14696. name: name$2,
  14697. uri: uri$2,
  14698. prefix: prefix$2,
  14699. types: types$2,
  14700. associations: associations$2
  14701. };
  14702. var name$3 = "DI";
  14703. var uri$3 = "http://www.omg.org/spec/DD/20100524/DI";
  14704. var prefix$3 = "di";
  14705. var types$3 = [
  14706. {
  14707. name: "DiagramElement",
  14708. isAbstract: true,
  14709. properties: [
  14710. {
  14711. name: "id",
  14712. isAttr: true,
  14713. isId: true,
  14714. type: "String"
  14715. },
  14716. {
  14717. name: "extension",
  14718. type: "Extension"
  14719. },
  14720. {
  14721. name: "owningDiagram",
  14722. type: "Diagram",
  14723. isReadOnly: true,
  14724. isVirtual: true,
  14725. isReference: true
  14726. },
  14727. {
  14728. name: "owningElement",
  14729. type: "DiagramElement",
  14730. isReadOnly: true,
  14731. isVirtual: true,
  14732. isReference: true
  14733. },
  14734. {
  14735. name: "modelElement",
  14736. isReadOnly: true,
  14737. isVirtual: true,
  14738. isReference: true,
  14739. type: "Element"
  14740. },
  14741. {
  14742. name: "style",
  14743. type: "Style",
  14744. isReadOnly: true,
  14745. isVirtual: true,
  14746. isReference: true
  14747. },
  14748. {
  14749. name: "ownedElement",
  14750. type: "DiagramElement",
  14751. isReadOnly: true,
  14752. isMany: true,
  14753. isVirtual: true
  14754. }
  14755. ]
  14756. },
  14757. {
  14758. name: "Node",
  14759. isAbstract: true,
  14760. superClass: [
  14761. "DiagramElement"
  14762. ]
  14763. },
  14764. {
  14765. name: "Edge",
  14766. isAbstract: true,
  14767. superClass: [
  14768. "DiagramElement"
  14769. ],
  14770. properties: [
  14771. {
  14772. name: "source",
  14773. type: "DiagramElement",
  14774. isReadOnly: true,
  14775. isVirtual: true,
  14776. isReference: true
  14777. },
  14778. {
  14779. name: "target",
  14780. type: "DiagramElement",
  14781. isReadOnly: true,
  14782. isVirtual: true,
  14783. isReference: true
  14784. },
  14785. {
  14786. name: "waypoint",
  14787. isUnique: false,
  14788. isMany: true,
  14789. type: "dc:Point",
  14790. xml: {
  14791. serialize: "xsi:type"
  14792. }
  14793. }
  14794. ]
  14795. },
  14796. {
  14797. name: "Diagram",
  14798. isAbstract: true,
  14799. properties: [
  14800. {
  14801. name: "id",
  14802. isAttr: true,
  14803. isId: true,
  14804. type: "String"
  14805. },
  14806. {
  14807. name: "rootElement",
  14808. type: "DiagramElement",
  14809. isReadOnly: true,
  14810. isVirtual: true
  14811. },
  14812. {
  14813. name: "name",
  14814. isAttr: true,
  14815. type: "String"
  14816. },
  14817. {
  14818. name: "documentation",
  14819. isAttr: true,
  14820. type: "String"
  14821. },
  14822. {
  14823. name: "resolution",
  14824. isAttr: true,
  14825. type: "Real"
  14826. },
  14827. {
  14828. name: "ownedStyle",
  14829. type: "Style",
  14830. isReadOnly: true,
  14831. isMany: true,
  14832. isVirtual: true
  14833. }
  14834. ]
  14835. },
  14836. {
  14837. name: "Shape",
  14838. isAbstract: true,
  14839. superClass: [
  14840. "Node"
  14841. ],
  14842. properties: [
  14843. {
  14844. name: "bounds",
  14845. type: "dc:Bounds"
  14846. }
  14847. ]
  14848. },
  14849. {
  14850. name: "Plane",
  14851. isAbstract: true,
  14852. superClass: [
  14853. "Node"
  14854. ],
  14855. properties: [
  14856. {
  14857. name: "planeElement",
  14858. type: "DiagramElement",
  14859. subsettedProperty: "DiagramElement-ownedElement",
  14860. isMany: true
  14861. }
  14862. ]
  14863. },
  14864. {
  14865. name: "LabeledEdge",
  14866. isAbstract: true,
  14867. superClass: [
  14868. "Edge"
  14869. ],
  14870. properties: [
  14871. {
  14872. name: "ownedLabel",
  14873. type: "Label",
  14874. isReadOnly: true,
  14875. subsettedProperty: "DiagramElement-ownedElement",
  14876. isMany: true,
  14877. isVirtual: true
  14878. }
  14879. ]
  14880. },
  14881. {
  14882. name: "LabeledShape",
  14883. isAbstract: true,
  14884. superClass: [
  14885. "Shape"
  14886. ],
  14887. properties: [
  14888. {
  14889. name: "ownedLabel",
  14890. type: "Label",
  14891. isReadOnly: true,
  14892. subsettedProperty: "DiagramElement-ownedElement",
  14893. isMany: true,
  14894. isVirtual: true
  14895. }
  14896. ]
  14897. },
  14898. {
  14899. name: "Label",
  14900. isAbstract: true,
  14901. superClass: [
  14902. "Node"
  14903. ],
  14904. properties: [
  14905. {
  14906. name: "bounds",
  14907. type: "dc:Bounds"
  14908. }
  14909. ]
  14910. },
  14911. {
  14912. name: "Style",
  14913. isAbstract: true,
  14914. properties: [
  14915. {
  14916. name: "id",
  14917. isAttr: true,
  14918. isId: true,
  14919. type: "String"
  14920. }
  14921. ]
  14922. },
  14923. {
  14924. name: "Extension",
  14925. properties: [
  14926. {
  14927. name: "values",
  14928. isMany: true,
  14929. type: "Element"
  14930. }
  14931. ]
  14932. }
  14933. ];
  14934. var associations$3 = [
  14935. ];
  14936. var xml$1 = {
  14937. tagAlias: "lowerCase"
  14938. };
  14939. var DiPackage = {
  14940. name: name$3,
  14941. uri: uri$3,
  14942. prefix: prefix$3,
  14943. types: types$3,
  14944. associations: associations$3,
  14945. xml: xml$1
  14946. };
  14947. var name$4 = "bpmn.io colors for BPMN";
  14948. var uri$4 = "http://bpmn.io/schema/bpmn/biocolor/1.0";
  14949. var prefix$4 = "bioc";
  14950. var types$4 = [
  14951. {
  14952. name: "ColoredShape",
  14953. "extends": [
  14954. "bpmndi:BPMNShape"
  14955. ],
  14956. properties: [
  14957. {
  14958. name: "stroke",
  14959. isAttr: true,
  14960. type: "String"
  14961. },
  14962. {
  14963. name: "fill",
  14964. isAttr: true,
  14965. type: "String"
  14966. }
  14967. ]
  14968. },
  14969. {
  14970. name: "ColoredEdge",
  14971. "extends": [
  14972. "bpmndi:BPMNEdge"
  14973. ],
  14974. properties: [
  14975. {
  14976. name: "stroke",
  14977. isAttr: true,
  14978. type: "String"
  14979. },
  14980. {
  14981. name: "fill",
  14982. isAttr: true,
  14983. type: "String"
  14984. }
  14985. ]
  14986. }
  14987. ];
  14988. var enumerations$2 = [
  14989. ];
  14990. var associations$4 = [
  14991. ];
  14992. var BiocPackage = {
  14993. name: name$4,
  14994. uri: uri$4,
  14995. prefix: prefix$4,
  14996. types: types$4,
  14997. enumerations: enumerations$2,
  14998. associations: associations$4
  14999. };
  15000. var packages = {
  15001. bpmn: BpmnPackage,
  15002. bpmndi: BpmnDiPackage,
  15003. dc: DcPackage,
  15004. di: DiPackage,
  15005. bioc: BiocPackage
  15006. };
  15007. function simple(additionalPackages, options) {
  15008. var pks = assign({}, packages, additionalPackages);
  15009. return new BpmnModdle(pks, options);
  15010. }
  15011. var diRefs = new objectRefs(
  15012. { name: 'bpmnElement', enumerable: true },
  15013. { name: 'di', configurable: true }
  15014. );
  15015. /**
  15016. * Returns true if an element has the given meta-model type
  15017. *
  15018. * @param {ModdleElement} element
  15019. * @param {string} type
  15020. *
  15021. * @return {boolean}
  15022. */
  15023. function is$1(element, type) {
  15024. return element.$instanceOf(type);
  15025. }
  15026. /**
  15027. * Find a suitable display candidate for definitions where the DI does not
  15028. * correctly specify one.
  15029. */
  15030. function findDisplayCandidate(definitions) {
  15031. return find(definitions.rootElements, function(e) {
  15032. return is$1(e, 'bpmn:Process') || is$1(e, 'bpmn:Collaboration');
  15033. });
  15034. }
  15035. function BpmnTreeWalker(handler, translate) {
  15036. // list of containers already walked
  15037. var handledElements = {};
  15038. // list of elements to handle deferred to ensure
  15039. // prerequisites are drawn
  15040. var deferred = [];
  15041. // Helpers //////////////////////
  15042. function contextual(fn, ctx) {
  15043. return function(e) {
  15044. fn(e, ctx);
  15045. };
  15046. }
  15047. function handled(element) {
  15048. handledElements[element.id] = element;
  15049. }
  15050. function isHandled(element) {
  15051. return handledElements[element.id];
  15052. }
  15053. function visit(element, ctx) {
  15054. var gfx = element.gfx;
  15055. // avoid multiple rendering of elements
  15056. if (gfx) {
  15057. throw new Error(
  15058. translate('already rendered {element}', { element: elementToString(element) })
  15059. );
  15060. }
  15061. // call handler
  15062. return handler.element(element, ctx);
  15063. }
  15064. function visitRoot(element, diagram) {
  15065. return handler.root(element, diagram);
  15066. }
  15067. function visitIfDi(element, ctx) {
  15068. try {
  15069. var gfx = element.di && visit(element, ctx);
  15070. handled(element);
  15071. return gfx;
  15072. } catch (e) {
  15073. logError(e.message, { element: element, error: e });
  15074. console.error(translate('failed to import {element}', { element: elementToString(element) }));
  15075. console.error(e);
  15076. }
  15077. }
  15078. function logError(message, context) {
  15079. handler.error(message, context);
  15080. }
  15081. // DI handling //////////////////////
  15082. function registerDi(di) {
  15083. var bpmnElement = di.bpmnElement;
  15084. if (bpmnElement) {
  15085. if (bpmnElement.di) {
  15086. logError(
  15087. translate('multiple DI elements defined for {element}', {
  15088. element: elementToString(bpmnElement)
  15089. }),
  15090. { element: bpmnElement }
  15091. );
  15092. } else {
  15093. diRefs.bind(bpmnElement, 'di');
  15094. bpmnElement.di = di;
  15095. }
  15096. } else {
  15097. logError(
  15098. translate('no bpmnElement referenced in {element}', {
  15099. element: elementToString(di)
  15100. }),
  15101. { element: di }
  15102. );
  15103. }
  15104. }
  15105. function handleDiagram(diagram) {
  15106. handlePlane(diagram.plane);
  15107. }
  15108. function handlePlane(plane) {
  15109. registerDi(plane);
  15110. forEach(plane.planeElement, handlePlaneElement);
  15111. }
  15112. function handlePlaneElement(planeElement) {
  15113. registerDi(planeElement);
  15114. }
  15115. // Semantic handling //////////////////////
  15116. /**
  15117. * Handle definitions and return the rendered diagram (if any)
  15118. *
  15119. * @param {ModdleElement} definitions to walk and import
  15120. * @param {ModdleElement} [diagram] specific diagram to import and display
  15121. *
  15122. * @throws {Error} if no diagram to display could be found
  15123. */
  15124. function handleDefinitions(definitions, diagram) {
  15125. // make sure we walk the correct bpmnElement
  15126. var diagrams = definitions.diagrams;
  15127. if (diagram && diagrams.indexOf(diagram) === -1) {
  15128. throw new Error(translate('diagram not part of bpmn:Definitions'));
  15129. }
  15130. if (!diagram && diagrams && diagrams.length) {
  15131. diagram = diagrams[0];
  15132. }
  15133. // no diagram -> nothing to import
  15134. if (!diagram) {
  15135. throw new Error(translate('no diagram to display'));
  15136. }
  15137. // load DI from selected diagram only
  15138. handleDiagram(diagram);
  15139. var plane = diagram.plane;
  15140. if (!plane) {
  15141. throw new Error(translate(
  15142. 'no plane for {element}',
  15143. { element: elementToString(diagram) }
  15144. ));
  15145. }
  15146. var rootElement = plane.bpmnElement;
  15147. // ensure we default to a suitable display candidate (process or collaboration),
  15148. // even if non is specified in DI
  15149. if (!rootElement) {
  15150. rootElement = findDisplayCandidate(definitions);
  15151. if (!rootElement) {
  15152. throw new Error(translate('no process or collaboration to display'));
  15153. } else {
  15154. logError(
  15155. translate('correcting missing bpmnElement on {plane} to {rootElement}', {
  15156. plane: elementToString(plane),
  15157. rootElement: elementToString(rootElement)
  15158. })
  15159. );
  15160. // correct DI on the fly
  15161. plane.bpmnElement = rootElement;
  15162. registerDi(plane);
  15163. }
  15164. }
  15165. var ctx = visitRoot(rootElement, plane);
  15166. if (is$1(rootElement, 'bpmn:Process')) {
  15167. handleProcess(rootElement, ctx);
  15168. } else if (is$1(rootElement, 'bpmn:Collaboration')) {
  15169. handleCollaboration(rootElement);
  15170. // force drawing of everything not yet drawn that is part of the target DI
  15171. handleUnhandledProcesses(definitions.rootElements, ctx);
  15172. } else {
  15173. throw new Error(
  15174. translate('unsupported bpmnElement for {plane}: {rootElement}', {
  15175. plane: elementToString(plane),
  15176. rootElement: elementToString(rootElement)
  15177. })
  15178. );
  15179. }
  15180. // handle all deferred elements
  15181. handleDeferred();
  15182. }
  15183. function handleDeferred() {
  15184. var fn;
  15185. // drain deferred until empty
  15186. while (deferred.length) {
  15187. fn = deferred.shift();
  15188. fn();
  15189. }
  15190. }
  15191. function handleProcess(process, context) {
  15192. handleFlowElementsContainer(process, context);
  15193. handleIoSpecification(process.ioSpecification, context);
  15194. handleArtifacts(process.artifacts, context);
  15195. // log process handled
  15196. handled(process);
  15197. }
  15198. function handleUnhandledProcesses(rootElements, ctx) {
  15199. // walk through all processes that have not yet been drawn and draw them
  15200. // if they contain lanes with DI information.
  15201. // we do this to pass the free-floating lane test cases in the MIWG test suite
  15202. var processes = filter(rootElements, function(e) {
  15203. return !isHandled(e) && is$1(e, 'bpmn:Process') && e.laneSets;
  15204. });
  15205. processes.forEach(contextual(handleProcess, ctx));
  15206. }
  15207. function handleMessageFlow(messageFlow, context) {
  15208. visitIfDi(messageFlow, context);
  15209. }
  15210. function handleMessageFlows(messageFlows, context) {
  15211. forEach(messageFlows, contextual(handleMessageFlow, context));
  15212. }
  15213. function handleDataAssociation(association, context) {
  15214. visitIfDi(association, context);
  15215. }
  15216. function handleDataInput(dataInput, context) {
  15217. visitIfDi(dataInput, context);
  15218. }
  15219. function handleDataOutput(dataOutput, context) {
  15220. visitIfDi(dataOutput, context);
  15221. }
  15222. function handleArtifact(artifact, context) {
  15223. // bpmn:TextAnnotation
  15224. // bpmn:Group
  15225. // bpmn:Association
  15226. visitIfDi(artifact, context);
  15227. }
  15228. function handleArtifacts(artifacts, context) {
  15229. forEach(artifacts, function(e) {
  15230. if (is$1(e, 'bpmn:Association')) {
  15231. deferred.push(function() {
  15232. handleArtifact(e, context);
  15233. });
  15234. } else {
  15235. handleArtifact(e, context);
  15236. }
  15237. });
  15238. }
  15239. function handleIoSpecification(ioSpecification, context) {
  15240. if (!ioSpecification) {
  15241. return;
  15242. }
  15243. forEach(ioSpecification.dataInputs, contextual(handleDataInput, context));
  15244. forEach(ioSpecification.dataOutputs, contextual(handleDataOutput, context));
  15245. }
  15246. function handleSubProcess(subProcess, context) {
  15247. handleFlowElementsContainer(subProcess, context);
  15248. handleArtifacts(subProcess.artifacts, context);
  15249. }
  15250. function handleFlowNode(flowNode, context) {
  15251. var childCtx = visitIfDi(flowNode, context);
  15252. if (is$1(flowNode, 'bpmn:SubProcess')) {
  15253. handleSubProcess(flowNode, childCtx || context);
  15254. }
  15255. if (is$1(flowNode, 'bpmn:Activity')) {
  15256. handleIoSpecification(flowNode.ioSpecification, context);
  15257. }
  15258. // defer handling of associations
  15259. // affected types:
  15260. //
  15261. // * bpmn:Activity
  15262. // * bpmn:ThrowEvent
  15263. // * bpmn:CatchEvent
  15264. //
  15265. deferred.push(function() {
  15266. forEach(flowNode.dataInputAssociations, contextual(handleDataAssociation, context));
  15267. forEach(flowNode.dataOutputAssociations, contextual(handleDataAssociation, context));
  15268. });
  15269. }
  15270. function handleSequenceFlow(sequenceFlow, context) {
  15271. visitIfDi(sequenceFlow, context);
  15272. }
  15273. function handleDataElement(dataObject, context) {
  15274. visitIfDi(dataObject, context);
  15275. }
  15276. function handleLane(lane, context) {
  15277. deferred.push(function() {
  15278. var newContext = visitIfDi(lane, context);
  15279. if (lane.childLaneSet) {
  15280. handleLaneSet(lane.childLaneSet, newContext || context);
  15281. }
  15282. wireFlowNodeRefs(lane);
  15283. });
  15284. }
  15285. function handleLaneSet(laneSet, context) {
  15286. forEach(laneSet.lanes, contextual(handleLane, context));
  15287. }
  15288. function handleLaneSets(laneSets, context) {
  15289. forEach(laneSets, contextual(handleLaneSet, context));
  15290. }
  15291. function handleFlowElementsContainer(container, context) {
  15292. handleFlowElements(container.flowElements, context);
  15293. if (container.laneSets) {
  15294. handleLaneSets(container.laneSets, context);
  15295. }
  15296. }
  15297. function handleFlowElements(flowElements, context) {
  15298. forEach(flowElements, function(e) {
  15299. if (is$1(e, 'bpmn:SequenceFlow')) {
  15300. deferred.push(function() {
  15301. handleSequenceFlow(e, context);
  15302. });
  15303. } else if (is$1(e, 'bpmn:BoundaryEvent')) {
  15304. deferred.unshift(function() {
  15305. handleFlowNode(e, context);
  15306. });
  15307. } else if (is$1(e, 'bpmn:FlowNode')) {
  15308. handleFlowNode(e, context);
  15309. } else if (is$1(e, 'bpmn:DataObject')) ; else if (is$1(e, 'bpmn:DataStoreReference')) {
  15310. handleDataElement(e, context);
  15311. } else if (is$1(e, 'bpmn:DataObjectReference')) {
  15312. handleDataElement(e, context);
  15313. } else {
  15314. logError(
  15315. translate('unrecognized flowElement {element} in context {context}', {
  15316. element: elementToString(e),
  15317. context: (context ? elementToString(context.businessObject) : 'null')
  15318. }),
  15319. { element: e, context: context }
  15320. );
  15321. }
  15322. });
  15323. }
  15324. function handleParticipant(participant, context) {
  15325. var newCtx = visitIfDi(participant, context);
  15326. var process = participant.processRef;
  15327. if (process) {
  15328. handleProcess(process, newCtx || context);
  15329. }
  15330. }
  15331. function handleCollaboration(collaboration) {
  15332. forEach(collaboration.participants, contextual(handleParticipant));
  15333. handleArtifacts(collaboration.artifacts);
  15334. // handle message flows latest in the process
  15335. deferred.push(function() {
  15336. handleMessageFlows(collaboration.messageFlows);
  15337. });
  15338. }
  15339. function wireFlowNodeRefs(lane) {
  15340. // wire the virtual flowNodeRefs <-> relationship
  15341. forEach(lane.flowNodeRef, function(flowNode) {
  15342. var lanes = flowNode.get('lanes');
  15343. if (lanes) {
  15344. lanes.push(lane);
  15345. }
  15346. });
  15347. }
  15348. // API //////////////////////
  15349. return {
  15350. handleDeferred: handleDeferred,
  15351. handleDefinitions: handleDefinitions,
  15352. handleSubProcess: handleSubProcess,
  15353. registerDi: registerDi
  15354. };
  15355. }
  15356. /**
  15357. * Import the definitions into a diagram.
  15358. *
  15359. * Errors and warnings are reported through the specified callback.
  15360. *
  15361. * @param {djs.Diagram} diagram
  15362. * @param {ModdleElement<Definitions>} definitions
  15363. * @param {ModdleElement<BPMNDiagram>} [bpmnDiagram] the diagram to be rendered
  15364. * (if not provided, the first one will be rendered)
  15365. * @param {Function} done the callback, invoked with (err, [ warning ]) once the import is done
  15366. */
  15367. function importBpmnDiagram(diagram, definitions, bpmnDiagram, done) {
  15368. if (isFunction(bpmnDiagram)) {
  15369. done = bpmnDiagram;
  15370. bpmnDiagram = null;
  15371. }
  15372. var importer,
  15373. eventBus,
  15374. translate;
  15375. var error,
  15376. warnings = [];
  15377. /**
  15378. * Walk the diagram semantically, importing (=drawing)
  15379. * all elements you encounter.
  15380. *
  15381. * @param {ModdleElement<Definitions>} definitions
  15382. * @param {ModdleElement<BPMNDiagram>} bpmnDiagram
  15383. */
  15384. function render(definitions, bpmnDiagram) {
  15385. var visitor = {
  15386. root: function(element) {
  15387. return importer.add(element);
  15388. },
  15389. element: function(element, parentShape) {
  15390. return importer.add(element, parentShape);
  15391. },
  15392. error: function(message, context) {
  15393. warnings.push({ message: message, context: context });
  15394. }
  15395. };
  15396. var walker = new BpmnTreeWalker(visitor, translate);
  15397. // traverse BPMN 2.0 document model,
  15398. // starting at definitions
  15399. walker.handleDefinitions(definitions, bpmnDiagram);
  15400. }
  15401. try {
  15402. importer = diagram.get('bpmnImporter');
  15403. eventBus = diagram.get('eventBus');
  15404. translate = diagram.get('translate');
  15405. eventBus.fire('import.render.start', { definitions: definitions });
  15406. render(definitions, bpmnDiagram);
  15407. eventBus.fire('import.render.complete', {
  15408. error: error,
  15409. warnings: warnings
  15410. });
  15411. } catch (e) {
  15412. error = e;
  15413. }
  15414. done(error, warnings);
  15415. }
  15416. /**
  15417. * This file must not be changed or exchanged.
  15418. *
  15419. * @see http://bpmn.io/license for more information.
  15420. */
  15421. // inlined ../../resources/logo.svg
  15422. var BPMNIO_LOGO_SVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 960"><path fill="#fff" d="M960 60v839c0 33-27 61-60 61H60c-33 0-60-27-60-60V60C0 27 27 0 60 0h839c34 0 61 27 61 60z"/><path fill="#52b415" d="M217 548a205 205 0 0 0-144 58 202 202 0 0 0-4 286 202 202 0 0 0 285 3 200 200 0 0 0 48-219 203 203 0 0 0-185-128zM752 6a206 206 0 0 0-192 285 206 206 0 0 0 269 111 207 207 0 0 0 111-260A204 204 0 0 0 752 6zM62 0A62 62 0 0 0 0 62v398l60 46a259 259 0 0 1 89-36c5-28 10-57 14-85l99 2 12 85a246 246 0 0 1 88 38l70-52 69 71-52 68c17 30 29 58 35 90l86 14-2 100-86 12a240 240 0 0 1-38 89l43 58h413c37 0 60-27 60-61V407a220 220 0 0 1-44 40l21 85-93 39-45-76a258 258 0 0 1-98 1l-45 76-94-39 22-85a298 298 0 0 1-70-69l-86 22-38-94 76-45a258 258 0 0 1-1-98l-76-45 40-94 85 22a271 271 0 0 1 41-47z"/></svg>';
  15423. var BPMNIO_LOGO_URL = 'data:image/svg+xml,' + encodeURIComponent(BPMNIO_LOGO_SVG);
  15424. var BPMNIO_IMG = '<img width="52" height="52" src="' + BPMNIO_LOGO_URL + '" />';
  15425. function css(attrs) {
  15426. return attrs.join(';');
  15427. }
  15428. var LIGHTBOX_STYLES = css([
  15429. 'z-index: 1001',
  15430. 'position: fixed',
  15431. 'top: 0',
  15432. 'left: 0',
  15433. 'right: 0',
  15434. 'bottom: 0'
  15435. ]);
  15436. var BACKDROP_STYLES = css([
  15437. 'width: 100%',
  15438. 'height: 100%',
  15439. 'background: rgba(0,0,0,0.2)'
  15440. ]);
  15441. var NOTICE_STYLES = css([
  15442. 'position: absolute',
  15443. 'left: 50%',
  15444. 'top: 40%',
  15445. 'margin: 0 -130px',
  15446. 'width: 260px',
  15447. 'padding: 10px',
  15448. 'background: white',
  15449. 'border: solid 1px #AAA',
  15450. 'border-radius: 3px',
  15451. 'font-family: Helvetica, Arial, sans-serif',
  15452. 'font-size: 14px',
  15453. 'line-height: 1.2em'
  15454. ]);
  15455. var LIGHTBOX_MARKUP =
  15456. '<div class="bjs-powered-by-lightbox" style="' + LIGHTBOX_STYLES + '">' +
  15457. '<div class="backdrop" style="' + BACKDROP_STYLES + '"></div>' +
  15458. '<div class="notice" style="' + NOTICE_STYLES + '">' +
  15459. '<a href="http://bpmn.io" target="_blank" style="float: left; margin-right: 10px">' +
  15460. BPMNIO_IMG +
  15461. '</a>' +
  15462. 'Web-based tooling for BPMN, DMN and CMMN diagrams ' +
  15463. 'powered by <a href="http://bpmn.io" target="_blank">bpmn.io</a>.' +
  15464. '</div>' +
  15465. '</div>';
  15466. var lightbox;
  15467. function open() {
  15468. if (!lightbox) {
  15469. lightbox = domify(LIGHTBOX_MARKUP);
  15470. delegateEvents.bind(lightbox, '.backdrop', 'click', function(event) {
  15471. document.body.removeChild(lightbox);
  15472. });
  15473. }
  15474. document.body.appendChild(lightbox);
  15475. }
  15476. /**
  15477. * The code in the <project-logo></project-logo> area
  15478. * must not be changed.
  15479. *
  15480. * @see http://bpmn.io/license for more information.
  15481. */
  15482. /**
  15483. * A base viewer for BPMN 2.0 diagrams.
  15484. *
  15485. * Have a look at {@link Viewer}, {@link NavigatedViewer} or {@link Modeler} for
  15486. * bundles that include actual features.
  15487. *
  15488. * @param {Object} [options] configuration options to pass to the viewer
  15489. * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
  15490. * @param {string|number} [options.width] the width of the viewer
  15491. * @param {string|number} [options.height] the height of the viewer
  15492. * @param {Object} [options.moddleExtensions] extension packages to provide
  15493. * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
  15494. * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
  15495. */
  15496. function BaseViewer(options) {
  15497. options = assign({}, DEFAULT_OPTIONS, options);
  15498. this._moddle = this._createModdle(options);
  15499. this._container = this._createContainer(options);
  15500. /* <project-logo> */
  15501. addProjectLogo(this._container);
  15502. /* </project-logo> */
  15503. this._init(this._container, this._moddle, options);
  15504. }
  15505. inherits_browser(BaseViewer, Diagram);
  15506. /**
  15507. * Parse and render a BPMN 2.0 diagram.
  15508. *
  15509. * Once finished the viewer reports back the result to the
  15510. * provided callback function with (err, warnings).
  15511. *
  15512. * ## Life-Cycle Events
  15513. *
  15514. * During import the viewer will fire life-cycle events:
  15515. *
  15516. * * import.parse.start (about to read model from xml)
  15517. * * import.parse.complete (model read; may have worked or not)
  15518. * * import.render.start (graphical import start)
  15519. * * import.render.complete (graphical import finished)
  15520. * * import.done (everything done)
  15521. *
  15522. * You can use these events to hook into the life-cycle.
  15523. *
  15524. * @param {string} xml the BPMN 2.0 xml
  15525. * @param {ModdleElement<BPMNDiagram>|string} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
  15526. * @param {Function} [done] invoked with (err, warnings=[])
  15527. */
  15528. BaseViewer.prototype.importXML = function(xml, bpmnDiagram, done) {
  15529. if (isFunction(bpmnDiagram)) {
  15530. done = bpmnDiagram;
  15531. bpmnDiagram = null;
  15532. }
  15533. // done is optional
  15534. done = done || function() {};
  15535. var self = this;
  15536. // hook in pre-parse listeners +
  15537. // allow xml manipulation
  15538. xml = this._emit('import.parse.start', { xml: xml }) || xml;
  15539. this._moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) {
  15540. // hook in post parse listeners +
  15541. // allow definitions manipulation
  15542. definitions = self._emit('import.parse.complete', {
  15543. error: err,
  15544. definitions: definitions,
  15545. context: context
  15546. }) || definitions;
  15547. var parseWarnings = context.warnings;
  15548. if (err) {
  15549. err = checkValidationError(err);
  15550. self._emit('import.done', { error: err, warnings: parseWarnings });
  15551. return done(err, parseWarnings);
  15552. }
  15553. self.importDefinitions(definitions, bpmnDiagram, function(err, importWarnings) {
  15554. var allWarnings = [].concat(parseWarnings, importWarnings || []);
  15555. self._emit('import.done', { error: err, warnings: allWarnings });
  15556. done(err, allWarnings);
  15557. });
  15558. });
  15559. };
  15560. /**
  15561. * Import parsed definitions and render a BPMN 2.0 diagram.
  15562. *
  15563. * Once finished the viewer reports back the result to the
  15564. * provided callback function with (err, warnings).
  15565. *
  15566. * ## Life-Cycle Events
  15567. *
  15568. * During import the viewer will fire life-cycle events:
  15569. *
  15570. * * import.render.start (graphical import start)
  15571. * * import.render.complete (graphical import finished)
  15572. *
  15573. * You can use these events to hook into the life-cycle.
  15574. *
  15575. * @param {ModdleElement<Definitions>} definitions parsed BPMN 2.0 definitions
  15576. * @param {ModdleElement<BPMNDiagram>|string} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
  15577. * @param {Function} [done] invoked with (err, warnings=[])
  15578. */
  15579. BaseViewer.prototype.importDefinitions = function(definitions, bpmnDiagram, done) {
  15580. if (isFunction(bpmnDiagram)) {
  15581. done = bpmnDiagram;
  15582. bpmnDiagram = null;
  15583. }
  15584. // done is optional
  15585. done = done || function() {};
  15586. this._setDefinitions(definitions);
  15587. return this.open(bpmnDiagram, done);
  15588. };
  15589. /**
  15590. * Open diagram of previously imported XML.
  15591. *
  15592. * Once finished the viewer reports back the result to the
  15593. * provided callback function with (err, warnings).
  15594. *
  15595. * ## Life-Cycle Events
  15596. *
  15597. * During switch the viewer will fire life-cycle events:
  15598. *
  15599. * * import.render.start (graphical import start)
  15600. * * import.render.complete (graphical import finished)
  15601. *
  15602. * You can use these events to hook into the life-cycle.
  15603. *
  15604. * @param {string|ModdleElement<BPMNDiagram>} [bpmnDiagramOrId] id or the diagram to open
  15605. * @param {Function} [done] invoked with (err, warnings=[])
  15606. */
  15607. BaseViewer.prototype.open = function(bpmnDiagramOrId, done) {
  15608. if (isFunction(bpmnDiagramOrId)) {
  15609. done = bpmnDiagramOrId;
  15610. bpmnDiagramOrId = null;
  15611. }
  15612. var definitions = this._definitions;
  15613. var bpmnDiagram = bpmnDiagramOrId;
  15614. // done is optional
  15615. done = done || function() {};
  15616. if (!definitions) {
  15617. return done(new Error('no XML imported'));
  15618. }
  15619. if (typeof bpmnDiagramOrId === 'string') {
  15620. bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId);
  15621. if (!bpmnDiagram) {
  15622. return done(new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found'));
  15623. }
  15624. }
  15625. // clear existing rendered diagram
  15626. // catch synchronous exceptions during #clear()
  15627. try {
  15628. this.clear();
  15629. } catch (error) {
  15630. return done(error);
  15631. }
  15632. // perform graphical import
  15633. return importBpmnDiagram(this, definitions, bpmnDiagram, done);
  15634. };
  15635. /**
  15636. * Export the currently displayed BPMN 2.0 diagram as
  15637. * a BPMN 2.0 XML document.
  15638. *
  15639. * ## Life-Cycle Events
  15640. *
  15641. * During XML saving the viewer will fire life-cycle events:
  15642. *
  15643. * * saveXML.start (before serialization)
  15644. * * saveXML.serialized (after xml generation)
  15645. * * saveXML.done (everything done)
  15646. *
  15647. * You can use these events to hook into the life-cycle.
  15648. *
  15649. * @param {Object} [options] export options
  15650. * @param {boolean} [options.format=false] output formatted XML
  15651. * @param {boolean} [options.preamble=true] output preamble
  15652. *
  15653. * @param {Function} done invoked with (err, xml)
  15654. */
  15655. BaseViewer.prototype.saveXML = function(options, done) {
  15656. if (!done) {
  15657. done = options;
  15658. options = {};
  15659. }
  15660. var self = this;
  15661. var definitions = this._definitions;
  15662. if (!definitions) {
  15663. return done(new Error('no definitions loaded'));
  15664. }
  15665. // allow to fiddle around with definitions
  15666. definitions = this._emit('saveXML.start', {
  15667. definitions: definitions
  15668. }) || definitions;
  15669. this._moddle.toXML(definitions, options, function(err, xml) {
  15670. try {
  15671. xml = self._emit('saveXML.serialized', {
  15672. error: err,
  15673. xml: xml
  15674. }) || xml;
  15675. self._emit('saveXML.done', {
  15676. error: err,
  15677. xml: xml
  15678. });
  15679. } catch (e) {
  15680. console.error('error in saveXML life-cycle listener', e);
  15681. }
  15682. done(err, xml);
  15683. });
  15684. };
  15685. /**
  15686. * Export the currently displayed BPMN 2.0 diagram as
  15687. * an SVG image.
  15688. *
  15689. * ## Life-Cycle Events
  15690. *
  15691. * During SVG saving the viewer will fire life-cycle events:
  15692. *
  15693. * * saveSVG.start (before serialization)
  15694. * * saveSVG.done (everything done)
  15695. *
  15696. * You can use these events to hook into the life-cycle.
  15697. *
  15698. * @param {Object} [options]
  15699. * @param {Function} done invoked with (err, svgStr)
  15700. */
  15701. BaseViewer.prototype.saveSVG = function(options, done) {
  15702. if (!done) {
  15703. done = options;
  15704. options = {};
  15705. }
  15706. this._emit('saveSVG.start');
  15707. var svg, err;
  15708. try {
  15709. var canvas = this.get('canvas');
  15710. var contentNode = canvas.getDefaultLayer(),
  15711. defsNode = query('defs', canvas._svg);
  15712. var contents = innerSVG(contentNode),
  15713. defs = defsNode ? '<defs>' + innerSVG(defsNode) + '</defs>' : '';
  15714. var bbox = contentNode.getBBox();
  15715. svg =
  15716. '<?xml version="1.0" encoding="utf-8"?>\n' +
  15717. '<!-- created with bpmn-js / http://bpmn.io -->\n' +
  15718. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
  15719. '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
  15720. 'width="' + bbox.width + '" height="' + bbox.height + '" ' +
  15721. 'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
  15722. defs + contents +
  15723. '</svg>';
  15724. } catch (e) {
  15725. err = e;
  15726. }
  15727. this._emit('saveSVG.done', {
  15728. error: err,
  15729. svg: svg
  15730. });
  15731. done(err, svg);
  15732. };
  15733. /**
  15734. * Get a named diagram service.
  15735. *
  15736. * @example
  15737. *
  15738. * var elementRegistry = viewer.get('elementRegistry');
  15739. * var startEventShape = elementRegistry.get('StartEvent_1');
  15740. *
  15741. * @param {string} name
  15742. *
  15743. * @return {Object} diagram service instance
  15744. *
  15745. * @method BaseViewer#get
  15746. */
  15747. /**
  15748. * Invoke a function in the context of this viewer.
  15749. *
  15750. * @example
  15751. *
  15752. * viewer.invoke(function(elementRegistry) {
  15753. * var startEventShape = elementRegistry.get('StartEvent_1');
  15754. * });
  15755. *
  15756. * @param {Function} fn to be invoked
  15757. *
  15758. * @return {Object} the functions return value
  15759. *
  15760. * @method BaseViewer#invoke
  15761. */
  15762. BaseViewer.prototype._setDefinitions = function(definitions) {
  15763. this._definitions = definitions;
  15764. };
  15765. BaseViewer.prototype.getModules = function() {
  15766. return this._modules;
  15767. };
  15768. /**
  15769. * Remove all drawn elements from the viewer.
  15770. *
  15771. * After calling this method the viewer can still
  15772. * be reused for opening another diagram.
  15773. *
  15774. * @method BaseViewer#clear
  15775. */
  15776. BaseViewer.prototype.clear = function() {
  15777. if (!this.getDefinitions()) {
  15778. // no diagram to clear
  15779. return;
  15780. }
  15781. // remove businessObject#di binding
  15782. //
  15783. // this is necessary, as we establish the bindings
  15784. // in the BpmnTreeWalker (and assume none are given
  15785. // on reimport)
  15786. this.get('elementRegistry').forEach(function(element) {
  15787. var bo = element.businessObject;
  15788. if (bo && bo.di) {
  15789. delete bo.di;
  15790. }
  15791. });
  15792. // remove drawn elements
  15793. Diagram.prototype.clear.call(this);
  15794. };
  15795. /**
  15796. * Destroy the viewer instance and remove all its
  15797. * remainders from the document tree.
  15798. */
  15799. BaseViewer.prototype.destroy = function() {
  15800. // diagram destroy
  15801. Diagram.prototype.destroy.call(this);
  15802. // dom detach
  15803. remove$1(this._container);
  15804. };
  15805. /**
  15806. * Register an event listener
  15807. *
  15808. * Remove a previously added listener via {@link #off(event, callback)}.
  15809. *
  15810. * @param {string} event
  15811. * @param {number} [priority]
  15812. * @param {Function} callback
  15813. * @param {Object} [that]
  15814. */
  15815. BaseViewer.prototype.on = function(event, priority, callback, target) {
  15816. return this.get('eventBus').on(event, priority, callback, target);
  15817. };
  15818. /**
  15819. * De-register an event listener
  15820. *
  15821. * @param {string} event
  15822. * @param {Function} callback
  15823. */
  15824. BaseViewer.prototype.off = function(event, callback) {
  15825. this.get('eventBus').off(event, callback);
  15826. };
  15827. BaseViewer.prototype.attachTo = function(parentNode) {
  15828. if (!parentNode) {
  15829. throw new Error('parentNode required');
  15830. }
  15831. // ensure we detach from the
  15832. // previous, old parent
  15833. this.detach();
  15834. // unwrap jQuery if provided
  15835. if (parentNode.get && parentNode.constructor.prototype.jquery) {
  15836. parentNode = parentNode.get(0);
  15837. }
  15838. if (typeof parentNode === 'string') {
  15839. parentNode = query(parentNode);
  15840. }
  15841. parentNode.appendChild(this._container);
  15842. this._emit('attach', {});
  15843. this.get('canvas').resized();
  15844. };
  15845. BaseViewer.prototype.getDefinitions = function() {
  15846. return this._definitions;
  15847. };
  15848. BaseViewer.prototype.detach = function() {
  15849. var container = this._container,
  15850. parentNode = container.parentNode;
  15851. if (!parentNode) {
  15852. return;
  15853. }
  15854. this._emit('detach', {});
  15855. parentNode.removeChild(container);
  15856. };
  15857. BaseViewer.prototype._init = function(container, moddle, options) {
  15858. var baseModules = options.modules || this.getModules(),
  15859. additionalModules = options.additionalModules || [],
  15860. staticModules = [
  15861. {
  15862. bpmnjs: [ 'value', this ],
  15863. moddle: [ 'value', moddle ]
  15864. }
  15865. ];
  15866. var diagramModules = [].concat(staticModules, baseModules, additionalModules);
  15867. var diagramOptions = assign(omit(options, [ 'additionalModules' ]), {
  15868. canvas: assign({}, options.canvas, { container: container }),
  15869. modules: diagramModules
  15870. });
  15871. // invoke diagram constructor
  15872. Diagram.call(this, diagramOptions);
  15873. if (options && options.container) {
  15874. this.attachTo(options.container);
  15875. }
  15876. };
  15877. /**
  15878. * Emit an event on the underlying {@link EventBus}
  15879. *
  15880. * @param {string} type
  15881. * @param {Object} event
  15882. *
  15883. * @return {Object} event processing result (if any)
  15884. */
  15885. BaseViewer.prototype._emit = function(type, event) {
  15886. return this.get('eventBus').fire(type, event);
  15887. };
  15888. BaseViewer.prototype._createContainer = function(options) {
  15889. var container = domify('<div class="bjs-container"></div>');
  15890. assign(container.style, {
  15891. width: ensureUnit(options.width),
  15892. height: ensureUnit(options.height),
  15893. position: options.position
  15894. });
  15895. return container;
  15896. };
  15897. BaseViewer.prototype._createModdle = function(options) {
  15898. var moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
  15899. return new simple(moddleOptions);
  15900. };
  15901. BaseViewer.prototype._modules = [];
  15902. // helpers ///////////////
  15903. function checkValidationError(err) {
  15904. // check if we can help the user by indicating wrong BPMN 2.0 xml
  15905. // (in case he or the exporting tool did not get that right)
  15906. var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
  15907. var match = pattern.exec(err.message);
  15908. if (match) {
  15909. err.message =
  15910. 'unparsable content <' + match[1] + '> detected; ' +
  15911. 'this may indicate an invalid BPMN 2.0 diagram file' + match[2];
  15912. }
  15913. return err;
  15914. }
  15915. var DEFAULT_OPTIONS = {
  15916. width: '100%',
  15917. height: '100%',
  15918. position: 'relative'
  15919. };
  15920. /**
  15921. * Ensure the passed argument is a proper unit (defaulting to px)
  15922. */
  15923. function ensureUnit(val) {
  15924. return val + (isNumber(val) ? 'px' : '');
  15925. }
  15926. /**
  15927. * Find BPMNDiagram in definitions by ID
  15928. *
  15929. * @param {ModdleElement<Definitions>} definitions
  15930. * @param {string} diagramId
  15931. *
  15932. * @return {ModdleElement<BPMNDiagram>|null}
  15933. */
  15934. function findBPMNDiagram(definitions, diagramId) {
  15935. if (!diagramId) {
  15936. return null;
  15937. }
  15938. return find(definitions.diagrams, function(element) {
  15939. return element.id === diagramId;
  15940. }) || null;
  15941. }
  15942. /**
  15943. * Adds the project logo to the diagram container as
  15944. * required by the bpmn.io license.
  15945. *
  15946. * @see http://bpmn.io/license
  15947. *
  15948. * @param {Element} container
  15949. */
  15950. function addProjectLogo(container) {
  15951. var img = BPMNIO_IMG;
  15952. var linkMarkup =
  15953. '<a href="http://bpmn.io" ' +
  15954. 'target="_blank" ' +
  15955. 'class="bjs-powered-by" ' +
  15956. 'title="Powered by bpmn.io" ' +
  15957. 'style="position: absolute; bottom: 15px; right: 15px; z-index: 100">' +
  15958. img +
  15959. '</a>';
  15960. var linkElement = domify(linkMarkup);
  15961. container.appendChild(linkElement);
  15962. componentEvent.bind(linkElement, 'click', function(event) {
  15963. open();
  15964. event.preventDefault();
  15965. });
  15966. }
  15967. /* </project-logo> */
  15968. /**
  15969. * A viewer for BPMN 2.0 diagrams.
  15970. *
  15971. * Have a look at {@link NavigatedViewer} or {@link Modeler} for bundles that include
  15972. * additional features.
  15973. *
  15974. *
  15975. * ## Extending the Viewer
  15976. *
  15977. * In order to extend the viewer pass extension modules to bootstrap via the
  15978. * `additionalModules` option. An extension module is an object that exposes
  15979. * named services.
  15980. *
  15981. * The following example depicts the integration of a simple
  15982. * logging component that integrates with interaction events:
  15983. *
  15984. *
  15985. * ```javascript
  15986. *
  15987. * // logging component
  15988. * function InteractionLogger(eventBus) {
  15989. * eventBus.on('element.hover', function(event) {
  15990. * console.log()
  15991. * })
  15992. * }
  15993. *
  15994. * InteractionLogger.$inject = [ 'eventBus' ]; // minification save
  15995. *
  15996. * // extension module
  15997. * var extensionModule = {
  15998. * __init__: [ 'interactionLogger' ],
  15999. * interactionLogger: [ 'type', InteractionLogger ]
  16000. * };
  16001. *
  16002. * // extend the viewer
  16003. * var bpmnViewer = new Viewer({ additionalModules: [ extensionModule ] });
  16004. * bpmnViewer.importXML(...);
  16005. * ```
  16006. *
  16007. * @param {Object} [options] configuration options to pass to the viewer
  16008. * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
  16009. * @param {string|number} [options.width] the width of the viewer
  16010. * @param {string|number} [options.height] the height of the viewer
  16011. * @param {Object} [options.moddleExtensions] extension packages to provide
  16012. * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
  16013. * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
  16014. */
  16015. function Viewer(options) {
  16016. BaseViewer.call(this, options);
  16017. }
  16018. inherits_browser(Viewer, BaseViewer);
  16019. // modules the viewer is composed of
  16020. Viewer.prototype._modules = [
  16021. CoreModule,
  16022. TranslateModule,
  16023. SelectionModule,
  16024. OverlaysModule
  16025. ];
  16026. // default moddle extensions the viewer is composed of
  16027. Viewer.prototype._moddleExtensions = {};
  16028. return Viewer;
  16029. }));