bpmn-viewer.development.js 500 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600
  1. /*!
  2. * bpmn-js - bpmn-viewer v9.2.2
  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: 2022-06-21
  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 = typeof globalThis !== 'undefined' ? globalThis : global || self, global.BpmnJS = factory());
  17. }(this, (function () { 'use strict';
  18. function e(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}));}
  19. /**
  20. * Flatten array, one level deep.
  21. *
  22. * @param {Array<?>} arr
  23. *
  24. * @return {Array<?>}
  25. */
  26. var nativeToString$1 = Object.prototype.toString;
  27. var nativeHasOwnProperty$1 = Object.prototype.hasOwnProperty;
  28. function isUndefined$2(obj) {
  29. return obj === undefined;
  30. }
  31. function isDefined(obj) {
  32. return obj !== undefined;
  33. }
  34. function isArray$2(obj) {
  35. return nativeToString$1.call(obj) === '[object Array]';
  36. }
  37. function isObject(obj) {
  38. return nativeToString$1.call(obj) === '[object Object]';
  39. }
  40. function isNumber(obj) {
  41. return nativeToString$1.call(obj) === '[object Number]';
  42. }
  43. function isFunction(obj) {
  44. var tag = nativeToString$1.call(obj);
  45. return tag === '[object Function]' || tag === '[object AsyncFunction]' || tag === '[object GeneratorFunction]' || tag === '[object AsyncGeneratorFunction]' || tag === '[object Proxy]';
  46. }
  47. function isString(obj) {
  48. return nativeToString$1.call(obj) === '[object String]';
  49. }
  50. /**
  51. * Return true, if target owns a property with the given key.
  52. *
  53. * @param {Object} target
  54. * @param {String} key
  55. *
  56. * @return {Boolean}
  57. */
  58. function has$1(target, key) {
  59. return nativeHasOwnProperty$1.call(target, key);
  60. }
  61. /**
  62. * Find element in collection.
  63. *
  64. * @param {Array|Object} collection
  65. * @param {Function|Object} matcher
  66. *
  67. * @return {Object}
  68. */
  69. function find(collection, matcher) {
  70. matcher = toMatcher(matcher);
  71. var match;
  72. forEach$1(collection, function (val, key) {
  73. if (matcher(val, key)) {
  74. match = val;
  75. return false;
  76. }
  77. });
  78. return match;
  79. }
  80. /**
  81. * Find element in collection.
  82. *
  83. * @param {Array|Object} collection
  84. * @param {Function} matcher
  85. *
  86. * @return {Array} result
  87. */
  88. function filter(collection, matcher) {
  89. var result = [];
  90. forEach$1(collection, function (val, key) {
  91. if (matcher(val, key)) {
  92. result.push(val);
  93. }
  94. });
  95. return result;
  96. }
  97. /**
  98. * Iterate over collection; returning something
  99. * (non-undefined) will stop iteration.
  100. *
  101. * @param {Array|Object} collection
  102. * @param {Function} iterator
  103. *
  104. * @return {Object} return result that stopped the iteration
  105. */
  106. function forEach$1(collection, iterator) {
  107. var val, result;
  108. if (isUndefined$2(collection)) {
  109. return;
  110. }
  111. var convertKey = isArray$2(collection) ? toNum$1 : identity$1;
  112. for (var key in collection) {
  113. if (has$1(collection, key)) {
  114. val = collection[key];
  115. result = iterator(val, convertKey(key));
  116. if (result === false) {
  117. return val;
  118. }
  119. }
  120. }
  121. }
  122. /**
  123. * Reduce collection, returning a single result.
  124. *
  125. * @param {Object|Array} collection
  126. * @param {Function} iterator
  127. * @param {Any} result
  128. *
  129. * @return {Any} result returned from last iterator
  130. */
  131. function reduce(collection, iterator, result) {
  132. forEach$1(collection, function (value, idx) {
  133. result = iterator(result, value, idx);
  134. });
  135. return result;
  136. }
  137. /**
  138. * Return true if every element in the collection
  139. * matches the criteria.
  140. *
  141. * @param {Object|Array} collection
  142. * @param {Function} matcher
  143. *
  144. * @return {Boolean}
  145. */
  146. function every(collection, matcher) {
  147. return !!reduce(collection, function (matches, val, key) {
  148. return matches && matcher(val, key);
  149. }, true);
  150. }
  151. /**
  152. * Return true if some elements in the collection
  153. * match the criteria.
  154. *
  155. * @param {Object|Array} collection
  156. * @param {Function} matcher
  157. *
  158. * @return {Boolean}
  159. */
  160. function some(collection, matcher) {
  161. return !!find(collection, matcher);
  162. }
  163. /**
  164. * Transform a collection into another collection
  165. * by piping each member through the given fn.
  166. *
  167. * @param {Object|Array} collection
  168. * @param {Function} fn
  169. *
  170. * @return {Array} transformed collection
  171. */
  172. function map(collection, fn) {
  173. var result = [];
  174. forEach$1(collection, function (val, key) {
  175. result.push(fn(val, key));
  176. });
  177. return result;
  178. }
  179. /**
  180. * Create an object pattern matcher.
  181. *
  182. * @example
  183. *
  184. * const matcher = matchPattern({ id: 1 });
  185. *
  186. * let element = find(elements, matcher);
  187. *
  188. * @param {Object} pattern
  189. *
  190. * @return {Function} matcherFn
  191. */
  192. function matchPattern(pattern) {
  193. return function (el) {
  194. return every(pattern, function (val, key) {
  195. return el[key] === val;
  196. });
  197. };
  198. }
  199. function toMatcher(matcher) {
  200. return isFunction(matcher) ? matcher : function (e) {
  201. return e === matcher;
  202. };
  203. }
  204. function identity$1(arg) {
  205. return arg;
  206. }
  207. function toNum$1(arg) {
  208. return Number(arg);
  209. }
  210. /**
  211. * Debounce fn, calling it only once if the given time
  212. * elapsed between calls.
  213. *
  214. * Lodash-style the function exposes methods to `#clear`
  215. * and `#flush` to control internal behavior.
  216. *
  217. * @param {Function} fn
  218. * @param {Number} timeout
  219. *
  220. * @return {Function} debounced function
  221. */
  222. function debounce(fn, timeout) {
  223. var timer;
  224. var lastArgs;
  225. var lastThis;
  226. var lastNow;
  227. function fire(force) {
  228. var now = Date.now();
  229. var scheduledDiff = force ? 0 : lastNow + timeout - now;
  230. if (scheduledDiff > 0) {
  231. return schedule(scheduledDiff);
  232. }
  233. fn.apply(lastThis, lastArgs);
  234. clear();
  235. }
  236. function schedule(timeout) {
  237. timer = setTimeout(fire, timeout);
  238. }
  239. function clear() {
  240. if (timer) {
  241. clearTimeout(timer);
  242. }
  243. timer = lastNow = lastArgs = lastThis = undefined;
  244. }
  245. function flush() {
  246. if (timer) {
  247. fire(true);
  248. }
  249. clear();
  250. }
  251. function callback() {
  252. lastNow = Date.now();
  253. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  254. args[_key] = arguments[_key];
  255. }
  256. lastArgs = args;
  257. lastThis = this; // ensure an execution is scheduled
  258. if (!timer) {
  259. schedule(timeout);
  260. }
  261. }
  262. callback.flush = flush;
  263. callback.cancel = clear;
  264. return callback;
  265. }
  266. /**
  267. * Bind function against target <this>.
  268. *
  269. * @param {Function} fn
  270. * @param {Object} target
  271. *
  272. * @return {Function} bound function
  273. */
  274. function bind(fn, target) {
  275. return fn.bind(target);
  276. }
  277. function _extends() {
  278. _extends = Object.assign || function (target) {
  279. for (var i = 1; i < arguments.length; i++) {
  280. var source = arguments[i];
  281. for (var key in source) {
  282. if (Object.prototype.hasOwnProperty.call(source, key)) {
  283. target[key] = source[key];
  284. }
  285. }
  286. }
  287. return target;
  288. };
  289. return _extends.apply(this, arguments);
  290. }
  291. /**
  292. * Convenience wrapper for `Object.assign`.
  293. *
  294. * @param {Object} target
  295. * @param {...Object} others
  296. *
  297. * @return {Object} the target
  298. */
  299. function assign(target) {
  300. for (var _len = arguments.length, others = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  301. others[_key - 1] = arguments[_key];
  302. }
  303. return _extends.apply(void 0, [target].concat(others));
  304. }
  305. /**
  306. * Pick given properties from the target object.
  307. *
  308. * @param {Object} target
  309. * @param {Array} properties
  310. *
  311. * @return {Object} target
  312. */
  313. function pick(target, properties) {
  314. var result = {};
  315. var obj = Object(target);
  316. forEach$1(properties, function (prop) {
  317. if (prop in obj) {
  318. result[prop] = target[prop];
  319. }
  320. });
  321. return result;
  322. }
  323. /**
  324. * Pick all target properties, excluding the given ones.
  325. *
  326. * @param {Object} target
  327. * @param {Array} properties
  328. *
  329. * @return {Object} target
  330. */
  331. function omit(target, properties) {
  332. var result = {};
  333. var obj = Object(target);
  334. forEach$1(obj, function (prop, key) {
  335. if (properties.indexOf(key) === -1) {
  336. result[key] = prop;
  337. }
  338. });
  339. return result;
  340. }
  341. var DEFAULT_RENDER_PRIORITY$1 = 1000;
  342. /**
  343. * The base implementation of shape and connection renderers.
  344. *
  345. * @param {EventBus} eventBus
  346. * @param {number} [renderPriority=1000]
  347. */
  348. function BaseRenderer(eventBus, renderPriority) {
  349. var self = this;
  350. renderPriority = renderPriority || DEFAULT_RENDER_PRIORITY$1;
  351. eventBus.on([ 'render.shape', 'render.connection' ], renderPriority, function(evt, context) {
  352. var type = evt.type,
  353. element = context.element,
  354. visuals = context.gfx,
  355. attrs = context.attrs;
  356. if (self.canRender(element)) {
  357. if (type === 'render.shape') {
  358. return self.drawShape(visuals, element, attrs);
  359. } else {
  360. return self.drawConnection(visuals, element, attrs);
  361. }
  362. }
  363. });
  364. eventBus.on([ 'render.getShapePath', 'render.getConnectionPath' ], renderPriority, function(evt, element) {
  365. if (self.canRender(element)) {
  366. if (evt.type === 'render.getShapePath') {
  367. return self.getShapePath(element);
  368. } else {
  369. return self.getConnectionPath(element);
  370. }
  371. }
  372. });
  373. }
  374. /**
  375. * Should check whether *this* renderer can render
  376. * the element/connection.
  377. *
  378. * @param {element} element
  379. *
  380. * @returns {boolean}
  381. */
  382. BaseRenderer.prototype.canRender = function() {};
  383. /**
  384. * Provides the shape's snap svg element to be drawn on the `canvas`.
  385. *
  386. * @param {djs.Graphics} visuals
  387. * @param {Shape} shape
  388. *
  389. * @returns {Snap.svg} [returns a Snap.svg paper element ]
  390. */
  391. BaseRenderer.prototype.drawShape = function() {};
  392. /**
  393. * Provides the shape's snap svg element to be drawn on the `canvas`.
  394. *
  395. * @param {djs.Graphics} visuals
  396. * @param {Connection} connection
  397. *
  398. * @returns {Snap.svg} [returns a Snap.svg paper element ]
  399. */
  400. BaseRenderer.prototype.drawConnection = function() {};
  401. /**
  402. * Gets the SVG path of a shape that represents it's visual bounds.
  403. *
  404. * @param {Shape} shape
  405. *
  406. * @return {string} svg path
  407. */
  408. BaseRenderer.prototype.getShapePath = function() {};
  409. /**
  410. * Gets the SVG path of a connection that represents it's visual bounds.
  411. *
  412. * @param {Connection} connection
  413. *
  414. * @return {string} svg path
  415. */
  416. BaseRenderer.prototype.getConnectionPath = function() {};
  417. /**
  418. * Is an element of the given BPMN type?
  419. *
  420. * @param {djs.model.Base|ModdleElement} element
  421. * @param {string} type
  422. *
  423. * @return {boolean}
  424. */
  425. function is$1(element, type) {
  426. var bo = getBusinessObject(element);
  427. return bo && (typeof bo.$instanceOf === 'function') && bo.$instanceOf(type);
  428. }
  429. /**
  430. * Return true if element has any of the given types.
  431. *
  432. * @param {djs.model.Base} element
  433. * @param {Array<string>} types
  434. *
  435. * @return {boolean}
  436. */
  437. function isAny(element, types) {
  438. return some(types, function(t) {
  439. return is$1(element, t);
  440. });
  441. }
  442. /**
  443. * Return the business object for a given element.
  444. *
  445. * @param {djs.model.Base|ModdleElement} element
  446. *
  447. * @return {ModdleElement}
  448. */
  449. function getBusinessObject(element) {
  450. return (element && element.businessObject) || element;
  451. }
  452. /**
  453. * Return the di object for a given element.
  454. *
  455. * @param {djs.model.Base} element
  456. *
  457. * @return {ModdleElement}
  458. */
  459. function getDi(element) {
  460. return element && element.di;
  461. }
  462. function isExpanded(element, di) {
  463. if (is$1(element, 'bpmn:CallActivity')) {
  464. return false;
  465. }
  466. if (is$1(element, 'bpmn:SubProcess')) {
  467. di = di || getDi(element);
  468. if (di && is$1(di, 'bpmndi:BPMNPlane')) {
  469. return true;
  470. }
  471. return di && !!di.isExpanded;
  472. }
  473. if (is$1(element, 'bpmn:Participant')) {
  474. return !!getBusinessObject(element).processRef;
  475. }
  476. return true;
  477. }
  478. function isEventSubProcess(element) {
  479. return element && !!getBusinessObject(element).triggeredByEvent;
  480. }
  481. function getLabelAttr(semantic) {
  482. if (
  483. is$1(semantic, 'bpmn:FlowElement') ||
  484. is$1(semantic, 'bpmn:Participant') ||
  485. is$1(semantic, 'bpmn:Lane') ||
  486. is$1(semantic, 'bpmn:SequenceFlow') ||
  487. is$1(semantic, 'bpmn:MessageFlow') ||
  488. is$1(semantic, 'bpmn:DataInput') ||
  489. is$1(semantic, 'bpmn:DataOutput')
  490. ) {
  491. return 'name';
  492. }
  493. if (is$1(semantic, 'bpmn:TextAnnotation')) {
  494. return 'text';
  495. }
  496. if (is$1(semantic, 'bpmn:Group')) {
  497. return 'categoryValueRef';
  498. }
  499. }
  500. function getCategoryValue(semantic) {
  501. var categoryValueRef = semantic['categoryValueRef'];
  502. if (!categoryValueRef) {
  503. return '';
  504. }
  505. return categoryValueRef.value || '';
  506. }
  507. function getLabel(element) {
  508. var semantic = element.businessObject,
  509. attr = getLabelAttr(semantic);
  510. if (attr) {
  511. if (attr === 'categoryValueRef') {
  512. return getCategoryValue(semantic);
  513. }
  514. return semantic[attr] || '';
  515. }
  516. }
  517. function ensureImported(element, target) {
  518. if (element.ownerDocument !== target.ownerDocument) {
  519. try {
  520. // may fail on webkit
  521. return target.ownerDocument.importNode(element, true);
  522. } catch (e) {
  523. // ignore
  524. }
  525. }
  526. return element;
  527. }
  528. /**
  529. * appendTo utility
  530. */
  531. /**
  532. * Append a node to a target element and return the appended node.
  533. *
  534. * @param {SVGElement} element
  535. * @param {SVGElement} target
  536. *
  537. * @return {SVGElement} the appended node
  538. */
  539. function appendTo(element, target) {
  540. return target.appendChild(ensureImported(element, target));
  541. }
  542. /**
  543. * append utility
  544. */
  545. /**
  546. * Append a node to an element
  547. *
  548. * @param {SVGElement} element
  549. * @param {SVGElement} node
  550. *
  551. * @return {SVGElement} the element
  552. */
  553. function append(target, node) {
  554. appendTo(node, target);
  555. return target;
  556. }
  557. /**
  558. * attribute accessor utility
  559. */
  560. var LENGTH_ATTR = 2;
  561. var CSS_PROPERTIES = {
  562. 'alignment-baseline': 1,
  563. 'baseline-shift': 1,
  564. 'clip': 1,
  565. 'clip-path': 1,
  566. 'clip-rule': 1,
  567. 'color': 1,
  568. 'color-interpolation': 1,
  569. 'color-interpolation-filters': 1,
  570. 'color-profile': 1,
  571. 'color-rendering': 1,
  572. 'cursor': 1,
  573. 'direction': 1,
  574. 'display': 1,
  575. 'dominant-baseline': 1,
  576. 'enable-background': 1,
  577. 'fill': 1,
  578. 'fill-opacity': 1,
  579. 'fill-rule': 1,
  580. 'filter': 1,
  581. 'flood-color': 1,
  582. 'flood-opacity': 1,
  583. 'font': 1,
  584. 'font-family': 1,
  585. 'font-size': LENGTH_ATTR,
  586. 'font-size-adjust': 1,
  587. 'font-stretch': 1,
  588. 'font-style': 1,
  589. 'font-variant': 1,
  590. 'font-weight': 1,
  591. 'glyph-orientation-horizontal': 1,
  592. 'glyph-orientation-vertical': 1,
  593. 'image-rendering': 1,
  594. 'kerning': 1,
  595. 'letter-spacing': 1,
  596. 'lighting-color': 1,
  597. 'marker': 1,
  598. 'marker-end': 1,
  599. 'marker-mid': 1,
  600. 'marker-start': 1,
  601. 'mask': 1,
  602. 'opacity': 1,
  603. 'overflow': 1,
  604. 'pointer-events': 1,
  605. 'shape-rendering': 1,
  606. 'stop-color': 1,
  607. 'stop-opacity': 1,
  608. 'stroke': 1,
  609. 'stroke-dasharray': 1,
  610. 'stroke-dashoffset': 1,
  611. 'stroke-linecap': 1,
  612. 'stroke-linejoin': 1,
  613. 'stroke-miterlimit': 1,
  614. 'stroke-opacity': 1,
  615. 'stroke-width': LENGTH_ATTR,
  616. 'text-anchor': 1,
  617. 'text-decoration': 1,
  618. 'text-rendering': 1,
  619. 'unicode-bidi': 1,
  620. 'visibility': 1,
  621. 'word-spacing': 1,
  622. 'writing-mode': 1
  623. };
  624. function getAttribute(node, name) {
  625. if (CSS_PROPERTIES[name]) {
  626. return node.style[name];
  627. } else {
  628. return node.getAttributeNS(null, name);
  629. }
  630. }
  631. function setAttribute(node, name, value) {
  632. var hyphenated = name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  633. var type = CSS_PROPERTIES[hyphenated];
  634. if (type) {
  635. // append pixel unit, unless present
  636. if (type === LENGTH_ATTR && typeof value === 'number') {
  637. value = String(value) + 'px';
  638. }
  639. node.style[hyphenated] = value;
  640. } else {
  641. node.setAttributeNS(null, name, value);
  642. }
  643. }
  644. function setAttributes(node, attrs) {
  645. var names = Object.keys(attrs), i, name;
  646. for (i = 0, name; (name = names[i]); i++) {
  647. setAttribute(node, name, attrs[name]);
  648. }
  649. }
  650. /**
  651. * Gets or sets raw attributes on a node.
  652. *
  653. * @param {SVGElement} node
  654. * @param {Object} [attrs]
  655. * @param {String} [name]
  656. * @param {String} [value]
  657. *
  658. * @return {String}
  659. */
  660. function attr$1(node, name, value) {
  661. if (typeof name === 'string') {
  662. if (value !== undefined) {
  663. setAttribute(node, name, value);
  664. } else {
  665. return getAttribute(node, name);
  666. }
  667. } else {
  668. setAttributes(node, name);
  669. }
  670. return node;
  671. }
  672. /**
  673. * Clear utility
  674. */
  675. function index(arr, obj) {
  676. if (arr.indexOf) {
  677. return arr.indexOf(obj);
  678. }
  679. for (var i = 0; i < arr.length; ++i) {
  680. if (arr[i] === obj) {
  681. return i;
  682. }
  683. }
  684. return -1;
  685. }
  686. var re$1 = /\s+/;
  687. var toString$1 = Object.prototype.toString;
  688. function defined(o) {
  689. return typeof o !== 'undefined';
  690. }
  691. /**
  692. * Wrap `el` in a `ClassList`.
  693. *
  694. * @param {Element} el
  695. * @return {ClassList}
  696. * @api public
  697. */
  698. function classes$1(el) {
  699. return new ClassList$1(el);
  700. }
  701. function ClassList$1(el) {
  702. if (!el || !el.nodeType) {
  703. throw new Error('A DOM element reference is required');
  704. }
  705. this.el = el;
  706. this.list = el.classList;
  707. }
  708. /**
  709. * Add class `name` if not already present.
  710. *
  711. * @param {String} name
  712. * @return {ClassList}
  713. * @api public
  714. */
  715. ClassList$1.prototype.add = function(name) {
  716. // classList
  717. if (this.list) {
  718. this.list.add(name);
  719. return this;
  720. }
  721. // fallback
  722. var arr = this.array();
  723. var i = index(arr, name);
  724. if (!~i) {
  725. arr.push(name);
  726. }
  727. if (defined(this.el.className.baseVal)) {
  728. this.el.className.baseVal = arr.join(' ');
  729. } else {
  730. this.el.className = arr.join(' ');
  731. }
  732. return this;
  733. };
  734. /**
  735. * Remove class `name` when present, or
  736. * pass a regular expression to remove
  737. * any which match.
  738. *
  739. * @param {String|RegExp} name
  740. * @return {ClassList}
  741. * @api public
  742. */
  743. ClassList$1.prototype.remove = function(name) {
  744. if ('[object RegExp]' === toString$1.call(name)) {
  745. return this.removeMatching(name);
  746. }
  747. // classList
  748. if (this.list) {
  749. this.list.remove(name);
  750. return this;
  751. }
  752. // fallback
  753. var arr = this.array();
  754. var i = index(arr, name);
  755. if (~i) {
  756. arr.splice(i, 1);
  757. }
  758. this.el.className.baseVal = arr.join(' ');
  759. return this;
  760. };
  761. /**
  762. * Remove all classes matching `re`.
  763. *
  764. * @param {RegExp} re
  765. * @return {ClassList}
  766. * @api private
  767. */
  768. ClassList$1.prototype.removeMatching = function(re) {
  769. var arr = this.array();
  770. for (var i = 0; i < arr.length; i++) {
  771. if (re.test(arr[i])) {
  772. this.remove(arr[i]);
  773. }
  774. }
  775. return this;
  776. };
  777. /**
  778. * Toggle class `name`, can force state via `force`.
  779. *
  780. * For browsers that support classList, but do not support `force` yet,
  781. * the mistake will be detected and corrected.
  782. *
  783. * @param {String} name
  784. * @param {Boolean} force
  785. * @return {ClassList}
  786. * @api public
  787. */
  788. ClassList$1.prototype.toggle = function(name, force) {
  789. // classList
  790. if (this.list) {
  791. if (defined(force)) {
  792. if (force !== this.list.toggle(name, force)) {
  793. this.list.toggle(name); // toggle again to correct
  794. }
  795. } else {
  796. this.list.toggle(name);
  797. }
  798. return this;
  799. }
  800. // fallback
  801. if (defined(force)) {
  802. if (!force) {
  803. this.remove(name);
  804. } else {
  805. this.add(name);
  806. }
  807. } else {
  808. if (this.has(name)) {
  809. this.remove(name);
  810. } else {
  811. this.add(name);
  812. }
  813. }
  814. return this;
  815. };
  816. /**
  817. * Return an array of classes.
  818. *
  819. * @return {Array}
  820. * @api public
  821. */
  822. ClassList$1.prototype.array = function() {
  823. var className = this.el.getAttribute('class') || '';
  824. var str = className.replace(/^\s+|\s+$/g, '');
  825. var arr = str.split(re$1);
  826. if ('' === arr[0]) {
  827. arr.shift();
  828. }
  829. return arr;
  830. };
  831. /**
  832. * Check if class `name` is present.
  833. *
  834. * @param {String} name
  835. * @return {ClassList}
  836. * @api public
  837. */
  838. ClassList$1.prototype.has =
  839. ClassList$1.prototype.contains = function(name) {
  840. return (
  841. this.list ?
  842. this.list.contains(name) :
  843. !! ~index(this.array(), name)
  844. );
  845. };
  846. function remove$2(element) {
  847. var parent = element.parentNode;
  848. if (parent) {
  849. parent.removeChild(element);
  850. }
  851. return element;
  852. }
  853. /**
  854. * Clear utility
  855. */
  856. /**
  857. * Removes all children from the given element
  858. *
  859. * @param {DOMElement} element
  860. * @return {DOMElement} the element (for chaining)
  861. */
  862. function clear$1(element) {
  863. var child;
  864. while ((child = element.firstChild)) {
  865. remove$2(child);
  866. }
  867. return element;
  868. }
  869. var ns = {
  870. svg: 'http://www.w3.org/2000/svg'
  871. };
  872. /**
  873. * DOM parsing utility
  874. */
  875. var SVG_START = '<svg xmlns="' + ns.svg + '"';
  876. function parse$1(svg) {
  877. var unwrap = false;
  878. // ensure we import a valid svg document
  879. if (svg.substring(0, 4) === '<svg') {
  880. if (svg.indexOf(ns.svg) === -1) {
  881. svg = SVG_START + svg.substring(4);
  882. }
  883. } else {
  884. // namespace svg
  885. svg = SVG_START + '>' + svg + '</svg>';
  886. unwrap = true;
  887. }
  888. var parsed = parseDocument(svg);
  889. if (!unwrap) {
  890. return parsed;
  891. }
  892. var fragment = document.createDocumentFragment();
  893. var parent = parsed.firstChild;
  894. while (parent.firstChild) {
  895. fragment.appendChild(parent.firstChild);
  896. }
  897. return fragment;
  898. }
  899. function parseDocument(svg) {
  900. var parser;
  901. // parse
  902. parser = new DOMParser();
  903. parser.async = false;
  904. return parser.parseFromString(svg, 'text/xml');
  905. }
  906. /**
  907. * Create utility for SVG elements
  908. */
  909. /**
  910. * Create a specific type from name or SVG markup.
  911. *
  912. * @param {String} name the name or markup of the element
  913. * @param {Object} [attrs] attributes to set on the element
  914. *
  915. * @returns {SVGElement}
  916. */
  917. function create$1(name, attrs) {
  918. var element;
  919. if (name.charAt(0) === '<') {
  920. element = parse$1(name).firstChild;
  921. element = document.importNode(element, true);
  922. } else {
  923. element = document.createElementNS(ns.svg, name);
  924. }
  925. if (attrs) {
  926. attr$1(element, attrs);
  927. }
  928. return element;
  929. }
  930. /**
  931. * Geometry helpers
  932. */
  933. // fake node used to instantiate svg geometry elements
  934. var node = create$1('svg');
  935. function extend$1(object, props) {
  936. var i, k, keys = Object.keys(props);
  937. for (i = 0; (k = keys[i]); i++) {
  938. object[k] = props[k];
  939. }
  940. return object;
  941. }
  942. /**
  943. * Create matrix via args.
  944. *
  945. * @example
  946. *
  947. * createMatrix({ a: 1, b: 1 });
  948. * createMatrix();
  949. * createMatrix(1, 2, 0, 0, 30, 20);
  950. *
  951. * @return {SVGMatrix}
  952. */
  953. function createMatrix(a, b, c, d, e, f) {
  954. var matrix = node.createSVGMatrix();
  955. switch (arguments.length) {
  956. case 0:
  957. return matrix;
  958. case 1:
  959. return extend$1(matrix, a);
  960. case 6:
  961. return extend$1(matrix, {
  962. a: a,
  963. b: b,
  964. c: c,
  965. d: d,
  966. e: e,
  967. f: f
  968. });
  969. }
  970. }
  971. function createTransform(matrix) {
  972. if (matrix) {
  973. return node.createSVGTransformFromMatrix(matrix);
  974. } else {
  975. return node.createSVGTransform();
  976. }
  977. }
  978. /**
  979. * Serialization util
  980. */
  981. var TEXT_ENTITIES = /([&<>]{1})/g;
  982. var ATTR_ENTITIES = /([\n\r"]{1})/g;
  983. var ENTITY_REPLACEMENT = {
  984. '&': '&amp;',
  985. '<': '&lt;',
  986. '>': '&gt;',
  987. '"': '\''
  988. };
  989. function escape$1(str, pattern) {
  990. function replaceFn(match, entity) {
  991. return ENTITY_REPLACEMENT[entity] || entity;
  992. }
  993. return str.replace(pattern, replaceFn);
  994. }
  995. function serialize(node, output) {
  996. var i, len, attrMap, attrNode, childNodes;
  997. switch (node.nodeType) {
  998. // TEXT
  999. case 3:
  1000. // replace special XML characters
  1001. output.push(escape$1(node.textContent, TEXT_ENTITIES));
  1002. break;
  1003. // ELEMENT
  1004. case 1:
  1005. output.push('<', node.tagName);
  1006. if (node.hasAttributes()) {
  1007. attrMap = node.attributes;
  1008. for (i = 0, len = attrMap.length; i < len; ++i) {
  1009. attrNode = attrMap.item(i);
  1010. output.push(' ', attrNode.name, '="', escape$1(attrNode.value, ATTR_ENTITIES), '"');
  1011. }
  1012. }
  1013. if (node.hasChildNodes()) {
  1014. output.push('>');
  1015. childNodes = node.childNodes;
  1016. for (i = 0, len = childNodes.length; i < len; ++i) {
  1017. serialize(childNodes.item(i), output);
  1018. }
  1019. output.push('</', node.tagName, '>');
  1020. } else {
  1021. output.push('/>');
  1022. }
  1023. break;
  1024. // COMMENT
  1025. case 8:
  1026. output.push('<!--', escape$1(node.nodeValue, TEXT_ENTITIES), '-->');
  1027. break;
  1028. // CDATA
  1029. case 4:
  1030. output.push('<![CDATA[', node.nodeValue, ']]>');
  1031. break;
  1032. default:
  1033. throw new Error('unable to handle node ' + node.nodeType);
  1034. }
  1035. return output;
  1036. }
  1037. /**
  1038. * innerHTML like functionality for SVG elements.
  1039. * based on innerSVG (https://code.google.com/p/innersvg)
  1040. */
  1041. function set(element, svg) {
  1042. var parsed = parse$1(svg);
  1043. // clear element contents
  1044. clear$1(element);
  1045. if (!svg) {
  1046. return;
  1047. }
  1048. if (!isFragment(parsed)) {
  1049. // extract <svg> from parsed document
  1050. parsed = parsed.documentElement;
  1051. }
  1052. var nodes = slice$1(parsed.childNodes);
  1053. // import + append each node
  1054. for (var i = 0; i < nodes.length; i++) {
  1055. appendTo(nodes[i], element);
  1056. }
  1057. }
  1058. function get(element) {
  1059. var child = element.firstChild,
  1060. output = [];
  1061. while (child) {
  1062. serialize(child, output);
  1063. child = child.nextSibling;
  1064. }
  1065. return output.join('');
  1066. }
  1067. function isFragment(node) {
  1068. return node.nodeName === '#document-fragment';
  1069. }
  1070. function innerSVG(element, svg) {
  1071. if (svg !== undefined) {
  1072. try {
  1073. set(element, svg);
  1074. } catch (e) {
  1075. throw new Error('error parsing SVG: ' + e.message);
  1076. }
  1077. return element;
  1078. } else {
  1079. return get(element);
  1080. }
  1081. }
  1082. function slice$1(arr) {
  1083. return Array.prototype.slice.call(arr);
  1084. }
  1085. /**
  1086. * transform accessor utility
  1087. */
  1088. function wrapMatrix(transformList, transform) {
  1089. if (transform instanceof SVGMatrix) {
  1090. return transformList.createSVGTransformFromMatrix(transform);
  1091. }
  1092. return transform;
  1093. }
  1094. function setTransforms(transformList, transforms) {
  1095. var i, t;
  1096. transformList.clear();
  1097. for (i = 0; (t = transforms[i]); i++) {
  1098. transformList.appendItem(wrapMatrix(transformList, t));
  1099. }
  1100. }
  1101. /**
  1102. * Get or set the transforms on the given node.
  1103. *
  1104. * @param {SVGElement} node
  1105. * @param {SVGTransform|SVGMatrix|Array<SVGTransform|SVGMatrix>} [transforms]
  1106. *
  1107. * @return {SVGTransform} the consolidated transform
  1108. */
  1109. function transform$1(node, transforms) {
  1110. var transformList = node.transform.baseVal;
  1111. if (transforms) {
  1112. if (!Array.isArray(transforms)) {
  1113. transforms = [ transforms ];
  1114. }
  1115. setTransforms(transformList, transforms);
  1116. }
  1117. return transformList.consolidate();
  1118. }
  1119. function componentsToPath(elements) {
  1120. return elements.join(',').replace(/,?([A-z]),?/g, '$1');
  1121. }
  1122. function toSVGPoints(points) {
  1123. var result = '';
  1124. for (var i = 0, p; (p = points[i]); i++) {
  1125. result += p.x + ',' + p.y + ' ';
  1126. }
  1127. return result;
  1128. }
  1129. function createLine(points, attrs) {
  1130. var line = create$1('polyline');
  1131. attr$1(line, { points: toSVGPoints(points) });
  1132. if (attrs) {
  1133. attr$1(line, attrs);
  1134. }
  1135. return line;
  1136. }
  1137. function updateLine(gfx, points) {
  1138. attr$1(gfx, { points: toSVGPoints(points) });
  1139. return gfx;
  1140. }
  1141. var black = 'hsl(225, 10%, 15%)';
  1142. // element utils //////////////////////
  1143. /**
  1144. * Checks if eventDefinition of the given element matches with semantic type.
  1145. *
  1146. * @return {boolean} true if element is of the given semantic type
  1147. */
  1148. function isTypedEvent(event, eventDefinitionType, filter) {
  1149. function matches(definition, filter) {
  1150. return every(filter, function(val, key) {
  1151. // we want a == conversion here, to be able to catch
  1152. // undefined == false and friends
  1153. /* jshint -W116 */
  1154. return definition[key] == val;
  1155. });
  1156. }
  1157. return some(event.eventDefinitions, function(definition) {
  1158. return definition.$type === eventDefinitionType && matches(event, filter);
  1159. });
  1160. }
  1161. function isThrowEvent(event) {
  1162. return (event.$type === 'bpmn:IntermediateThrowEvent') || (event.$type === 'bpmn:EndEvent');
  1163. }
  1164. function isCollection(element) {
  1165. var dataObject = element.dataObjectRef;
  1166. return element.isCollection || (dataObject && dataObject.isCollection);
  1167. }
  1168. function getSemantic(element) {
  1169. return element.businessObject;
  1170. }
  1171. // color access //////////////////////
  1172. function getFillColor(element, defaultColor) {
  1173. var di = getDi(element);
  1174. return di.get('color:background-color') || di.get('bioc:fill') || defaultColor || 'white';
  1175. }
  1176. function getStrokeColor(element, defaultColor) {
  1177. var di = getDi(element);
  1178. return di.get('color:border-color') || di.get('bioc:stroke') || defaultColor || black;
  1179. }
  1180. function getLabelColor(element, defaultColor, defaultStrokeColor) {
  1181. var di = getDi(element),
  1182. label = di.get('label');
  1183. return label && label.get('color:color') || defaultColor ||
  1184. getStrokeColor(element, defaultStrokeColor);
  1185. }
  1186. // cropping path customizations //////////////////////
  1187. function getCirclePath(shape) {
  1188. var cx = shape.x + shape.width / 2,
  1189. cy = shape.y + shape.height / 2,
  1190. radius = shape.width / 2;
  1191. var circlePath = [
  1192. ['M', cx, cy],
  1193. ['m', 0, -radius],
  1194. ['a', radius, radius, 0, 1, 1, 0, 2 * radius],
  1195. ['a', radius, radius, 0, 1, 1, 0, -2 * radius],
  1196. ['z']
  1197. ];
  1198. return componentsToPath(circlePath);
  1199. }
  1200. function getRoundRectPath(shape, borderRadius) {
  1201. var x = shape.x,
  1202. y = shape.y,
  1203. width = shape.width,
  1204. height = shape.height;
  1205. var roundRectPath = [
  1206. ['M', x + borderRadius, y],
  1207. ['l', width - borderRadius * 2, 0],
  1208. ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, borderRadius],
  1209. ['l', 0, height - borderRadius * 2],
  1210. ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, borderRadius],
  1211. ['l', borderRadius * 2 - width, 0],
  1212. ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, -borderRadius],
  1213. ['l', 0, borderRadius * 2 - height],
  1214. ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, -borderRadius],
  1215. ['z']
  1216. ];
  1217. return componentsToPath(roundRectPath);
  1218. }
  1219. function getDiamondPath(shape) {
  1220. var width = shape.width,
  1221. height = shape.height,
  1222. x = shape.x,
  1223. y = shape.y,
  1224. halfWidth = width / 2,
  1225. halfHeight = height / 2;
  1226. var diamondPath = [
  1227. ['M', x + halfWidth, y],
  1228. ['l', halfWidth, halfHeight],
  1229. ['l', -halfWidth, halfHeight],
  1230. ['l', -halfWidth, -halfHeight],
  1231. ['z']
  1232. ];
  1233. return componentsToPath(diamondPath);
  1234. }
  1235. function getRectPath(shape) {
  1236. var x = shape.x,
  1237. y = shape.y,
  1238. width = shape.width,
  1239. height = shape.height;
  1240. var rectPath = [
  1241. ['M', x, y],
  1242. ['l', width, 0],
  1243. ['l', 0, height],
  1244. ['l', -width, 0],
  1245. ['z']
  1246. ];
  1247. return componentsToPath(rectPath);
  1248. }
  1249. /**
  1250. * Flatten array, one level deep.
  1251. *
  1252. * @param {Array<?>} arr
  1253. *
  1254. * @return {Array<?>}
  1255. */
  1256. var nativeToString = Object.prototype.toString;
  1257. var nativeHasOwnProperty = Object.prototype.hasOwnProperty;
  1258. function isUndefined$1(obj) {
  1259. return obj === undefined;
  1260. }
  1261. function isArray$1(obj) {
  1262. return nativeToString.call(obj) === '[object Array]';
  1263. }
  1264. /**
  1265. * Return true, if target owns a property with the given key.
  1266. *
  1267. * @param {Object} target
  1268. * @param {String} key
  1269. *
  1270. * @return {Boolean}
  1271. */
  1272. function has(target, key) {
  1273. return nativeHasOwnProperty.call(target, key);
  1274. }
  1275. /**
  1276. * Iterate over collection; returning something
  1277. * (non-undefined) will stop iteration.
  1278. *
  1279. * @param {Array|Object} collection
  1280. * @param {Function} iterator
  1281. *
  1282. * @return {Object} return result that stopped the iteration
  1283. */
  1284. function forEach(collection, iterator) {
  1285. var val, result;
  1286. if (isUndefined$1(collection)) {
  1287. return;
  1288. }
  1289. var convertKey = isArray$1(collection) ? toNum : identity;
  1290. for (var key in collection) {
  1291. if (has(collection, key)) {
  1292. val = collection[key];
  1293. result = iterator(val, convertKey(key));
  1294. if (result === false) {
  1295. return val;
  1296. }
  1297. }
  1298. }
  1299. }
  1300. function identity(arg) {
  1301. return arg;
  1302. }
  1303. function toNum(arg) {
  1304. return Number(arg);
  1305. }
  1306. /**
  1307. * Assigns style attributes in a style-src compliant way.
  1308. *
  1309. * @param {Element} element
  1310. * @param {...Object} styleSources
  1311. *
  1312. * @return {Element} the element
  1313. */
  1314. function assign$1(element) {
  1315. var target = element.style;
  1316. for (var _len = arguments.length, styleSources = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  1317. styleSources[_key - 1] = arguments[_key];
  1318. }
  1319. forEach(styleSources, function (style) {
  1320. if (!style) {
  1321. return;
  1322. }
  1323. forEach(style, function (value, key) {
  1324. target[key] = value;
  1325. });
  1326. });
  1327. return element;
  1328. }
  1329. /**
  1330. * Set attribute `name` to `val`, or get attr `name`.
  1331. *
  1332. * @param {Element} el
  1333. * @param {String} name
  1334. * @param {String} [val]
  1335. * @api public
  1336. */
  1337. function attr(el, name, val) {
  1338. // get
  1339. if (arguments.length == 2) {
  1340. return el.getAttribute(name);
  1341. }
  1342. // remove
  1343. if (val === null) {
  1344. return el.removeAttribute(name);
  1345. }
  1346. // set
  1347. el.setAttribute(name, val);
  1348. return el;
  1349. }
  1350. var indexOf = [].indexOf;
  1351. var indexof = function(arr, obj){
  1352. if (indexOf) return arr.indexOf(obj);
  1353. for (var i = 0; i < arr.length; ++i) {
  1354. if (arr[i] === obj) return i;
  1355. }
  1356. return -1;
  1357. };
  1358. /**
  1359. * Taken from https://github.com/component/classes
  1360. *
  1361. * Without the component bits.
  1362. */
  1363. /**
  1364. * Whitespace regexp.
  1365. */
  1366. var re = /\s+/;
  1367. /**
  1368. * toString reference.
  1369. */
  1370. var toString = Object.prototype.toString;
  1371. /**
  1372. * Wrap `el` in a `ClassList`.
  1373. *
  1374. * @param {Element} el
  1375. * @return {ClassList}
  1376. * @api public
  1377. */
  1378. function classes(el) {
  1379. return new ClassList(el);
  1380. }
  1381. /**
  1382. * Initialize a new ClassList for `el`.
  1383. *
  1384. * @param {Element} el
  1385. * @api private
  1386. */
  1387. function ClassList(el) {
  1388. if (!el || !el.nodeType) {
  1389. throw new Error('A DOM element reference is required');
  1390. }
  1391. this.el = el;
  1392. this.list = el.classList;
  1393. }
  1394. /**
  1395. * Add class `name` if not already present.
  1396. *
  1397. * @param {String} name
  1398. * @return {ClassList}
  1399. * @api public
  1400. */
  1401. ClassList.prototype.add = function (name) {
  1402. // classList
  1403. if (this.list) {
  1404. this.list.add(name);
  1405. return this;
  1406. }
  1407. // fallback
  1408. var arr = this.array();
  1409. var i = indexof(arr, name);
  1410. if (!~i) arr.push(name);
  1411. this.el.className = arr.join(' ');
  1412. return this;
  1413. };
  1414. /**
  1415. * Remove class `name` when present, or
  1416. * pass a regular expression to remove
  1417. * any which match.
  1418. *
  1419. * @param {String|RegExp} name
  1420. * @return {ClassList}
  1421. * @api public
  1422. */
  1423. ClassList.prototype.remove = function (name) {
  1424. if ('[object RegExp]' == toString.call(name)) {
  1425. return this.removeMatching(name);
  1426. }
  1427. // classList
  1428. if (this.list) {
  1429. this.list.remove(name);
  1430. return this;
  1431. }
  1432. // fallback
  1433. var arr = this.array();
  1434. var i = indexof(arr, name);
  1435. if (~i) arr.splice(i, 1);
  1436. this.el.className = arr.join(' ');
  1437. return this;
  1438. };
  1439. /**
  1440. * Remove all classes matching `re`.
  1441. *
  1442. * @param {RegExp} re
  1443. * @return {ClassList}
  1444. * @api private
  1445. */
  1446. ClassList.prototype.removeMatching = function (re) {
  1447. var arr = this.array();
  1448. for (var i = 0; i < arr.length; i++) {
  1449. if (re.test(arr[i])) {
  1450. this.remove(arr[i]);
  1451. }
  1452. }
  1453. return this;
  1454. };
  1455. /**
  1456. * Toggle class `name`, can force state via `force`.
  1457. *
  1458. * For browsers that support classList, but do not support `force` yet,
  1459. * the mistake will be detected and corrected.
  1460. *
  1461. * @param {String} name
  1462. * @param {Boolean} force
  1463. * @return {ClassList}
  1464. * @api public
  1465. */
  1466. ClassList.prototype.toggle = function (name, force) {
  1467. // classList
  1468. if (this.list) {
  1469. if ('undefined' !== typeof force) {
  1470. if (force !== this.list.toggle(name, force)) {
  1471. this.list.toggle(name); // toggle again to correct
  1472. }
  1473. } else {
  1474. this.list.toggle(name);
  1475. }
  1476. return this;
  1477. }
  1478. // fallback
  1479. if ('undefined' !== typeof force) {
  1480. if (!force) {
  1481. this.remove(name);
  1482. } else {
  1483. this.add(name);
  1484. }
  1485. } else {
  1486. if (this.has(name)) {
  1487. this.remove(name);
  1488. } else {
  1489. this.add(name);
  1490. }
  1491. }
  1492. return this;
  1493. };
  1494. /**
  1495. * Return an array of classes.
  1496. *
  1497. * @return {Array}
  1498. * @api public
  1499. */
  1500. ClassList.prototype.array = function () {
  1501. var className = this.el.getAttribute('class') || '';
  1502. var str = className.replace(/^\s+|\s+$/g, '');
  1503. var arr = str.split(re);
  1504. if ('' === arr[0]) arr.shift();
  1505. return arr;
  1506. };
  1507. /**
  1508. * Check if class `name` is present.
  1509. *
  1510. * @param {String} name
  1511. * @return {ClassList}
  1512. * @api public
  1513. */
  1514. ClassList.prototype.has = ClassList.prototype.contains = function (name) {
  1515. return this.list ? this.list.contains(name) : !!~indexof(this.array(), name);
  1516. };
  1517. /**
  1518. * Remove all children from the given element.
  1519. */
  1520. function clear(el) {
  1521. var c;
  1522. while (el.childNodes.length) {
  1523. c = el.childNodes[0];
  1524. el.removeChild(c);
  1525. }
  1526. return el;
  1527. }
  1528. var proto = typeof Element !== 'undefined' ? Element.prototype : {};
  1529. var vendor = proto.matches
  1530. || proto.matchesSelector
  1531. || proto.webkitMatchesSelector
  1532. || proto.mozMatchesSelector
  1533. || proto.msMatchesSelector
  1534. || proto.oMatchesSelector;
  1535. var matchesSelector = match;
  1536. /**
  1537. * Match `el` to `selector`.
  1538. *
  1539. * @param {Element} el
  1540. * @param {String} selector
  1541. * @return {Boolean}
  1542. * @api public
  1543. */
  1544. function match(el, selector) {
  1545. if (!el || el.nodeType !== 1) return false;
  1546. if (vendor) return vendor.call(el, selector);
  1547. var nodes = el.parentNode.querySelectorAll(selector);
  1548. for (var i = 0; i < nodes.length; i++) {
  1549. if (nodes[i] == el) return true;
  1550. }
  1551. return false;
  1552. }
  1553. /**
  1554. * Closest
  1555. *
  1556. * @param {Element} el
  1557. * @param {String} selector
  1558. * @param {Boolean} checkYourSelf (optional)
  1559. */
  1560. function closest (element, selector, checkYourSelf) {
  1561. var currentElem = checkYourSelf ? element : element.parentNode;
  1562. while (currentElem && currentElem.nodeType !== document.DOCUMENT_NODE && currentElem.nodeType !== document.DOCUMENT_FRAGMENT_NODE) {
  1563. if (matchesSelector(currentElem, selector)) {
  1564. return currentElem;
  1565. }
  1566. currentElem = currentElem.parentNode;
  1567. }
  1568. return matchesSelector(currentElem, selector) ? currentElem : null;
  1569. }
  1570. var bind$1 = window.addEventListener ? 'addEventListener' : 'attachEvent',
  1571. unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
  1572. prefix$6 = bind$1 !== 'addEventListener' ? 'on' : '';
  1573. /**
  1574. * Bind `el` event `type` to `fn`.
  1575. *
  1576. * @param {Element} el
  1577. * @param {String} type
  1578. * @param {Function} fn
  1579. * @param {Boolean} capture
  1580. * @return {Function}
  1581. * @api public
  1582. */
  1583. var bind_1 = function(el, type, fn, capture){
  1584. el[bind$1](prefix$6 + type, fn, capture || false);
  1585. return fn;
  1586. };
  1587. /**
  1588. * Unbind `el` event `type`'s callback `fn`.
  1589. *
  1590. * @param {Element} el
  1591. * @param {String} type
  1592. * @param {Function} fn
  1593. * @param {Boolean} capture
  1594. * @return {Function}
  1595. * @api public
  1596. */
  1597. var unbind_1 = function(el, type, fn, capture){
  1598. el[unbind](prefix$6 + type, fn, capture || false);
  1599. return fn;
  1600. };
  1601. var componentEvent = {
  1602. bind: bind_1,
  1603. unbind: unbind_1
  1604. };
  1605. /**
  1606. * Module dependencies.
  1607. */
  1608. /**
  1609. * Delegate event `type` to `selector`
  1610. * and invoke `fn(e)`. A callback function
  1611. * is returned which may be passed to `.unbind()`.
  1612. *
  1613. * @param {Element} el
  1614. * @param {String} selector
  1615. * @param {String} type
  1616. * @param {Function} fn
  1617. * @param {Boolean} capture
  1618. * @return {Function}
  1619. * @api public
  1620. */
  1621. // Some events don't bubble, so we want to bind to the capture phase instead
  1622. // when delegating.
  1623. var forceCaptureEvents = ['focus', 'blur'];
  1624. function bind$2(el, selector, type, fn, capture) {
  1625. if (forceCaptureEvents.indexOf(type) !== -1) {
  1626. capture = true;
  1627. }
  1628. return componentEvent.bind(el, type, function (e) {
  1629. var target = e.target || e.srcElement;
  1630. e.delegateTarget = closest(target, selector, true);
  1631. if (e.delegateTarget) {
  1632. fn.call(el, e);
  1633. }
  1634. }, capture);
  1635. }
  1636. /**
  1637. * Unbind event `type`'s callback `fn`.
  1638. *
  1639. * @param {Element} el
  1640. * @param {String} type
  1641. * @param {Function} fn
  1642. * @param {Boolean} capture
  1643. * @api public
  1644. */
  1645. function unbind$1(el, type, fn, capture) {
  1646. if (forceCaptureEvents.indexOf(type) !== -1) {
  1647. capture = true;
  1648. }
  1649. return componentEvent.unbind(el, type, fn, capture);
  1650. }
  1651. var delegate = {
  1652. bind: bind$2,
  1653. unbind: unbind$1
  1654. };
  1655. /**
  1656. * Expose `parse`.
  1657. */
  1658. var domify = parse;
  1659. /**
  1660. * Tests for browser support.
  1661. */
  1662. var innerHTMLBug = false;
  1663. var bugTestDiv;
  1664. if (typeof document !== 'undefined') {
  1665. bugTestDiv = document.createElement('div');
  1666. // Setup
  1667. bugTestDiv.innerHTML = ' <link/><table></table><a href="/a">a</a><input type="checkbox"/>';
  1668. // Make sure that link elements get serialized correctly by innerHTML
  1669. // This requires a wrapper element in IE
  1670. innerHTMLBug = !bugTestDiv.getElementsByTagName('link').length;
  1671. bugTestDiv = undefined;
  1672. }
  1673. /**
  1674. * Wrap map from jquery.
  1675. */
  1676. var map$1 = {
  1677. legend: [1, '<fieldset>', '</fieldset>'],
  1678. tr: [2, '<table><tbody>', '</tbody></table>'],
  1679. col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
  1680. // for script/link/style tags to work in IE6-8, you have to wrap
  1681. // in a div with a non-whitespace character in front, ha!
  1682. _default: innerHTMLBug ? [1, 'X<div>', '</div>'] : [0, '', '']
  1683. };
  1684. map$1.td =
  1685. map$1.th = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
  1686. map$1.option =
  1687. map$1.optgroup = [1, '<select multiple="multiple">', '</select>'];
  1688. map$1.thead =
  1689. map$1.tbody =
  1690. map$1.colgroup =
  1691. map$1.caption =
  1692. map$1.tfoot = [1, '<table>', '</table>'];
  1693. map$1.polyline =
  1694. map$1.ellipse =
  1695. map$1.polygon =
  1696. map$1.circle =
  1697. map$1.text =
  1698. map$1.line =
  1699. map$1.path =
  1700. map$1.rect =
  1701. map$1.g = [1, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">','</svg>'];
  1702. /**
  1703. * Parse `html` and return a DOM Node instance, which could be a TextNode,
  1704. * HTML DOM Node of some kind (<div> for example), or a DocumentFragment
  1705. * instance, depending on the contents of the `html` string.
  1706. *
  1707. * @param {String} html - HTML string to "domify"
  1708. * @param {Document} doc - The `document` instance to create the Node for
  1709. * @return {DOMNode} the TextNode, DOM Node, or DocumentFragment instance
  1710. * @api private
  1711. */
  1712. function parse(html, doc) {
  1713. if ('string' != typeof html) throw new TypeError('String expected');
  1714. // default to the global `document` object
  1715. if (!doc) doc = document;
  1716. // tag name
  1717. var m = /<([\w:]+)/.exec(html);
  1718. if (!m) return doc.createTextNode(html);
  1719. html = html.replace(/^\s+|\s+$/g, ''); // Remove leading/trailing whitespace
  1720. var tag = m[1];
  1721. // body support
  1722. if (tag == 'body') {
  1723. var el = doc.createElement('html');
  1724. el.innerHTML = html;
  1725. return el.removeChild(el.lastChild);
  1726. }
  1727. // wrap map
  1728. var wrap = map$1[tag] || map$1._default;
  1729. var depth = wrap[0];
  1730. var prefix = wrap[1];
  1731. var suffix = wrap[2];
  1732. var el = doc.createElement('div');
  1733. el.innerHTML = prefix + html + suffix;
  1734. while (depth--) el = el.lastChild;
  1735. // one element
  1736. if (el.firstChild == el.lastChild) {
  1737. return el.removeChild(el.firstChild);
  1738. }
  1739. // several elements
  1740. var fragment = doc.createDocumentFragment();
  1741. while (el.firstChild) {
  1742. fragment.appendChild(el.removeChild(el.firstChild));
  1743. }
  1744. return fragment;
  1745. }
  1746. function query(selector, el) {
  1747. el = el || document;
  1748. return el.querySelector(selector);
  1749. }
  1750. function all(selector, el) {
  1751. el = el || document;
  1752. return el.querySelectorAll(selector);
  1753. }
  1754. function remove$1(el) {
  1755. el.parentNode && el.parentNode.removeChild(el);
  1756. }
  1757. /**
  1758. * @param {<SVGElement>} element
  1759. * @param {number} x
  1760. * @param {number} y
  1761. * @param {number} angle
  1762. * @param {number} amount
  1763. */
  1764. function transform(gfx, x, y, angle, amount) {
  1765. var translate = createTransform();
  1766. translate.setTranslate(x, y);
  1767. var rotate = createTransform();
  1768. rotate.setRotate(angle || 0, 0, 0);
  1769. var scale = createTransform();
  1770. scale.setScale(amount || 1, amount || 1);
  1771. transform$1(gfx, [ translate, rotate, scale ]);
  1772. }
  1773. /**
  1774. * @param {SVGElement} element
  1775. * @param {number} x
  1776. * @param {number} y
  1777. */
  1778. function translate$1(gfx, x, y) {
  1779. var translate = createTransform();
  1780. translate.setTranslate(x, y);
  1781. transform$1(gfx, translate);
  1782. }
  1783. /**
  1784. * @param {SVGElement} element
  1785. * @param {number} angle
  1786. */
  1787. function rotate(gfx, angle) {
  1788. var rotate = createTransform();
  1789. rotate.setRotate(angle, 0, 0);
  1790. transform$1(gfx, rotate);
  1791. }
  1792. function createCommonjsModule(fn, module) {
  1793. return module = { exports: {} }, fn(module, module.exports), module.exports;
  1794. }
  1795. var hat_1 = createCommonjsModule(function (module) {
  1796. var hat = module.exports = function (bits, base) {
  1797. if (!base) base = 16;
  1798. if (bits === undefined) bits = 128;
  1799. if (bits <= 0) return '0';
  1800. var digits = Math.log(Math.pow(2, bits)) / Math.log(base);
  1801. for (var i = 2; digits === Infinity; i *= 2) {
  1802. digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i;
  1803. }
  1804. var rem = digits - Math.floor(digits);
  1805. var res = '';
  1806. for (var i = 0; i < Math.floor(digits); i++) {
  1807. var x = Math.floor(Math.random() * base).toString(base);
  1808. res = x + res;
  1809. }
  1810. if (rem) {
  1811. var b = Math.pow(base, rem);
  1812. var x = Math.floor(Math.random() * b).toString(base);
  1813. res = x + res;
  1814. }
  1815. var parsed = parseInt(res, base);
  1816. if (parsed !== Infinity && parsed >= Math.pow(2, bits)) {
  1817. return hat(bits, base)
  1818. }
  1819. else return res;
  1820. };
  1821. hat.rack = function (bits, base, expandBy) {
  1822. var fn = function (data) {
  1823. var iters = 0;
  1824. do {
  1825. if (iters ++ > 10) {
  1826. if (expandBy) bits += expandBy;
  1827. else throw new Error('too many ID collisions, use more bits')
  1828. }
  1829. var id = hat(bits, base);
  1830. } while (Object.hasOwnProperty.call(hats, id));
  1831. hats[id] = data;
  1832. return id;
  1833. };
  1834. var hats = fn.hats = {};
  1835. fn.get = function (id) {
  1836. return fn.hats[id];
  1837. };
  1838. fn.set = function (id, value) {
  1839. fn.hats[id] = value;
  1840. return fn;
  1841. };
  1842. fn.bits = bits || 128;
  1843. fn.base = base || 16;
  1844. return fn;
  1845. };
  1846. });
  1847. /**
  1848. * Create a new id generator / cache instance.
  1849. *
  1850. * You may optionally provide a seed that is used internally.
  1851. *
  1852. * @param {Seed} seed
  1853. */
  1854. function Ids(seed) {
  1855. if (!(this instanceof Ids)) {
  1856. return new Ids(seed);
  1857. }
  1858. seed = seed || [128, 36, 1];
  1859. this._seed = seed.length ? hat_1.rack(seed[0], seed[1], seed[2]) : seed;
  1860. }
  1861. /**
  1862. * Generate a next id.
  1863. *
  1864. * @param {Object} [element] element to bind the id to
  1865. *
  1866. * @return {String} id
  1867. */
  1868. Ids.prototype.next = function (element) {
  1869. return this._seed(element || true);
  1870. };
  1871. /**
  1872. * Generate a next id with a given prefix.
  1873. *
  1874. * @param {Object} [element] element to bind the id to
  1875. *
  1876. * @return {String} id
  1877. */
  1878. Ids.prototype.nextPrefixed = function (prefix, element) {
  1879. var id;
  1880. do {
  1881. id = prefix + this.next(true);
  1882. } while (this.assigned(id)); // claim {prefix}{random}
  1883. this.claim(id, element); // return
  1884. return id;
  1885. };
  1886. /**
  1887. * Manually claim an existing id.
  1888. *
  1889. * @param {String} id
  1890. * @param {String} [element] element the id is claimed by
  1891. */
  1892. Ids.prototype.claim = function (id, element) {
  1893. this._seed.set(id, element || true);
  1894. };
  1895. /**
  1896. * Returns true if the given id has already been assigned.
  1897. *
  1898. * @param {String} id
  1899. * @return {Boolean}
  1900. */
  1901. Ids.prototype.assigned = function (id) {
  1902. return this._seed.get(id) || false;
  1903. };
  1904. /**
  1905. * Unclaim an id.
  1906. *
  1907. * @param {String} id the id to unclaim
  1908. */
  1909. Ids.prototype.unclaim = function (id) {
  1910. delete this._seed.hats[id];
  1911. };
  1912. /**
  1913. * Clear all claimed ids.
  1914. */
  1915. Ids.prototype.clear = function () {
  1916. var hats = this._seed.hats,
  1917. id;
  1918. for (id in hats) {
  1919. this.unclaim(id);
  1920. }
  1921. };
  1922. var RENDERER_IDS = new Ids();
  1923. var TASK_BORDER_RADIUS = 10;
  1924. var INNER_OUTER_DIST = 3;
  1925. var DEFAULT_FILL_OPACITY = .95,
  1926. HIGH_FILL_OPACITY = .35;
  1927. var ELEMENT_LABEL_DISTANCE = 10;
  1928. function BpmnRenderer(
  1929. config, eventBus, styles, pathMap,
  1930. canvas, textRenderer, priority) {
  1931. BaseRenderer.call(this, eventBus, priority);
  1932. var defaultFillColor = config && config.defaultFillColor,
  1933. defaultStrokeColor = config && config.defaultStrokeColor,
  1934. defaultLabelColor = config && config.defaultLabelColor;
  1935. var rendererId = RENDERER_IDS.next();
  1936. var markers = {};
  1937. var computeStyle = styles.computeStyle;
  1938. function addMarker(id, options) {
  1939. var attrs = assign({
  1940. fill: black,
  1941. strokeWidth: 1,
  1942. strokeLinecap: 'round',
  1943. strokeDasharray: 'none'
  1944. }, options.attrs);
  1945. var ref = options.ref || { x: 0, y: 0 };
  1946. var scale = options.scale || 1;
  1947. // fix for safari / chrome / firefox bug not correctly
  1948. // resetting stroke dash array
  1949. if (attrs.strokeDasharray === 'none') {
  1950. attrs.strokeDasharray = [10000, 1];
  1951. }
  1952. var marker = create$1('marker');
  1953. attr$1(options.element, attrs);
  1954. append(marker, options.element);
  1955. attr$1(marker, {
  1956. id: id,
  1957. viewBox: '0 0 20 20',
  1958. refX: ref.x,
  1959. refY: ref.y,
  1960. markerWidth: 20 * scale,
  1961. markerHeight: 20 * scale,
  1962. orient: 'auto'
  1963. });
  1964. var defs = query('defs', canvas._svg);
  1965. if (!defs) {
  1966. defs = create$1('defs');
  1967. append(canvas._svg, defs);
  1968. }
  1969. append(defs, marker);
  1970. markers[id] = marker;
  1971. }
  1972. function colorEscape(str) {
  1973. // only allow characters and numbers
  1974. return str.replace(/[^0-9a-zA-z]+/g, '_');
  1975. }
  1976. function marker(type, fill, stroke) {
  1977. var id = type + '-' + colorEscape(fill) + '-' + colorEscape(stroke) + '-' + rendererId;
  1978. if (!markers[id]) {
  1979. createMarker(id, type, fill, stroke);
  1980. }
  1981. return 'url(#' + id + ')';
  1982. }
  1983. function createMarker(id, type, fill, stroke) {
  1984. if (type === 'sequenceflow-end') {
  1985. var sequenceflowEnd = create$1('path');
  1986. attr$1(sequenceflowEnd, { d: 'M 1 5 L 11 10 L 1 15 Z' });
  1987. addMarker(id, {
  1988. element: sequenceflowEnd,
  1989. ref: { x: 11, y: 10 },
  1990. scale: 0.5,
  1991. attrs: {
  1992. fill: stroke,
  1993. stroke: stroke
  1994. }
  1995. });
  1996. }
  1997. if (type === 'messageflow-start') {
  1998. var messageflowStart = create$1('circle');
  1999. attr$1(messageflowStart, { cx: 6, cy: 6, r: 3.5 });
  2000. addMarker(id, {
  2001. element: messageflowStart,
  2002. attrs: {
  2003. fill: fill,
  2004. stroke: stroke
  2005. },
  2006. ref: { x: 6, y: 6 }
  2007. });
  2008. }
  2009. if (type === 'messageflow-end') {
  2010. var messageflowEnd = create$1('path');
  2011. attr$1(messageflowEnd, { d: 'm 1 5 l 0 -3 l 7 3 l -7 3 z' });
  2012. addMarker(id, {
  2013. element: messageflowEnd,
  2014. attrs: {
  2015. fill: fill,
  2016. stroke: stroke,
  2017. strokeLinecap: 'butt'
  2018. },
  2019. ref: { x: 8.5, y: 5 }
  2020. });
  2021. }
  2022. if (type === 'association-start') {
  2023. var associationStart = create$1('path');
  2024. attr$1(associationStart, { d: 'M 11 5 L 1 10 L 11 15' });
  2025. addMarker(id, {
  2026. element: associationStart,
  2027. attrs: {
  2028. fill: 'none',
  2029. stroke: stroke,
  2030. strokeWidth: 1.5
  2031. },
  2032. ref: { x: 1, y: 10 },
  2033. scale: 0.5
  2034. });
  2035. }
  2036. if (type === 'association-end') {
  2037. var associationEnd = create$1('path');
  2038. attr$1(associationEnd, { d: 'M 1 5 L 11 10 L 1 15' });
  2039. addMarker(id, {
  2040. element: associationEnd,
  2041. attrs: {
  2042. fill: 'none',
  2043. stroke: stroke,
  2044. strokeWidth: 1.5
  2045. },
  2046. ref: { x: 12, y: 10 },
  2047. scale: 0.5
  2048. });
  2049. }
  2050. if (type === 'conditional-flow-marker') {
  2051. var conditionalflowMarker = create$1('path');
  2052. attr$1(conditionalflowMarker, { d: 'M 0 10 L 8 6 L 16 10 L 8 14 Z' });
  2053. addMarker(id, {
  2054. element: conditionalflowMarker,
  2055. attrs: {
  2056. fill: fill,
  2057. stroke: stroke
  2058. },
  2059. ref: { x: -1, y: 10 },
  2060. scale: 0.5
  2061. });
  2062. }
  2063. if (type === 'conditional-default-flow-marker') {
  2064. var conditionaldefaultflowMarker = create$1('path');
  2065. attr$1(conditionaldefaultflowMarker, { d: 'M 6 4 L 10 16' });
  2066. addMarker(id, {
  2067. element: conditionaldefaultflowMarker,
  2068. attrs: {
  2069. stroke: stroke
  2070. },
  2071. ref: { x: 0, y: 10 },
  2072. scale: 0.5
  2073. });
  2074. }
  2075. }
  2076. function drawCircle(parentGfx, width, height, offset, attrs) {
  2077. if (isObject(offset)) {
  2078. attrs = offset;
  2079. offset = 0;
  2080. }
  2081. offset = offset || 0;
  2082. attrs = computeStyle(attrs, {
  2083. stroke: black,
  2084. strokeWidth: 2,
  2085. fill: 'white'
  2086. });
  2087. if (attrs.fill === 'none') {
  2088. delete attrs.fillOpacity;
  2089. }
  2090. var cx = width / 2,
  2091. cy = height / 2;
  2092. var circle = create$1('circle');
  2093. attr$1(circle, {
  2094. cx: cx,
  2095. cy: cy,
  2096. r: Math.round((width + height) / 4 - offset)
  2097. });
  2098. attr$1(circle, attrs);
  2099. append(parentGfx, circle);
  2100. return circle;
  2101. }
  2102. function drawRect(parentGfx, width, height, r, offset, attrs) {
  2103. if (isObject(offset)) {
  2104. attrs = offset;
  2105. offset = 0;
  2106. }
  2107. offset = offset || 0;
  2108. attrs = computeStyle(attrs, {
  2109. stroke: black,
  2110. strokeWidth: 2,
  2111. fill: 'white'
  2112. });
  2113. var rect = create$1('rect');
  2114. attr$1(rect, {
  2115. x: offset,
  2116. y: offset,
  2117. width: width - offset * 2,
  2118. height: height - offset * 2,
  2119. rx: r,
  2120. ry: r
  2121. });
  2122. attr$1(rect, attrs);
  2123. append(parentGfx, rect);
  2124. return rect;
  2125. }
  2126. function drawDiamond(parentGfx, width, height, attrs) {
  2127. var x_2 = width / 2;
  2128. var y_2 = height / 2;
  2129. var points = [{ x: x_2, y: 0 }, { x: width, y: y_2 }, { x: x_2, y: height }, { x: 0, y: y_2 }];
  2130. var pointsString = points.map(function(point) {
  2131. return point.x + ',' + point.y;
  2132. }).join(' ');
  2133. attrs = computeStyle(attrs, {
  2134. stroke: black,
  2135. strokeWidth: 2,
  2136. fill: 'white'
  2137. });
  2138. var polygon = create$1('polygon');
  2139. attr$1(polygon, {
  2140. points: pointsString
  2141. });
  2142. attr$1(polygon, attrs);
  2143. append(parentGfx, polygon);
  2144. return polygon;
  2145. }
  2146. function drawLine(parentGfx, waypoints, attrs) {
  2147. attrs = computeStyle(attrs, [ 'no-fill' ], {
  2148. stroke: black,
  2149. strokeWidth: 2,
  2150. fill: 'none'
  2151. });
  2152. var line = createLine(waypoints, attrs);
  2153. append(parentGfx, line);
  2154. return line;
  2155. }
  2156. function drawPath(parentGfx, d, attrs) {
  2157. attrs = computeStyle(attrs, [ 'no-fill' ], {
  2158. strokeWidth: 2,
  2159. stroke: black
  2160. });
  2161. var path = create$1('path');
  2162. attr$1(path, { d: d });
  2163. attr$1(path, attrs);
  2164. append(parentGfx, path);
  2165. return path;
  2166. }
  2167. function drawMarker(type, parentGfx, path, attrs) {
  2168. return drawPath(parentGfx, path, assign({ 'data-marker': type }, attrs));
  2169. }
  2170. function renderer(type) {
  2171. return handlers[type];
  2172. }
  2173. function as(type) {
  2174. return function(parentGfx, element) {
  2175. return renderer(type)(parentGfx, element);
  2176. };
  2177. }
  2178. function renderEventContent(element, parentGfx) {
  2179. var event = getSemantic(element);
  2180. var isThrowing = isThrowEvent(event);
  2181. if (event.eventDefinitions && event.eventDefinitions.length>1) {
  2182. if (event.parallelMultiple) {
  2183. return renderer('bpmn:ParallelMultipleEventDefinition')(parentGfx, element, isThrowing);
  2184. }
  2185. else {
  2186. return renderer('bpmn:MultipleEventDefinition')(parentGfx, element, isThrowing);
  2187. }
  2188. }
  2189. if (isTypedEvent(event, 'bpmn:MessageEventDefinition')) {
  2190. return renderer('bpmn:MessageEventDefinition')(parentGfx, element, isThrowing);
  2191. }
  2192. if (isTypedEvent(event, 'bpmn:TimerEventDefinition')) {
  2193. return renderer('bpmn:TimerEventDefinition')(parentGfx, element, isThrowing);
  2194. }
  2195. if (isTypedEvent(event, 'bpmn:ConditionalEventDefinition')) {
  2196. return renderer('bpmn:ConditionalEventDefinition')(parentGfx, element);
  2197. }
  2198. if (isTypedEvent(event, 'bpmn:SignalEventDefinition')) {
  2199. return renderer('bpmn:SignalEventDefinition')(parentGfx, element, isThrowing);
  2200. }
  2201. if (isTypedEvent(event, 'bpmn:EscalationEventDefinition')) {
  2202. return renderer('bpmn:EscalationEventDefinition')(parentGfx, element, isThrowing);
  2203. }
  2204. if (isTypedEvent(event, 'bpmn:LinkEventDefinition')) {
  2205. return renderer('bpmn:LinkEventDefinition')(parentGfx, element, isThrowing);
  2206. }
  2207. if (isTypedEvent(event, 'bpmn:ErrorEventDefinition')) {
  2208. return renderer('bpmn:ErrorEventDefinition')(parentGfx, element, isThrowing);
  2209. }
  2210. if (isTypedEvent(event, 'bpmn:CancelEventDefinition')) {
  2211. return renderer('bpmn:CancelEventDefinition')(parentGfx, element, isThrowing);
  2212. }
  2213. if (isTypedEvent(event, 'bpmn:CompensateEventDefinition')) {
  2214. return renderer('bpmn:CompensateEventDefinition')(parentGfx, element, isThrowing);
  2215. }
  2216. if (isTypedEvent(event, 'bpmn:TerminateEventDefinition')) {
  2217. return renderer('bpmn:TerminateEventDefinition')(parentGfx, element, isThrowing);
  2218. }
  2219. return null;
  2220. }
  2221. function renderLabel(parentGfx, label, options) {
  2222. options = assign({
  2223. size: {
  2224. width: 100
  2225. }
  2226. }, options);
  2227. var text = textRenderer.createText(label || '', options);
  2228. classes$1(text).add('djs-label');
  2229. append(parentGfx, text);
  2230. return text;
  2231. }
  2232. function renderEmbeddedLabel(parentGfx, element, align) {
  2233. var semantic = getSemantic(element);
  2234. return renderLabel(parentGfx, semantic.name, {
  2235. box: element,
  2236. align: align,
  2237. padding: 5,
  2238. style: {
  2239. fill: getLabelColor(element, defaultLabelColor, defaultStrokeColor)
  2240. }
  2241. });
  2242. }
  2243. function renderExternalLabel(parentGfx, element) {
  2244. var box = {
  2245. width: 90,
  2246. height: 30,
  2247. x: element.width / 2 + element.x,
  2248. y: element.height / 2 + element.y
  2249. };
  2250. return renderLabel(parentGfx, getLabel(element), {
  2251. box: box,
  2252. fitBox: true,
  2253. style: assign(
  2254. {},
  2255. textRenderer.getExternalStyle(),
  2256. {
  2257. fill: getLabelColor(element, defaultLabelColor, defaultStrokeColor)
  2258. }
  2259. )
  2260. });
  2261. }
  2262. function renderLaneLabel(parentGfx, text, element) {
  2263. var textBox = renderLabel(parentGfx, text, {
  2264. box: {
  2265. height: 30,
  2266. width: element.height
  2267. },
  2268. align: 'center-middle',
  2269. style: {
  2270. fill: getLabelColor(element, defaultLabelColor, defaultStrokeColor)
  2271. }
  2272. });
  2273. var top = -1 * element.height;
  2274. transform(textBox, 0, -top, 270);
  2275. }
  2276. function createPathFromConnection(connection) {
  2277. var waypoints = connection.waypoints;
  2278. var pathData = 'm ' + waypoints[0].x + ',' + waypoints[0].y;
  2279. for (var i = 1; i < waypoints.length; i++) {
  2280. pathData += 'L' + waypoints[i].x + ',' + waypoints[i].y + ' ';
  2281. }
  2282. return pathData;
  2283. }
  2284. var handlers = this.handlers = {
  2285. 'bpmn:Event': function(parentGfx, element, attrs) {
  2286. if (!('fillOpacity' in attrs)) {
  2287. attrs.fillOpacity = DEFAULT_FILL_OPACITY;
  2288. }
  2289. return drawCircle(parentGfx, element.width, element.height, attrs);
  2290. },
  2291. 'bpmn:StartEvent': function(parentGfx, element) {
  2292. var attrs = {
  2293. fill: getFillColor(element, defaultFillColor),
  2294. stroke: getStrokeColor(element, defaultStrokeColor)
  2295. };
  2296. var semantic = getSemantic(element);
  2297. if (!semantic.isInterrupting) {
  2298. attrs = {
  2299. strokeDasharray: '6',
  2300. strokeLinecap: 'round',
  2301. fill: getFillColor(element, defaultFillColor),
  2302. stroke: getStrokeColor(element, defaultStrokeColor)
  2303. };
  2304. }
  2305. var circle = renderer('bpmn:Event')(parentGfx, element, attrs);
  2306. renderEventContent(element, parentGfx);
  2307. return circle;
  2308. },
  2309. 'bpmn:MessageEventDefinition': function(parentGfx, element, isThrowing) {
  2310. var pathData = pathMap.getScaledPath('EVENT_MESSAGE', {
  2311. xScaleFactor: 0.9,
  2312. yScaleFactor: 0.9,
  2313. containerWidth: element.width,
  2314. containerHeight: element.height,
  2315. position: {
  2316. mx: 0.235,
  2317. my: 0.315
  2318. }
  2319. });
  2320. var fill = isThrowing ? getStrokeColor(element, defaultStrokeColor) : getFillColor(element, defaultFillColor);
  2321. var stroke = isThrowing ? getFillColor(element, defaultFillColor) : getStrokeColor(element, defaultStrokeColor);
  2322. var messagePath = drawPath(parentGfx, pathData, {
  2323. strokeWidth: 1,
  2324. fill: fill,
  2325. stroke: stroke
  2326. });
  2327. return messagePath;
  2328. },
  2329. 'bpmn:TimerEventDefinition': function(parentGfx, element) {
  2330. var circle = drawCircle(parentGfx, element.width, element.height, 0.2 * element.height, {
  2331. strokeWidth: 2,
  2332. fill: getFillColor(element, defaultFillColor),
  2333. stroke: getStrokeColor(element, defaultStrokeColor)
  2334. });
  2335. var pathData = pathMap.getScaledPath('EVENT_TIMER_WH', {
  2336. xScaleFactor: 0.75,
  2337. yScaleFactor: 0.75,
  2338. containerWidth: element.width,
  2339. containerHeight: element.height,
  2340. position: {
  2341. mx: 0.5,
  2342. my: 0.5
  2343. }
  2344. });
  2345. drawPath(parentGfx, pathData, {
  2346. strokeWidth: 2,
  2347. strokeLinecap: 'square',
  2348. stroke: getStrokeColor(element, defaultStrokeColor)
  2349. });
  2350. for (var i = 0;i < 12; i++) {
  2351. var linePathData = pathMap.getScaledPath('EVENT_TIMER_LINE', {
  2352. xScaleFactor: 0.75,
  2353. yScaleFactor: 0.75,
  2354. containerWidth: element.width,
  2355. containerHeight: element.height,
  2356. position: {
  2357. mx: 0.5,
  2358. my: 0.5
  2359. }
  2360. });
  2361. var width = element.width / 2;
  2362. var height = element.height / 2;
  2363. drawPath(parentGfx, linePathData, {
  2364. strokeWidth: 1,
  2365. strokeLinecap: 'square',
  2366. transform: 'rotate(' + (i * 30) + ',' + height + ',' + width + ')',
  2367. stroke: getStrokeColor(element, defaultStrokeColor)
  2368. });
  2369. }
  2370. return circle;
  2371. },
  2372. 'bpmn:EscalationEventDefinition': function(parentGfx, event, isThrowing) {
  2373. var pathData = pathMap.getScaledPath('EVENT_ESCALATION', {
  2374. xScaleFactor: 1,
  2375. yScaleFactor: 1,
  2376. containerWidth: event.width,
  2377. containerHeight: event.height,
  2378. position: {
  2379. mx: 0.5,
  2380. my: 0.2
  2381. }
  2382. });
  2383. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2384. return drawPath(parentGfx, pathData, {
  2385. strokeWidth: 1,
  2386. fill: fill,
  2387. stroke: getStrokeColor(event, defaultStrokeColor)
  2388. });
  2389. },
  2390. 'bpmn:ConditionalEventDefinition': function(parentGfx, event) {
  2391. var pathData = pathMap.getScaledPath('EVENT_CONDITIONAL', {
  2392. xScaleFactor: 1,
  2393. yScaleFactor: 1,
  2394. containerWidth: event.width,
  2395. containerHeight: event.height,
  2396. position: {
  2397. mx: 0.5,
  2398. my: 0.222
  2399. }
  2400. });
  2401. return drawPath(parentGfx, pathData, {
  2402. strokeWidth: 1,
  2403. stroke: getStrokeColor(event, defaultStrokeColor)
  2404. });
  2405. },
  2406. 'bpmn:LinkEventDefinition': function(parentGfx, event, isThrowing) {
  2407. var pathData = pathMap.getScaledPath('EVENT_LINK', {
  2408. xScaleFactor: 1,
  2409. yScaleFactor: 1,
  2410. containerWidth: event.width,
  2411. containerHeight: event.height,
  2412. position: {
  2413. mx: 0.57,
  2414. my: 0.263
  2415. }
  2416. });
  2417. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2418. return drawPath(parentGfx, pathData, {
  2419. strokeWidth: 1,
  2420. fill: fill,
  2421. stroke: getStrokeColor(event, defaultStrokeColor)
  2422. });
  2423. },
  2424. 'bpmn:ErrorEventDefinition': function(parentGfx, event, isThrowing) {
  2425. var pathData = pathMap.getScaledPath('EVENT_ERROR', {
  2426. xScaleFactor: 1.1,
  2427. yScaleFactor: 1.1,
  2428. containerWidth: event.width,
  2429. containerHeight: event.height,
  2430. position: {
  2431. mx: 0.2,
  2432. my: 0.722
  2433. }
  2434. });
  2435. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2436. return drawPath(parentGfx, pathData, {
  2437. strokeWidth: 1,
  2438. fill: fill,
  2439. stroke: getStrokeColor(event, defaultStrokeColor)
  2440. });
  2441. },
  2442. 'bpmn:CancelEventDefinition': function(parentGfx, event, isThrowing) {
  2443. var pathData = pathMap.getScaledPath('EVENT_CANCEL_45', {
  2444. xScaleFactor: 1.0,
  2445. yScaleFactor: 1.0,
  2446. containerWidth: event.width,
  2447. containerHeight: event.height,
  2448. position: {
  2449. mx: 0.638,
  2450. my: -0.055
  2451. }
  2452. });
  2453. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2454. var path = drawPath(parentGfx, pathData, {
  2455. strokeWidth: 1,
  2456. fill: fill,
  2457. stroke: getStrokeColor(event, defaultStrokeColor)
  2458. });
  2459. rotate(path, 45);
  2460. return path;
  2461. },
  2462. 'bpmn:CompensateEventDefinition': function(parentGfx, event, isThrowing) {
  2463. var pathData = pathMap.getScaledPath('EVENT_COMPENSATION', {
  2464. xScaleFactor: 1,
  2465. yScaleFactor: 1,
  2466. containerWidth: event.width,
  2467. containerHeight: event.height,
  2468. position: {
  2469. mx: 0.22,
  2470. my: 0.5
  2471. }
  2472. });
  2473. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2474. return drawPath(parentGfx, pathData, {
  2475. strokeWidth: 1,
  2476. fill: fill,
  2477. stroke: getStrokeColor(event, defaultStrokeColor)
  2478. });
  2479. },
  2480. 'bpmn:SignalEventDefinition': function(parentGfx, event, isThrowing) {
  2481. var pathData = pathMap.getScaledPath('EVENT_SIGNAL', {
  2482. xScaleFactor: 0.9,
  2483. yScaleFactor: 0.9,
  2484. containerWidth: event.width,
  2485. containerHeight: event.height,
  2486. position: {
  2487. mx: 0.5,
  2488. my: 0.2
  2489. }
  2490. });
  2491. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2492. return drawPath(parentGfx, pathData, {
  2493. strokeWidth: 1,
  2494. fill: fill,
  2495. stroke: getStrokeColor(event, defaultStrokeColor)
  2496. });
  2497. },
  2498. 'bpmn:MultipleEventDefinition': function(parentGfx, event, isThrowing) {
  2499. var pathData = pathMap.getScaledPath('EVENT_MULTIPLE', {
  2500. xScaleFactor: 1.1,
  2501. yScaleFactor: 1.1,
  2502. containerWidth: event.width,
  2503. containerHeight: event.height,
  2504. position: {
  2505. mx: 0.222,
  2506. my: 0.36
  2507. }
  2508. });
  2509. var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
  2510. return drawPath(parentGfx, pathData, {
  2511. strokeWidth: 1,
  2512. fill: fill
  2513. });
  2514. },
  2515. 'bpmn:ParallelMultipleEventDefinition': function(parentGfx, event) {
  2516. var pathData = pathMap.getScaledPath('EVENT_PARALLEL_MULTIPLE', {
  2517. xScaleFactor: 1.2,
  2518. yScaleFactor: 1.2,
  2519. containerWidth: event.width,
  2520. containerHeight: event.height,
  2521. position: {
  2522. mx: 0.458,
  2523. my: 0.194
  2524. }
  2525. });
  2526. return drawPath(parentGfx, pathData, {
  2527. strokeWidth: 1,
  2528. fill: getStrokeColor(event, defaultStrokeColor),
  2529. stroke: getStrokeColor(event, defaultStrokeColor)
  2530. });
  2531. },
  2532. 'bpmn:EndEvent': function(parentGfx, element) {
  2533. var circle = renderer('bpmn:Event')(parentGfx, element, {
  2534. strokeWidth: 4,
  2535. fill: getFillColor(element, defaultFillColor),
  2536. stroke: getStrokeColor(element, defaultStrokeColor)
  2537. });
  2538. renderEventContent(element, parentGfx);
  2539. return circle;
  2540. },
  2541. 'bpmn:TerminateEventDefinition': function(parentGfx, element) {
  2542. var circle = drawCircle(parentGfx, element.width, element.height, 8, {
  2543. strokeWidth: 4,
  2544. fill: getStrokeColor(element, defaultStrokeColor),
  2545. stroke: getStrokeColor(element, defaultStrokeColor)
  2546. });
  2547. return circle;
  2548. },
  2549. 'bpmn:IntermediateEvent': function(parentGfx, element) {
  2550. var outer = renderer('bpmn:Event')(parentGfx, element, {
  2551. strokeWidth: 1,
  2552. fill: getFillColor(element, defaultFillColor),
  2553. stroke: getStrokeColor(element, defaultStrokeColor)
  2554. });
  2555. /* inner */
  2556. drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, {
  2557. strokeWidth: 1,
  2558. fill: getFillColor(element, 'none'),
  2559. stroke: getStrokeColor(element, defaultStrokeColor)
  2560. });
  2561. renderEventContent(element, parentGfx);
  2562. return outer;
  2563. },
  2564. 'bpmn:IntermediateCatchEvent': as('bpmn:IntermediateEvent'),
  2565. 'bpmn:IntermediateThrowEvent': as('bpmn:IntermediateEvent'),
  2566. 'bpmn:Activity': function(parentGfx, element, attrs) {
  2567. attrs = attrs || {};
  2568. if (!('fillOpacity' in attrs)) {
  2569. attrs.fillOpacity = DEFAULT_FILL_OPACITY;
  2570. }
  2571. return drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, attrs);
  2572. },
  2573. 'bpmn:Task': function(parentGfx, element) {
  2574. var attrs = {
  2575. fill: getFillColor(element, defaultFillColor),
  2576. stroke: getStrokeColor(element, defaultStrokeColor)
  2577. };
  2578. var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
  2579. renderEmbeddedLabel(parentGfx, element, 'center-middle');
  2580. attachTaskMarkers(parentGfx, element);
  2581. return rect;
  2582. },
  2583. 'bpmn:ServiceTask': function(parentGfx, element) {
  2584. var task = renderer('bpmn:Task')(parentGfx, element);
  2585. var pathDataBG = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
  2586. abspos: {
  2587. x: 12,
  2588. y: 18
  2589. }
  2590. });
  2591. /* service bg */ drawPath(parentGfx, pathDataBG, {
  2592. strokeWidth: 1,
  2593. fill: getFillColor(element, defaultFillColor),
  2594. stroke: getStrokeColor(element, defaultStrokeColor)
  2595. });
  2596. var fillPathData = pathMap.getScaledPath('TASK_TYPE_SERVICE_FILL', {
  2597. abspos: {
  2598. x: 17.2,
  2599. y: 18
  2600. }
  2601. });
  2602. /* service fill */ drawPath(parentGfx, fillPathData, {
  2603. strokeWidth: 0,
  2604. fill: getFillColor(element, defaultFillColor)
  2605. });
  2606. var pathData = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
  2607. abspos: {
  2608. x: 17,
  2609. y: 22
  2610. }
  2611. });
  2612. /* service */ drawPath(parentGfx, pathData, {
  2613. strokeWidth: 1,
  2614. fill: getFillColor(element, defaultFillColor),
  2615. stroke: getStrokeColor(element, defaultStrokeColor)
  2616. });
  2617. return task;
  2618. },
  2619. 'bpmn:UserTask': function(parentGfx, element) {
  2620. var task = renderer('bpmn:Task')(parentGfx, element);
  2621. var x = 15;
  2622. var y = 12;
  2623. var pathData = pathMap.getScaledPath('TASK_TYPE_USER_1', {
  2624. abspos: {
  2625. x: x,
  2626. y: y
  2627. }
  2628. });
  2629. /* user path */ drawPath(parentGfx, pathData, {
  2630. strokeWidth: 0.5,
  2631. fill: getFillColor(element, defaultFillColor),
  2632. stroke: getStrokeColor(element, defaultStrokeColor)
  2633. });
  2634. var pathData2 = pathMap.getScaledPath('TASK_TYPE_USER_2', {
  2635. abspos: {
  2636. x: x,
  2637. y: y
  2638. }
  2639. });
  2640. /* user2 path */ drawPath(parentGfx, pathData2, {
  2641. strokeWidth: 0.5,
  2642. fill: getFillColor(element, defaultFillColor),
  2643. stroke: getStrokeColor(element, defaultStrokeColor)
  2644. });
  2645. var pathData3 = pathMap.getScaledPath('TASK_TYPE_USER_3', {
  2646. abspos: {
  2647. x: x,
  2648. y: y
  2649. }
  2650. });
  2651. /* user3 path */ drawPath(parentGfx, pathData3, {
  2652. strokeWidth: 0.5,
  2653. fill: getStrokeColor(element, defaultStrokeColor),
  2654. stroke: getStrokeColor(element, defaultStrokeColor)
  2655. });
  2656. return task;
  2657. },
  2658. 'bpmn:ManualTask': function(parentGfx, element) {
  2659. var task = renderer('bpmn:Task')(parentGfx, element);
  2660. var pathData = pathMap.getScaledPath('TASK_TYPE_MANUAL', {
  2661. abspos: {
  2662. x: 17,
  2663. y: 15
  2664. }
  2665. });
  2666. /* manual path */ drawPath(parentGfx, pathData, {
  2667. strokeWidth: 0.5, // 0.25,
  2668. fill: getFillColor(element, defaultFillColor),
  2669. stroke: getStrokeColor(element, defaultStrokeColor)
  2670. });
  2671. return task;
  2672. },
  2673. 'bpmn:SendTask': function(parentGfx, element) {
  2674. var task = renderer('bpmn:Task')(parentGfx, element);
  2675. var pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
  2676. xScaleFactor: 1,
  2677. yScaleFactor: 1,
  2678. containerWidth: 21,
  2679. containerHeight: 14,
  2680. position: {
  2681. mx: 0.285,
  2682. my: 0.357
  2683. }
  2684. });
  2685. /* send path */ drawPath(parentGfx, pathData, {
  2686. strokeWidth: 1,
  2687. fill: getStrokeColor(element, defaultStrokeColor),
  2688. stroke: getFillColor(element, defaultFillColor)
  2689. });
  2690. return task;
  2691. },
  2692. 'bpmn:ReceiveTask' : function(parentGfx, element) {
  2693. var semantic = getSemantic(element);
  2694. var task = renderer('bpmn:Task')(parentGfx, element);
  2695. var pathData;
  2696. if (semantic.instantiate) {
  2697. drawCircle(parentGfx, 28, 28, 20 * 0.22, { strokeWidth: 1 });
  2698. pathData = pathMap.getScaledPath('TASK_TYPE_INSTANTIATING_SEND', {
  2699. abspos: {
  2700. x: 7.77,
  2701. y: 9.52
  2702. }
  2703. });
  2704. } else {
  2705. pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
  2706. xScaleFactor: 0.9,
  2707. yScaleFactor: 0.9,
  2708. containerWidth: 21,
  2709. containerHeight: 14,
  2710. position: {
  2711. mx: 0.3,
  2712. my: 0.4
  2713. }
  2714. });
  2715. }
  2716. /* receive path */ drawPath(parentGfx, pathData, {
  2717. strokeWidth: 1,
  2718. fill: getFillColor(element, defaultFillColor),
  2719. stroke: getStrokeColor(element, defaultStrokeColor)
  2720. });
  2721. return task;
  2722. },
  2723. 'bpmn:ScriptTask': function(parentGfx, element) {
  2724. var task = renderer('bpmn:Task')(parentGfx, element);
  2725. var pathData = pathMap.getScaledPath('TASK_TYPE_SCRIPT', {
  2726. abspos: {
  2727. x: 15,
  2728. y: 20
  2729. }
  2730. });
  2731. /* script path */ drawPath(parentGfx, pathData, {
  2732. strokeWidth: 1,
  2733. stroke: getStrokeColor(element, defaultStrokeColor)
  2734. });
  2735. return task;
  2736. },
  2737. 'bpmn:BusinessRuleTask': function(parentGfx, element) {
  2738. var task = renderer('bpmn:Task')(parentGfx, element);
  2739. var headerPathData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_HEADER', {
  2740. abspos: {
  2741. x: 8,
  2742. y: 8
  2743. }
  2744. });
  2745. var businessHeaderPath = drawPath(parentGfx, headerPathData);
  2746. attr$1(businessHeaderPath, {
  2747. strokeWidth: 1,
  2748. fill: getFillColor(element, '#aaaaaa'),
  2749. stroke: getStrokeColor(element, defaultStrokeColor)
  2750. });
  2751. var headerData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_MAIN', {
  2752. abspos: {
  2753. x: 8,
  2754. y: 8
  2755. }
  2756. });
  2757. var businessPath = drawPath(parentGfx, headerData);
  2758. attr$1(businessPath, {
  2759. strokeWidth: 1,
  2760. stroke: getStrokeColor(element, defaultStrokeColor)
  2761. });
  2762. return task;
  2763. },
  2764. 'bpmn:SubProcess': function(parentGfx, element, attrs) {
  2765. attrs = assign({
  2766. fill: getFillColor(element, defaultFillColor),
  2767. stroke: getStrokeColor(element, defaultStrokeColor)
  2768. }, attrs);
  2769. var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
  2770. var expanded = isExpanded(element);
  2771. if (isEventSubProcess(element)) {
  2772. attr$1(rect, {
  2773. strokeDasharray: '1,2'
  2774. });
  2775. }
  2776. renderEmbeddedLabel(parentGfx, element, expanded ? 'center-top' : 'center-middle');
  2777. if (expanded) {
  2778. attachTaskMarkers(parentGfx, element);
  2779. } else {
  2780. attachTaskMarkers(parentGfx, element, ['SubProcessMarker']);
  2781. }
  2782. return rect;
  2783. },
  2784. 'bpmn:AdHocSubProcess': function(parentGfx, element) {
  2785. return renderer('bpmn:SubProcess')(parentGfx, element);
  2786. },
  2787. 'bpmn:Transaction': function(parentGfx, element) {
  2788. var outer = renderer('bpmn:SubProcess')(parentGfx, element);
  2789. var innerAttrs = styles.style([ 'no-fill', 'no-events' ], {
  2790. stroke: getStrokeColor(element, defaultStrokeColor)
  2791. });
  2792. /* inner path */ drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS - 2, INNER_OUTER_DIST, innerAttrs);
  2793. return outer;
  2794. },
  2795. 'bpmn:CallActivity': function(parentGfx, element) {
  2796. return renderer('bpmn:SubProcess')(parentGfx, element, {
  2797. strokeWidth: 5
  2798. });
  2799. },
  2800. 'bpmn:Participant': function(parentGfx, element) {
  2801. var attrs = {
  2802. fillOpacity: DEFAULT_FILL_OPACITY,
  2803. fill: getFillColor(element, defaultFillColor),
  2804. stroke: getStrokeColor(element, defaultStrokeColor)
  2805. };
  2806. var lane = renderer('bpmn:Lane')(parentGfx, element, attrs);
  2807. var expandedPool = isExpanded(element);
  2808. if (expandedPool) {
  2809. drawLine(parentGfx, [
  2810. { x: 30, y: 0 },
  2811. { x: 30, y: element.height }
  2812. ], {
  2813. stroke: getStrokeColor(element, defaultStrokeColor)
  2814. });
  2815. var text = getSemantic(element).name;
  2816. renderLaneLabel(parentGfx, text, element);
  2817. } else {
  2818. // Collapsed pool draw text inline
  2819. var text2 = getSemantic(element).name;
  2820. renderLabel(parentGfx, text2, {
  2821. box: element, align: 'center-middle',
  2822. style: {
  2823. fill: getLabelColor(element, defaultLabelColor, defaultStrokeColor)
  2824. }
  2825. });
  2826. }
  2827. var participantMultiplicity = !!(getSemantic(element).participantMultiplicity);
  2828. if (participantMultiplicity) {
  2829. renderer('ParticipantMultiplicityMarker')(parentGfx, element);
  2830. }
  2831. return lane;
  2832. },
  2833. 'bpmn:Lane': function(parentGfx, element, attrs) {
  2834. var rect = drawRect(parentGfx, element.width, element.height, 0, assign({
  2835. fill: getFillColor(element, defaultFillColor),
  2836. fillOpacity: HIGH_FILL_OPACITY,
  2837. stroke: getStrokeColor(element, defaultStrokeColor)
  2838. }, attrs));
  2839. var semantic = getSemantic(element);
  2840. if (semantic.$type === 'bpmn:Lane') {
  2841. var text = semantic.name;
  2842. renderLaneLabel(parentGfx, text, element);
  2843. }
  2844. return rect;
  2845. },
  2846. 'bpmn:InclusiveGateway': function(parentGfx, element) {
  2847. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  2848. /* circle path */
  2849. drawCircle(parentGfx, element.width, element.height, element.height * 0.24, {
  2850. strokeWidth: 2.5,
  2851. fill: getFillColor(element, defaultFillColor),
  2852. stroke: getStrokeColor(element, defaultStrokeColor)
  2853. });
  2854. return diamond;
  2855. },
  2856. 'bpmn:ExclusiveGateway': function(parentGfx, element) {
  2857. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  2858. var pathData = pathMap.getScaledPath('GATEWAY_EXCLUSIVE', {
  2859. xScaleFactor: 0.4,
  2860. yScaleFactor: 0.4,
  2861. containerWidth: element.width,
  2862. containerHeight: element.height,
  2863. position: {
  2864. mx: 0.32,
  2865. my: 0.3
  2866. }
  2867. });
  2868. if ((getDi(element).isMarkerVisible)) {
  2869. drawPath(parentGfx, pathData, {
  2870. strokeWidth: 1,
  2871. fill: getStrokeColor(element, defaultStrokeColor),
  2872. stroke: getStrokeColor(element, defaultStrokeColor)
  2873. });
  2874. }
  2875. return diamond;
  2876. },
  2877. 'bpmn:ComplexGateway': function(parentGfx, element) {
  2878. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  2879. var pathData = pathMap.getScaledPath('GATEWAY_COMPLEX', {
  2880. xScaleFactor: 0.5,
  2881. yScaleFactor:0.5,
  2882. containerWidth: element.width,
  2883. containerHeight: element.height,
  2884. position: {
  2885. mx: 0.46,
  2886. my: 0.26
  2887. }
  2888. });
  2889. /* complex path */ drawPath(parentGfx, pathData, {
  2890. strokeWidth: 1,
  2891. fill: getStrokeColor(element, defaultStrokeColor),
  2892. stroke: getStrokeColor(element, defaultStrokeColor)
  2893. });
  2894. return diamond;
  2895. },
  2896. 'bpmn:ParallelGateway': function(parentGfx, element) {
  2897. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  2898. var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
  2899. xScaleFactor: 0.6,
  2900. yScaleFactor:0.6,
  2901. containerWidth: element.width,
  2902. containerHeight: element.height,
  2903. position: {
  2904. mx: 0.46,
  2905. my: 0.2
  2906. }
  2907. });
  2908. /* parallel path */ drawPath(parentGfx, pathData, {
  2909. strokeWidth: 1,
  2910. fill: getStrokeColor(element, defaultStrokeColor),
  2911. stroke: getStrokeColor(element, defaultStrokeColor)
  2912. });
  2913. return diamond;
  2914. },
  2915. 'bpmn:EventBasedGateway': function(parentGfx, element) {
  2916. var semantic = getSemantic(element);
  2917. var diamond = renderer('bpmn:Gateway')(parentGfx, element);
  2918. /* outer circle path */ drawCircle(parentGfx, element.width, element.height, element.height * 0.20, {
  2919. strokeWidth: 1,
  2920. fill: 'none',
  2921. stroke: getStrokeColor(element, defaultStrokeColor)
  2922. });
  2923. var type = semantic.eventGatewayType;
  2924. var instantiate = !!semantic.instantiate;
  2925. function drawEvent() {
  2926. var pathData = pathMap.getScaledPath('GATEWAY_EVENT_BASED', {
  2927. xScaleFactor: 0.18,
  2928. yScaleFactor: 0.18,
  2929. containerWidth: element.width,
  2930. containerHeight: element.height,
  2931. position: {
  2932. mx: 0.36,
  2933. my: 0.44
  2934. }
  2935. });
  2936. var attrs = {
  2937. strokeWidth: 2,
  2938. fill: getFillColor(element, 'none'),
  2939. stroke: getStrokeColor(element, defaultStrokeColor)
  2940. };
  2941. /* event path */ drawPath(parentGfx, pathData, attrs);
  2942. }
  2943. if (type === 'Parallel') {
  2944. var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
  2945. xScaleFactor: 0.4,
  2946. yScaleFactor:0.4,
  2947. containerWidth: element.width,
  2948. containerHeight: element.height,
  2949. position: {
  2950. mx: 0.474,
  2951. my: 0.296
  2952. }
  2953. });
  2954. var parallelPath = drawPath(parentGfx, pathData);
  2955. attr$1(parallelPath, {
  2956. strokeWidth: 1,
  2957. fill: 'none'
  2958. });
  2959. } else if (type === 'Exclusive') {
  2960. if (!instantiate) {
  2961. var innerCircle = drawCircle(parentGfx, element.width, element.height, element.height * 0.26);
  2962. attr$1(innerCircle, {
  2963. strokeWidth: 1,
  2964. fill: 'none',
  2965. stroke: getStrokeColor(element, defaultStrokeColor)
  2966. });
  2967. }
  2968. drawEvent();
  2969. }
  2970. return diamond;
  2971. },
  2972. 'bpmn:Gateway': function(parentGfx, element) {
  2973. var attrs = {
  2974. fill: getFillColor(element, defaultFillColor),
  2975. fillOpacity: DEFAULT_FILL_OPACITY,
  2976. stroke: getStrokeColor(element, defaultStrokeColor)
  2977. };
  2978. return drawDiamond(parentGfx, element.width, element.height, attrs);
  2979. },
  2980. 'bpmn:SequenceFlow': function(parentGfx, element) {
  2981. var pathData = createPathFromConnection(element);
  2982. var fill = getFillColor(element, defaultFillColor),
  2983. stroke = getStrokeColor(element, defaultStrokeColor);
  2984. var attrs = {
  2985. strokeLinejoin: 'round',
  2986. markerEnd: marker('sequenceflow-end', fill, stroke),
  2987. stroke: getStrokeColor(element, defaultStrokeColor)
  2988. };
  2989. var path = drawPath(parentGfx, pathData, attrs);
  2990. var sequenceFlow = getSemantic(element);
  2991. var source;
  2992. if (element.source) {
  2993. source = element.source.businessObject;
  2994. // conditional flow marker
  2995. if (sequenceFlow.conditionExpression && source.$instanceOf('bpmn:Activity')) {
  2996. attr$1(path, {
  2997. markerStart: marker('conditional-flow-marker', fill, stroke)
  2998. });
  2999. }
  3000. // default marker
  3001. if (source.default && (source.$instanceOf('bpmn:Gateway') || source.$instanceOf('bpmn:Activity')) &&
  3002. source.default === sequenceFlow) {
  3003. attr$1(path, {
  3004. markerStart: marker('conditional-default-flow-marker', fill, stroke)
  3005. });
  3006. }
  3007. }
  3008. return path;
  3009. },
  3010. 'bpmn:Association': function(parentGfx, element, attrs) {
  3011. var semantic = getSemantic(element);
  3012. var fill = getFillColor(element, defaultFillColor),
  3013. stroke = getStrokeColor(element, defaultStrokeColor);
  3014. attrs = assign({
  3015. strokeDasharray: '0.5, 5',
  3016. strokeLinecap: 'round',
  3017. strokeLinejoin: 'round',
  3018. stroke: getStrokeColor(element, defaultStrokeColor)
  3019. }, attrs || {});
  3020. if (semantic.associationDirection === 'One' ||
  3021. semantic.associationDirection === 'Both') {
  3022. attrs.markerEnd = marker('association-end', fill, stroke);
  3023. }
  3024. if (semantic.associationDirection === 'Both') {
  3025. attrs.markerStart = marker('association-start', fill, stroke);
  3026. }
  3027. return drawLine(parentGfx, element.waypoints, attrs);
  3028. },
  3029. 'bpmn:DataInputAssociation': function(parentGfx, element) {
  3030. var fill = getFillColor(element, defaultFillColor),
  3031. stroke = getStrokeColor(element, defaultStrokeColor);
  3032. return renderer('bpmn:Association')(parentGfx, element, {
  3033. markerEnd: marker('association-end', fill, stroke)
  3034. });
  3035. },
  3036. 'bpmn:DataOutputAssociation': function(parentGfx, element) {
  3037. var fill = getFillColor(element, defaultFillColor),
  3038. stroke = getStrokeColor(element, defaultStrokeColor);
  3039. return renderer('bpmn:Association')(parentGfx, element, {
  3040. markerEnd: marker('association-end', fill, stroke)
  3041. });
  3042. },
  3043. 'bpmn:MessageFlow': function(parentGfx, element) {
  3044. var semantic = getSemantic(element),
  3045. di = getDi(element);
  3046. var fill = getFillColor(element, defaultFillColor),
  3047. stroke = getStrokeColor(element, defaultStrokeColor);
  3048. var pathData = createPathFromConnection(element);
  3049. var attrs = {
  3050. markerEnd: marker('messageflow-end', fill, stroke),
  3051. markerStart: marker('messageflow-start', fill, stroke),
  3052. strokeDasharray: '10, 12',
  3053. strokeLinecap: 'round',
  3054. strokeLinejoin: 'round',
  3055. strokeWidth: '1.5px',
  3056. stroke: getStrokeColor(element, defaultStrokeColor)
  3057. };
  3058. var path = drawPath(parentGfx, pathData, attrs);
  3059. if (semantic.messageRef) {
  3060. var midPoint = path.getPointAtLength(path.getTotalLength() / 2);
  3061. var markerPathData = pathMap.getScaledPath('MESSAGE_FLOW_MARKER', {
  3062. abspos: {
  3063. x: midPoint.x,
  3064. y: midPoint.y
  3065. }
  3066. });
  3067. var messageAttrs = { strokeWidth: 1 };
  3068. if (di.messageVisibleKind === 'initiating') {
  3069. messageAttrs.fill = 'white';
  3070. messageAttrs.stroke = black;
  3071. } else {
  3072. messageAttrs.fill = '#888';
  3073. messageAttrs.stroke = 'white';
  3074. }
  3075. var message = drawPath(parentGfx, markerPathData, messageAttrs);
  3076. var labelText = semantic.messageRef.name;
  3077. var label = renderLabel(parentGfx, labelText, {
  3078. align: 'center-top',
  3079. fitBox: true,
  3080. style: {
  3081. fill: getStrokeColor(element, defaultLabelColor)
  3082. }
  3083. });
  3084. var messageBounds = message.getBBox(),
  3085. labelBounds = label.getBBox();
  3086. var translateX = midPoint.x - labelBounds.width / 2,
  3087. translateY = midPoint.y + messageBounds.height / 2 + ELEMENT_LABEL_DISTANCE;
  3088. transform(label, translateX, translateY, 0);
  3089. }
  3090. return path;
  3091. },
  3092. 'bpmn:DataObject': function(parentGfx, element) {
  3093. var pathData = pathMap.getScaledPath('DATA_OBJECT_PATH', {
  3094. xScaleFactor: 1,
  3095. yScaleFactor: 1,
  3096. containerWidth: element.width,
  3097. containerHeight: element.height,
  3098. position: {
  3099. mx: 0.474,
  3100. my: 0.296
  3101. }
  3102. });
  3103. var elementObject = drawPath(parentGfx, pathData, {
  3104. fill: getFillColor(element, defaultFillColor),
  3105. fillOpacity: DEFAULT_FILL_OPACITY,
  3106. stroke: getStrokeColor(element, defaultStrokeColor)
  3107. });
  3108. var semantic = getSemantic(element);
  3109. if (isCollection(semantic)) {
  3110. renderDataItemCollection(parentGfx, element);
  3111. }
  3112. return elementObject;
  3113. },
  3114. 'bpmn:DataObjectReference': as('bpmn:DataObject'),
  3115. 'bpmn:DataInput': function(parentGfx, element) {
  3116. var arrowPathData = pathMap.getRawPath('DATA_ARROW');
  3117. // page
  3118. var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
  3119. /* input arrow path */ drawPath(parentGfx, arrowPathData, { strokeWidth: 1 });
  3120. return elementObject;
  3121. },
  3122. 'bpmn:DataOutput': function(parentGfx, element) {
  3123. var arrowPathData = pathMap.getRawPath('DATA_ARROW');
  3124. // page
  3125. var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
  3126. /* output arrow path */ drawPath(parentGfx, arrowPathData, {
  3127. strokeWidth: 1,
  3128. fill: black
  3129. });
  3130. return elementObject;
  3131. },
  3132. 'bpmn:DataStoreReference': function(parentGfx, element) {
  3133. var DATA_STORE_PATH = pathMap.getScaledPath('DATA_STORE', {
  3134. xScaleFactor: 1,
  3135. yScaleFactor: 1,
  3136. containerWidth: element.width,
  3137. containerHeight: element.height,
  3138. position: {
  3139. mx: 0,
  3140. my: 0.133
  3141. }
  3142. });
  3143. var elementStore = drawPath(parentGfx, DATA_STORE_PATH, {
  3144. strokeWidth: 2,
  3145. fill: getFillColor(element, defaultFillColor),
  3146. fillOpacity: DEFAULT_FILL_OPACITY,
  3147. stroke: getStrokeColor(element, defaultStrokeColor)
  3148. });
  3149. return elementStore;
  3150. },
  3151. 'bpmn:BoundaryEvent': function(parentGfx, element) {
  3152. var semantic = getSemantic(element),
  3153. cancel = semantic.cancelActivity;
  3154. var attrs = {
  3155. strokeWidth: 1,
  3156. fill: getFillColor(element, defaultFillColor),
  3157. stroke: getStrokeColor(element, defaultStrokeColor)
  3158. };
  3159. if (!cancel) {
  3160. attrs.strokeDasharray = '6';
  3161. attrs.strokeLinecap = 'round';
  3162. }
  3163. // apply fillOpacity
  3164. var outerAttrs = assign({}, attrs, {
  3165. fillOpacity: 1
  3166. });
  3167. // apply no-fill
  3168. var innerAttrs = assign({}, attrs, {
  3169. fill: 'none'
  3170. });
  3171. var outer = renderer('bpmn:Event')(parentGfx, element, outerAttrs);
  3172. /* inner path */ drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, innerAttrs);
  3173. renderEventContent(element, parentGfx);
  3174. return outer;
  3175. },
  3176. 'bpmn:Group': function(parentGfx, element) {
  3177. var group = drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, {
  3178. stroke: getStrokeColor(element, defaultStrokeColor),
  3179. strokeWidth: 1,
  3180. strokeDasharray: '8,3,1,3',
  3181. fill: 'none',
  3182. pointerEvents: 'none'
  3183. });
  3184. return group;
  3185. },
  3186. 'label': function(parentGfx, element) {
  3187. return renderExternalLabel(parentGfx, element);
  3188. },
  3189. 'bpmn:TextAnnotation': function(parentGfx, element) {
  3190. var style = {
  3191. 'fill': 'none',
  3192. 'stroke': 'none'
  3193. };
  3194. var textElement = drawRect(parentGfx, element.width, element.height, 0, 0, style);
  3195. var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
  3196. xScaleFactor: 1,
  3197. yScaleFactor: 1,
  3198. containerWidth: element.width,
  3199. containerHeight: element.height,
  3200. position: {
  3201. mx: 0.0,
  3202. my: 0.0
  3203. }
  3204. });
  3205. drawPath(parentGfx, textPathData, {
  3206. stroke: getStrokeColor(element, defaultStrokeColor)
  3207. });
  3208. var text = getSemantic(element).text || '';
  3209. renderLabel(parentGfx, text, {
  3210. box: element,
  3211. align: 'left-top',
  3212. padding: 5,
  3213. style: {
  3214. fill: getLabelColor(element, defaultLabelColor, defaultStrokeColor)
  3215. }
  3216. });
  3217. return textElement;
  3218. },
  3219. 'ParticipantMultiplicityMarker': function(parentGfx, element) {
  3220. var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
  3221. xScaleFactor: 1,
  3222. yScaleFactor: 1,
  3223. containerWidth: element.width,
  3224. containerHeight: element.height,
  3225. position: {
  3226. mx: ((element.width / 2) / element.width),
  3227. my: (element.height - 15) / element.height
  3228. }
  3229. });
  3230. drawMarker('participant-multiplicity', parentGfx, markerPath, {
  3231. strokeWidth: 2,
  3232. fill: getFillColor(element, defaultFillColor),
  3233. stroke: getStrokeColor(element, defaultStrokeColor)
  3234. });
  3235. },
  3236. 'SubProcessMarker': function(parentGfx, element) {
  3237. var markerRect = drawRect(parentGfx, 14, 14, 0, {
  3238. strokeWidth: 1,
  3239. fill: getFillColor(element, defaultFillColor),
  3240. stroke: getStrokeColor(element, defaultStrokeColor)
  3241. });
  3242. // Process marker is placed in the middle of the box
  3243. // therefore fixed values can be used here
  3244. translate$1(markerRect, element.width / 2 - 7.5, element.height - 20);
  3245. var markerPath = pathMap.getScaledPath('MARKER_SUB_PROCESS', {
  3246. xScaleFactor: 1.5,
  3247. yScaleFactor: 1.5,
  3248. containerWidth: element.width,
  3249. containerHeight: element.height,
  3250. position: {
  3251. mx: (element.width / 2 - 7.5) / element.width,
  3252. my: (element.height - 20) / element.height
  3253. }
  3254. });
  3255. drawMarker('sub-process', parentGfx, markerPath, {
  3256. fill: getFillColor(element, defaultFillColor),
  3257. stroke: getStrokeColor(element, defaultStrokeColor)
  3258. });
  3259. },
  3260. 'ParallelMarker': function(parentGfx, element, position) {
  3261. var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
  3262. xScaleFactor: 1,
  3263. yScaleFactor: 1,
  3264. containerWidth: element.width,
  3265. containerHeight: element.height,
  3266. position: {
  3267. mx: ((element.width / 2 + position.parallel) / element.width),
  3268. my: (element.height - 20) / element.height
  3269. }
  3270. });
  3271. drawMarker('parallel', parentGfx, markerPath, {
  3272. fill: getFillColor(element, defaultFillColor),
  3273. stroke: getStrokeColor(element, defaultStrokeColor)
  3274. });
  3275. },
  3276. 'SequentialMarker': function(parentGfx, element, position) {
  3277. var markerPath = pathMap.getScaledPath('MARKER_SEQUENTIAL', {
  3278. xScaleFactor: 1,
  3279. yScaleFactor: 1,
  3280. containerWidth: element.width,
  3281. containerHeight: element.height,
  3282. position: {
  3283. mx: ((element.width / 2 + position.seq) / element.width),
  3284. my: (element.height - 19) / element.height
  3285. }
  3286. });
  3287. drawMarker('sequential', parentGfx, markerPath, {
  3288. fill: getFillColor(element, defaultFillColor),
  3289. stroke: getStrokeColor(element, defaultStrokeColor)
  3290. });
  3291. },
  3292. 'CompensationMarker': function(parentGfx, element, position) {
  3293. var markerMath = pathMap.getScaledPath('MARKER_COMPENSATION', {
  3294. xScaleFactor: 1,
  3295. yScaleFactor: 1,
  3296. containerWidth: element.width,
  3297. containerHeight: element.height,
  3298. position: {
  3299. mx: ((element.width / 2 + position.compensation) / element.width),
  3300. my: (element.height - 13) / element.height
  3301. }
  3302. });
  3303. drawMarker('compensation', parentGfx, markerMath, {
  3304. strokeWidth: 1,
  3305. fill: getFillColor(element, defaultFillColor),
  3306. stroke: getStrokeColor(element, defaultStrokeColor)
  3307. });
  3308. },
  3309. 'LoopMarker': function(parentGfx, element, position) {
  3310. var markerPath = pathMap.getScaledPath('MARKER_LOOP', {
  3311. xScaleFactor: 1,
  3312. yScaleFactor: 1,
  3313. containerWidth: element.width,
  3314. containerHeight: element.height,
  3315. position: {
  3316. mx: ((element.width / 2 + position.loop) / element.width),
  3317. my: (element.height - 7) / element.height
  3318. }
  3319. });
  3320. drawMarker('loop', parentGfx, markerPath, {
  3321. strokeWidth: 1,
  3322. fill: getFillColor(element, defaultFillColor),
  3323. stroke: getStrokeColor(element, defaultStrokeColor),
  3324. strokeLinecap: 'round',
  3325. strokeMiterlimit: 0.5
  3326. });
  3327. },
  3328. 'AdhocMarker': function(parentGfx, element, position) {
  3329. var markerPath = pathMap.getScaledPath('MARKER_ADHOC', {
  3330. xScaleFactor: 1,
  3331. yScaleFactor: 1,
  3332. containerWidth: element.width,
  3333. containerHeight: element.height,
  3334. position: {
  3335. mx: ((element.width / 2 + position.adhoc) / element.width),
  3336. my: (element.height - 15) / element.height
  3337. }
  3338. });
  3339. drawMarker('adhoc', parentGfx, markerPath, {
  3340. strokeWidth: 1,
  3341. fill: getStrokeColor(element, defaultStrokeColor),
  3342. stroke: getStrokeColor(element, defaultStrokeColor)
  3343. });
  3344. }
  3345. };
  3346. function attachTaskMarkers(parentGfx, element, taskMarkers) {
  3347. var obj = getSemantic(element);
  3348. var subprocess = taskMarkers && taskMarkers.indexOf('SubProcessMarker') !== -1;
  3349. var position;
  3350. if (subprocess) {
  3351. position = {
  3352. seq: -21,
  3353. parallel: -22,
  3354. compensation: -42,
  3355. loop: -18,
  3356. adhoc: 10
  3357. };
  3358. } else {
  3359. position = {
  3360. seq: -3,
  3361. parallel: -6,
  3362. compensation: -27,
  3363. loop: 0,
  3364. adhoc: 10
  3365. };
  3366. }
  3367. forEach$1(taskMarkers, function(marker) {
  3368. renderer(marker)(parentGfx, element, position);
  3369. });
  3370. if (obj.isForCompensation) {
  3371. renderer('CompensationMarker')(parentGfx, element, position);
  3372. }
  3373. if (obj.$type === 'bpmn:AdHocSubProcess') {
  3374. renderer('AdhocMarker')(parentGfx, element, position);
  3375. }
  3376. var loopCharacteristics = obj.loopCharacteristics,
  3377. isSequential = loopCharacteristics && loopCharacteristics.isSequential;
  3378. if (loopCharacteristics) {
  3379. if (isSequential === undefined) {
  3380. renderer('LoopMarker')(parentGfx, element, position);
  3381. }
  3382. if (isSequential === false) {
  3383. renderer('ParallelMarker')(parentGfx, element, position);
  3384. }
  3385. if (isSequential === true) {
  3386. renderer('SequentialMarker')(parentGfx, element, position);
  3387. }
  3388. }
  3389. }
  3390. function renderDataItemCollection(parentGfx, element) {
  3391. var yPosition = (element.height - 18) / element.height;
  3392. var pathData = pathMap.getScaledPath('DATA_OBJECT_COLLECTION_PATH', {
  3393. xScaleFactor: 1,
  3394. yScaleFactor: 1,
  3395. containerWidth: element.width,
  3396. containerHeight: element.height,
  3397. position: {
  3398. mx: 0.33,
  3399. my: yPosition
  3400. }
  3401. });
  3402. /* collection path */ drawPath(parentGfx, pathData, {
  3403. strokeWidth: 2
  3404. });
  3405. }
  3406. // extension API, use at your own risk
  3407. this._drawPath = drawPath;
  3408. this._renderer = renderer;
  3409. }
  3410. e(BpmnRenderer, BaseRenderer);
  3411. BpmnRenderer.$inject = [
  3412. 'config.bpmnRenderer',
  3413. 'eventBus',
  3414. 'styles',
  3415. 'pathMap',
  3416. 'canvas',
  3417. 'textRenderer'
  3418. ];
  3419. BpmnRenderer.prototype.canRender = function(element) {
  3420. return is$1(element, 'bpmn:BaseElement');
  3421. };
  3422. BpmnRenderer.prototype.drawShape = function(parentGfx, element) {
  3423. var type = element.type;
  3424. var h = this._renderer(type);
  3425. /* jshint -W040 */
  3426. return h(parentGfx, element);
  3427. };
  3428. BpmnRenderer.prototype.drawConnection = function(parentGfx, element) {
  3429. var type = element.type;
  3430. var h = this._renderer(type);
  3431. /* jshint -W040 */
  3432. return h(parentGfx, element);
  3433. };
  3434. BpmnRenderer.prototype.getShapePath = function(element) {
  3435. if (is$1(element, 'bpmn:Event')) {
  3436. return getCirclePath(element);
  3437. }
  3438. if (is$1(element, 'bpmn:Activity')) {
  3439. return getRoundRectPath(element, TASK_BORDER_RADIUS);
  3440. }
  3441. if (is$1(element, 'bpmn:Gateway')) {
  3442. return getDiamondPath(element);
  3443. }
  3444. return getRectPath(element);
  3445. };
  3446. var DEFAULT_BOX_PADDING = 0;
  3447. var DEFAULT_LABEL_SIZE$1 = {
  3448. width: 150,
  3449. height: 50
  3450. };
  3451. function parseAlign(align) {
  3452. var parts = align.split('-');
  3453. return {
  3454. horizontal: parts[0] || 'center',
  3455. vertical: parts[1] || 'top'
  3456. };
  3457. }
  3458. function parsePadding(padding) {
  3459. if (isObject(padding)) {
  3460. return assign({ top: 0, left: 0, right: 0, bottom: 0 }, padding);
  3461. } else {
  3462. return {
  3463. top: padding,
  3464. left: padding,
  3465. right: padding,
  3466. bottom: padding
  3467. };
  3468. }
  3469. }
  3470. function getTextBBox(text, fakeText) {
  3471. fakeText.textContent = text;
  3472. var textBBox;
  3473. try {
  3474. var bbox,
  3475. emptyLine = text === '';
  3476. // add dummy text, when line is empty to
  3477. // determine correct height
  3478. fakeText.textContent = emptyLine ? 'dummy' : text;
  3479. textBBox = fakeText.getBBox();
  3480. // take text rendering related horizontal
  3481. // padding into account
  3482. bbox = {
  3483. width: textBBox.width + textBBox.x * 2,
  3484. height: textBBox.height
  3485. };
  3486. if (emptyLine) {
  3487. // correct width
  3488. bbox.width = 0;
  3489. }
  3490. return bbox;
  3491. } catch (e) {
  3492. return { width: 0, height: 0 };
  3493. }
  3494. }
  3495. /**
  3496. * Layout the next line and return the layouted element.
  3497. *
  3498. * Alters the lines passed.
  3499. *
  3500. * @param {Array<string>} lines
  3501. * @return {Object} the line descriptor, an object { width, height, text }
  3502. */
  3503. function layoutNext(lines, maxWidth, fakeText) {
  3504. var originalLine = lines.shift(),
  3505. fitLine = originalLine;
  3506. var textBBox;
  3507. for (;;) {
  3508. textBBox = getTextBBox(fitLine, fakeText);
  3509. textBBox.width = fitLine ? textBBox.width : 0;
  3510. // try to fit
  3511. if (fitLine === ' ' || fitLine === '' || textBBox.width < Math.round(maxWidth) || fitLine.length < 2) {
  3512. return fit(lines, fitLine, originalLine, textBBox);
  3513. }
  3514. fitLine = shortenLine(fitLine, textBBox.width, maxWidth);
  3515. }
  3516. }
  3517. function fit(lines, fitLine, originalLine, textBBox) {
  3518. if (fitLine.length < originalLine.length) {
  3519. var remainder = originalLine.slice(fitLine.length).trim();
  3520. lines.unshift(remainder);
  3521. }
  3522. return {
  3523. width: textBBox.width,
  3524. height: textBBox.height,
  3525. text: fitLine
  3526. };
  3527. }
  3528. var SOFT_BREAK = '\u00AD';
  3529. /**
  3530. * Shortens a line based on spacing and hyphens.
  3531. * Returns the shortened result on success.
  3532. *
  3533. * @param {string} line
  3534. * @param {number} maxLength the maximum characters of the string
  3535. * @return {string} the shortened string
  3536. */
  3537. function semanticShorten(line, maxLength) {
  3538. var parts = line.split(/(\s|-|\u00AD)/g),
  3539. part,
  3540. shortenedParts = [],
  3541. length = 0;
  3542. // try to shorten via break chars
  3543. if (parts.length > 1) {
  3544. while ((part = parts.shift())) {
  3545. if (part.length + length < maxLength) {
  3546. shortenedParts.push(part);
  3547. length += part.length;
  3548. } else {
  3549. // remove previous part, too if hyphen does not fit anymore
  3550. if (part === '-' || part === SOFT_BREAK) {
  3551. shortenedParts.pop();
  3552. }
  3553. break;
  3554. }
  3555. }
  3556. }
  3557. var last = shortenedParts[shortenedParts.length - 1];
  3558. // translate trailing soft break to actual hyphen
  3559. if (last && last === SOFT_BREAK) {
  3560. shortenedParts[shortenedParts.length - 1] = '-';
  3561. }
  3562. return shortenedParts.join('');
  3563. }
  3564. function shortenLine(line, width, maxWidth) {
  3565. var length = Math.max(line.length * (maxWidth / width), 1);
  3566. // try to shorten semantically (i.e. based on spaces and hyphens)
  3567. var shortenedLine = semanticShorten(line, length);
  3568. if (!shortenedLine) {
  3569. // force shorten by cutting the long word
  3570. shortenedLine = line.slice(0, Math.max(Math.round(length - 1), 1));
  3571. }
  3572. return shortenedLine;
  3573. }
  3574. function getHelperSvg() {
  3575. var helperSvg = document.getElementById('helper-svg');
  3576. if (!helperSvg) {
  3577. helperSvg = create$1('svg');
  3578. attr$1(helperSvg, {
  3579. id: 'helper-svg',
  3580. width: 0,
  3581. height: 0,
  3582. visibility: 'hidden',
  3583. position: 'fixed'
  3584. });
  3585. document.body.appendChild(helperSvg);
  3586. }
  3587. return helperSvg;
  3588. }
  3589. /**
  3590. * Creates a new label utility
  3591. *
  3592. * @param {Object} config
  3593. * @param {Dimensions} config.size
  3594. * @param {number} config.padding
  3595. * @param {Object} config.style
  3596. * @param {string} config.align
  3597. */
  3598. function Text(config) {
  3599. this._config = assign({}, {
  3600. size: DEFAULT_LABEL_SIZE$1,
  3601. padding: DEFAULT_BOX_PADDING,
  3602. style: {},
  3603. align: 'center-top'
  3604. }, config || {});
  3605. }
  3606. /**
  3607. * Returns the layouted text as an SVG element.
  3608. *
  3609. * @param {string} text
  3610. * @param {Object} options
  3611. *
  3612. * @return {SVGElement}
  3613. */
  3614. Text.prototype.createText = function(text, options) {
  3615. return this.layoutText(text, options).element;
  3616. };
  3617. /**
  3618. * Returns a labels layouted dimensions.
  3619. *
  3620. * @param {string} text to layout
  3621. * @param {Object} options
  3622. *
  3623. * @return {Dimensions}
  3624. */
  3625. Text.prototype.getDimensions = function(text, options) {
  3626. return this.layoutText(text, options).dimensions;
  3627. };
  3628. /**
  3629. * Creates and returns a label and its bounding box.
  3630. *
  3631. * @method Text#createText
  3632. *
  3633. * @param {string} text the text to render on the label
  3634. * @param {Object} options
  3635. * @param {string} options.align how to align in the bounding box.
  3636. * Any of { 'center-middle', 'center-top' },
  3637. * defaults to 'center-top'.
  3638. * @param {string} options.style style to be applied to the text
  3639. * @param {boolean} options.fitBox indicates if box will be recalculated to
  3640. * fit text
  3641. *
  3642. * @return {Object} { element, dimensions }
  3643. */
  3644. Text.prototype.layoutText = function(text, options) {
  3645. var box = assign({}, this._config.size, options.box),
  3646. style = assign({}, this._config.style, options.style),
  3647. align = parseAlign(options.align || this._config.align),
  3648. padding = parsePadding(options.padding !== undefined ? options.padding : this._config.padding),
  3649. fitBox = options.fitBox || false;
  3650. var lineHeight = getLineHeight(style);
  3651. // we split text by lines and normalize
  3652. // {soft break} + {line break} => { line break }
  3653. var lines = text.split(/\u00AD?\r?\n/),
  3654. layouted = [];
  3655. var maxWidth = box.width - padding.left - padding.right;
  3656. // ensure correct rendering by attaching helper text node to invisible SVG
  3657. var helperText = create$1('text');
  3658. attr$1(helperText, { x: 0, y: 0 });
  3659. attr$1(helperText, style);
  3660. var helperSvg = getHelperSvg();
  3661. append(helperSvg, helperText);
  3662. while (lines.length) {
  3663. layouted.push(layoutNext(lines, maxWidth, helperText));
  3664. }
  3665. if (align.vertical === 'middle') {
  3666. padding.top = padding.bottom = 0;
  3667. }
  3668. var totalHeight = reduce(layouted, function(sum, line, idx) {
  3669. return sum + (lineHeight || line.height);
  3670. }, 0) + padding.top + padding.bottom;
  3671. var maxLineWidth = reduce(layouted, function(sum, line, idx) {
  3672. return line.width > sum ? line.width : sum;
  3673. }, 0);
  3674. // the y position of the next line
  3675. var y = padding.top;
  3676. if (align.vertical === 'middle') {
  3677. y += (box.height - totalHeight) / 2;
  3678. }
  3679. // magic number initial offset
  3680. y -= (lineHeight || layouted[0].height) / 4;
  3681. var textElement = create$1('text');
  3682. attr$1(textElement, style);
  3683. // layout each line taking into account that parent
  3684. // shape might resize to fit text size
  3685. forEach$1(layouted, function(line) {
  3686. var x;
  3687. y += (lineHeight || line.height);
  3688. switch (align.horizontal) {
  3689. case 'left':
  3690. x = padding.left;
  3691. break;
  3692. case 'right':
  3693. x = ((fitBox ? maxLineWidth : maxWidth)
  3694. - padding.right - line.width);
  3695. break;
  3696. default:
  3697. // aka center
  3698. x = Math.max((((fitBox ? maxLineWidth : maxWidth)
  3699. - line.width) / 2 + padding.left), 0);
  3700. }
  3701. var tspan = create$1('tspan');
  3702. attr$1(tspan, { x: x, y: y });
  3703. tspan.textContent = line.text;
  3704. append(textElement, tspan);
  3705. });
  3706. remove$2(helperText);
  3707. var dimensions = {
  3708. width: maxLineWidth,
  3709. height: totalHeight
  3710. };
  3711. return {
  3712. dimensions: dimensions,
  3713. element: textElement
  3714. };
  3715. };
  3716. function getLineHeight(style) {
  3717. if ('fontSize' in style && 'lineHeight' in style) {
  3718. return style.lineHeight * parseInt(style.fontSize, 10);
  3719. }
  3720. }
  3721. var DEFAULT_FONT_SIZE = 12;
  3722. var LINE_HEIGHT_RATIO = 1.2;
  3723. var MIN_TEXT_ANNOTATION_HEIGHT = 30;
  3724. function TextRenderer(config) {
  3725. var defaultStyle = assign({
  3726. fontFamily: 'Arial, sans-serif',
  3727. fontSize: DEFAULT_FONT_SIZE,
  3728. fontWeight: 'normal',
  3729. lineHeight: LINE_HEIGHT_RATIO
  3730. }, config && config.defaultStyle || {});
  3731. var fontSize = parseInt(defaultStyle.fontSize, 10) - 1;
  3732. var externalStyle = assign({}, defaultStyle, {
  3733. fontSize: fontSize
  3734. }, config && config.externalStyle || {});
  3735. var textUtil = new Text({
  3736. style: defaultStyle
  3737. });
  3738. /**
  3739. * Get the new bounds of an externally rendered,
  3740. * layouted label.
  3741. *
  3742. * @param {Bounds} bounds
  3743. * @param {string} text
  3744. *
  3745. * @return {Bounds}
  3746. */
  3747. this.getExternalLabelBounds = function(bounds, text) {
  3748. var layoutedDimensions = textUtil.getDimensions(text, {
  3749. box: {
  3750. width: 90,
  3751. height: 30,
  3752. x: bounds.width / 2 + bounds.x,
  3753. y: bounds.height / 2 + bounds.y
  3754. },
  3755. style: externalStyle
  3756. });
  3757. // resize label shape to fit label text
  3758. return {
  3759. x: Math.round(bounds.x + bounds.width / 2 - layoutedDimensions.width / 2),
  3760. y: Math.round(bounds.y),
  3761. width: Math.ceil(layoutedDimensions.width),
  3762. height: Math.ceil(layoutedDimensions.height)
  3763. };
  3764. };
  3765. /**
  3766. * Get the new bounds of text annotation.
  3767. *
  3768. * @param {Bounds} bounds
  3769. * @param {string} text
  3770. *
  3771. * @return {Bounds}
  3772. */
  3773. this.getTextAnnotationBounds = function(bounds, text) {
  3774. var layoutedDimensions = textUtil.getDimensions(text, {
  3775. box: bounds,
  3776. style: defaultStyle,
  3777. align: 'left-top',
  3778. padding: 5
  3779. });
  3780. return {
  3781. x: bounds.x,
  3782. y: bounds.y,
  3783. width: bounds.width,
  3784. height: Math.max(MIN_TEXT_ANNOTATION_HEIGHT, Math.round(layoutedDimensions.height))
  3785. };
  3786. };
  3787. /**
  3788. * Create a layouted text element.
  3789. *
  3790. * @param {string} text
  3791. * @param {Object} [options]
  3792. *
  3793. * @return {SVGElement} rendered text
  3794. */
  3795. this.createText = function(text, options) {
  3796. return textUtil.createText(text, options || {});
  3797. };
  3798. /**
  3799. * Get default text style.
  3800. */
  3801. this.getDefaultStyle = function() {
  3802. return defaultStyle;
  3803. };
  3804. /**
  3805. * Get the external text style.
  3806. */
  3807. this.getExternalStyle = function() {
  3808. return externalStyle;
  3809. };
  3810. }
  3811. TextRenderer.$inject = [
  3812. 'config.textRenderer'
  3813. ];
  3814. /**
  3815. * Map containing SVG paths needed by BpmnRenderer.
  3816. */
  3817. function PathMap() {
  3818. /**
  3819. * Contains a map of path elements
  3820. *
  3821. * <h1>Path definition</h1>
  3822. * A parameterized path is defined like this:
  3823. * <pre>
  3824. * 'GATEWAY_PARALLEL': {
  3825. * d: 'm {mx},{my} {e.x0},0 0,{e.x1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
  3826. '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
  3827. * height: 17.5,
  3828. * width: 17.5,
  3829. * heightElements: [2.5, 7.5],
  3830. * widthElements: [2.5, 7.5]
  3831. * }
  3832. * </pre>
  3833. * <p>It's important to specify a correct <b>height and width</b> for the path as the scaling
  3834. * is based on the ratio between the specified height and width in this object and the
  3835. * height and width that is set as scale target (Note x,y coordinates will be scaled with
  3836. * individual ratios).</p>
  3837. * <p>The '<b>heightElements</b>' and '<b>widthElements</b>' array must contain the values that will be scaled.
  3838. * The scaling is based on the computed ratios.
  3839. * Coordinates on the y axis should be in the <b>heightElement</b>'s array, they will be scaled using
  3840. * the computed ratio coefficient.
  3841. * In the parameterized path the scaled values can be accessed through the 'e' object in {} brackets.
  3842. * <ul>
  3843. * <li>The values for the y axis can be accessed in the path string using {e.y0}, {e.y1}, ....</li>
  3844. * <li>The values for the x axis can be accessed in the path string using {e.x0}, {e.x1}, ....</li>
  3845. * </ul>
  3846. * The numbers x0, x1 respectively y0, y1, ... map to the corresponding array index.
  3847. * </p>
  3848. */
  3849. this.pathMap = {
  3850. 'EVENT_MESSAGE': {
  3851. 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}',
  3852. height: 36,
  3853. width: 36,
  3854. heightElements: [6, 14],
  3855. widthElements: [10.5, 21]
  3856. },
  3857. 'EVENT_SIGNAL': {
  3858. d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x1},0 Z',
  3859. height: 36,
  3860. width: 36,
  3861. heightElements: [18],
  3862. widthElements: [10, 20]
  3863. },
  3864. 'EVENT_ESCALATION': {
  3865. d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x0},-{e.y1} l -{e.x0},{e.y1} Z',
  3866. height: 36,
  3867. width: 36,
  3868. heightElements: [20, 7],
  3869. widthElements: [8]
  3870. },
  3871. 'EVENT_CONDITIONAL': {
  3872. d: 'M {e.x0},{e.y0} l {e.x1},0 l 0,{e.y2} l -{e.x1},0 Z ' +
  3873. 'M {e.x2},{e.y3} l {e.x0},0 ' +
  3874. 'M {e.x2},{e.y4} l {e.x0},0 ' +
  3875. 'M {e.x2},{e.y5} l {e.x0},0 ' +
  3876. 'M {e.x2},{e.y6} l {e.x0},0 ' +
  3877. 'M {e.x2},{e.y7} l {e.x0},0 ' +
  3878. 'M {e.x2},{e.y8} l {e.x0},0 ',
  3879. height: 36,
  3880. width: 36,
  3881. heightElements: [8.5, 14.5, 18, 11.5, 14.5, 17.5, 20.5, 23.5, 26.5],
  3882. widthElements: [10.5, 14.5, 12.5]
  3883. },
  3884. 'EVENT_LINK': {
  3885. 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',
  3886. height: 36,
  3887. width: 36,
  3888. heightElements: [4.4375, 6.75, 7.8125],
  3889. widthElements: [9.84375, 13.5]
  3890. },
  3891. 'EVENT_ERROR': {
  3892. 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',
  3893. height: 36,
  3894. width: 36,
  3895. heightElements: [0.023, 8.737, 8.151, 16.564, 10.591, 8.714],
  3896. widthElements: [0.085, 6.672, 6.97, 4.273, 5.337, 6.636]
  3897. },
  3898. 'EVENT_CANCEL_45': {
  3899. d: 'm {mx},{my} -{e.x1},0 0,{e.x0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
  3900. '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
  3901. height: 36,
  3902. width: 36,
  3903. heightElements: [4.75, 8.5],
  3904. widthElements: [4.75, 8.5]
  3905. },
  3906. 'EVENT_COMPENSATION': {
  3907. 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',
  3908. height: 36,
  3909. width: 36,
  3910. heightElements: [6.5, 13, 0.4, 6.1],
  3911. widthElements: [9, 9.3, 8.7]
  3912. },
  3913. 'EVENT_TIMER_WH': {
  3914. d: 'M {mx},{my} l {e.x0},-{e.y0} m -{e.x0},{e.y0} l {e.x1},{e.y1} ',
  3915. height: 36,
  3916. width: 36,
  3917. heightElements: [10, 2],
  3918. widthElements: [3, 7]
  3919. },
  3920. 'EVENT_TIMER_LINE': {
  3921. d: 'M {mx},{my} ' +
  3922. 'm {e.x0},{e.y0} l -{e.x1},{e.y1} ',
  3923. height: 36,
  3924. width: 36,
  3925. heightElements: [10, 3],
  3926. widthElements: [0, 0]
  3927. },
  3928. 'EVENT_MULTIPLE': {
  3929. d:'m {mx},{my} {e.x1},-{e.y0} {e.x1},{e.y0} -{e.x0},{e.y1} -{e.x2},0 z',
  3930. height: 36,
  3931. width: 36,
  3932. heightElements: [6.28099, 12.56199],
  3933. widthElements: [3.1405, 9.42149, 12.56198]
  3934. },
  3935. 'EVENT_PARALLEL_MULTIPLE': {
  3936. d:'m {mx},{my} {e.x0},0 0,{e.y1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
  3937. '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
  3938. height: 36,
  3939. width: 36,
  3940. heightElements: [2.56228, 7.68683],
  3941. widthElements: [2.56228, 7.68683]
  3942. },
  3943. 'GATEWAY_EXCLUSIVE': {
  3944. d:'m {mx},{my} {e.x0},{e.y0} {e.x1},{e.y0} {e.x2},0 {e.x4},{e.y2} ' +
  3945. '{e.x4},{e.y1} {e.x2},0 {e.x1},{e.y3} {e.x0},{e.y3} ' +
  3946. '{e.x3},0 {e.x5},{e.y1} {e.x5},{e.y2} {e.x3},0 z',
  3947. height: 17.5,
  3948. width: 17.5,
  3949. heightElements: [8.5, 6.5312, -6.5312, -8.5],
  3950. widthElements: [6.5, -6.5, 3, -3, 5, -5]
  3951. },
  3952. 'GATEWAY_PARALLEL': {
  3953. d:'m {mx},{my} 0,{e.y1} -{e.x1},0 0,{e.y0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
  3954. '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
  3955. height: 30,
  3956. width: 30,
  3957. heightElements: [5, 12.5],
  3958. widthElements: [5, 12.5]
  3959. },
  3960. 'GATEWAY_EVENT_BASED': {
  3961. d:'m {mx},{my} {e.x0},{e.y0} {e.x0},{e.y1} {e.x1},{e.y2} {e.x2},0 z',
  3962. height: 11,
  3963. width: 11,
  3964. heightElements: [-6, 6, 12, -12],
  3965. widthElements: [9, -3, -12]
  3966. },
  3967. 'GATEWAY_COMPLEX': {
  3968. 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} ' +
  3969. '{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} ' +
  3970. '{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} ' +
  3971. '-{e.x0},{e.y1} 0,-{e.y0} -{e.x3},0 z',
  3972. height: 17.125,
  3973. width: 17.125,
  3974. heightElements: [4.875, 3.4375, 2.125, 3],
  3975. widthElements: [3.4375, 2.125, 4.875, 3]
  3976. },
  3977. 'DATA_OBJECT_PATH': {
  3978. 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',
  3979. height: 61,
  3980. width: 51,
  3981. heightElements: [10, 50, 60],
  3982. widthElements: [10, 40, 50, 60]
  3983. },
  3984. 'DATA_OBJECT_COLLECTION_PATH': {
  3985. d: 'm{mx},{my} m 3,2 l 0,10 m 3,-10 l 0,10 m 3,-10 l 0,10',
  3986. height: 10,
  3987. width: 10,
  3988. heightElements: [],
  3989. widthElements: []
  3990. },
  3991. 'DATA_ARROW': {
  3992. d:'m 5,9 9,0 0,-3 5,5 -5,5 0,-3 -9,0 z',
  3993. height: 61,
  3994. width: 51,
  3995. heightElements: [],
  3996. widthElements: []
  3997. },
  3998. 'DATA_STORE': {
  3999. d:'m {mx},{my} ' +
  4000. 'l 0,{e.y2} ' +
  4001. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
  4002. 'l 0,-{e.y2} ' +
  4003. 'c -{e.x0},-{e.y1} -{e.x1},-{e.y1} -{e.x2},0' +
  4004. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
  4005. 'm -{e.x2},{e.y0}' +
  4006. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0' +
  4007. 'm -{e.x2},{e.y0}' +
  4008. 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0',
  4009. height: 61,
  4010. width: 61,
  4011. heightElements: [7, 10, 45],
  4012. widthElements: [2, 58, 60]
  4013. },
  4014. 'TEXT_ANNOTATION': {
  4015. d: 'm {mx}, {my} m 10,0 l -10,0 l 0,{e.y0} l 10,0',
  4016. height: 30,
  4017. width: 10,
  4018. heightElements: [30],
  4019. widthElements: [10]
  4020. },
  4021. 'MARKER_SUB_PROCESS': {
  4022. d: 'm{mx},{my} m 7,2 l 0,10 m -5,-5 l 10,0',
  4023. height: 10,
  4024. width: 10,
  4025. heightElements: [],
  4026. widthElements: []
  4027. },
  4028. 'MARKER_PARALLEL': {
  4029. d: 'm{mx},{my} m 3,2 l 0,10 m 3,-10 l 0,10 m 3,-10 l 0,10',
  4030. height: 10,
  4031. width: 10,
  4032. heightElements: [],
  4033. widthElements: []
  4034. },
  4035. 'MARKER_SEQUENTIAL': {
  4036. d: 'm{mx},{my} m 0,3 l 10,0 m -10,3 l 10,0 m -10,3 l 10,0',
  4037. height: 10,
  4038. width: 10,
  4039. heightElements: [],
  4040. widthElements: []
  4041. },
  4042. 'MARKER_COMPENSATION': {
  4043. 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',
  4044. height: 10,
  4045. width: 21,
  4046. heightElements: [],
  4047. widthElements: []
  4048. },
  4049. 'MARKER_LOOP': {
  4050. d: 'm {mx},{my} c 3.526979,0 6.386161,-2.829858 6.386161,-6.320661 0,-3.490806 -2.859182,-6.320661 ' +
  4051. '-6.386161,-6.320661 -3.526978,0 -6.38616,2.829855 -6.38616,6.320661 0,1.745402 ' +
  4052. '0.714797,3.325567 1.870463,4.469381 0.577834,0.571908 1.265885,1.034728 2.029916,1.35457 ' +
  4053. 'l -0.718163,-3.909793 m 0.718163,3.909793 -3.885211,0.802902',
  4054. height: 13.9,
  4055. width: 13.7,
  4056. heightElements: [],
  4057. widthElements: []
  4058. },
  4059. 'MARKER_ADHOC': {
  4060. 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 ' +
  4061. '3.85579,1.15803 5.76082,1.79107 1.06385,0.34139996 2.24454,0.1438 3.18759,-0.43767 0.61743,-0.33642 ' +
  4062. '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 ' +
  4063. '-3.6918,1.66181996 -1.24459,0.0927 -2.46671,-0.2491 -3.59505,-0.74812 -1.35789,-0.55965 ' +
  4064. '-2.75133,-1.33436996 -4.27027,-1.18121996 -1.37741,0.14601 -2.41842,1.13685996 -3.44288,1.96782996 z',
  4065. height: 4,
  4066. width: 15,
  4067. heightElements: [],
  4068. widthElements: []
  4069. },
  4070. 'TASK_TYPE_SEND': {
  4071. 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}',
  4072. height: 14,
  4073. width: 21,
  4074. heightElements: [6, 14],
  4075. widthElements: [10.5, 21]
  4076. },
  4077. 'TASK_TYPE_SCRIPT': {
  4078. d: 'm {mx},{my} c 9.966553,-6.27276 -8.000926,-7.91932 2.968968,-14.938 l -8.802728,0 ' +
  4079. 'c -10.969894,7.01868 6.997585,8.66524 -2.968967,14.938 z ' +
  4080. 'm -7,-12 l 5,0 ' +
  4081. 'm -4.5,3 l 4.5,0 ' +
  4082. 'm -3,3 l 5,0' +
  4083. 'm -4,3 l 5,0',
  4084. height: 15,
  4085. width: 12.6,
  4086. heightElements: [6, 14],
  4087. widthElements: [10.5, 21]
  4088. },
  4089. 'TASK_TYPE_USER_1': {
  4090. d: 'm {mx},{my} c 0.909,-0.845 1.594,-2.049 1.594,-3.385 0,-2.554 -1.805,-4.62199999 ' +
  4091. '-4.357,-4.62199999 -2.55199998,0 -4.28799998,2.06799999 -4.28799998,4.62199999 0,1.348 ' +
  4092. '0.974,2.562 1.89599998,3.405 -0.52899998,0.187 -5.669,2.097 -5.794,4.7560005 v 6.718 ' +
  4093. 'h 17 v -6.718 c 0,-2.2980005 -5.5279996,-4.5950005 -6.0509996,-4.7760005 z' +
  4094. 'm -8,6 l 0,5.5 m 11,0 l 0,-5'
  4095. },
  4096. 'TASK_TYPE_USER_2': {
  4097. d: 'm {mx},{my} m 2.162,1.009 c 0,2.4470005 -2.158,4.4310005 -4.821,4.4310005 ' +
  4098. '-2.66499998,0 -4.822,-1.981 -4.822,-4.4310005 '
  4099. },
  4100. 'TASK_TYPE_USER_3': {
  4101. 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 ' +
  4102. '4.124,0.965 -0.098,-0.57 -0.117,-3.79099999 -4.191,-4.13599999 -3.57499998,0.001 ' +
  4103. '-4.20799998,3.36699999 -4.20699998,4.34799999 z'
  4104. },
  4105. 'TASK_TYPE_MANUAL': {
  4106. 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 ' +
  4107. '-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 ' +
  4108. '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 ' +
  4109. '-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 ' +
  4110. '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 ' +
  4111. '-10.86,-0.003 -11.0829995,-0.003 -0.022,-0.047 -0.045,-0.094 -0.069,-0.139 0.3939995,-0.319 ' +
  4112. '2.0409995,-1.626 2.4149995,-2.017 0.469,-0.4870005 0.519,-1.1650005 0.162,-1.6040005 -0.414,-0.511 ' +
  4113. '-0.973,-0.5 -1.48,-0.236 -1.4609995,0.764 -6.5999995,3.6430005 -7.7329995,4.2710005 -0.9,0.499 ' +
  4114. '-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 ' +
  4115. '-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 ' +
  4116. '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 ' +
  4117. '-5.824,-0.004 -6.04,-0.004 10e-4,-0.084 0.003,-0.586 10e-4,-0.67 z'
  4118. },
  4119. 'TASK_TYPE_INSTANTIATING_SEND': {
  4120. 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'
  4121. },
  4122. 'TASK_TYPE_SERVICE': {
  4123. d: 'm {mx},{my} v -1.71335 c 0.352326,-0.0705 0.703932,-0.17838 1.047628,-0.32133 ' +
  4124. '0.344416,-0.14465 0.665822,-0.32133 0.966377,-0.52145 l 1.19431,1.18005 1.567487,-1.57688 ' +
  4125. '-1.195028,-1.18014 c 0.403376,-0.61394 0.683079,-1.29908 0.825447,-2.01824 l 1.622133,-0.01 ' +
  4126. 'v -2.2196 l -1.636514,0.01 c -0.07333,-0.35153 -0.178319,-0.70024 -0.323564,-1.04372 ' +
  4127. '-0.145244,-0.34406 -0.321407,-0.6644 -0.522735,-0.96217 l 1.131035,-1.13631 -1.583305,-1.56293 ' +
  4128. '-1.129598,1.13589 c -0.614052,-0.40108 -1.302883,-0.68093 -2.022633,-0.82247 l 0.0093,-1.61852 ' +
  4129. '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 ' +
  4130. '-0.665102,0.32092 -0.9635006,0.52046 l -1.1698628,-1.15823 -1.5667691,1.5792 1.1684265,1.15669 ' +
  4131. 'c -0.4026573,0.61283 -0.68308,1.29797 -0.8247287,2.01713 l -1.6588041,0.003 v 2.22174 ' +
  4132. 'l 1.6724648,-0.006 c 0.073327,0.35077 0.1797598,0.70243 0.3242851,1.04472 0.1452428,0.34448 ' +
  4133. '0.3214064,0.6644 0.5227339,0.96066 l -1.1993431,1.19723 1.5840256,1.56011 1.1964668,-1.19348 ' +
  4134. 'c 0.6140517,0.40346 1.3028827,0.68232 2.0233517,0.82331 l 7.19e-4,1.69892 h 2.226848 z ' +
  4135. 'm 0.221462,-3.9957 c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
  4136. '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
  4137. '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
  4138. },
  4139. 'TASK_TYPE_SERVICE_FILL': {
  4140. d: 'm {mx},{my} c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
  4141. '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
  4142. '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
  4143. },
  4144. 'TASK_TYPE_BUSINESS_RULE_HEADER': {
  4145. d: 'm {mx},{my} 0,4 20,0 0,-4 z'
  4146. },
  4147. 'TASK_TYPE_BUSINESS_RULE_MAIN': {
  4148. d: 'm {mx},{my} 0,12 20,0 0,-12 z' +
  4149. 'm 0,8 l 20,0 ' +
  4150. 'm -13,-4 l 0,8'
  4151. },
  4152. 'MESSAGE_FLOW_MARKER': {
  4153. 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'
  4154. }
  4155. };
  4156. this.getRawPath = function getRawPath(pathId) {
  4157. return this.pathMap[pathId].d;
  4158. };
  4159. /**
  4160. * Scales the path to the given height and width.
  4161. * <h1>Use case</h1>
  4162. * <p>Use case is to scale the content of elements (event, gateways) based
  4163. * on the element bounding box's size.
  4164. * </p>
  4165. * <h1>Why not transform</h1>
  4166. * <p>Scaling a path with transform() will also scale the stroke and IE does not support
  4167. * the option 'non-scaling-stroke' to prevent this.
  4168. * Also there are use cases where only some parts of a path should be
  4169. * scaled.</p>
  4170. *
  4171. * @param {string} pathId The ID of the path.
  4172. * @param {Object} param <p>
  4173. * Example param object scales the path to 60% size of the container (data.width, data.height).
  4174. * <pre>
  4175. * {
  4176. * xScaleFactor: 0.6,
  4177. * yScaleFactor:0.6,
  4178. * containerWidth: data.width,
  4179. * containerHeight: data.height,
  4180. * position: {
  4181. * mx: 0.46,
  4182. * my: 0.2,
  4183. * }
  4184. * }
  4185. * </pre>
  4186. * <ul>
  4187. * <li>targetpathwidth = xScaleFactor * containerWidth</li>
  4188. * <li>targetpathheight = yScaleFactor * containerHeight</li>
  4189. * <li>Position is used to set the starting coordinate of the path. M is computed:
  4190. * <ul>
  4191. * <li>position.x * containerWidth</li>
  4192. * <li>position.y * containerHeight</li>
  4193. * </ul>
  4194. * Center of the container <pre> position: {
  4195. * mx: 0.5,
  4196. * my: 0.5,
  4197. * }</pre>
  4198. * Upper left corner of the container
  4199. * <pre> position: {
  4200. * mx: 0.0,
  4201. * my: 0.0,
  4202. * }</pre>
  4203. * </li>
  4204. * </ul>
  4205. * </p>
  4206. *
  4207. */
  4208. this.getScaledPath = function getScaledPath(pathId, param) {
  4209. var rawPath = this.pathMap[pathId];
  4210. // positioning
  4211. // compute the start point of the path
  4212. var mx, my;
  4213. if (param.abspos) {
  4214. mx = param.abspos.x;
  4215. my = param.abspos.y;
  4216. } else {
  4217. mx = param.containerWidth * param.position.mx;
  4218. my = param.containerHeight * param.position.my;
  4219. }
  4220. var coordinates = {}; // map for the scaled coordinates
  4221. if (param.position) {
  4222. // path
  4223. var heightRatio = (param.containerHeight / rawPath.height) * param.yScaleFactor;
  4224. var widthRatio = (param.containerWidth / rawPath.width) * param.xScaleFactor;
  4225. // Apply height ratio
  4226. for (var heightIndex = 0; heightIndex < rawPath.heightElements.length; heightIndex++) {
  4227. coordinates['y' + heightIndex] = rawPath.heightElements[heightIndex] * heightRatio;
  4228. }
  4229. // Apply width ratio
  4230. for (var widthIndex = 0; widthIndex < rawPath.widthElements.length; widthIndex++) {
  4231. coordinates['x' + widthIndex] = rawPath.widthElements[widthIndex] * widthRatio;
  4232. }
  4233. }
  4234. // Apply value to raw path
  4235. var path = format(
  4236. rawPath.d, {
  4237. mx: mx,
  4238. my: my,
  4239. e: coordinates
  4240. }
  4241. );
  4242. return path;
  4243. };
  4244. }
  4245. // helpers //////////////////////
  4246. // copied and adjusted from https://github.com/adobe-webplatform/Snap.svg/blob/master/src/svg.js
  4247. var tokenRegex = /\{([^{}]+)\}/g,
  4248. objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g; // matches .xxxxx or ["xxxxx"] to run over object properties
  4249. function replacer(all, key, obj) {
  4250. var res = obj;
  4251. key.replace(objNotationRegex, function(all, name, quote, quotedName, isFunc) {
  4252. name = name || quotedName;
  4253. if (res) {
  4254. if (name in res) {
  4255. res = res[name];
  4256. }
  4257. typeof res == 'function' && isFunc && (res = res());
  4258. }
  4259. });
  4260. res = (res == null || res == obj ? all : res) + '';
  4261. return res;
  4262. }
  4263. function format(str, obj) {
  4264. return String(str).replace(tokenRegex, function(all, key) {
  4265. return replacer(all, key, obj);
  4266. });
  4267. }
  4268. var DrawModule$1 = {
  4269. __init__: [ 'bpmnRenderer' ],
  4270. bpmnRenderer: [ 'type', BpmnRenderer ],
  4271. textRenderer: [ 'type', TextRenderer ],
  4272. pathMap: [ 'type', PathMap ]
  4273. };
  4274. /**
  4275. * A simple translation stub to be used for multi-language support
  4276. * in diagrams. Can be easily replaced with a more sophisticated
  4277. * solution.
  4278. *
  4279. * @example
  4280. *
  4281. * // use it inside any diagram component by injecting `translate`.
  4282. *
  4283. * function MyService(translate) {
  4284. * alert(translate('HELLO {you}', { you: 'You!' }));
  4285. * }
  4286. *
  4287. * @param {string} template to interpolate
  4288. * @param {Object} [replacements] a map with substitutes
  4289. *
  4290. * @return {string} the translated string
  4291. */
  4292. function translate(template, replacements) {
  4293. replacements = replacements || {};
  4294. return template.replace(/{([^}]+)}/g, function(_, key) {
  4295. return replacements[key] || '{' + key + '}';
  4296. });
  4297. }
  4298. var TranslateModule = {
  4299. translate: [ 'value', translate ]
  4300. };
  4301. var DEFAULT_LABEL_SIZE = {
  4302. width: 90,
  4303. height: 20
  4304. };
  4305. var FLOW_LABEL_INDENT = 15;
  4306. /**
  4307. * Returns true if the given semantic has an external label
  4308. *
  4309. * @param {BpmnElement} semantic
  4310. * @return {boolean} true if has label
  4311. */
  4312. function isLabelExternal(semantic) {
  4313. return is$1(semantic, 'bpmn:Event') ||
  4314. is$1(semantic, 'bpmn:Gateway') ||
  4315. is$1(semantic, 'bpmn:DataStoreReference') ||
  4316. is$1(semantic, 'bpmn:DataObjectReference') ||
  4317. is$1(semantic, 'bpmn:DataInput') ||
  4318. is$1(semantic, 'bpmn:DataOutput') ||
  4319. is$1(semantic, 'bpmn:SequenceFlow') ||
  4320. is$1(semantic, 'bpmn:MessageFlow') ||
  4321. is$1(semantic, 'bpmn:Group');
  4322. }
  4323. /**
  4324. * Get the position for sequence flow labels
  4325. *
  4326. * @param {Array<Point>} waypoints
  4327. * @return {Point} the label position
  4328. */
  4329. function getFlowLabelPosition(waypoints) {
  4330. // get the waypoints mid
  4331. var mid = waypoints.length / 2 - 1;
  4332. var first = waypoints[Math.floor(mid)];
  4333. var second = waypoints[Math.ceil(mid + 0.01)];
  4334. // get position
  4335. var position = getWaypointsMid(waypoints);
  4336. // calculate angle
  4337. var angle = Math.atan((second.y - first.y) / (second.x - first.x));
  4338. var x = position.x,
  4339. y = position.y;
  4340. if (Math.abs(angle) < Math.PI / 2) {
  4341. y -= FLOW_LABEL_INDENT;
  4342. } else {
  4343. x += FLOW_LABEL_INDENT;
  4344. }
  4345. return { x: x, y: y };
  4346. }
  4347. /**
  4348. * Get the middle of a number of waypoints
  4349. *
  4350. * @param {Array<Point>} waypoints
  4351. * @return {Point} the mid point
  4352. */
  4353. function getWaypointsMid(waypoints) {
  4354. var mid = waypoints.length / 2 - 1;
  4355. var first = waypoints[Math.floor(mid)];
  4356. var second = waypoints[Math.ceil(mid + 0.01)];
  4357. return {
  4358. x: first.x + (second.x - first.x) / 2,
  4359. y: first.y + (second.y - first.y) / 2
  4360. };
  4361. }
  4362. function getExternalLabelMid(element) {
  4363. if (element.waypoints) {
  4364. return getFlowLabelPosition(element.waypoints);
  4365. } else if (is$1(element, 'bpmn:Group')) {
  4366. return {
  4367. x: element.x + element.width / 2,
  4368. y: element.y + DEFAULT_LABEL_SIZE.height / 2
  4369. };
  4370. } else {
  4371. return {
  4372. x: element.x + element.width / 2,
  4373. y: element.y + element.height + DEFAULT_LABEL_SIZE.height / 2
  4374. };
  4375. }
  4376. }
  4377. /**
  4378. * Returns the bounds of an elements label, parsed from the elements DI or
  4379. * generated from its bounds.
  4380. *
  4381. * @param {BpmndDi} di
  4382. * @param {djs.model.Base} element
  4383. */
  4384. function getExternalLabelBounds(di, element) {
  4385. var mid,
  4386. size,
  4387. bounds,
  4388. label = di.label;
  4389. if (label && label.bounds) {
  4390. bounds = label.bounds;
  4391. size = {
  4392. width: Math.max(DEFAULT_LABEL_SIZE.width, bounds.width),
  4393. height: bounds.height
  4394. };
  4395. mid = {
  4396. x: bounds.x + bounds.width / 2,
  4397. y: bounds.y + bounds.height / 2
  4398. };
  4399. } else {
  4400. mid = getExternalLabelMid(element);
  4401. size = DEFAULT_LABEL_SIZE;
  4402. }
  4403. return assign({
  4404. x: mid.x - size.width / 2,
  4405. y: mid.y - size.height / 2
  4406. }, size);
  4407. }
  4408. var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  4409. function roundPoint(point) {
  4410. return {
  4411. x: Math.round(point.x),
  4412. y: Math.round(point.y)
  4413. };
  4414. }
  4415. /**
  4416. * Convert the given bounds to a { top, left, bottom, right } descriptor.
  4417. *
  4418. * @param {Bounds|Point} bounds
  4419. *
  4420. * @return {Object}
  4421. */
  4422. function asTRBL(bounds) {
  4423. return {
  4424. top: bounds.y,
  4425. right: bounds.x + (bounds.width || 0),
  4426. bottom: bounds.y + (bounds.height || 0),
  4427. left: bounds.x
  4428. };
  4429. }
  4430. /**
  4431. * Convert a { top, left, bottom, right } to an objects bounds.
  4432. *
  4433. * @param {Object} trbl
  4434. *
  4435. * @return {Bounds}
  4436. */
  4437. function asBounds(trbl) {
  4438. return {
  4439. x: trbl.left,
  4440. y: trbl.top,
  4441. width: trbl.right - trbl.left,
  4442. height: trbl.bottom - trbl.top
  4443. };
  4444. }
  4445. /**
  4446. * Get the mid of the given bounds or point.
  4447. *
  4448. * @param {Bounds|Point} bounds
  4449. *
  4450. * @return {Point}
  4451. */
  4452. function getBoundsMid(bounds) {
  4453. return roundPoint({
  4454. x: bounds.x + (bounds.width || 0) / 2,
  4455. y: bounds.y + (bounds.height || 0) / 2
  4456. });
  4457. }
  4458. /**
  4459. * Get the mid of the given Connection.
  4460. *
  4461. * @param {djs.Base.Connection} connection
  4462. *
  4463. * @return {Point}
  4464. */
  4465. function getConnectionMid(connection) {
  4466. var waypoints = connection.waypoints;
  4467. // calculate total length and length of each segment
  4468. var parts = waypoints.reduce(function(parts, point, index) {
  4469. var lastPoint = waypoints[index - 1];
  4470. if (lastPoint) {
  4471. var lastPart = parts[parts.length - 1];
  4472. var startLength = lastPart && lastPart.endLength || 0;
  4473. var length = distance(lastPoint, point);
  4474. parts.push({
  4475. start: lastPoint,
  4476. end: point,
  4477. startLength: startLength,
  4478. endLength: startLength + length,
  4479. length: length
  4480. });
  4481. }
  4482. return parts;
  4483. }, []);
  4484. var totalLength = parts.reduce(function(length, part) {
  4485. return length + part.length;
  4486. }, 0);
  4487. // find which segement contains middle point
  4488. var midLength = totalLength / 2;
  4489. var i = 0;
  4490. var midSegment = parts[i];
  4491. while (midSegment.endLength < midLength) {
  4492. midSegment = parts[++i];
  4493. }
  4494. // calculate relative position on mid segment
  4495. var segmentProgress = (midLength - midSegment.startLength) / midSegment.length;
  4496. var midPoint = {
  4497. x: midSegment.start.x + (midSegment.end.x - midSegment.start.x) * segmentProgress,
  4498. y: midSegment.start.y + (midSegment.end.y - midSegment.start.y) * segmentProgress
  4499. };
  4500. return midPoint;
  4501. }
  4502. /**
  4503. * Get the mid of the given Element.
  4504. *
  4505. * @param {djs.Base.Connection} connection
  4506. *
  4507. * @return {Point}
  4508. */
  4509. function getMid(element) {
  4510. if (isConnection(element)) {
  4511. return getConnectionMid(element);
  4512. }
  4513. return getBoundsMid(element);
  4514. }
  4515. // helpers //////////////////////
  4516. function distance(a, b) {
  4517. return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));
  4518. }
  4519. function isConnection(element) {
  4520. return !!element.waypoints;
  4521. }
  4522. function elementToString(e) {
  4523. if (!e) {
  4524. return '<null>';
  4525. }
  4526. return '<' + e.$type + (e.id ? ' id="' + e.id : '') + '" />';
  4527. }
  4528. /**
  4529. * @param {ModdleElement} semantic
  4530. * @param {ModdleElement} di
  4531. * @param {Object} [attrs=null]
  4532. *
  4533. * @return {Object}
  4534. */
  4535. function elementData(semantic, di, attrs) {
  4536. return assign({
  4537. id: semantic.id,
  4538. type: semantic.$type,
  4539. businessObject: semantic,
  4540. di: di
  4541. }, attrs);
  4542. }
  4543. function getWaypoints(di, source, target) {
  4544. var waypoints = di.waypoint;
  4545. if (!waypoints || waypoints.length < 2) {
  4546. return [ getMid(source), getMid(target) ];
  4547. }
  4548. return waypoints.map(function(p) {
  4549. return { x: p.x, y: p.y };
  4550. });
  4551. }
  4552. function notYetDrawn(translate, semantic, refSemantic, property) {
  4553. return new Error(translate('element {element} referenced by {referenced}#{property} not yet drawn', {
  4554. element: elementToString(refSemantic),
  4555. referenced: elementToString(semantic),
  4556. property: property
  4557. }));
  4558. }
  4559. /**
  4560. * An importer that adds bpmn elements to the canvas
  4561. *
  4562. * @param {EventBus} eventBus
  4563. * @param {Canvas} canvas
  4564. * @param {ElementFactory} elementFactory
  4565. * @param {ElementRegistry} elementRegistry
  4566. * @param {Function} translate
  4567. * @param {TextRenderer} textRenderer
  4568. */
  4569. function BpmnImporter(
  4570. eventBus, canvas, elementFactory,
  4571. elementRegistry, translate, textRenderer) {
  4572. this._eventBus = eventBus;
  4573. this._canvas = canvas;
  4574. this._elementFactory = elementFactory;
  4575. this._elementRegistry = elementRegistry;
  4576. this._translate = translate;
  4577. this._textRenderer = textRenderer;
  4578. }
  4579. BpmnImporter.$inject = [
  4580. 'eventBus',
  4581. 'canvas',
  4582. 'elementFactory',
  4583. 'elementRegistry',
  4584. 'translate',
  4585. 'textRenderer'
  4586. ];
  4587. /**
  4588. * Add bpmn element (semantic) to the canvas onto the
  4589. * specified parent shape.
  4590. */
  4591. BpmnImporter.prototype.add = function(semantic, di, parentElement) {
  4592. var element,
  4593. translate = this._translate,
  4594. hidden;
  4595. var parentIndex;
  4596. // ROOT ELEMENT
  4597. // handle the special case that we deal with a
  4598. // invisible root element (process, subprocess or collaboration)
  4599. if (is$1(di, 'bpmndi:BPMNPlane')) {
  4600. var attrs = is$1(semantic, 'bpmn:SubProcess')
  4601. ? { id: semantic.id + '_plane' }
  4602. : {};
  4603. // add a virtual element (not being drawn)
  4604. element = this._elementFactory.createRoot(elementData(semantic, di, attrs));
  4605. this._canvas.addRootElement(element);
  4606. }
  4607. // SHAPE
  4608. else if (is$1(di, 'bpmndi:BPMNShape')) {
  4609. var collapsed = !isExpanded(semantic, di),
  4610. isFrame = isFrameElement$1(semantic);
  4611. hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
  4612. var bounds = di.bounds;
  4613. element = this._elementFactory.createShape(elementData(semantic, di, {
  4614. collapsed: collapsed,
  4615. hidden: hidden,
  4616. x: Math.round(bounds.x),
  4617. y: Math.round(bounds.y),
  4618. width: Math.round(bounds.width),
  4619. height: Math.round(bounds.height),
  4620. isFrame: isFrame
  4621. }));
  4622. if (is$1(semantic, 'bpmn:BoundaryEvent')) {
  4623. this._attachBoundary(semantic, element);
  4624. }
  4625. // insert lanes behind other flow nodes (cf. #727)
  4626. if (is$1(semantic, 'bpmn:Lane')) {
  4627. parentIndex = 0;
  4628. }
  4629. if (is$1(semantic, 'bpmn:DataStoreReference')) {
  4630. // check whether data store is inside our outside of its semantic parent
  4631. if (!isPointInsideBBox(parentElement, getMid(bounds))) {
  4632. parentElement = this._canvas.findRoot(parentElement);
  4633. }
  4634. }
  4635. this._canvas.addShape(element, parentElement, parentIndex);
  4636. }
  4637. // CONNECTION
  4638. else if (is$1(di, 'bpmndi:BPMNEdge')) {
  4639. var source = this._getSource(semantic),
  4640. target = this._getTarget(semantic);
  4641. hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
  4642. element = this._elementFactory.createConnection(elementData(semantic, di, {
  4643. hidden: hidden,
  4644. source: source,
  4645. target: target,
  4646. waypoints: getWaypoints(di, source, target)
  4647. }));
  4648. if (is$1(semantic, 'bpmn:DataAssociation')) {
  4649. // render always on top; this ensures DataAssociations
  4650. // are rendered correctly across different "hacks" people
  4651. // love to model such as cross participant / sub process
  4652. // associations
  4653. parentElement = this._canvas.findRoot(parentElement);
  4654. }
  4655. // insert sequence flows behind other flow nodes (cf. #727)
  4656. if (is$1(semantic, 'bpmn:SequenceFlow')) {
  4657. parentIndex = 0;
  4658. }
  4659. this._canvas.addConnection(element, parentElement, parentIndex);
  4660. } else {
  4661. throw new Error(translate('unknown di {di} for element {semantic}', {
  4662. di: elementToString(di),
  4663. semantic: elementToString(semantic)
  4664. }));
  4665. }
  4666. // (optional) LABEL
  4667. if (isLabelExternal(semantic) && getLabel(element)) {
  4668. this.addLabel(semantic, di, element);
  4669. }
  4670. this._eventBus.fire('bpmnElement.added', { element: element });
  4671. return element;
  4672. };
  4673. /**
  4674. * Attach the boundary element to the given host
  4675. *
  4676. * @param {ModdleElement} boundarySemantic
  4677. * @param {djs.model.Base} boundaryElement
  4678. */
  4679. BpmnImporter.prototype._attachBoundary = function(boundarySemantic, boundaryElement) {
  4680. var translate = this._translate;
  4681. var hostSemantic = boundarySemantic.attachedToRef;
  4682. if (!hostSemantic) {
  4683. throw new Error(translate('missing {semantic}#attachedToRef', {
  4684. semantic: elementToString(boundarySemantic)
  4685. }));
  4686. }
  4687. var host = this._elementRegistry.get(hostSemantic.id),
  4688. attachers = host && host.attachers;
  4689. if (!host) {
  4690. throw notYetDrawn(translate, boundarySemantic, hostSemantic, 'attachedToRef');
  4691. }
  4692. // wire element.host <> host.attachers
  4693. boundaryElement.host = host;
  4694. if (!attachers) {
  4695. host.attachers = attachers = [];
  4696. }
  4697. if (attachers.indexOf(boundaryElement) === -1) {
  4698. attachers.push(boundaryElement);
  4699. }
  4700. };
  4701. /**
  4702. * add label for an element
  4703. */
  4704. BpmnImporter.prototype.addLabel = function(semantic, di, element) {
  4705. var bounds,
  4706. text,
  4707. label;
  4708. bounds = getExternalLabelBounds(di, element);
  4709. text = getLabel(element);
  4710. if (text) {
  4711. // get corrected bounds from actual layouted text
  4712. bounds = this._textRenderer.getExternalLabelBounds(bounds, text);
  4713. }
  4714. label = this._elementFactory.createLabel(elementData(semantic, di, {
  4715. id: semantic.id + '_label',
  4716. labelTarget: element,
  4717. type: 'label',
  4718. hidden: element.hidden || !getLabel(element),
  4719. x: Math.round(bounds.x),
  4720. y: Math.round(bounds.y),
  4721. width: Math.round(bounds.width),
  4722. height: Math.round(bounds.height)
  4723. }));
  4724. return this._canvas.addShape(label, element.parent);
  4725. };
  4726. /**
  4727. * Return the drawn connection end based on the given side.
  4728. *
  4729. * @throws {Error} if the end is not yet drawn
  4730. */
  4731. BpmnImporter.prototype._getEnd = function(semantic, side) {
  4732. var element,
  4733. refSemantic,
  4734. type = semantic.$type,
  4735. translate = this._translate;
  4736. refSemantic = semantic[side + 'Ref'];
  4737. // handle mysterious isMany DataAssociation#sourceRef
  4738. if (side === 'source' && type === 'bpmn:DataInputAssociation') {
  4739. refSemantic = refSemantic && refSemantic[0];
  4740. }
  4741. // fix source / target for DataInputAssociation / DataOutputAssociation
  4742. if (side === 'source' && type === 'bpmn:DataOutputAssociation' ||
  4743. side === 'target' && type === 'bpmn:DataInputAssociation') {
  4744. refSemantic = semantic.$parent;
  4745. }
  4746. element = refSemantic && this._getElement(refSemantic);
  4747. if (element) {
  4748. return element;
  4749. }
  4750. if (refSemantic) {
  4751. throw notYetDrawn(translate, semantic, refSemantic, side + 'Ref');
  4752. } else {
  4753. throw new Error(translate('{semantic}#{side} Ref not specified', {
  4754. semantic: elementToString(semantic),
  4755. side: side
  4756. }));
  4757. }
  4758. };
  4759. BpmnImporter.prototype._getSource = function(semantic) {
  4760. return this._getEnd(semantic, 'source');
  4761. };
  4762. BpmnImporter.prototype._getTarget = function(semantic) {
  4763. return this._getEnd(semantic, 'target');
  4764. };
  4765. BpmnImporter.prototype._getElement = function(semantic) {
  4766. return this._elementRegistry.get(semantic.id);
  4767. };
  4768. // helpers ////////////////////
  4769. function isPointInsideBBox(bbox, point) {
  4770. var x = point.x,
  4771. y = point.y;
  4772. return x >= bbox.x &&
  4773. x <= bbox.x + bbox.width &&
  4774. y >= bbox.y &&
  4775. y <= bbox.y + bbox.height;
  4776. }
  4777. function isFrameElement$1(semantic) {
  4778. return is$1(semantic, 'bpmn:Group');
  4779. }
  4780. var ImportModule = {
  4781. __depends__: [
  4782. TranslateModule
  4783. ],
  4784. bpmnImporter: [ 'type', BpmnImporter ]
  4785. };
  4786. var CoreModule$1 = {
  4787. __depends__: [
  4788. DrawModule$1,
  4789. ImportModule
  4790. ]
  4791. };
  4792. function getOriginal(event) {
  4793. return event.originalEvent || event.srcEvent;
  4794. }
  4795. function isMac() {
  4796. return (/mac/i).test(navigator.platform);
  4797. }
  4798. function isButton(event, button) {
  4799. return (getOriginal(event) || event).button === button;
  4800. }
  4801. function isPrimaryButton(event) {
  4802. // button === 0 -> left áka primary mouse button
  4803. return isButton(event, 0);
  4804. }
  4805. function isAuxiliaryButton(event) {
  4806. // button === 1 -> auxiliary áka wheel button
  4807. return isButton(event, 1);
  4808. }
  4809. function hasPrimaryModifier(event) {
  4810. var originalEvent = getOriginal(event) || event;
  4811. if (!isPrimaryButton(event)) {
  4812. return false;
  4813. }
  4814. // Use cmd as primary modifier key for mac OS
  4815. if (isMac()) {
  4816. return originalEvent.metaKey;
  4817. } else {
  4818. return originalEvent.ctrlKey;
  4819. }
  4820. }
  4821. function hasSecondaryModifier(event) {
  4822. var originalEvent = getOriginal(event) || event;
  4823. return isPrimaryButton(event) && originalEvent.shiftKey;
  4824. }
  4825. function allowAll(event) { return true; }
  4826. function allowPrimaryAndAuxiliary(event) {
  4827. return isPrimaryButton(event) || isAuxiliaryButton(event);
  4828. }
  4829. var LOW_PRIORITY$3 = 500;
  4830. /**
  4831. * A plugin that provides interaction events for diagram elements.
  4832. *
  4833. * It emits the following events:
  4834. *
  4835. * * element.click
  4836. * * element.contextmenu
  4837. * * element.dblclick
  4838. * * element.hover
  4839. * * element.mousedown
  4840. * * element.mousemove
  4841. * * element.mouseup
  4842. * * element.out
  4843. *
  4844. * Each event is a tuple { element, gfx, originalEvent }.
  4845. *
  4846. * Canceling the event via Event#preventDefault()
  4847. * prevents the original DOM operation.
  4848. *
  4849. * @param {EventBus} eventBus
  4850. */
  4851. function InteractionEvents(eventBus, elementRegistry, styles) {
  4852. var self = this;
  4853. /**
  4854. * Fire an interaction event.
  4855. *
  4856. * @param {string} type local event name, e.g. element.click.
  4857. * @param {DOMEvent} event native event
  4858. * @param {djs.model.Base} [element] the diagram element to emit the event on;
  4859. * defaults to the event target
  4860. */
  4861. function fire(type, event, element) {
  4862. if (isIgnored(type, event)) {
  4863. return;
  4864. }
  4865. var target, gfx, returnValue;
  4866. if (!element) {
  4867. target = event.delegateTarget || event.target;
  4868. if (target) {
  4869. gfx = target;
  4870. element = elementRegistry.get(gfx);
  4871. }
  4872. } else {
  4873. gfx = elementRegistry.getGraphics(element);
  4874. }
  4875. if (!gfx || !element) {
  4876. return;
  4877. }
  4878. returnValue = eventBus.fire(type, {
  4879. element: element,
  4880. gfx: gfx,
  4881. originalEvent: event
  4882. });
  4883. if (returnValue === false) {
  4884. event.stopPropagation();
  4885. event.preventDefault();
  4886. }
  4887. }
  4888. // TODO(nikku): document this
  4889. var handlers = {};
  4890. function mouseHandler(localEventName) {
  4891. return handlers[localEventName];
  4892. }
  4893. function isIgnored(localEventName, event) {
  4894. var filter = ignoredFilters[localEventName] || isPrimaryButton;
  4895. // only react on left mouse button interactions
  4896. // except for interaction events that are enabled
  4897. // for secundary mouse button
  4898. return !filter(event);
  4899. }
  4900. var bindings = {
  4901. click: 'element.click',
  4902. contextmenu: 'element.contextmenu',
  4903. dblclick: 'element.dblclick',
  4904. mousedown: 'element.mousedown',
  4905. mousemove: 'element.mousemove',
  4906. mouseover: 'element.hover',
  4907. mouseout: 'element.out',
  4908. mouseup: 'element.mouseup',
  4909. };
  4910. var ignoredFilters = {
  4911. 'element.contextmenu': allowAll,
  4912. 'element.mousedown': allowPrimaryAndAuxiliary,
  4913. 'element.mouseup': allowPrimaryAndAuxiliary,
  4914. 'element.click': allowPrimaryAndAuxiliary,
  4915. 'element.dblclick': allowPrimaryAndAuxiliary
  4916. };
  4917. // manual event trigger //////////
  4918. /**
  4919. * Trigger an interaction event (based on a native dom event)
  4920. * on the target shape or connection.
  4921. *
  4922. * @param {string} eventName the name of the triggered DOM event
  4923. * @param {MouseEvent} event
  4924. * @param {djs.model.Base} targetElement
  4925. */
  4926. function triggerMouseEvent(eventName, event, targetElement) {
  4927. // i.e. element.mousedown...
  4928. var localEventName = bindings[eventName];
  4929. if (!localEventName) {
  4930. throw new Error('unmapped DOM event name <' + eventName + '>');
  4931. }
  4932. return fire(localEventName, event, targetElement);
  4933. }
  4934. var ELEMENT_SELECTOR = 'svg, .djs-element';
  4935. // event handling ///////
  4936. function registerEvent(node, event, localEvent, ignoredFilter) {
  4937. var handler = handlers[localEvent] = function(event) {
  4938. fire(localEvent, event);
  4939. };
  4940. if (ignoredFilter) {
  4941. ignoredFilters[localEvent] = ignoredFilter;
  4942. }
  4943. handler.$delegate = delegate.bind(node, ELEMENT_SELECTOR, event, handler);
  4944. }
  4945. function unregisterEvent(node, event, localEvent) {
  4946. var handler = mouseHandler(localEvent);
  4947. if (!handler) {
  4948. return;
  4949. }
  4950. delegate.unbind(node, event, handler.$delegate);
  4951. }
  4952. function registerEvents(svg) {
  4953. forEach$1(bindings, function(val, key) {
  4954. registerEvent(svg, key, val);
  4955. });
  4956. }
  4957. function unregisterEvents(svg) {
  4958. forEach$1(bindings, function(val, key) {
  4959. unregisterEvent(svg, key, val);
  4960. });
  4961. }
  4962. eventBus.on('canvas.destroy', function(event) {
  4963. unregisterEvents(event.svg);
  4964. });
  4965. eventBus.on('canvas.init', function(event) {
  4966. registerEvents(event.svg);
  4967. });
  4968. // hit box updating ////////////////
  4969. eventBus.on([ 'shape.added', 'connection.added' ], function(event) {
  4970. var element = event.element,
  4971. gfx = event.gfx;
  4972. eventBus.fire('interactionEvents.createHit', { element: element, gfx: gfx });
  4973. });
  4974. // Update djs-hit on change.
  4975. // A low priortity is necessary, because djs-hit of labels has to be updated
  4976. // after the label bounds have been updated in the renderer.
  4977. eventBus.on([
  4978. 'shape.changed',
  4979. 'connection.changed'
  4980. ], LOW_PRIORITY$3, function(event) {
  4981. var element = event.element,
  4982. gfx = event.gfx;
  4983. eventBus.fire('interactionEvents.updateHit', { element: element, gfx: gfx });
  4984. });
  4985. eventBus.on('interactionEvents.createHit', LOW_PRIORITY$3, function(event) {
  4986. var element = event.element,
  4987. gfx = event.gfx;
  4988. self.createDefaultHit(element, gfx);
  4989. });
  4990. eventBus.on('interactionEvents.updateHit', function(event) {
  4991. var element = event.element,
  4992. gfx = event.gfx;
  4993. self.updateDefaultHit(element, gfx);
  4994. });
  4995. // hit styles ////////////
  4996. var STROKE_HIT_STYLE = createHitStyle('djs-hit djs-hit-stroke');
  4997. var CLICK_STROKE_HIT_STYLE = createHitStyle('djs-hit djs-hit-click-stroke');
  4998. var ALL_HIT_STYLE = createHitStyle('djs-hit djs-hit-all');
  4999. var NO_MOVE_HIT_STYLE = createHitStyle('djs-hit djs-hit-no-move');
  5000. var HIT_TYPES = {
  5001. 'all': ALL_HIT_STYLE,
  5002. 'click-stroke': CLICK_STROKE_HIT_STYLE,
  5003. 'stroke': STROKE_HIT_STYLE,
  5004. 'no-move': NO_MOVE_HIT_STYLE
  5005. };
  5006. function createHitStyle(classNames, attrs) {
  5007. attrs = assign({
  5008. stroke: 'white',
  5009. strokeWidth: 15
  5010. }, attrs || {});
  5011. return styles.cls(classNames, [ 'no-fill', 'no-border' ], attrs);
  5012. }
  5013. // style helpers ///////////////
  5014. function applyStyle(hit, type) {
  5015. var attrs = HIT_TYPES[type];
  5016. if (!attrs) {
  5017. throw new Error('invalid hit type <' + type + '>');
  5018. }
  5019. attr$1(hit, attrs);
  5020. return hit;
  5021. }
  5022. function appendHit(gfx, hit) {
  5023. append(gfx, hit);
  5024. }
  5025. // API
  5026. /**
  5027. * Remove hints on the given graphics.
  5028. *
  5029. * @param {SVGElement} gfx
  5030. */
  5031. this.removeHits = function(gfx) {
  5032. var hits = all('.djs-hit', gfx);
  5033. forEach$1(hits, remove$2);
  5034. };
  5035. /**
  5036. * Create default hit for the given element.
  5037. *
  5038. * @param {djs.model.Base} element
  5039. * @param {SVGElement} gfx
  5040. *
  5041. * @return {SVGElement} created hit
  5042. */
  5043. this.createDefaultHit = function(element, gfx) {
  5044. var waypoints = element.waypoints,
  5045. isFrame = element.isFrame,
  5046. boxType;
  5047. if (waypoints) {
  5048. return this.createWaypointsHit(gfx, waypoints);
  5049. } else {
  5050. boxType = isFrame ? 'stroke' : 'all';
  5051. return this.createBoxHit(gfx, boxType, {
  5052. width: element.width,
  5053. height: element.height
  5054. });
  5055. }
  5056. };
  5057. /**
  5058. * Create hits for the given waypoints.
  5059. *
  5060. * @param {SVGElement} gfx
  5061. * @param {Array<Point>} waypoints
  5062. *
  5063. * @return {SVGElement}
  5064. */
  5065. this.createWaypointsHit = function(gfx, waypoints) {
  5066. var hit = createLine(waypoints);
  5067. applyStyle(hit, 'stroke');
  5068. appendHit(gfx, hit);
  5069. return hit;
  5070. };
  5071. /**
  5072. * Create hits for a box.
  5073. *
  5074. * @param {SVGElement} gfx
  5075. * @param {string} hitType
  5076. * @param {Object} attrs
  5077. *
  5078. * @return {SVGElement}
  5079. */
  5080. this.createBoxHit = function(gfx, type, attrs) {
  5081. attrs = assign({
  5082. x: 0,
  5083. y: 0
  5084. }, attrs);
  5085. var hit = create$1('rect');
  5086. applyStyle(hit, type);
  5087. attr$1(hit, attrs);
  5088. appendHit(gfx, hit);
  5089. return hit;
  5090. };
  5091. /**
  5092. * Update default hit of the element.
  5093. *
  5094. * @param {djs.model.Base} element
  5095. * @param {SVGElement} gfx
  5096. *
  5097. * @return {SVGElement} updated hit
  5098. */
  5099. this.updateDefaultHit = function(element, gfx) {
  5100. var hit = query('.djs-hit', gfx);
  5101. if (!hit) {
  5102. return;
  5103. }
  5104. if (element.waypoints) {
  5105. updateLine(hit, element.waypoints);
  5106. } else {
  5107. attr$1(hit, {
  5108. width: element.width,
  5109. height: element.height
  5110. });
  5111. }
  5112. return hit;
  5113. };
  5114. this.fire = fire;
  5115. this.triggerMouseEvent = triggerMouseEvent;
  5116. this.mouseHandler = mouseHandler;
  5117. this.registerEvent = registerEvent;
  5118. this.unregisterEvent = unregisterEvent;
  5119. }
  5120. InteractionEvents.$inject = [
  5121. 'eventBus',
  5122. 'elementRegistry',
  5123. 'styles'
  5124. ];
  5125. /**
  5126. * An event indicating that the mouse hovered over an element
  5127. *
  5128. * @event element.hover
  5129. *
  5130. * @type {Object}
  5131. * @property {djs.model.Base} element
  5132. * @property {SVGElement} gfx
  5133. * @property {Event} originalEvent
  5134. */
  5135. /**
  5136. * An event indicating that the mouse has left an element
  5137. *
  5138. * @event element.out
  5139. *
  5140. * @type {Object}
  5141. * @property {djs.model.Base} element
  5142. * @property {SVGElement} gfx
  5143. * @property {Event} originalEvent
  5144. */
  5145. /**
  5146. * An event indicating that the mouse has clicked an element
  5147. *
  5148. * @event element.click
  5149. *
  5150. * @type {Object}
  5151. * @property {djs.model.Base} element
  5152. * @property {SVGElement} gfx
  5153. * @property {Event} originalEvent
  5154. */
  5155. /**
  5156. * An event indicating that the mouse has double clicked an element
  5157. *
  5158. * @event element.dblclick
  5159. *
  5160. * @type {Object}
  5161. * @property {djs.model.Base} element
  5162. * @property {SVGElement} gfx
  5163. * @property {Event} originalEvent
  5164. */
  5165. /**
  5166. * An event indicating that the mouse has gone down on an element.
  5167. *
  5168. * @event element.mousedown
  5169. *
  5170. * @type {Object}
  5171. * @property {djs.model.Base} element
  5172. * @property {SVGElement} gfx
  5173. * @property {Event} originalEvent
  5174. */
  5175. /**
  5176. * An event indicating that the mouse has gone up on an element.
  5177. *
  5178. * @event element.mouseup
  5179. *
  5180. * @type {Object}
  5181. * @property {djs.model.Base} element
  5182. * @property {SVGElement} gfx
  5183. * @property {Event} originalEvent
  5184. */
  5185. /**
  5186. * An event indicating that the context menu action is triggered
  5187. * via mouse or touch controls.
  5188. *
  5189. * @event element.contextmenu
  5190. *
  5191. * @type {Object}
  5192. * @property {djs.model.Base} element
  5193. * @property {SVGElement} gfx
  5194. * @property {Event} originalEvent
  5195. */
  5196. var InteractionEventsModule = {
  5197. __init__: [ 'interactionEvents' ],
  5198. interactionEvents: [ 'type', InteractionEvents ]
  5199. };
  5200. /**
  5201. * Returns the surrounding bbox for all elements in
  5202. * the array or the element primitive.
  5203. *
  5204. * @param {Array<djs.model.Shape>|djs.model.Shape} elements
  5205. * @param {boolean} [stopRecursion=false]
  5206. *
  5207. * @return {Bounds}
  5208. */
  5209. function getBBox(elements, stopRecursion) {
  5210. stopRecursion = !!stopRecursion;
  5211. if (!isArray$2(elements)) {
  5212. elements = [ elements ];
  5213. }
  5214. var minX,
  5215. minY,
  5216. maxX,
  5217. maxY;
  5218. forEach$1(elements, function(element) {
  5219. // If element is a connection the bbox must be computed first
  5220. var bbox = element;
  5221. if (element.waypoints && !stopRecursion) {
  5222. bbox = getBBox(element.waypoints, true);
  5223. }
  5224. var x = bbox.x,
  5225. y = bbox.y,
  5226. height = bbox.height || 0,
  5227. width = bbox.width || 0;
  5228. if (x < minX || minX === undefined) {
  5229. minX = x;
  5230. }
  5231. if (y < minY || minY === undefined) {
  5232. minY = y;
  5233. }
  5234. if ((x + width) > maxX || maxX === undefined) {
  5235. maxX = x + width;
  5236. }
  5237. if ((y + height) > maxY || maxY === undefined) {
  5238. maxY = y + height;
  5239. }
  5240. });
  5241. return {
  5242. x: minX,
  5243. y: minY,
  5244. height: maxY - minY,
  5245. width: maxX - minX
  5246. };
  5247. }
  5248. function getType(element) {
  5249. if ('waypoints' in element) {
  5250. return 'connection';
  5251. }
  5252. if ('x' in element) {
  5253. return 'shape';
  5254. }
  5255. return 'root';
  5256. }
  5257. function isFrameElement(element) {
  5258. return !!(element && element.isFrame);
  5259. }
  5260. var LOW_PRIORITY$2 = 500;
  5261. /**
  5262. * @class
  5263. *
  5264. * A plugin that adds an outline to shapes and connections that may be activated and styled
  5265. * via CSS classes.
  5266. *
  5267. * @param {EventBus} eventBus
  5268. * @param {Styles} styles
  5269. * @param {ElementRegistry} elementRegistry
  5270. */
  5271. function Outline(eventBus, styles, elementRegistry) {
  5272. this.offset = 6;
  5273. var OUTLINE_STYLE = styles.cls('djs-outline', [ 'no-fill' ]);
  5274. var self = this;
  5275. function createOutline(gfx, bounds) {
  5276. var outline = create$1('rect');
  5277. attr$1(outline, assign({
  5278. x: 10,
  5279. y: 10,
  5280. rx: 3,
  5281. width: 100,
  5282. height: 100
  5283. }, OUTLINE_STYLE));
  5284. append(gfx, outline);
  5285. return outline;
  5286. }
  5287. // A low priortity is necessary, because outlines of labels have to be updated
  5288. // after the label bounds have been updated in the renderer.
  5289. eventBus.on([ 'shape.added', 'shape.changed' ], LOW_PRIORITY$2, function(event) {
  5290. var element = event.element,
  5291. gfx = event.gfx;
  5292. var outline = query('.djs-outline', gfx);
  5293. if (!outline) {
  5294. outline = createOutline(gfx);
  5295. }
  5296. self.updateShapeOutline(outline, element);
  5297. });
  5298. eventBus.on([ 'connection.added', 'connection.changed' ], function(event) {
  5299. var element = event.element,
  5300. gfx = event.gfx;
  5301. var outline = query('.djs-outline', gfx);
  5302. if (!outline) {
  5303. outline = createOutline(gfx);
  5304. }
  5305. self.updateConnectionOutline(outline, element);
  5306. });
  5307. }
  5308. /**
  5309. * Updates the outline of a shape respecting the dimension of the
  5310. * element and an outline offset.
  5311. *
  5312. * @param {SVGElement} outline
  5313. * @param {djs.model.Base} element
  5314. */
  5315. Outline.prototype.updateShapeOutline = function(outline, element) {
  5316. attr$1(outline, {
  5317. x: -this.offset,
  5318. y: -this.offset,
  5319. width: element.width + this.offset * 2,
  5320. height: element.height + this.offset * 2
  5321. });
  5322. };
  5323. /**
  5324. * Updates the outline of a connection respecting the bounding box of
  5325. * the connection and an outline offset.
  5326. *
  5327. * @param {SVGElement} outline
  5328. * @param {djs.model.Base} element
  5329. */
  5330. Outline.prototype.updateConnectionOutline = function(outline, connection) {
  5331. var bbox = getBBox(connection);
  5332. attr$1(outline, {
  5333. x: bbox.x - this.offset,
  5334. y: bbox.y - this.offset,
  5335. width: bbox.width + this.offset * 2,
  5336. height: bbox.height + this.offset * 2
  5337. });
  5338. };
  5339. Outline.$inject = [ 'eventBus', 'styles', 'elementRegistry' ];
  5340. var OutlineModule = {
  5341. __init__: [ 'outline' ],
  5342. outline: [ 'type', Outline ]
  5343. };
  5344. /**
  5345. * A service that offers the current selection in a diagram.
  5346. * Offers the api to control the selection, too.
  5347. *
  5348. * @class
  5349. *
  5350. * @param {EventBus} eventBus the event bus
  5351. */
  5352. function Selection(eventBus, canvas) {
  5353. this._eventBus = eventBus;
  5354. this._canvas = canvas;
  5355. this._selectedElements = [];
  5356. var self = this;
  5357. eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
  5358. var element = e.element;
  5359. self.deselect(element);
  5360. });
  5361. eventBus.on([ 'diagram.clear', 'root.set' ], function(e) {
  5362. self.select(null);
  5363. });
  5364. }
  5365. Selection.$inject = [ 'eventBus', 'canvas' ];
  5366. Selection.prototype.deselect = function(element) {
  5367. var selectedElements = this._selectedElements;
  5368. var idx = selectedElements.indexOf(element);
  5369. if (idx !== -1) {
  5370. var oldSelection = selectedElements.slice();
  5371. selectedElements.splice(idx, 1);
  5372. this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
  5373. }
  5374. };
  5375. Selection.prototype.get = function() {
  5376. return this._selectedElements;
  5377. };
  5378. Selection.prototype.isSelected = function(element) {
  5379. return this._selectedElements.indexOf(element) !== -1;
  5380. };
  5381. /**
  5382. * This method selects one or more elements on the diagram.
  5383. *
  5384. * By passing an additional add parameter you can decide whether or not the element(s)
  5385. * should be added to the already existing selection or not.
  5386. *
  5387. * @method Selection#select
  5388. *
  5389. * @param {Object|Object[]} elements element or array of elements to be selected
  5390. * @param {boolean} [add] whether the element(s) should be appended to the current selection, defaults to false
  5391. */
  5392. Selection.prototype.select = function(elements, add) {
  5393. var selectedElements = this._selectedElements,
  5394. oldSelection = selectedElements.slice();
  5395. if (!isArray$2(elements)) {
  5396. elements = elements ? [ elements ] : [];
  5397. }
  5398. var canvas = this._canvas;
  5399. var rootElement = canvas.getRootElement();
  5400. elements = elements.filter(function(element) {
  5401. var elementRoot = canvas.findRoot(element);
  5402. return rootElement === elementRoot;
  5403. });
  5404. // selection may be cleared by passing an empty array or null
  5405. // to the method
  5406. if (add) {
  5407. forEach$1(elements, function(element) {
  5408. if (selectedElements.indexOf(element) !== -1) {
  5409. // already selected
  5410. return;
  5411. } else {
  5412. selectedElements.push(element);
  5413. }
  5414. });
  5415. } else {
  5416. this._selectedElements = selectedElements = elements.slice();
  5417. }
  5418. this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
  5419. };
  5420. var MARKER_HOVER = 'hover',
  5421. MARKER_SELECTED = 'selected';
  5422. var SELECTION_OUTLINE_PADDING = 6;
  5423. /**
  5424. * A plugin that adds a visible selection UI to shapes and connections
  5425. * by appending the <code>hover</code> and <code>selected</code> classes to them.
  5426. *
  5427. * @class
  5428. *
  5429. * Makes elements selectable, too.
  5430. *
  5431. * @param {Canvas} canvas
  5432. * @param {EventBus} eventBus
  5433. */
  5434. function SelectionVisuals(canvas, eventBus, selection) {
  5435. this._canvas = canvas;
  5436. var self = this;
  5437. this._multiSelectionBox = null;
  5438. function addMarker(e, cls) {
  5439. canvas.addMarker(e, cls);
  5440. }
  5441. function removeMarker(e, cls) {
  5442. canvas.removeMarker(e, cls);
  5443. }
  5444. eventBus.on('element.hover', function(event) {
  5445. addMarker(event.element, MARKER_HOVER);
  5446. });
  5447. eventBus.on('element.out', function(event) {
  5448. removeMarker(event.element, MARKER_HOVER);
  5449. });
  5450. eventBus.on('selection.changed', function(event) {
  5451. function deselect(s) {
  5452. removeMarker(s, MARKER_SELECTED);
  5453. }
  5454. function select(s) {
  5455. addMarker(s, MARKER_SELECTED);
  5456. }
  5457. var oldSelection = event.oldSelection,
  5458. newSelection = event.newSelection;
  5459. forEach$1(oldSelection, function(e) {
  5460. if (newSelection.indexOf(e) === -1) {
  5461. deselect(e);
  5462. }
  5463. });
  5464. forEach$1(newSelection, function(e) {
  5465. if (oldSelection.indexOf(e) === -1) {
  5466. select(e);
  5467. }
  5468. });
  5469. self._updateSelectionOutline(newSelection);
  5470. });
  5471. eventBus.on('element.changed', function(event) {
  5472. if (selection.isSelected(event.element)) {
  5473. self._updateSelectionOutline(selection.get());
  5474. }
  5475. });
  5476. }
  5477. SelectionVisuals.$inject = [
  5478. 'canvas',
  5479. 'eventBus',
  5480. 'selection'
  5481. ];
  5482. SelectionVisuals.prototype._updateSelectionOutline = function(selection) {
  5483. var layer = this._canvas.getLayer('selectionOutline');
  5484. clear$1(layer);
  5485. var enabled = selection.length > 1;
  5486. var container = this._canvas.getContainer();
  5487. classes$1(container)[enabled ? 'add' : 'remove']('djs-multi-select');
  5488. if (!enabled) {
  5489. return;
  5490. }
  5491. var bBox = addSelectionOutlinePadding(getBBox(selection));
  5492. var rect = create$1('rect');
  5493. attr$1(rect, assign({
  5494. rx: 3
  5495. }, bBox));
  5496. classes$1(rect).add('djs-selection-outline');
  5497. append(layer, rect);
  5498. };
  5499. // helpers //////////
  5500. function addSelectionOutlinePadding(bBox) {
  5501. return {
  5502. x: bBox.x - SELECTION_OUTLINE_PADDING,
  5503. y: bBox.y - SELECTION_OUTLINE_PADDING,
  5504. width: bBox.width + SELECTION_OUTLINE_PADDING * 2,
  5505. height: bBox.height + SELECTION_OUTLINE_PADDING * 2
  5506. };
  5507. }
  5508. function SelectionBehavior(eventBus, selection, canvas, elementRegistry) {
  5509. // Select elements on create
  5510. eventBus.on('create.end', 500, function(event) {
  5511. var context = event.context,
  5512. canExecute = context.canExecute,
  5513. elements = context.elements,
  5514. hints = context.hints || {},
  5515. autoSelect = hints.autoSelect;
  5516. if (canExecute) {
  5517. if (autoSelect === false) {
  5518. // Select no elements
  5519. return;
  5520. }
  5521. if (isArray$2(autoSelect)) {
  5522. selection.select(autoSelect);
  5523. } else {
  5524. // Select all elements by default
  5525. selection.select(elements.filter(isShown));
  5526. }
  5527. }
  5528. });
  5529. // Select connection targets on connect
  5530. eventBus.on('connect.end', 500, function(event) {
  5531. var context = event.context,
  5532. connection = context.connection;
  5533. if (connection) {
  5534. selection.select(connection);
  5535. }
  5536. });
  5537. // Select shapes on move
  5538. eventBus.on('shape.move.end', 500, function(event) {
  5539. var previousSelection = event.previousSelection || [];
  5540. var shape = elementRegistry.get(event.context.shape.id);
  5541. // Always select main shape on move
  5542. var isSelected = find(previousSelection, function(selectedShape) {
  5543. return shape.id === selectedShape.id;
  5544. });
  5545. if (!isSelected) {
  5546. selection.select(shape);
  5547. }
  5548. });
  5549. // Select elements on click
  5550. eventBus.on('element.click', function(event) {
  5551. if (!isPrimaryButton(event)) {
  5552. return;
  5553. }
  5554. var element = event.element;
  5555. if (element === canvas.getRootElement()) {
  5556. element = null;
  5557. }
  5558. var isSelected = selection.isSelected(element),
  5559. isMultiSelect = selection.get().length > 1;
  5560. // Add to selection if CTRL or SHIFT pressed
  5561. var add = hasPrimaryModifier(event) || hasSecondaryModifier(event);
  5562. if (isSelected && isMultiSelect) {
  5563. if (add) {
  5564. // Deselect element
  5565. return selection.deselect(element);
  5566. } else {
  5567. // Select element only
  5568. return selection.select(element);
  5569. }
  5570. } else if (!isSelected) {
  5571. // Select element
  5572. selection.select(element, add);
  5573. } else {
  5574. // Deselect element
  5575. selection.deselect(element);
  5576. }
  5577. });
  5578. }
  5579. SelectionBehavior.$inject = [
  5580. 'eventBus',
  5581. 'selection',
  5582. 'canvas',
  5583. 'elementRegistry'
  5584. ];
  5585. function isShown(element) {
  5586. return !element.hidden;
  5587. }
  5588. var SelectionModule = {
  5589. __init__: [ 'selectionVisuals', 'selectionBehavior' ],
  5590. __depends__: [
  5591. InteractionEventsModule,
  5592. OutlineModule
  5593. ],
  5594. selection: [ 'type', Selection ],
  5595. selectionVisuals: [ 'type', SelectionVisuals ],
  5596. selectionBehavior: [ 'type', SelectionBehavior ]
  5597. };
  5598. /**
  5599. * Util that provides unique IDs.
  5600. *
  5601. * @class djs.util.IdGenerator
  5602. * @constructor
  5603. * @memberOf djs.util
  5604. *
  5605. * The ids can be customized via a given prefix and contain a random value to avoid collisions.
  5606. *
  5607. * @param {string} prefix a prefix to prepend to generated ids (for better readability)
  5608. */
  5609. function IdGenerator(prefix) {
  5610. this._counter = 0;
  5611. this._prefix = (prefix ? prefix + '-' : '') + Math.floor(Math.random() * 1000000000) + '-';
  5612. }
  5613. /**
  5614. * Returns a next unique ID.
  5615. *
  5616. * @method djs.util.IdGenerator#next
  5617. *
  5618. * @returns {string} the id
  5619. */
  5620. IdGenerator.prototype.next = function() {
  5621. return this._prefix + (++this._counter);
  5622. };
  5623. // document wide unique overlay ids
  5624. var ids = new IdGenerator('ov');
  5625. var LOW_PRIORITY$1 = 500;
  5626. /**
  5627. * A service that allows users to attach overlays to diagram elements.
  5628. *
  5629. * The overlay service will take care of overlay positioning during updates.
  5630. *
  5631. * @example
  5632. *
  5633. * // add a pink badge on the top left of the shape
  5634. * overlays.add(someShape, {
  5635. * position: {
  5636. * top: -5,
  5637. * left: -5
  5638. * },
  5639. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  5640. * });
  5641. *
  5642. * // or add via shape id
  5643. *
  5644. * overlays.add('some-element-id', {
  5645. * position: {
  5646. * top: -5,
  5647. * left: -5
  5648. * }
  5649. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  5650. * });
  5651. *
  5652. * // or add with optional type
  5653. *
  5654. * overlays.add(someShape, 'badge', {
  5655. * position: {
  5656. * top: -5,
  5657. * left: -5
  5658. * }
  5659. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  5660. * });
  5661. *
  5662. *
  5663. * // remove an overlay
  5664. *
  5665. * var id = overlays.add(...);
  5666. * overlays.remove(id);
  5667. *
  5668. *
  5669. * You may configure overlay defaults during tool by providing a `config` module
  5670. * with `overlays.defaults` as an entry:
  5671. *
  5672. * {
  5673. * overlays: {
  5674. * defaults: {
  5675. * show: {
  5676. * minZoom: 0.7,
  5677. * maxZoom: 5.0
  5678. * },
  5679. * scale: {
  5680. * min: 1
  5681. * }
  5682. * }
  5683. * }
  5684. *
  5685. * @param {Object} config
  5686. * @param {EventBus} eventBus
  5687. * @param {Canvas} canvas
  5688. * @param {ElementRegistry} elementRegistry
  5689. */
  5690. function Overlays(config, eventBus, canvas, elementRegistry) {
  5691. this._eventBus = eventBus;
  5692. this._canvas = canvas;
  5693. this._elementRegistry = elementRegistry;
  5694. this._ids = ids;
  5695. this._overlayDefaults = assign({
  5696. // no show constraints
  5697. show: null,
  5698. // always scale
  5699. scale: true
  5700. }, config && config.defaults);
  5701. /**
  5702. * Mapping overlayId -> overlay
  5703. */
  5704. this._overlays = {};
  5705. /**
  5706. * Mapping elementId -> overlay container
  5707. */
  5708. this._overlayContainers = [];
  5709. // root html element for all overlays
  5710. this._overlayRoot = createRoot(canvas.getContainer());
  5711. this._init();
  5712. }
  5713. Overlays.$inject = [
  5714. 'config.overlays',
  5715. 'eventBus',
  5716. 'canvas',
  5717. 'elementRegistry'
  5718. ];
  5719. /**
  5720. * Returns the overlay with the specified id or a list of overlays
  5721. * for an element with a given type.
  5722. *
  5723. * @example
  5724. *
  5725. * // return the single overlay with the given id
  5726. * overlays.get('some-id');
  5727. *
  5728. * // return all overlays for the shape
  5729. * overlays.get({ element: someShape });
  5730. *
  5731. * // return all overlays on shape with type 'badge'
  5732. * overlays.get({ element: someShape, type: 'badge' });
  5733. *
  5734. * // shape can also be specified as id
  5735. * overlays.get({ element: 'element-id', type: 'badge' });
  5736. *
  5737. *
  5738. * @param {Object} search
  5739. * @param {string} [search.id]
  5740. * @param {string|djs.model.Base} [search.element]
  5741. * @param {string} [search.type]
  5742. *
  5743. * @return {Object|Array<Object>} the overlay(s)
  5744. */
  5745. Overlays.prototype.get = function(search) {
  5746. if (isString(search)) {
  5747. search = { id: search };
  5748. }
  5749. if (isString(search.element)) {
  5750. search.element = this._elementRegistry.get(search.element);
  5751. }
  5752. if (search.element) {
  5753. var container = this._getOverlayContainer(search.element, true);
  5754. // return a list of overlays when searching by element (+type)
  5755. if (container) {
  5756. return search.type ? filter(container.overlays, matchPattern({ type: search.type })) : container.overlays.slice();
  5757. } else {
  5758. return [];
  5759. }
  5760. } else
  5761. if (search.type) {
  5762. return filter(this._overlays, matchPattern({ type: search.type }));
  5763. } else {
  5764. // return single element when searching by id
  5765. return search.id ? this._overlays[search.id] : null;
  5766. }
  5767. };
  5768. /**
  5769. * Adds a HTML overlay to an element.
  5770. *
  5771. * @param {string|djs.model.Base} element attach overlay to this shape
  5772. * @param {string} [type] optional type to assign to the overlay
  5773. * @param {Object} overlay the overlay configuration
  5774. *
  5775. * @param {string|DOMElement} overlay.html html element to use as an overlay
  5776. * @param {Object} [overlay.show] show configuration
  5777. * @param {number} [overlay.show.minZoom] minimal zoom level to show the overlay
  5778. * @param {number} [overlay.show.maxZoom] maximum zoom level to show the overlay
  5779. * @param {Object} overlay.position where to attach the overlay
  5780. * @param {number} [overlay.position.left] relative to element bbox left attachment
  5781. * @param {number} [overlay.position.top] relative to element bbox top attachment
  5782. * @param {number} [overlay.position.bottom] relative to element bbox bottom attachment
  5783. * @param {number} [overlay.position.right] relative to element bbox right attachment
  5784. * @param {boolean|Object} [overlay.scale=true] false to preserve the same size regardless of
  5785. * diagram zoom
  5786. * @param {number} [overlay.scale.min]
  5787. * @param {number} [overlay.scale.max]
  5788. *
  5789. * @return {string} id that may be used to reference the overlay for update or removal
  5790. */
  5791. Overlays.prototype.add = function(element, type, overlay) {
  5792. if (isObject(type)) {
  5793. overlay = type;
  5794. type = null;
  5795. }
  5796. if (!element.id) {
  5797. element = this._elementRegistry.get(element);
  5798. }
  5799. if (!overlay.position) {
  5800. throw new Error('must specifiy overlay position');
  5801. }
  5802. if (!overlay.html) {
  5803. throw new Error('must specifiy overlay html');
  5804. }
  5805. if (!element) {
  5806. throw new Error('invalid element specified');
  5807. }
  5808. var id = this._ids.next();
  5809. overlay = assign({}, this._overlayDefaults, overlay, {
  5810. id: id,
  5811. type: type,
  5812. element: element,
  5813. html: overlay.html
  5814. });
  5815. this._addOverlay(overlay);
  5816. return id;
  5817. };
  5818. /**
  5819. * Remove an overlay with the given id or all overlays matching the given filter.
  5820. *
  5821. * @see Overlays#get for filter options.
  5822. *
  5823. * @param {string|object} [filter]
  5824. */
  5825. Overlays.prototype.remove = function(filter) {
  5826. var overlays = this.get(filter) || [];
  5827. if (!isArray$2(overlays)) {
  5828. overlays = [ overlays ];
  5829. }
  5830. var self = this;
  5831. forEach$1(overlays, function(overlay) {
  5832. var container = self._getOverlayContainer(overlay.element, true);
  5833. if (overlay) {
  5834. remove$1(overlay.html);
  5835. remove$1(overlay.htmlContainer);
  5836. delete overlay.htmlContainer;
  5837. delete overlay.element;
  5838. delete self._overlays[overlay.id];
  5839. }
  5840. if (container) {
  5841. var idx = container.overlays.indexOf(overlay);
  5842. if (idx !== -1) {
  5843. container.overlays.splice(idx, 1);
  5844. }
  5845. }
  5846. });
  5847. };
  5848. Overlays.prototype.show = function() {
  5849. setVisible(this._overlayRoot);
  5850. };
  5851. Overlays.prototype.hide = function() {
  5852. setVisible(this._overlayRoot, false);
  5853. };
  5854. Overlays.prototype.clear = function() {
  5855. this._overlays = {};
  5856. this._overlayContainers = [];
  5857. clear(this._overlayRoot);
  5858. };
  5859. Overlays.prototype._updateOverlayContainer = function(container) {
  5860. var element = container.element,
  5861. html = container.html;
  5862. // update container left,top according to the elements x,y coordinates
  5863. // this ensures we can attach child elements relative to this container
  5864. var x = element.x,
  5865. y = element.y;
  5866. if (element.waypoints) {
  5867. var bbox = getBBox(element);
  5868. x = bbox.x;
  5869. y = bbox.y;
  5870. }
  5871. setPosition(html, x, y);
  5872. attr(container.html, 'data-container-id', element.id);
  5873. };
  5874. Overlays.prototype._updateOverlay = function(overlay) {
  5875. var position = overlay.position,
  5876. htmlContainer = overlay.htmlContainer,
  5877. element = overlay.element;
  5878. // update overlay html relative to shape because
  5879. // it is already positioned on the element
  5880. // update relative
  5881. var left = position.left,
  5882. top = position.top;
  5883. if (position.right !== undefined) {
  5884. var width;
  5885. if (element.waypoints) {
  5886. width = getBBox(element).width;
  5887. } else {
  5888. width = element.width;
  5889. }
  5890. left = position.right * -1 + width;
  5891. }
  5892. if (position.bottom !== undefined) {
  5893. var height;
  5894. if (element.waypoints) {
  5895. height = getBBox(element).height;
  5896. } else {
  5897. height = element.height;
  5898. }
  5899. top = position.bottom * -1 + height;
  5900. }
  5901. setPosition(htmlContainer, left || 0, top || 0);
  5902. this._updateOverlayVisibilty(overlay, this._canvas.viewbox());
  5903. };
  5904. Overlays.prototype._createOverlayContainer = function(element) {
  5905. var html = domify('<div class="djs-overlays" />');
  5906. assign$1(html, { position: 'absolute' });
  5907. this._overlayRoot.appendChild(html);
  5908. var container = {
  5909. html: html,
  5910. element: element,
  5911. overlays: []
  5912. };
  5913. this._updateOverlayContainer(container);
  5914. this._overlayContainers.push(container);
  5915. return container;
  5916. };
  5917. Overlays.prototype._updateRoot = function(viewbox) {
  5918. var scale = viewbox.scale || 1;
  5919. var matrix = 'matrix(' +
  5920. [
  5921. scale,
  5922. 0,
  5923. 0,
  5924. scale,
  5925. -1 * viewbox.x * scale,
  5926. -1 * viewbox.y * scale
  5927. ].join(',') +
  5928. ')';
  5929. setTransform(this._overlayRoot, matrix);
  5930. };
  5931. Overlays.prototype._getOverlayContainer = function(element, raw) {
  5932. var container = find(this._overlayContainers, function(c) {
  5933. return c.element === element;
  5934. });
  5935. if (!container && !raw) {
  5936. return this._createOverlayContainer(element);
  5937. }
  5938. return container;
  5939. };
  5940. Overlays.prototype._addOverlay = function(overlay) {
  5941. var id = overlay.id,
  5942. element = overlay.element,
  5943. html = overlay.html,
  5944. htmlContainer,
  5945. overlayContainer;
  5946. // unwrap jquery (for those who need it)
  5947. if (html.get && html.constructor.prototype.jquery) {
  5948. html = html.get(0);
  5949. }
  5950. // create proper html elements from
  5951. // overlay HTML strings
  5952. if (isString(html)) {
  5953. html = domify(html);
  5954. }
  5955. overlayContainer = this._getOverlayContainer(element);
  5956. htmlContainer = domify('<div class="djs-overlay" data-overlay-id="' + id + '">');
  5957. assign$1(htmlContainer, { position: 'absolute' });
  5958. htmlContainer.appendChild(html);
  5959. if (overlay.type) {
  5960. classes(htmlContainer).add('djs-overlay-' + overlay.type);
  5961. }
  5962. var elementRoot = this._canvas.findRoot(element);
  5963. var activeRoot = this._canvas.getRootElement();
  5964. setVisible(htmlContainer, elementRoot === activeRoot);
  5965. overlay.htmlContainer = htmlContainer;
  5966. overlayContainer.overlays.push(overlay);
  5967. overlayContainer.html.appendChild(htmlContainer);
  5968. this._overlays[id] = overlay;
  5969. this._updateOverlay(overlay);
  5970. this._updateOverlayVisibilty(overlay, this._canvas.viewbox());
  5971. };
  5972. Overlays.prototype._updateOverlayVisibilty = function(overlay, viewbox) {
  5973. var show = overlay.show,
  5974. rootElement = this._canvas.findRoot(overlay.element),
  5975. minZoom = show && show.minZoom,
  5976. maxZoom = show && show.maxZoom,
  5977. htmlContainer = overlay.htmlContainer,
  5978. activeRootElement = this._canvas.getRootElement(),
  5979. visible = true;
  5980. if (rootElement !== activeRootElement) {
  5981. visible = false;
  5982. } else if (show) {
  5983. if (
  5984. (isDefined(minZoom) && minZoom > viewbox.scale) ||
  5985. (isDefined(maxZoom) && maxZoom < viewbox.scale)
  5986. ) {
  5987. visible = false;
  5988. }
  5989. }
  5990. setVisible(htmlContainer, visible);
  5991. this._updateOverlayScale(overlay, viewbox);
  5992. };
  5993. Overlays.prototype._updateOverlayScale = function(overlay, viewbox) {
  5994. var shouldScale = overlay.scale,
  5995. minScale,
  5996. maxScale,
  5997. htmlContainer = overlay.htmlContainer;
  5998. var scale, transform = '';
  5999. if (shouldScale !== true) {
  6000. if (shouldScale === false) {
  6001. minScale = 1;
  6002. maxScale = 1;
  6003. } else {
  6004. minScale = shouldScale.min;
  6005. maxScale = shouldScale.max;
  6006. }
  6007. if (isDefined(minScale) && viewbox.scale < minScale) {
  6008. scale = (1 / viewbox.scale || 1) * minScale;
  6009. }
  6010. if (isDefined(maxScale) && viewbox.scale > maxScale) {
  6011. scale = (1 / viewbox.scale || 1) * maxScale;
  6012. }
  6013. }
  6014. if (isDefined(scale)) {
  6015. transform = 'scale(' + scale + ',' + scale + ')';
  6016. }
  6017. setTransform(htmlContainer, transform);
  6018. };
  6019. Overlays.prototype._updateOverlaysVisibilty = function(viewbox) {
  6020. var self = this;
  6021. forEach$1(this._overlays, function(overlay) {
  6022. self._updateOverlayVisibilty(overlay, viewbox);
  6023. });
  6024. };
  6025. Overlays.prototype._init = function() {
  6026. var eventBus = this._eventBus;
  6027. var self = this;
  6028. // scroll/zoom integration
  6029. function updateViewbox(viewbox) {
  6030. self._updateRoot(viewbox);
  6031. self._updateOverlaysVisibilty(viewbox);
  6032. self.show();
  6033. }
  6034. eventBus.on('canvas.viewbox.changing', function(event) {
  6035. self.hide();
  6036. });
  6037. eventBus.on('canvas.viewbox.changed', function(event) {
  6038. updateViewbox(event.viewbox);
  6039. });
  6040. // remove integration
  6041. eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
  6042. var element = e.element;
  6043. var overlays = self.get({ element: element });
  6044. forEach$1(overlays, function(o) {
  6045. self.remove(o.id);
  6046. });
  6047. var container = self._getOverlayContainer(element);
  6048. if (container) {
  6049. remove$1(container.html);
  6050. var i = self._overlayContainers.indexOf(container);
  6051. if (i !== -1) {
  6052. self._overlayContainers.splice(i, 1);
  6053. }
  6054. }
  6055. });
  6056. // move integration
  6057. eventBus.on('element.changed', LOW_PRIORITY$1, function(e) {
  6058. var element = e.element;
  6059. var container = self._getOverlayContainer(element, true);
  6060. if (container) {
  6061. forEach$1(container.overlays, function(overlay) {
  6062. self._updateOverlay(overlay);
  6063. });
  6064. self._updateOverlayContainer(container);
  6065. }
  6066. });
  6067. // marker integration, simply add them on the overlays as classes, too.
  6068. eventBus.on('element.marker.update', function(e) {
  6069. var container = self._getOverlayContainer(e.element, true);
  6070. if (container) {
  6071. classes(container.html)[e.add ? 'add' : 'remove'](e.marker);
  6072. }
  6073. });
  6074. eventBus.on('root.set', function() {
  6075. self._updateOverlaysVisibilty(self._canvas.viewbox());
  6076. });
  6077. // clear overlays with diagram
  6078. eventBus.on('diagram.clear', this.clear, this);
  6079. };
  6080. // helpers /////////////////////////////
  6081. function createRoot(parentNode) {
  6082. var root = domify(
  6083. '<div class="djs-overlay-container" />'
  6084. );
  6085. assign$1(root, {
  6086. position: 'absolute',
  6087. width: 0,
  6088. height: 0
  6089. });
  6090. parentNode.insertBefore(root, parentNode.firstChild);
  6091. return root;
  6092. }
  6093. function setPosition(el, x, y) {
  6094. assign$1(el, { left: x + 'px', top: y + 'px' });
  6095. }
  6096. /**
  6097. * Set element visible
  6098. *
  6099. * @param {DOMElement} el
  6100. * @param {boolean} [visible=true]
  6101. */
  6102. function setVisible(el, visible) {
  6103. el.style.display = visible === false ? 'none' : '';
  6104. }
  6105. function setTransform(el, transform) {
  6106. el.style['transform-origin'] = 'top left';
  6107. [ '', '-ms-', '-webkit-' ].forEach(function(prefix) {
  6108. el.style[prefix + 'transform'] = transform;
  6109. });
  6110. }
  6111. var OverlaysModule = {
  6112. __init__: [ 'overlays' ],
  6113. overlays: [ 'type', Overlays ]
  6114. };
  6115. /**
  6116. * Adds change support to the diagram, including
  6117. *
  6118. * <ul>
  6119. * <li>redrawing shapes and connections on change</li>
  6120. * </ul>
  6121. *
  6122. * @param {EventBus} eventBus
  6123. * @param {Canvas} canvas
  6124. * @param {ElementRegistry} elementRegistry
  6125. * @param {GraphicsFactory} graphicsFactory
  6126. */
  6127. function ChangeSupport(
  6128. eventBus, canvas, elementRegistry,
  6129. graphicsFactory) {
  6130. // redraw shapes / connections on change
  6131. eventBus.on('element.changed', function(event) {
  6132. var element = event.element;
  6133. // element might have been deleted and replaced by new element with same ID
  6134. // thus check for parent of element except for root element
  6135. if (element.parent || element === canvas.getRootElement()) {
  6136. event.gfx = elementRegistry.getGraphics(element);
  6137. }
  6138. // shape + gfx may have been deleted
  6139. if (!event.gfx) {
  6140. return;
  6141. }
  6142. eventBus.fire(getType(element) + '.changed', event);
  6143. });
  6144. eventBus.on('elements.changed', function(event) {
  6145. var elements = event.elements;
  6146. elements.forEach(function(e) {
  6147. eventBus.fire('element.changed', { element: e });
  6148. });
  6149. graphicsFactory.updateContainments(elements);
  6150. });
  6151. eventBus.on('shape.changed', function(event) {
  6152. graphicsFactory.update('shape', event.element, event.gfx);
  6153. });
  6154. eventBus.on('connection.changed', function(event) {
  6155. graphicsFactory.update('connection', event.element, event.gfx);
  6156. });
  6157. }
  6158. ChangeSupport.$inject = [
  6159. 'eventBus',
  6160. 'canvas',
  6161. 'elementRegistry',
  6162. 'graphicsFactory'
  6163. ];
  6164. var ChangeSupportModule = {
  6165. __init__: [ 'changeSupport' ],
  6166. changeSupport: [ 'type', ChangeSupport ]
  6167. };
  6168. var DEFAULT_PRIORITY$1 = 1000;
  6169. /**
  6170. * A utility that can be used to plug-in into the command execution for
  6171. * extension and/or validation.
  6172. *
  6173. * @param {EventBus} eventBus
  6174. *
  6175. * @example
  6176. *
  6177. * import inherits from 'inherits-browser';
  6178. *
  6179. * import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
  6180. *
  6181. * function CommandLogger(eventBus) {
  6182. * CommandInterceptor.call(this, eventBus);
  6183. *
  6184. * this.preExecute(function(event) {
  6185. * console.log('command pre-execute', event);
  6186. * });
  6187. * }
  6188. *
  6189. * inherits(CommandLogger, CommandInterceptor);
  6190. *
  6191. */
  6192. function CommandInterceptor(eventBus) {
  6193. this._eventBus = eventBus;
  6194. }
  6195. CommandInterceptor.$inject = [ 'eventBus' ];
  6196. function unwrapEvent(fn, that) {
  6197. return function(event) {
  6198. return fn.call(that || null, event.context, event.command, event);
  6199. };
  6200. }
  6201. /**
  6202. * Register an interceptor for a command execution
  6203. *
  6204. * @param {string|Array<string>} [events] list of commands to register on
  6205. * @param {string} [hook] command hook, i.e. preExecute, executed to listen on
  6206. * @param {number} [priority] the priority on which to hook into the execution
  6207. * @param {Function} handlerFn interceptor to be invoked with (event)
  6208. * @param {boolean} unwrap if true, unwrap the event and pass (context, command, event) to the
  6209. * listener instead
  6210. * @param {Object} [that] Pass context (`this`) to the handler function
  6211. */
  6212. CommandInterceptor.prototype.on = function(events, hook, priority, handlerFn, unwrap, that) {
  6213. if (isFunction(hook) || isNumber(hook)) {
  6214. that = unwrap;
  6215. unwrap = handlerFn;
  6216. handlerFn = priority;
  6217. priority = hook;
  6218. hook = null;
  6219. }
  6220. if (isFunction(priority)) {
  6221. that = unwrap;
  6222. unwrap = handlerFn;
  6223. handlerFn = priority;
  6224. priority = DEFAULT_PRIORITY$1;
  6225. }
  6226. if (isObject(unwrap)) {
  6227. that = unwrap;
  6228. unwrap = false;
  6229. }
  6230. if (!isFunction(handlerFn)) {
  6231. throw new Error('handlerFn must be a function');
  6232. }
  6233. if (!isArray$2(events)) {
  6234. events = [ events ];
  6235. }
  6236. var eventBus = this._eventBus;
  6237. forEach$1(events, function(event) {
  6238. // concat commandStack(.event)?(.hook)?
  6239. var fullEvent = [ 'commandStack', event, hook ].filter(function(e) { return e; }).join('.');
  6240. eventBus.on(fullEvent, priority, unwrap ? unwrapEvent(handlerFn, that) : handlerFn, that);
  6241. });
  6242. };
  6243. var hooks = [
  6244. 'canExecute',
  6245. 'preExecute',
  6246. 'preExecuted',
  6247. 'execute',
  6248. 'executed',
  6249. 'postExecute',
  6250. 'postExecuted',
  6251. 'revert',
  6252. 'reverted'
  6253. ];
  6254. /*
  6255. * Install hook shortcuts
  6256. *
  6257. * This will generate the CommandInterceptor#(preExecute|...|reverted) methods
  6258. * which will in term forward to CommandInterceptor#on.
  6259. */
  6260. forEach$1(hooks, function(hook) {
  6261. /**
  6262. * {canExecute|preExecute|preExecuted|execute|executed|postExecute|postExecuted|revert|reverted}
  6263. *
  6264. * A named hook for plugging into the command execution
  6265. *
  6266. * @param {string|Array<string>} [events] list of commands to register on
  6267. * @param {number} [priority] the priority on which to hook into the execution
  6268. * @param {Function} handlerFn interceptor to be invoked with (event)
  6269. * @param {boolean} [unwrap=false] if true, unwrap the event and pass (context, command, event) to the
  6270. * listener instead
  6271. * @param {Object} [that] Pass context (`this`) to the handler function
  6272. */
  6273. CommandInterceptor.prototype[hook] = function(events, priority, handlerFn, unwrap, that) {
  6274. if (isFunction(events) || isNumber(events)) {
  6275. that = unwrap;
  6276. unwrap = handlerFn;
  6277. handlerFn = priority;
  6278. priority = events;
  6279. events = null;
  6280. }
  6281. this.on(events, hook, priority, handlerFn, unwrap, that);
  6282. };
  6283. });
  6284. /**
  6285. * A modeling behavior that ensures we set the correct root element
  6286. * as we undo and redo commands.
  6287. *
  6288. * @param {Canvas} canvas
  6289. * @param {didi.Injector} injector
  6290. */
  6291. function RootElementsBehavior(canvas, injector) {
  6292. injector.invoke(CommandInterceptor, this);
  6293. this.executed(function(event) {
  6294. var context = event.context;
  6295. if (context.rootElement) {
  6296. canvas.setRootElement(context.rootElement);
  6297. } else {
  6298. context.rootElement = canvas.getRootElement();
  6299. }
  6300. });
  6301. this.revert(function(event) {
  6302. var context = event.context;
  6303. if (context.rootElement) {
  6304. canvas.setRootElement(context.rootElement);
  6305. }
  6306. });
  6307. }
  6308. e(RootElementsBehavior, CommandInterceptor);
  6309. RootElementsBehavior.$inject = [ 'canvas', 'injector' ];
  6310. var RootElementsModule = {
  6311. __init__: [ 'rootElementsBehavior' ],
  6312. rootElementsBehavior: [ 'type', RootElementsBehavior ]
  6313. };
  6314. var css_escape = {exports: {}};
  6315. /*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
  6316. (function (module, exports) {
  6317. (function(root, factory) {
  6318. // https://github.com/umdjs/umd/blob/master/returnExports.js
  6319. {
  6320. // For Node.js.
  6321. module.exports = factory(root);
  6322. }
  6323. }(typeof commonjsGlobal != 'undefined' ? commonjsGlobal : commonjsGlobal, function(root) {
  6324. if (root.CSS && root.CSS.escape) {
  6325. return root.CSS.escape;
  6326. }
  6327. // https://drafts.csswg.org/cssom/#serialize-an-identifier
  6328. var cssEscape = function(value) {
  6329. if (arguments.length == 0) {
  6330. throw new TypeError('`CSS.escape` requires an argument.');
  6331. }
  6332. var string = String(value);
  6333. var length = string.length;
  6334. var index = -1;
  6335. var codeUnit;
  6336. var result = '';
  6337. var firstCodeUnit = string.charCodeAt(0);
  6338. while (++index < length) {
  6339. codeUnit = string.charCodeAt(index);
  6340. // Note: there’s no need to special-case astral symbols, surrogate
  6341. // pairs, or lone surrogates.
  6342. // If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
  6343. // (U+FFFD).
  6344. if (codeUnit == 0x0000) {
  6345. result += '\uFFFD';
  6346. continue;
  6347. }
  6348. if (
  6349. // If the character is in the range [\1-\1F] (U+0001 to U+001F) or is
  6350. // U+007F, […]
  6351. (codeUnit >= 0x0001 && codeUnit <= 0x001F) || codeUnit == 0x007F ||
  6352. // If the character is the first character and is in the range [0-9]
  6353. // (U+0030 to U+0039), […]
  6354. (index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
  6355. // If the character is the second character and is in the range [0-9]
  6356. // (U+0030 to U+0039) and the first character is a `-` (U+002D), […]
  6357. (
  6358. index == 1 &&
  6359. codeUnit >= 0x0030 && codeUnit <= 0x0039 &&
  6360. firstCodeUnit == 0x002D
  6361. )
  6362. ) {
  6363. // https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
  6364. result += '\\' + codeUnit.toString(16) + ' ';
  6365. continue;
  6366. }
  6367. if (
  6368. // If the character is the first character and is a `-` (U+002D), and
  6369. // there is no second character, […]
  6370. index == 0 &&
  6371. length == 1 &&
  6372. codeUnit == 0x002D
  6373. ) {
  6374. result += '\\' + string.charAt(index);
  6375. continue;
  6376. }
  6377. // If the character is not handled by one of the above rules and is
  6378. // greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
  6379. // is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
  6380. // U+005A), or [a-z] (U+0061 to U+007A), […]
  6381. if (
  6382. codeUnit >= 0x0080 ||
  6383. codeUnit == 0x002D ||
  6384. codeUnit == 0x005F ||
  6385. codeUnit >= 0x0030 && codeUnit <= 0x0039 ||
  6386. codeUnit >= 0x0041 && codeUnit <= 0x005A ||
  6387. codeUnit >= 0x0061 && codeUnit <= 0x007A
  6388. ) {
  6389. // the character itself
  6390. result += string.charAt(index);
  6391. continue;
  6392. }
  6393. // Otherwise, the escaped character.
  6394. // https://drafts.csswg.org/cssom/#escape-a-character
  6395. result += '\\' + string.charAt(index);
  6396. }
  6397. return result;
  6398. };
  6399. if (!root.CSS) {
  6400. root.CSS = {};
  6401. }
  6402. root.CSS.escape = cssEscape;
  6403. return cssEscape;
  6404. }));
  6405. }(css_escape));
  6406. var HTML_ESCAPE_MAP = {
  6407. '&': '&amp;',
  6408. '<': '&lt;',
  6409. '>': '&gt;',
  6410. '"': '&quot;',
  6411. '\'': '&#39;'
  6412. };
  6413. function escapeHTML(str) {
  6414. str = '' + str;
  6415. return str && str.replace(/[&<>"']/g, function(match) {
  6416. return HTML_ESCAPE_MAP[match];
  6417. });
  6418. }
  6419. var planeSuffix = '_plane';
  6420. /**
  6421. * Get plane ID for a primary shape.
  6422. *
  6423. * @param {djs.model.Base|ModdleElement} element
  6424. *
  6425. * @returns {String}
  6426. */
  6427. function getPlaneIdFromShape(element) {
  6428. var id = element.id;
  6429. if (is$1(element, 'bpmn:SubProcess')) {
  6430. return addPlaneSuffix(id);
  6431. }
  6432. return id;
  6433. }
  6434. function addPlaneSuffix(id) {
  6435. return id + planeSuffix;
  6436. }
  6437. var OPEN_CLASS = 'bjs-breadcrumbs-shown';
  6438. /**
  6439. * Adds overlays that allow switching planes on collapsed subprocesses.
  6440. *
  6441. * @param {eventBus} eventBus
  6442. * @param {elementRegistry} elementRegistry
  6443. * @param {overlays} overlays
  6444. * @param {canvas} canvas
  6445. */
  6446. function DrilldownBreadcrumbs(eventBus, elementRegistry, overlays, canvas) {
  6447. var breadcrumbs = domify('<ul class="bjs-breadcrumbs"></ul>');
  6448. var container = canvas.getContainer();
  6449. var containerClasses = classes(container);
  6450. container.appendChild(breadcrumbs);
  6451. var boParents = [];
  6452. // update breadcrumbs if name or ID of the primary shape changes
  6453. eventBus.on('element.changed', function(e) {
  6454. var shape = e.element,
  6455. bo = getBusinessObject(shape);
  6456. var isPresent = find(boParents, function(el) {
  6457. return el === bo;
  6458. });
  6459. if (!isPresent) {
  6460. return;
  6461. }
  6462. updateBreadcrumbs();
  6463. });
  6464. /**
  6465. * Updates the displayed breadcrumbs. If no element is provided, only the
  6466. * labels are updated.
  6467. *
  6468. * @param {djs.model.Base} [element]
  6469. */
  6470. function updateBreadcrumbs(element) {
  6471. if (element) {
  6472. boParents = getBoParentChain(element);
  6473. }
  6474. var path = boParents.map(function(parent) {
  6475. var title = escapeHTML(parent.name || parent.id);
  6476. var link = domify('<li><span class="bjs-crumb"><a title="' + title + '">' + title + '</a></span></li>');
  6477. var parentPlane = canvas.findRoot(getPlaneIdFromShape(parent)) || canvas.findRoot(parent.id);
  6478. // when the root is a collaboration, the process does not have a corresponding
  6479. // element in the elementRegisty. Instead, we search for the corresponding participant
  6480. if (!parentPlane && is$1(parent, 'bpmn:Process')) {
  6481. var participant = elementRegistry.find(function(element) {
  6482. var bo = getBusinessObject(element);
  6483. return bo && bo.processRef && bo.processRef === parent;
  6484. });
  6485. parentPlane = canvas.findRoot(participant.id);
  6486. }
  6487. link.addEventListener('click', function() {
  6488. canvas.setRootElement(parentPlane);
  6489. });
  6490. return link;
  6491. });
  6492. breadcrumbs.innerHTML = '';
  6493. // show breadcrumbs and expose state to .djs-container
  6494. var visible = path.length > 1;
  6495. containerClasses.toggle(OPEN_CLASS, visible);
  6496. path.forEach(function(el) {
  6497. breadcrumbs.appendChild(el);
  6498. });
  6499. }
  6500. eventBus.on('root.set', function(event) {
  6501. updateBreadcrumbs(event.element);
  6502. });
  6503. }
  6504. DrilldownBreadcrumbs.$inject = [ 'eventBus', 'elementRegistry', 'overlays', 'canvas' ];
  6505. // helpers //////////
  6506. /**
  6507. * Returns the parents for the element using the business object chain,
  6508. * starting with the root element.
  6509. *
  6510. * @param {djs.model.Shape} child
  6511. *
  6512. * @returns {Array<djs.model.Shape>} parents
  6513. */
  6514. function getBoParentChain(child) {
  6515. var bo = getBusinessObject(child);
  6516. var parents = [];
  6517. for (var element = bo; element; element = element.$parent) {
  6518. if (is$1(element, 'bpmn:SubProcess') || is$1(element, 'bpmn:Process')) {
  6519. parents.push(element);
  6520. }
  6521. }
  6522. return parents.reverse();
  6523. }
  6524. /**
  6525. * Move collapsed subprocesses into view when drilling down.
  6526. *
  6527. * Zoom and scroll are saved in a session.
  6528. *
  6529. * @param {eventBus} eventBus
  6530. * @param {canvas} canvas
  6531. */
  6532. function DrilldownCentering(eventBus, canvas) {
  6533. var currentRoot = null;
  6534. var positionMap = new Map();
  6535. eventBus.on('root.set', function(event) {
  6536. var newRoot = event.element;
  6537. var currentViewbox = canvas.viewbox();
  6538. var storedViewbox = positionMap.get(newRoot);
  6539. positionMap.set(currentRoot, {
  6540. x: currentViewbox.x,
  6541. y: currentViewbox.y,
  6542. zoom: currentViewbox.scale
  6543. });
  6544. currentRoot = newRoot;
  6545. // current root was replaced with a collaboration, we don't update the viewbox
  6546. if (is$1(newRoot, 'bpmn:Collaboration') && !storedViewbox) {
  6547. return;
  6548. }
  6549. storedViewbox = storedViewbox || { x: 0, y: 0, zoom: 1 };
  6550. var dx = (currentViewbox.x - storedViewbox.x) * currentViewbox.scale,
  6551. dy = (currentViewbox.y - storedViewbox.y) * currentViewbox.scale;
  6552. if (dx !== 0 || dy !== 0) {
  6553. canvas.scroll({
  6554. dx: dx,
  6555. dy: dy
  6556. });
  6557. }
  6558. if (storedViewbox.zoom !== currentViewbox.scale) {
  6559. canvas.zoom(storedViewbox.zoom, { x: 0, y: 0 });
  6560. }
  6561. });
  6562. eventBus.on('diagram.clear', function() {
  6563. positionMap.clear();
  6564. currentRoot = null;
  6565. });
  6566. }
  6567. DrilldownCentering.$inject = [ 'eventBus', 'canvas' ];
  6568. /**
  6569. * ES5 Map implementation. Works.
  6570. */
  6571. function Map() {
  6572. this._entries = [];
  6573. this.set = function(key, value) {
  6574. var found = false;
  6575. for (var k in this._entries) {
  6576. if (this._entries[k][0] === key) {
  6577. this._entries[k][1] = value;
  6578. found = true;
  6579. break;
  6580. }
  6581. }
  6582. if (!found) {
  6583. this._entries.push([ key, value ]);
  6584. }
  6585. };
  6586. this.get = function(key) {
  6587. for (var k in this._entries) {
  6588. if (this._entries[k][0] === key) {
  6589. return this._entries[k][1];
  6590. }
  6591. }
  6592. return null;
  6593. };
  6594. this.clear = function() {
  6595. this._entries.length = 0;
  6596. };
  6597. this.remove = function(key) {
  6598. var idx = -1;
  6599. for (var k in this._entries) {
  6600. if (this._entries[k][0] === key) {
  6601. idx = k;
  6602. break;
  6603. }
  6604. }
  6605. if (idx !== -1) {
  6606. this._entries.splice(idx, 1);
  6607. }
  6608. };
  6609. }
  6610. var DEFAULT_POSITION = {
  6611. x: 180,
  6612. y: 160
  6613. };
  6614. /**
  6615. * Hook into `import.render.start` and create new planes for diagrams with
  6616. * collapsed subprocesses and all dis on the same plane.
  6617. *
  6618. * @param {eventBus} eventBus
  6619. * @param {moddle} moddle
  6620. */
  6621. function SubprocessCompatibility(eventBus, moddle) {
  6622. this._eventBus = eventBus;
  6623. this._moddle = moddle;
  6624. var self = this;
  6625. eventBus.on('import.render.start', 1500, function(e, context) {
  6626. self.handleImport(context.definitions);
  6627. });
  6628. }
  6629. SubprocessCompatibility.prototype.handleImport = function(definitions) {
  6630. if (!definitions.diagrams) {
  6631. return;
  6632. }
  6633. var self = this;
  6634. this._definitions = definitions;
  6635. this._processToDiagramMap = {};
  6636. definitions.diagrams.forEach(function(diagram) {
  6637. if (!diagram.plane || !diagram.plane.bpmnElement) {
  6638. return;
  6639. }
  6640. self._processToDiagramMap[diagram.plane.bpmnElement.id] = diagram;
  6641. });
  6642. var newDiagrams = [];
  6643. definitions.diagrams.forEach(function(diagram) {
  6644. var createdDiagrams = self.createNewDiagrams(diagram.plane);
  6645. Array.prototype.push.apply(newDiagrams, createdDiagrams);
  6646. });
  6647. newDiagrams.forEach(function(diagram) {
  6648. self.movePlaneElementsToOrigin(diagram.plane);
  6649. });
  6650. };
  6651. /**
  6652. * Moves all DI elements from collapsed subprocesses to a new plane.
  6653. *
  6654. * @param {Object} plane
  6655. * @return {Array} new diagrams created for the collapsed subprocesses
  6656. */
  6657. SubprocessCompatibility.prototype.createNewDiagrams = function(plane) {
  6658. var self = this;
  6659. var collapsedElements = [];
  6660. var elementsToMove = [];
  6661. plane.get('planeElement').forEach(function(diElement) {
  6662. var bo = diElement.bpmnElement;
  6663. if (!bo) {
  6664. return;
  6665. }
  6666. var parent = bo.$parent;
  6667. if (is$1(bo, 'bpmn:SubProcess') && !diElement.isExpanded) {
  6668. collapsedElements.push(bo);
  6669. }
  6670. if (shouldMoveToPlane(bo, plane)) {
  6671. // don't change the array while we iterate over it
  6672. elementsToMove.push({ diElement: diElement, parent: parent });
  6673. }
  6674. });
  6675. var newDiagrams = [];
  6676. // create new planes for all collapsed subprocesses, even when they are empty
  6677. collapsedElements.forEach(function(element) {
  6678. if (!self._processToDiagramMap[element.id]) {
  6679. var diagram = self.createDiagram(element);
  6680. self._processToDiagramMap[element.id] = diagram;
  6681. newDiagrams.push(diagram);
  6682. }
  6683. });
  6684. elementsToMove.forEach(function(element) {
  6685. var diElement = element.diElement;
  6686. var parent = element.parent;
  6687. // parent is expanded, get nearest collapsed parent
  6688. while (parent && collapsedElements.indexOf(parent) === -1) {
  6689. parent = parent.$parent;
  6690. }
  6691. // false positive, all parents are expanded
  6692. if (!parent) {
  6693. return;
  6694. }
  6695. var diagram = self._processToDiagramMap[parent.id];
  6696. self.moveToDiPlane(diElement, diagram.plane);
  6697. });
  6698. return newDiagrams;
  6699. };
  6700. SubprocessCompatibility.prototype.movePlaneElementsToOrigin = function(plane) {
  6701. var elements = plane.get('planeElement');
  6702. // get bounding box of all elements
  6703. var planeBounds = getPlaneBounds(plane);
  6704. var offset = {
  6705. x: planeBounds.x - DEFAULT_POSITION.x,
  6706. y: planeBounds.y - DEFAULT_POSITION.y
  6707. };
  6708. elements.forEach(function(diElement) {
  6709. if (diElement.waypoint) {
  6710. diElement.waypoint.forEach(function(waypoint) {
  6711. waypoint.x = waypoint.x - offset.x;
  6712. waypoint.y = waypoint.y - offset.y;
  6713. });
  6714. } else if (diElement.bounds) {
  6715. diElement.bounds.x = diElement.bounds.x - offset.x;
  6716. diElement.bounds.y = diElement.bounds.y - offset.y;
  6717. }
  6718. });
  6719. };
  6720. SubprocessCompatibility.prototype.moveToDiPlane = function(diElement, newPlane) {
  6721. var containingDiagram = findRootDiagram(diElement);
  6722. // remove DI from old Plane and add it to the new one
  6723. var parentPlaneElement = containingDiagram.plane.get('planeElement');
  6724. parentPlaneElement.splice(parentPlaneElement.indexOf(diElement), 1);
  6725. newPlane.get('planeElement').push(diElement);
  6726. };
  6727. SubprocessCompatibility.prototype.createDiagram = function(bo) {
  6728. var plane = this._moddle.create('bpmndi:BPMNPlane', { bpmnElement: bo });
  6729. var diagram = this._moddle.create('bpmndi:BPMNDiagram', {
  6730. plane: plane
  6731. });
  6732. plane.$parent = diagram;
  6733. plane.bpmnElement = bo;
  6734. diagram.$parent = this._definitions;
  6735. this._definitions.diagrams.push(diagram);
  6736. return diagram;
  6737. };
  6738. SubprocessCompatibility.$inject = [ 'eventBus', 'moddle' ];
  6739. // helpers //////////////////////////
  6740. function findRootDiagram(element) {
  6741. if (is$1(element, 'bpmndi:BPMNDiagram')) {
  6742. return element;
  6743. } else {
  6744. return findRootDiagram(element.$parent);
  6745. }
  6746. }
  6747. function getPlaneBounds(plane) {
  6748. var planeTrbl = {
  6749. top: Infinity,
  6750. right: -Infinity,
  6751. bottom: -Infinity,
  6752. left: Infinity
  6753. };
  6754. plane.planeElement.forEach(function(element) {
  6755. if (!element.bounds) {
  6756. return;
  6757. }
  6758. var trbl = asTRBL(element.bounds);
  6759. planeTrbl.top = Math.min(trbl.top, planeTrbl.top);
  6760. planeTrbl.left = Math.min(trbl.left, planeTrbl.left);
  6761. });
  6762. return asBounds(planeTrbl);
  6763. }
  6764. function shouldMoveToPlane(bo, plane) {
  6765. var parent = bo.$parent;
  6766. // don't move elements that are already on the plane
  6767. if (!is$1(parent, 'bpmn:SubProcess') || parent === plane.bpmnElement) {
  6768. return false;
  6769. }
  6770. // dataAssociations are children of the subprocess but rendered on process level
  6771. // cf. https://github.com/bpmn-io/bpmn-js/issues/1619
  6772. if (isAny(bo, ['bpmn:DataInputAssociation', 'bpmn:DataOutputAssociation'])) {
  6773. return false;
  6774. }
  6775. return true;
  6776. }
  6777. var LOW_PRIORITY = 250;
  6778. var ARROW_DOWN_SVG = '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4.81801948,3.50735931 L10.4996894,9.1896894 L10.5,4 L12,4 L12,12 L4,12 L4,10.5 L9.6896894,10.4996894 L3.75735931,4.56801948 C3.46446609,4.27512627 3.46446609,3.80025253 3.75735931,3.50735931 C4.05025253,3.21446609 4.52512627,3.21446609 4.81801948,3.50735931 Z"/></svg>';
  6779. var EMPTY_MARKER = 'bjs-drilldown-empty';
  6780. function DrilldownOverlayBehavior(
  6781. canvas, eventBus, elementRegistry, overlays
  6782. ) {
  6783. CommandInterceptor.call(this, eventBus);
  6784. this._canvas = canvas;
  6785. this._eventBus = eventBus;
  6786. this._elementRegistry = elementRegistry;
  6787. this._overlays = overlays;
  6788. var self = this;
  6789. this.executed('shape.toggleCollapse', LOW_PRIORITY, function(context) {
  6790. var shape = context.shape;
  6791. // Add overlay to the collapsed shape
  6792. if (self.canDrillDown(shape)) {
  6793. self.addOverlay(shape);
  6794. } else {
  6795. self.removeOverlay(shape);
  6796. }
  6797. }, true);
  6798. this.reverted('shape.toggleCollapse', LOW_PRIORITY, function(context) {
  6799. var shape = context.shape;
  6800. // Add overlay to the collapsed shape
  6801. if (self.canDrillDown(shape)) {
  6802. self.addOverlay(shape);
  6803. } else {
  6804. self.removeOverlay(shape);
  6805. }
  6806. }, true);
  6807. this.executed(['shape.create', 'shape.move', 'shape.delete'], LOW_PRIORITY,
  6808. function(context) {
  6809. var oldParent = context.oldParent,
  6810. newParent = context.newParent || context.parent,
  6811. shape = context.shape;
  6812. // Add overlay to the collapsed shape
  6813. if (self.canDrillDown(shape)) {
  6814. self.addOverlay(shape);
  6815. }
  6816. self.updateDrilldownOverlay(oldParent);
  6817. self.updateDrilldownOverlay(newParent);
  6818. self.updateDrilldownOverlay(shape);
  6819. }, true);
  6820. this.reverted(['shape.create', 'shape.move', 'shape.delete'], LOW_PRIORITY,
  6821. function(context) {
  6822. var oldParent = context.oldParent,
  6823. newParent = context.newParent || context.parent,
  6824. shape = context.shape;
  6825. // Add overlay to the collapsed shape
  6826. if (self.canDrillDown(shape)) {
  6827. self.addOverlay(shape);
  6828. }
  6829. self.updateDrilldownOverlay(oldParent);
  6830. self.updateDrilldownOverlay(newParent);
  6831. self.updateDrilldownOverlay(shape);
  6832. }, true);
  6833. eventBus.on('import.render.complete', function() {
  6834. elementRegistry.filter(function(e) {
  6835. return self.canDrillDown(e);
  6836. }).map(function(el) {
  6837. self.addOverlay(el);
  6838. });
  6839. });
  6840. }
  6841. e(DrilldownOverlayBehavior, CommandInterceptor);
  6842. DrilldownOverlayBehavior.prototype.updateDrilldownOverlay = function(shape) {
  6843. var canvas = this._canvas;
  6844. if (!shape) {
  6845. return;
  6846. }
  6847. var root = canvas.findRoot(shape);
  6848. if (root) {
  6849. this.updateOverlayVisibility(root);
  6850. }
  6851. };
  6852. DrilldownOverlayBehavior.prototype.canDrillDown = function(element) {
  6853. var canvas = this._canvas;
  6854. return is$1(element, 'bpmn:SubProcess') && canvas.findRoot(getPlaneIdFromShape(element));
  6855. };
  6856. /**
  6857. * Updates visibility of the drilldown overlay. If the plane has no elements,
  6858. * the drilldown will be only shown when the element is selected.
  6859. *
  6860. * @param {djs.model.Shape|djs.model.Root} element collapsed shape or root element
  6861. */
  6862. DrilldownOverlayBehavior.prototype.updateOverlayVisibility = function(element) {
  6863. var overlays = this._overlays;
  6864. var bo = element.businessObject;
  6865. var overlay = overlays.get({ element: bo.id, type: 'drilldown' })[0];
  6866. if (!overlay) {
  6867. return;
  6868. }
  6869. var hasContent = bo && bo.flowElements && bo.flowElements.length;
  6870. classes(overlay.html).toggle(EMPTY_MARKER, !hasContent);
  6871. };
  6872. /**
  6873. * Attaches a drilldown button to the given element. We assume that the plane has
  6874. * the same id as the element.
  6875. *
  6876. * @param {djs.model.Shape} element collapsed shape
  6877. */
  6878. DrilldownOverlayBehavior.prototype.addOverlay = function(element) {
  6879. var canvas = this._canvas;
  6880. var overlays = this._overlays;
  6881. var existingOverlays = overlays.get({ element: element, type: 'drilldown' });
  6882. if (existingOverlays.length) {
  6883. this.removeOverlay(element);
  6884. }
  6885. var button = domify('<button class="bjs-drilldown">' + ARROW_DOWN_SVG + '</button>');
  6886. button.addEventListener('click', function() {
  6887. canvas.setRootElement(canvas.findRoot(getPlaneIdFromShape(element)));
  6888. });
  6889. overlays.add(element, 'drilldown', {
  6890. position: {
  6891. bottom: -7,
  6892. right: -8
  6893. },
  6894. html: button
  6895. });
  6896. this.updateOverlayVisibility(element);
  6897. };
  6898. DrilldownOverlayBehavior.prototype.removeOverlay = function(element) {
  6899. var overlays = this._overlays;
  6900. overlays.remove({
  6901. element: element,
  6902. type: 'drilldown'
  6903. });
  6904. };
  6905. DrilldownOverlayBehavior.$inject = [
  6906. 'canvas',
  6907. 'eventBus',
  6908. 'elementRegistry',
  6909. 'overlays'
  6910. ];
  6911. var DrilldownModdule = {
  6912. __depends__: [ OverlaysModule, ChangeSupportModule, RootElementsModule ],
  6913. __init__: [ 'drilldownBreadcrumbs', 'drilldownOverlayBehavior', 'drilldownCentering', 'subprocessCompatibility'],
  6914. drilldownBreadcrumbs: [ 'type', DrilldownBreadcrumbs ],
  6915. drilldownCentering: [ 'type', DrilldownCentering ],
  6916. drilldownOverlayBehavior: [ 'type', DrilldownOverlayBehavior ],
  6917. subprocessCompatibility: [ 'type', SubprocessCompatibility ]
  6918. };
  6919. var CLASS_PATTERN = /^class /;
  6920. /**
  6921. * @param {function} fn
  6922. *
  6923. * @return {boolean}
  6924. */
  6925. function isClass(fn) {
  6926. return CLASS_PATTERN.test(fn.toString());
  6927. }
  6928. /**
  6929. * @param {any} obj
  6930. *
  6931. * @return {boolean}
  6932. */
  6933. function isArray(obj) {
  6934. return Object.prototype.toString.call(obj) === '[object Array]';
  6935. }
  6936. /**
  6937. * @param {any} obj
  6938. * @param {string} prop
  6939. *
  6940. * @return {boolean}
  6941. */
  6942. function hasOwnProp(obj, prop) {
  6943. return Object.prototype.hasOwnProperty.call(obj, prop);
  6944. }
  6945. /**
  6946. * @typedef {import('./index').InjectAnnotated } InjectAnnotated
  6947. */
  6948. /**
  6949. * @template T
  6950. *
  6951. * @params {[...string[], T] | ...string[], T} args
  6952. *
  6953. * @return {T & InjectAnnotated}
  6954. */
  6955. function annotate() {
  6956. var args = Array.prototype.slice.call(arguments);
  6957. if (args.length === 1 && isArray(args[0])) {
  6958. args = args[0];
  6959. }
  6960. var fn = args.pop();
  6961. fn.$inject = args;
  6962. return fn;
  6963. }
  6964. // Current limitations:
  6965. // - can't put into "function arg" comments
  6966. // function /* (no parenthesis like this) */ (){}
  6967. // function abc( /* xx (no parenthesis like this) */ a, b) {}
  6968. //
  6969. // Just put the comment before function or inside:
  6970. // /* (((this is fine))) */ function(a, b) {}
  6971. // function abc(a) { /* (((this is fine))) */}
  6972. //
  6973. // - can't reliably auto-annotate constructor; we'll match the
  6974. // first constructor(...) pattern found which may be the one
  6975. // of a nested class, too.
  6976. var CONSTRUCTOR_ARGS = /constructor\s*[^(]*\(\s*([^)]*)\)/m;
  6977. var FN_ARGS = /^(?:async\s+)?(?:function\s*[^(]*)?(?:\(\s*([^)]*)\)|(\w+))/m;
  6978. var FN_ARG = /\/\*([^*]*)\*\//m;
  6979. /**
  6980. * @param {unknown} fn
  6981. *
  6982. * @return {string[]}
  6983. */
  6984. function parseAnnotations(fn) {
  6985. if (typeof fn !== 'function') {
  6986. throw new Error('Cannot annotate "' + fn + '". Expected a function!');
  6987. }
  6988. var match = fn.toString().match(isClass(fn) ? CONSTRUCTOR_ARGS : FN_ARGS);
  6989. // may parse class without constructor
  6990. if (!match) {
  6991. return [];
  6992. }
  6993. var args = match[1] || match[2];
  6994. return args && args.split(',').map(function(arg) {
  6995. var argMatch = arg.match(FN_ARG);
  6996. return (argMatch && argMatch[1] || arg).trim();
  6997. }) || [];
  6998. }
  6999. /**
  7000. * @typedef { import('./index').ModuleDeclaration } ModuleDeclaration
  7001. * @typedef { import('./index').ModuleDefinition } ModuleDefinition
  7002. * @typedef { import('./index').InjectorContext } InjectorContext
  7003. */
  7004. /**
  7005. * Create a new injector with the given modules.
  7006. *
  7007. * @param {ModuleDefinition[]} modules
  7008. * @param {InjectorContext} [parent]
  7009. */
  7010. function Injector(modules, parent) {
  7011. parent = parent || {
  7012. get: function(name, strict) {
  7013. currentlyResolving.push(name);
  7014. if (strict === false) {
  7015. return null;
  7016. } else {
  7017. throw error('No provider for "' + name + '"!');
  7018. }
  7019. }
  7020. };
  7021. var currentlyResolving = [];
  7022. var providers = this._providers = Object.create(parent._providers || null);
  7023. var instances = this._instances = Object.create(null);
  7024. var self = instances.injector = this;
  7025. var error = function(msg) {
  7026. var stack = currentlyResolving.join(' -> ');
  7027. currentlyResolving.length = 0;
  7028. return new Error(stack ? msg + ' (Resolving: ' + stack + ')' : msg);
  7029. };
  7030. /**
  7031. * Return a named service.
  7032. *
  7033. * @param {string} name
  7034. * @param {boolean} [strict=true] if false, resolve missing services to null
  7035. *
  7036. * @return {any}
  7037. */
  7038. function get(name, strict) {
  7039. if (!providers[name] && name.indexOf('.') !== -1) {
  7040. var parts = name.split('.');
  7041. var pivot = get(parts.shift());
  7042. while (parts.length) {
  7043. pivot = pivot[parts.shift()];
  7044. }
  7045. return pivot;
  7046. }
  7047. if (hasOwnProp(instances, name)) {
  7048. return instances[name];
  7049. }
  7050. if (hasOwnProp(providers, name)) {
  7051. if (currentlyResolving.indexOf(name) !== -1) {
  7052. currentlyResolving.push(name);
  7053. throw error('Cannot resolve circular dependency!');
  7054. }
  7055. currentlyResolving.push(name);
  7056. instances[name] = providers[name][0](providers[name][1]);
  7057. currentlyResolving.pop();
  7058. return instances[name];
  7059. }
  7060. return parent.get(name, strict);
  7061. }
  7062. function fnDef(fn, locals) {
  7063. if (typeof locals === 'undefined') {
  7064. locals = {};
  7065. }
  7066. if (typeof fn !== 'function') {
  7067. if (isArray(fn)) {
  7068. fn = annotate(fn.slice());
  7069. } else {
  7070. throw new Error('Cannot invoke "' + fn + '". Expected a function!');
  7071. }
  7072. }
  7073. var inject = fn.$inject || parseAnnotations(fn);
  7074. var dependencies = inject.map(function(dep) {
  7075. if (hasOwnProp(locals, dep)) {
  7076. return locals[dep];
  7077. } else {
  7078. return get(dep);
  7079. }
  7080. });
  7081. return {
  7082. fn: fn,
  7083. dependencies: dependencies
  7084. };
  7085. }
  7086. function instantiate(Type) {
  7087. var def = fnDef(Type);
  7088. var fn = def.fn,
  7089. dependencies = def.dependencies;
  7090. // instantiate var args constructor
  7091. var Constructor = Function.prototype.bind.apply(fn, [ null ].concat(dependencies));
  7092. return new Constructor();
  7093. }
  7094. function invoke(func, context, locals) {
  7095. var def = fnDef(func, locals);
  7096. var fn = def.fn,
  7097. dependencies = def.dependencies;
  7098. return fn.apply(context, dependencies);
  7099. }
  7100. /**
  7101. * @param {Injector} childInjector
  7102. *
  7103. * @return {Function}
  7104. */
  7105. function createPrivateInjectorFactory(childInjector) {
  7106. return annotate(function(key) {
  7107. return childInjector.get(key);
  7108. });
  7109. }
  7110. /**
  7111. * @param {ModuleDefinition[]} modules
  7112. * @param {string[]} [forceNewInstances]
  7113. *
  7114. * @return {Injector}
  7115. */
  7116. function createChild(modules, forceNewInstances) {
  7117. if (forceNewInstances && forceNewInstances.length) {
  7118. var fromParentModule = Object.create(null);
  7119. var matchedScopes = Object.create(null);
  7120. var privateInjectorsCache = [];
  7121. var privateChildInjectors = [];
  7122. var privateChildFactories = [];
  7123. var provider;
  7124. var cacheIdx;
  7125. var privateChildInjector;
  7126. var privateChildInjectorFactory;
  7127. for (var name in providers) {
  7128. provider = providers[name];
  7129. if (forceNewInstances.indexOf(name) !== -1) {
  7130. if (provider[2] === 'private') {
  7131. cacheIdx = privateInjectorsCache.indexOf(provider[3]);
  7132. if (cacheIdx === -1) {
  7133. privateChildInjector = provider[3].createChild([], forceNewInstances);
  7134. privateChildInjectorFactory = createPrivateInjectorFactory(privateChildInjector);
  7135. privateInjectorsCache.push(provider[3]);
  7136. privateChildInjectors.push(privateChildInjector);
  7137. privateChildFactories.push(privateChildInjectorFactory);
  7138. fromParentModule[name] = [ privateChildInjectorFactory, name, 'private', privateChildInjector ];
  7139. } else {
  7140. fromParentModule[name] = [ privateChildFactories[cacheIdx], name, 'private', privateChildInjectors[cacheIdx] ];
  7141. }
  7142. } else {
  7143. fromParentModule[name] = [ provider[2], provider[1] ];
  7144. }
  7145. matchedScopes[name] = true;
  7146. }
  7147. if ((provider[2] === 'factory' || provider[2] === 'type') && provider[1].$scope) {
  7148. /* jshint -W083 */
  7149. forceNewInstances.forEach(function(scope) {
  7150. if (provider[1].$scope.indexOf(scope) !== -1) {
  7151. fromParentModule[name] = [ provider[2], provider[1] ];
  7152. matchedScopes[scope] = true;
  7153. }
  7154. });
  7155. }
  7156. }
  7157. forceNewInstances.forEach(function(scope) {
  7158. if (!matchedScopes[scope]) {
  7159. throw new Error('No provider for "' + scope + '". Cannot use provider from the parent!');
  7160. }
  7161. });
  7162. modules.unshift(fromParentModule);
  7163. }
  7164. return new Injector(modules, self);
  7165. }
  7166. var factoryMap = {
  7167. factory: invoke,
  7168. type: instantiate,
  7169. value: function(value) {
  7170. return value;
  7171. }
  7172. };
  7173. /**
  7174. * @param {ModuleDefinition} moduleDefinition
  7175. * @param {Injector} injector
  7176. */
  7177. function createInitializer(moduleDefinition, injector) {
  7178. var initializers = moduleDefinition.__init__ || [];
  7179. return function() {
  7180. initializers.forEach(function(initializer) {
  7181. try {
  7182. // eagerly resolve component (fn or string)
  7183. if (typeof initializer === 'string') {
  7184. injector.get(initializer);
  7185. } else {
  7186. injector.invoke(initializer);
  7187. }
  7188. } catch (error) {
  7189. if (typeof AggregateError !== 'undefined') {
  7190. throw new AggregateError([ error ], 'Failed to initialize!');
  7191. }
  7192. throw new Error('Failed to initialize! ' + error.message);
  7193. }
  7194. });
  7195. };
  7196. }
  7197. /**
  7198. * @param {ModuleDefinition} moduleDefinition
  7199. */
  7200. function loadModule(moduleDefinition) {
  7201. var moduleExports = moduleDefinition.__exports__;
  7202. // private module
  7203. if (moduleExports) {
  7204. var nestedModules = moduleDefinition.__modules__;
  7205. var clonedModule = Object.keys(moduleDefinition).reduce(function(clonedModule, key) {
  7206. if (key !== '__exports__' && key !== '__modules__' && key !== '__init__' && key !== '__depends__') {
  7207. clonedModule[key] = moduleDefinition[key];
  7208. }
  7209. return clonedModule;
  7210. }, Object.create(null));
  7211. var childModules = (nestedModules || []).concat(clonedModule);
  7212. var privateInjector = createChild(childModules);
  7213. var getFromPrivateInjector = annotate(function(key) {
  7214. return privateInjector.get(key);
  7215. });
  7216. moduleExports.forEach(function(key) {
  7217. providers[key] = [ getFromPrivateInjector, key, 'private', privateInjector ];
  7218. });
  7219. // ensure child injector initializes
  7220. var initializers = (moduleDefinition.__init__ || []).slice();
  7221. initializers.unshift(function() {
  7222. privateInjector.init();
  7223. });
  7224. moduleDefinition = Object.assign({}, moduleDefinition, {
  7225. __init__: initializers
  7226. });
  7227. return createInitializer(moduleDefinition, privateInjector);
  7228. }
  7229. // normal module
  7230. Object.keys(moduleDefinition).forEach(function(key) {
  7231. if (key === '__init__' || key === '__depends__') {
  7232. return;
  7233. }
  7234. if (moduleDefinition[key][2] === 'private') {
  7235. providers[key] = moduleDefinition[key];
  7236. return;
  7237. }
  7238. var type = moduleDefinition[key][0];
  7239. var value = moduleDefinition[key][1];
  7240. providers[key] = [ factoryMap[type], arrayUnwrap(type, value), type ];
  7241. });
  7242. return createInitializer(moduleDefinition, self);
  7243. }
  7244. /**
  7245. * @param {ModuleDefinition[]} moduleDefinitions
  7246. * @param {ModuleDefinition} moduleDefinition
  7247. *
  7248. * @return {ModuleDefinition[]}
  7249. */
  7250. function resolveDependencies(moduleDefinitions, moduleDefinition) {
  7251. if (moduleDefinitions.indexOf(moduleDefinition) !== -1) {
  7252. return moduleDefinitions;
  7253. }
  7254. moduleDefinitions = (moduleDefinition.__depends__ || []).reduce(resolveDependencies, moduleDefinitions);
  7255. if (moduleDefinitions.indexOf(moduleDefinition) !== -1) {
  7256. return moduleDefinitions;
  7257. }
  7258. return moduleDefinitions.concat(moduleDefinition);
  7259. }
  7260. /**
  7261. * @param {ModuleDefinition[]} moduleDefinitions
  7262. *
  7263. * @return { () => void } initializerFn
  7264. */
  7265. function bootstrap(moduleDefinitions) {
  7266. var initializers = moduleDefinitions
  7267. .reduce(resolveDependencies, [])
  7268. .map(loadModule);
  7269. var initialized = false;
  7270. return function() {
  7271. if (initialized) {
  7272. return;
  7273. }
  7274. initialized = true;
  7275. initializers.forEach(function(initializer) {
  7276. return initializer();
  7277. });
  7278. };
  7279. }
  7280. // public API
  7281. this.get = get;
  7282. this.invoke = invoke;
  7283. this.instantiate = instantiate;
  7284. this.createChild = createChild;
  7285. // setup
  7286. this.init = bootstrap(modules);
  7287. }
  7288. // helpers ///////////////
  7289. function arrayUnwrap(type, value) {
  7290. if (type !== 'value' && isArray(value)) {
  7291. value = annotate(value.slice());
  7292. }
  7293. return value;
  7294. }
  7295. // apply default renderer with lowest possible priority
  7296. // so that it only kicks in if noone else could render
  7297. var DEFAULT_RENDER_PRIORITY = 1;
  7298. /**
  7299. * The default renderer used for shapes and connections.
  7300. *
  7301. * @param {EventBus} eventBus
  7302. * @param {Styles} styles
  7303. */
  7304. function DefaultRenderer(eventBus, styles) {
  7305. //
  7306. BaseRenderer.call(this, eventBus, DEFAULT_RENDER_PRIORITY);
  7307. this.CONNECTION_STYLE = styles.style([ 'no-fill' ], { strokeWidth: 5, stroke: 'fuchsia' });
  7308. this.SHAPE_STYLE = styles.style({ fill: 'white', stroke: 'fuchsia', strokeWidth: 2 });
  7309. this.FRAME_STYLE = styles.style([ 'no-fill' ], { stroke: 'fuchsia', strokeDasharray: 4, strokeWidth: 2 });
  7310. }
  7311. e(DefaultRenderer, BaseRenderer);
  7312. DefaultRenderer.prototype.canRender = function() {
  7313. return true;
  7314. };
  7315. DefaultRenderer.prototype.drawShape = function drawShape(visuals, element, attrs) {
  7316. var rect = create$1('rect');
  7317. attr$1(rect, {
  7318. x: 0,
  7319. y: 0,
  7320. width: element.width || 0,
  7321. height: element.height || 0
  7322. });
  7323. if (isFrameElement(element)) {
  7324. attr$1(rect, assign({}, this.FRAME_STYLE, attrs || {}));
  7325. } else {
  7326. attr$1(rect, assign({}, this.SHAPE_STYLE, attrs || {}));
  7327. }
  7328. append(visuals, rect);
  7329. return rect;
  7330. };
  7331. DefaultRenderer.prototype.drawConnection = function drawConnection(visuals, connection, attrs) {
  7332. var line = createLine(connection.waypoints, assign({}, this.CONNECTION_STYLE, attrs || {}));
  7333. append(visuals, line);
  7334. return line;
  7335. };
  7336. DefaultRenderer.prototype.getShapePath = function getShapePath(shape) {
  7337. var x = shape.x,
  7338. y = shape.y,
  7339. width = shape.width,
  7340. height = shape.height;
  7341. var shapePath = [
  7342. [ 'M', x, y ],
  7343. [ 'l', width, 0 ],
  7344. [ 'l', 0, height ],
  7345. [ 'l', -width, 0 ],
  7346. [ 'z' ]
  7347. ];
  7348. return componentsToPath(shapePath);
  7349. };
  7350. DefaultRenderer.prototype.getConnectionPath = function getConnectionPath(connection) {
  7351. var waypoints = connection.waypoints;
  7352. var idx, point, connectionPath = [];
  7353. for (idx = 0; (point = waypoints[idx]); idx++) {
  7354. // take invisible docking into account
  7355. // when creating the path
  7356. point = point.original || point;
  7357. connectionPath.push([ idx === 0 ? 'M' : 'L', point.x, point.y ]);
  7358. }
  7359. return componentsToPath(connectionPath);
  7360. };
  7361. DefaultRenderer.$inject = [ 'eventBus', 'styles' ];
  7362. /**
  7363. * A component that manages shape styles
  7364. */
  7365. function Styles() {
  7366. var defaultTraits = {
  7367. 'no-fill': {
  7368. fill: 'none'
  7369. },
  7370. 'no-border': {
  7371. strokeOpacity: 0.0
  7372. },
  7373. 'no-events': {
  7374. pointerEvents: 'none'
  7375. }
  7376. };
  7377. var self = this;
  7378. /**
  7379. * Builds a style definition from a className, a list of traits and an object of additional attributes.
  7380. *
  7381. * @param {string} className
  7382. * @param {Array<string>} traits
  7383. * @param {Object} additionalAttrs
  7384. *
  7385. * @return {Object} the style defintion
  7386. */
  7387. this.cls = function(className, traits, additionalAttrs) {
  7388. var attrs = this.style(traits, additionalAttrs);
  7389. return assign(attrs, { 'class': className });
  7390. };
  7391. /**
  7392. * Builds a style definition from a list of traits and an object of additional attributes.
  7393. *
  7394. * @param {Array<string>} traits
  7395. * @param {Object} additionalAttrs
  7396. *
  7397. * @return {Object} the style defintion
  7398. */
  7399. this.style = function(traits, additionalAttrs) {
  7400. if (!isArray$2(traits) && !additionalAttrs) {
  7401. additionalAttrs = traits;
  7402. traits = [];
  7403. }
  7404. var attrs = reduce(traits, function(attrs, t) {
  7405. return assign(attrs, defaultTraits[t] || {});
  7406. }, {});
  7407. return additionalAttrs ? assign(attrs, additionalAttrs) : attrs;
  7408. };
  7409. this.computeStyle = function(custom, traits, defaultStyles) {
  7410. if (!isArray$2(traits)) {
  7411. defaultStyles = traits;
  7412. traits = [];
  7413. }
  7414. return self.style(traits || [], assign({}, defaultStyles, custom || {}));
  7415. };
  7416. }
  7417. var DrawModule = {
  7418. __init__: [ 'defaultRenderer' ],
  7419. defaultRenderer: [ 'type', DefaultRenderer ],
  7420. styles: [ 'type', Styles ]
  7421. };
  7422. /**
  7423. * Failsafe remove an element from a collection
  7424. *
  7425. * @param {Array<Object>} [collection]
  7426. * @param {Object} [element]
  7427. *
  7428. * @return {number} the previous index of the element
  7429. */
  7430. function remove(collection, element) {
  7431. if (!collection || !element) {
  7432. return -1;
  7433. }
  7434. var idx = collection.indexOf(element);
  7435. if (idx !== -1) {
  7436. collection.splice(idx, 1);
  7437. }
  7438. return idx;
  7439. }
  7440. /**
  7441. * Fail save add an element to the given connection, ensuring
  7442. * it does not yet exist.
  7443. *
  7444. * @param {Array<Object>} collection
  7445. * @param {Object} element
  7446. * @param {number} idx
  7447. */
  7448. function add(collection, element, idx) {
  7449. if (!collection || !element) {
  7450. return;
  7451. }
  7452. if (typeof idx !== 'number') {
  7453. idx = -1;
  7454. }
  7455. var currentIdx = collection.indexOf(element);
  7456. if (currentIdx !== -1) {
  7457. if (currentIdx === idx) {
  7458. // nothing to do, position has not changed
  7459. return;
  7460. } else {
  7461. if (idx !== -1) {
  7462. // remove from current position
  7463. collection.splice(currentIdx, 1);
  7464. } else {
  7465. // already exists in collection
  7466. return;
  7467. }
  7468. }
  7469. }
  7470. if (idx !== -1) {
  7471. // insert at specified position
  7472. collection.splice(idx, 0, element);
  7473. } else {
  7474. // push to end
  7475. collection.push(element);
  7476. }
  7477. }
  7478. function round(number, resolution) {
  7479. return Math.round(number * resolution) / resolution;
  7480. }
  7481. function ensurePx(number) {
  7482. return isNumber(number) ? number + 'px' : number;
  7483. }
  7484. function findRoot(element) {
  7485. while (element.parent) {
  7486. element = element.parent;
  7487. }
  7488. return element;
  7489. }
  7490. /**
  7491. * Creates a HTML container element for a SVG element with
  7492. * the given configuration
  7493. *
  7494. * @param {Object} options
  7495. * @return {HTMLElement} the container element
  7496. */
  7497. function createContainer(options) {
  7498. options = assign({}, { width: '100%', height: '100%' }, options);
  7499. var container = options.container || document.body;
  7500. // create a <div> around the svg element with the respective size
  7501. // this way we can always get the correct container size
  7502. // (this is impossible for <svg> elements at the moment)
  7503. var parent = document.createElement('div');
  7504. parent.setAttribute('class', 'djs-container');
  7505. assign$1(parent, {
  7506. position: 'relative',
  7507. overflow: 'hidden',
  7508. width: ensurePx(options.width),
  7509. height: ensurePx(options.height)
  7510. });
  7511. container.appendChild(parent);
  7512. return parent;
  7513. }
  7514. function createGroup(parent, cls, childIndex) {
  7515. var group = create$1('g');
  7516. classes$1(group).add(cls);
  7517. var index = childIndex !== undefined ? childIndex : parent.childNodes.length - 1;
  7518. // must ensure second argument is node or _null_
  7519. // cf. https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
  7520. parent.insertBefore(group, parent.childNodes[index] || null);
  7521. return group;
  7522. }
  7523. var BASE_LAYER = 'base';
  7524. // render plane contents behind utility layers
  7525. var PLANE_LAYER_INDEX = 0;
  7526. var UTILITY_LAYER_INDEX = 1;
  7527. var REQUIRED_MODEL_ATTRS = {
  7528. shape: [ 'x', 'y', 'width', 'height' ],
  7529. connection: [ 'waypoints' ]
  7530. };
  7531. /**
  7532. * The main drawing canvas.
  7533. *
  7534. * @class
  7535. * @constructor
  7536. *
  7537. * @emits Canvas#canvas.init
  7538. *
  7539. * @param {Object} config
  7540. * @param {EventBus} eventBus
  7541. * @param {GraphicsFactory} graphicsFactory
  7542. * @param {ElementRegistry} elementRegistry
  7543. */
  7544. function Canvas(config, eventBus, graphicsFactory, elementRegistry) {
  7545. this._eventBus = eventBus;
  7546. this._elementRegistry = elementRegistry;
  7547. this._graphicsFactory = graphicsFactory;
  7548. this._rootsIdx = 0;
  7549. this._layers = {};
  7550. this._planes = [];
  7551. this._rootElement = null;
  7552. this._init(config || {});
  7553. }
  7554. Canvas.$inject = [
  7555. 'config.canvas',
  7556. 'eventBus',
  7557. 'graphicsFactory',
  7558. 'elementRegistry'
  7559. ];
  7560. /**
  7561. * Creates a <svg> element that is wrapped into a <div>.
  7562. * This way we are always able to correctly figure out the size of the svg element
  7563. * by querying the parent node.
  7564. * (It is not possible to get the size of a svg element cross browser @ 2014-04-01)
  7565. * <div class="djs-container" style="width: {desired-width}, height: {desired-height}">
  7566. * <svg width="100%" height="100%">
  7567. * ...
  7568. * </svg>
  7569. * </div>
  7570. */
  7571. Canvas.prototype._init = function(config) {
  7572. var eventBus = this._eventBus;
  7573. // html container
  7574. var container = this._container = createContainer(config);
  7575. var svg = this._svg = create$1('svg');
  7576. attr$1(svg, { width: '100%', height: '100%' });
  7577. append(container, svg);
  7578. var viewport = this._viewport = createGroup(svg, 'viewport');
  7579. // debounce canvas.viewbox.changed events
  7580. // for smoother diagram interaction
  7581. if (config.deferUpdate !== false) {
  7582. this._viewboxChanged = debounce(bind(this._viewboxChanged, this), 300);
  7583. }
  7584. eventBus.on('diagram.init', function() {
  7585. /**
  7586. * An event indicating that the canvas is ready to be drawn on.
  7587. *
  7588. * @memberOf Canvas
  7589. *
  7590. * @event canvas.init
  7591. *
  7592. * @type {Object}
  7593. * @property {SVGElement} svg the created svg element
  7594. * @property {SVGElement} viewport the direct parent of diagram elements and shapes
  7595. */
  7596. eventBus.fire('canvas.init', {
  7597. svg: svg,
  7598. viewport: viewport
  7599. });
  7600. }, this);
  7601. // reset viewbox on shape changes to
  7602. // recompute the viewbox
  7603. eventBus.on([
  7604. 'shape.added',
  7605. 'connection.added',
  7606. 'shape.removed',
  7607. 'connection.removed',
  7608. 'elements.changed',
  7609. 'root.set'
  7610. ], function() {
  7611. delete this._cachedViewbox;
  7612. }, this);
  7613. eventBus.on('diagram.destroy', 500, this._destroy, this);
  7614. eventBus.on('diagram.clear', 500, this._clear, this);
  7615. };
  7616. Canvas.prototype._destroy = function(emit) {
  7617. this._eventBus.fire('canvas.destroy', {
  7618. svg: this._svg,
  7619. viewport: this._viewport
  7620. });
  7621. var parent = this._container.parentNode;
  7622. if (parent) {
  7623. parent.removeChild(this._container);
  7624. }
  7625. delete this._svg;
  7626. delete this._container;
  7627. delete this._layers;
  7628. delete this._planes;
  7629. delete this._rootElement;
  7630. delete this._viewport;
  7631. };
  7632. Canvas.prototype._clear = function() {
  7633. var self = this;
  7634. var allElements = this._elementRegistry.getAll();
  7635. // remove all elements
  7636. allElements.forEach(function(element) {
  7637. var type = getType(element);
  7638. if (type === 'root') {
  7639. self.removeRootElement(element);
  7640. } else {
  7641. self._removeElement(element, type);
  7642. }
  7643. });
  7644. // remove all planes
  7645. this._planes = [];
  7646. this._rootElement = null;
  7647. // force recomputation of view box
  7648. delete this._cachedViewbox;
  7649. };
  7650. /**
  7651. * Returns the default layer on which
  7652. * all elements are drawn.
  7653. *
  7654. * @returns {SVGElement}
  7655. */
  7656. Canvas.prototype.getDefaultLayer = function() {
  7657. return this.getLayer(BASE_LAYER, PLANE_LAYER_INDEX);
  7658. };
  7659. /**
  7660. * Returns a layer that is used to draw elements
  7661. * or annotations on it.
  7662. *
  7663. * Non-existing layers retrieved through this method
  7664. * will be created. During creation, the optional index
  7665. * may be used to create layers below or above existing layers.
  7666. * A layer with a certain index is always created above all
  7667. * existing layers with the same index.
  7668. *
  7669. * @param {string} name
  7670. * @param {number} index
  7671. *
  7672. * @returns {SVGElement}
  7673. */
  7674. Canvas.prototype.getLayer = function(name, index) {
  7675. if (!name) {
  7676. throw new Error('must specify a name');
  7677. }
  7678. var layer = this._layers[name];
  7679. if (!layer) {
  7680. layer = this._layers[name] = this._createLayer(name, index);
  7681. }
  7682. // throw an error if layer creation / retrival is
  7683. // requested on different index
  7684. if (typeof index !== 'undefined' && layer.index !== index) {
  7685. throw new Error('layer <' + name + '> already created at index <' + index + '>');
  7686. }
  7687. return layer.group;
  7688. };
  7689. /**
  7690. * For a given index, return the number of layers that have a higher index and
  7691. * are visible.
  7692. *
  7693. * This is used to determine the node a layer should be inserted at.
  7694. *
  7695. * @param {Number} index
  7696. * @returns {Number}
  7697. */
  7698. Canvas.prototype._getChildIndex = function(index) {
  7699. return reduce(this._layers, function(childIndex, layer) {
  7700. if (layer.visible && index >= layer.index) {
  7701. childIndex++;
  7702. }
  7703. return childIndex;
  7704. }, 0);
  7705. };
  7706. /**
  7707. * Creates a given layer and returns it.
  7708. *
  7709. * @param {string} name
  7710. * @param {number} [index=0]
  7711. *
  7712. * @return {Object} layer descriptor with { index, group: SVGGroup }
  7713. */
  7714. Canvas.prototype._createLayer = function(name, index) {
  7715. if (typeof index === 'undefined') {
  7716. index = UTILITY_LAYER_INDEX;
  7717. }
  7718. var childIndex = this._getChildIndex(index);
  7719. return {
  7720. group: createGroup(this._viewport, 'layer-' + name, childIndex),
  7721. index: index,
  7722. visible: true
  7723. };
  7724. };
  7725. /**
  7726. * Shows a given layer.
  7727. *
  7728. * @param {String} layer
  7729. * @returns {SVGElement}
  7730. */
  7731. Canvas.prototype.showLayer = function(name) {
  7732. if (!name) {
  7733. throw new Error('must specify a name');
  7734. }
  7735. var layer = this._layers[name];
  7736. if (!layer) {
  7737. throw new Error('layer <' + name + '> does not exist');
  7738. }
  7739. var viewport = this._viewport;
  7740. var group = layer.group;
  7741. var index = layer.index;
  7742. if (layer.visible) {
  7743. return group;
  7744. }
  7745. var childIndex = this._getChildIndex(index);
  7746. viewport.insertBefore(group, viewport.childNodes[childIndex] || null);
  7747. layer.visible = true;
  7748. return group;
  7749. };
  7750. /**
  7751. * Hides a given layer.
  7752. *
  7753. * @param {String} layer
  7754. * @returns {SVGElement}
  7755. */
  7756. Canvas.prototype.hideLayer = function(name) {
  7757. if (!name) {
  7758. throw new Error('must specify a name');
  7759. }
  7760. var layer = this._layers[name];
  7761. if (!layer) {
  7762. throw new Error('layer <' + name + '> does not exist');
  7763. }
  7764. var group = layer.group;
  7765. if (!layer.visible) {
  7766. return group;
  7767. }
  7768. remove$2(group);
  7769. layer.visible = false;
  7770. return group;
  7771. };
  7772. Canvas.prototype._removeLayer = function(name) {
  7773. var layer = this._layers[name];
  7774. if (layer) {
  7775. delete this._layers[name];
  7776. remove$2(layer.group);
  7777. }
  7778. };
  7779. /**
  7780. * Returns the currently active layer. Can be null.
  7781. *
  7782. * @returns {SVGElement|null}
  7783. */
  7784. Canvas.prototype.getActiveLayer = function() {
  7785. var plane = this._findPlaneForRoot(this.getRootElement());
  7786. if (!plane) {
  7787. return null;
  7788. }
  7789. return plane.layer;
  7790. };
  7791. /**
  7792. * Returns the plane which contains the given element.
  7793. *
  7794. * @param {string|djs.model.Base} element
  7795. *
  7796. * @return {djs.model.Base} root for element
  7797. */
  7798. Canvas.prototype.findRoot = function(element) {
  7799. if (typeof element === 'string') {
  7800. element = this._elementRegistry.get(element);
  7801. }
  7802. if (!element) {
  7803. return;
  7804. }
  7805. var plane = this._findPlaneForRoot(
  7806. findRoot(element)
  7807. ) || {};
  7808. return plane.rootElement;
  7809. };
  7810. /**
  7811. * Return a list of all root elements on the diagram.
  7812. *
  7813. * @return {djs.model.Root[]}
  7814. */
  7815. Canvas.prototype.getRootElements = function() {
  7816. return this._planes.map(function(plane) {
  7817. return plane.rootElement;
  7818. });
  7819. };
  7820. Canvas.prototype._findPlaneForRoot = function(rootElement) {
  7821. return find(this._planes, function(plane) {
  7822. return plane.rootElement === rootElement;
  7823. });
  7824. };
  7825. /**
  7826. * Returns the html element that encloses the
  7827. * drawing canvas.
  7828. *
  7829. * @return {DOMNode}
  7830. */
  7831. Canvas.prototype.getContainer = function() {
  7832. return this._container;
  7833. };
  7834. // markers //////////////////////
  7835. Canvas.prototype._updateMarker = function(element, marker, add) {
  7836. var container;
  7837. if (!element.id) {
  7838. element = this._elementRegistry.get(element);
  7839. }
  7840. // we need to access all
  7841. container = this._elementRegistry._elements[element.id];
  7842. if (!container) {
  7843. return;
  7844. }
  7845. forEach$1([ container.gfx, container.secondaryGfx ], function(gfx) {
  7846. if (gfx) {
  7847. // invoke either addClass or removeClass based on mode
  7848. if (add) {
  7849. classes$1(gfx).add(marker);
  7850. } else {
  7851. classes$1(gfx).remove(marker);
  7852. }
  7853. }
  7854. });
  7855. /**
  7856. * An event indicating that a marker has been updated for an element
  7857. *
  7858. * @event element.marker.update
  7859. * @type {Object}
  7860. * @property {djs.model.Element} element the shape
  7861. * @property {Object} gfx the graphical representation of the shape
  7862. * @property {string} marker
  7863. * @property {boolean} add true if the marker was added, false if it got removed
  7864. */
  7865. this._eventBus.fire('element.marker.update', { element: element, gfx: container.gfx, marker: marker, add: !!add });
  7866. };
  7867. /**
  7868. * Adds a marker to an element (basically a css class).
  7869. *
  7870. * Fires the element.marker.update event, making it possible to
  7871. * integrate extension into the marker life-cycle, too.
  7872. *
  7873. * @example
  7874. * canvas.addMarker('foo', 'some-marker');
  7875. *
  7876. * var fooGfx = canvas.getGraphics('foo');
  7877. *
  7878. * fooGfx; // <g class="... some-marker"> ... </g>
  7879. *
  7880. * @param {string|djs.model.Base} element
  7881. * @param {string} marker
  7882. */
  7883. Canvas.prototype.addMarker = function(element, marker) {
  7884. this._updateMarker(element, marker, true);
  7885. };
  7886. /**
  7887. * Remove a marker from an element.
  7888. *
  7889. * Fires the element.marker.update event, making it possible to
  7890. * integrate extension into the marker life-cycle, too.
  7891. *
  7892. * @param {string|djs.model.Base} element
  7893. * @param {string} marker
  7894. */
  7895. Canvas.prototype.removeMarker = function(element, marker) {
  7896. this._updateMarker(element, marker, false);
  7897. };
  7898. /**
  7899. * Check the existence of a marker on element.
  7900. *
  7901. * @param {string|djs.model.Base} element
  7902. * @param {string} marker
  7903. */
  7904. Canvas.prototype.hasMarker = function(element, marker) {
  7905. if (!element.id) {
  7906. element = this._elementRegistry.get(element);
  7907. }
  7908. var gfx = this.getGraphics(element);
  7909. return classes$1(gfx).has(marker);
  7910. };
  7911. /**
  7912. * Toggles a marker on an element.
  7913. *
  7914. * Fires the element.marker.update event, making it possible to
  7915. * integrate extension into the marker life-cycle, too.
  7916. *
  7917. * @param {string|djs.model.Base} element
  7918. * @param {string} marker
  7919. */
  7920. Canvas.prototype.toggleMarker = function(element, marker) {
  7921. if (this.hasMarker(element, marker)) {
  7922. this.removeMarker(element, marker);
  7923. } else {
  7924. this.addMarker(element, marker);
  7925. }
  7926. };
  7927. /**
  7928. * Returns the current root element.
  7929. *
  7930. * Supports two different modes for handling root elements:
  7931. *
  7932. * 1. if no root element has been added before, an implicit root will be added
  7933. * and returned. This is used in applications that don't require explicit
  7934. * root elements.
  7935. *
  7936. * 2. when root elements have been added before calling `getRootElement`,
  7937. * root elements can be null. This is used for applications that want to manage
  7938. * root elements themselves.
  7939. *
  7940. * @returns {Object|djs.model.Root|null} rootElement.
  7941. */
  7942. Canvas.prototype.getRootElement = function() {
  7943. var rootElement = this._rootElement;
  7944. // can return null if root elements are present but none was set yet
  7945. if (rootElement || this._planes.length) {
  7946. return rootElement;
  7947. }
  7948. return this.setRootElement(this.addRootElement(null));
  7949. };
  7950. /**
  7951. * Adds a given root element and returns it.
  7952. *
  7953. * @param {Object|djs.model.Root} rootElement
  7954. *
  7955. * @return {Object|djs.model.Root} rootElement
  7956. */
  7957. Canvas.prototype.addRootElement = function(rootElement) {
  7958. var idx = this._rootsIdx++;
  7959. if (!rootElement) {
  7960. rootElement = {
  7961. id: '__implicitroot_' + idx,
  7962. children: [],
  7963. isImplicit: true
  7964. };
  7965. }
  7966. var layerName = rootElement.layer = 'root-' + idx;
  7967. this._ensureValid('root', rootElement);
  7968. var layer = this.getLayer(layerName, PLANE_LAYER_INDEX);
  7969. this.hideLayer(layerName);
  7970. this._addRoot(rootElement, layer);
  7971. this._planes.push({
  7972. rootElement: rootElement,
  7973. layer: layer
  7974. });
  7975. return rootElement;
  7976. };
  7977. /**
  7978. * Removes a given rootElement and returns it.
  7979. *
  7980. * @param {djs.model.Root|String} rootElement
  7981. *
  7982. * @return {Object|djs.model.Root} rootElement
  7983. */
  7984. Canvas.prototype.removeRootElement = function(rootElement) {
  7985. if (typeof rootElement === 'string') {
  7986. rootElement = this._elementRegistry.get(rootElement);
  7987. }
  7988. var plane = this._findPlaneForRoot(rootElement);
  7989. if (!plane) {
  7990. return;
  7991. }
  7992. // hook up life-cycle events
  7993. this._removeRoot(rootElement);
  7994. // clean up layer
  7995. this._removeLayer(rootElement.layer);
  7996. // clean up plane
  7997. this._planes = this._planes.filter(function(plane) {
  7998. return plane.rootElement !== rootElement;
  7999. });
  8000. // clean up active root
  8001. if (this._rootElement === rootElement) {
  8002. this._rootElement = null;
  8003. }
  8004. return rootElement;
  8005. };
  8006. // root element handling //////////////////////
  8007. /**
  8008. * Sets a given element as the new root element for the canvas
  8009. * and returns the new root element.
  8010. *
  8011. * @param {Object|djs.model.Root} rootElement
  8012. *
  8013. * @return {Object|djs.model.Root} new root element
  8014. */
  8015. Canvas.prototype.setRootElement = function(rootElement, override) {
  8016. if (isDefined(override)) {
  8017. throw new Error('override not supported');
  8018. }
  8019. if (rootElement === this._rootElement) {
  8020. return;
  8021. }
  8022. var plane;
  8023. if (!rootElement) {
  8024. throw new Error('rootElement required');
  8025. }
  8026. plane = this._findPlaneForRoot(rootElement);
  8027. // give set add semantics for backwards compatibility
  8028. if (!plane) {
  8029. rootElement = this.addRootElement(rootElement);
  8030. }
  8031. this._setRoot(rootElement);
  8032. return rootElement;
  8033. };
  8034. Canvas.prototype._removeRoot = function(element) {
  8035. var elementRegistry = this._elementRegistry,
  8036. eventBus = this._eventBus;
  8037. // simulate element remove event sequence
  8038. eventBus.fire('root.remove', { element: element });
  8039. eventBus.fire('root.removed', { element: element });
  8040. elementRegistry.remove(element);
  8041. };
  8042. Canvas.prototype._addRoot = function(element, gfx) {
  8043. var elementRegistry = this._elementRegistry,
  8044. eventBus = this._eventBus;
  8045. // resemble element add event sequence
  8046. eventBus.fire('root.add', { element: element });
  8047. elementRegistry.add(element, gfx);
  8048. eventBus.fire('root.added', { element: element, gfx: gfx });
  8049. };
  8050. Canvas.prototype._setRoot = function(rootElement, layer) {
  8051. var currentRoot = this._rootElement;
  8052. if (currentRoot) {
  8053. // un-associate previous root element <svg>
  8054. this._elementRegistry.updateGraphics(currentRoot, null, true);
  8055. // hide previous layer
  8056. this.hideLayer(currentRoot.layer);
  8057. }
  8058. if (rootElement) {
  8059. if (!layer) {
  8060. layer = this._findPlaneForRoot(rootElement).layer;
  8061. }
  8062. // associate element with <svg>
  8063. this._elementRegistry.updateGraphics(rootElement, this._svg, true);
  8064. // show root layer
  8065. this.showLayer(rootElement.layer);
  8066. }
  8067. this._rootElement = rootElement;
  8068. this._eventBus.fire('root.set', { element: rootElement });
  8069. };
  8070. // add functionality //////////////////////
  8071. Canvas.prototype._ensureValid = function(type, element) {
  8072. if (!element.id) {
  8073. throw new Error('element must have an id');
  8074. }
  8075. if (this._elementRegistry.get(element.id)) {
  8076. throw new Error('element <' + element.id + '> already exists');
  8077. }
  8078. var requiredAttrs = REQUIRED_MODEL_ATTRS[type];
  8079. var valid = every(requiredAttrs, function(attr) {
  8080. return typeof element[attr] !== 'undefined';
  8081. });
  8082. if (!valid) {
  8083. throw new Error(
  8084. 'must supply { ' + requiredAttrs.join(', ') + ' } with ' + type);
  8085. }
  8086. };
  8087. Canvas.prototype._setParent = function(element, parent, parentIndex) {
  8088. add(parent.children, element, parentIndex);
  8089. element.parent = parent;
  8090. };
  8091. /**
  8092. * Adds an element to the canvas.
  8093. *
  8094. * This wires the parent <-> child relationship between the element and
  8095. * a explicitly specified parent or an implicit root element.
  8096. *
  8097. * During add it emits the events
  8098. *
  8099. * * <{type}.add> (element, parent)
  8100. * * <{type}.added> (element, gfx)
  8101. *
  8102. * Extensions may hook into these events to perform their magic.
  8103. *
  8104. * @param {string} type
  8105. * @param {Object|djs.model.Base} element
  8106. * @param {Object|djs.model.Base} [parent]
  8107. * @param {number} [parentIndex]
  8108. *
  8109. * @return {Object|djs.model.Base} the added element
  8110. */
  8111. Canvas.prototype._addElement = function(type, element, parent, parentIndex) {
  8112. parent = parent || this.getRootElement();
  8113. var eventBus = this._eventBus,
  8114. graphicsFactory = this._graphicsFactory;
  8115. this._ensureValid(type, element);
  8116. eventBus.fire(type + '.add', { element: element, parent: parent });
  8117. this._setParent(element, parent, parentIndex);
  8118. // create graphics
  8119. var gfx = graphicsFactory.create(type, element, parentIndex);
  8120. this._elementRegistry.add(element, gfx);
  8121. // update its visual
  8122. graphicsFactory.update(type, element, gfx);
  8123. eventBus.fire(type + '.added', { element: element, gfx: gfx });
  8124. return element;
  8125. };
  8126. /**
  8127. * Adds a shape to the canvas
  8128. *
  8129. * @param {Object|djs.model.Shape} shape to add to the diagram
  8130. * @param {djs.model.Base} [parent]
  8131. * @param {number} [parentIndex]
  8132. *
  8133. * @return {djs.model.Shape} the added shape
  8134. */
  8135. Canvas.prototype.addShape = function(shape, parent, parentIndex) {
  8136. return this._addElement('shape', shape, parent, parentIndex);
  8137. };
  8138. /**
  8139. * Adds a connection to the canvas
  8140. *
  8141. * @param {Object|djs.model.Connection} connection to add to the diagram
  8142. * @param {djs.model.Base} [parent]
  8143. * @param {number} [parentIndex]
  8144. *
  8145. * @return {djs.model.Connection} the added connection
  8146. */
  8147. Canvas.prototype.addConnection = function(connection, parent, parentIndex) {
  8148. return this._addElement('connection', connection, parent, parentIndex);
  8149. };
  8150. /**
  8151. * Internal remove element
  8152. */
  8153. Canvas.prototype._removeElement = function(element, type) {
  8154. var elementRegistry = this._elementRegistry,
  8155. graphicsFactory = this._graphicsFactory,
  8156. eventBus = this._eventBus;
  8157. element = elementRegistry.get(element.id || element);
  8158. if (!element) {
  8159. // element was removed already
  8160. return;
  8161. }
  8162. eventBus.fire(type + '.remove', { element: element });
  8163. graphicsFactory.remove(element);
  8164. // unset parent <-> child relationship
  8165. remove(element.parent && element.parent.children, element);
  8166. element.parent = null;
  8167. eventBus.fire(type + '.removed', { element: element });
  8168. elementRegistry.remove(element);
  8169. return element;
  8170. };
  8171. /**
  8172. * Removes a shape from the canvas
  8173. *
  8174. * @param {string|djs.model.Shape} shape or shape id to be removed
  8175. *
  8176. * @return {djs.model.Shape} the removed shape
  8177. */
  8178. Canvas.prototype.removeShape = function(shape) {
  8179. /**
  8180. * An event indicating that a shape is about to be removed from the canvas.
  8181. *
  8182. * @memberOf Canvas
  8183. *
  8184. * @event shape.remove
  8185. * @type {Object}
  8186. * @property {djs.model.Shape} element the shape descriptor
  8187. * @property {Object} gfx the graphical representation of the shape
  8188. */
  8189. /**
  8190. * An event indicating that a shape has been removed from the canvas.
  8191. *
  8192. * @memberOf Canvas
  8193. *
  8194. * @event shape.removed
  8195. * @type {Object}
  8196. * @property {djs.model.Shape} element the shape descriptor
  8197. * @property {Object} gfx the graphical representation of the shape
  8198. */
  8199. return this._removeElement(shape, 'shape');
  8200. };
  8201. /**
  8202. * Removes a connection from the canvas
  8203. *
  8204. * @param {string|djs.model.Connection} connection or connection id to be removed
  8205. *
  8206. * @return {djs.model.Connection} the removed connection
  8207. */
  8208. Canvas.prototype.removeConnection = function(connection) {
  8209. /**
  8210. * An event indicating that a connection is about to be removed from the canvas.
  8211. *
  8212. * @memberOf Canvas
  8213. *
  8214. * @event connection.remove
  8215. * @type {Object}
  8216. * @property {djs.model.Connection} element the connection descriptor
  8217. * @property {Object} gfx the graphical representation of the connection
  8218. */
  8219. /**
  8220. * An event indicating that a connection has been removed from the canvas.
  8221. *
  8222. * @memberOf Canvas
  8223. *
  8224. * @event connection.removed
  8225. * @type {Object}
  8226. * @property {djs.model.Connection} element the connection descriptor
  8227. * @property {Object} gfx the graphical representation of the connection
  8228. */
  8229. return this._removeElement(connection, 'connection');
  8230. };
  8231. /**
  8232. * Return the graphical object underlaying a certain diagram element
  8233. *
  8234. * @param {string|djs.model.Base} element descriptor of the element
  8235. * @param {boolean} [secondary=false] whether to return the secondary connected element
  8236. *
  8237. * @return {SVGElement}
  8238. */
  8239. Canvas.prototype.getGraphics = function(element, secondary) {
  8240. return this._elementRegistry.getGraphics(element, secondary);
  8241. };
  8242. /**
  8243. * Perform a viewbox update via a given change function.
  8244. *
  8245. * @param {Function} changeFn
  8246. */
  8247. Canvas.prototype._changeViewbox = function(changeFn) {
  8248. // notify others of the upcoming viewbox change
  8249. this._eventBus.fire('canvas.viewbox.changing');
  8250. // perform actual change
  8251. changeFn.apply(this);
  8252. // reset the cached viewbox so that
  8253. // a new get operation on viewbox or zoom
  8254. // triggers a viewbox re-computation
  8255. this._cachedViewbox = null;
  8256. // notify others of the change; this step
  8257. // may or may not be debounced
  8258. this._viewboxChanged();
  8259. };
  8260. Canvas.prototype._viewboxChanged = function() {
  8261. this._eventBus.fire('canvas.viewbox.changed', { viewbox: this.viewbox() });
  8262. };
  8263. /**
  8264. * Gets or sets the view box of the canvas, i.e. the
  8265. * area that is currently displayed.
  8266. *
  8267. * The getter may return a cached viewbox (if it is currently
  8268. * changing). To force a recomputation, pass `false` as the first argument.
  8269. *
  8270. * @example
  8271. *
  8272. * canvas.viewbox({ x: 100, y: 100, width: 500, height: 500 })
  8273. *
  8274. * // sets the visible area of the diagram to (100|100) -> (600|100)
  8275. * // and and scales it according to the diagram width
  8276. *
  8277. * var viewbox = canvas.viewbox(); // pass `false` to force recomputing the box.
  8278. *
  8279. * console.log(viewbox);
  8280. * // {
  8281. * // inner: Dimensions,
  8282. * // outer: Dimensions,
  8283. * // scale,
  8284. * // x, y,
  8285. * // width, height
  8286. * // }
  8287. *
  8288. * // if the current diagram is zoomed and scrolled, you may reset it to the
  8289. * // default zoom via this method, too:
  8290. *
  8291. * var zoomedAndScrolledViewbox = canvas.viewbox();
  8292. *
  8293. * canvas.viewbox({
  8294. * x: 0,
  8295. * y: 0,
  8296. * width: zoomedAndScrolledViewbox.outer.width,
  8297. * height: zoomedAndScrolledViewbox.outer.height
  8298. * });
  8299. *
  8300. * @param {Object} [box] the new view box to set
  8301. * @param {number} box.x the top left X coordinate of the canvas visible in view box
  8302. * @param {number} box.y the top left Y coordinate of the canvas visible in view box
  8303. * @param {number} box.width the visible width
  8304. * @param {number} box.height
  8305. *
  8306. * @return {Object} the current view box
  8307. */
  8308. Canvas.prototype.viewbox = function(box) {
  8309. if (box === undefined && this._cachedViewbox) {
  8310. return this._cachedViewbox;
  8311. }
  8312. var viewport = this._viewport,
  8313. innerBox,
  8314. outerBox = this.getSize(),
  8315. matrix,
  8316. activeLayer,
  8317. transform,
  8318. scale,
  8319. x, y;
  8320. if (!box) {
  8321. // compute the inner box based on the
  8322. // diagrams active layer. This allows us to exclude
  8323. // external components, such as overlays
  8324. activeLayer = this._rootElement ? this.getActiveLayer() : null;
  8325. innerBox = activeLayer && activeLayer.getBBox() || {};
  8326. transform = transform$1(viewport);
  8327. matrix = transform ? transform.matrix : createMatrix();
  8328. scale = round(matrix.a, 1000);
  8329. x = round(-matrix.e || 0, 1000);
  8330. y = round(-matrix.f || 0, 1000);
  8331. box = this._cachedViewbox = {
  8332. x: x ? x / scale : 0,
  8333. y: y ? y / scale : 0,
  8334. width: outerBox.width / scale,
  8335. height: outerBox.height / scale,
  8336. scale: scale,
  8337. inner: {
  8338. width: innerBox.width || 0,
  8339. height: innerBox.height || 0,
  8340. x: innerBox.x || 0,
  8341. y: innerBox.y || 0
  8342. },
  8343. outer: outerBox
  8344. };
  8345. return box;
  8346. } else {
  8347. this._changeViewbox(function() {
  8348. scale = Math.min(outerBox.width / box.width, outerBox.height / box.height);
  8349. var matrix = this._svg.createSVGMatrix()
  8350. .scale(scale)
  8351. .translate(-box.x, -box.y);
  8352. transform$1(viewport, matrix);
  8353. });
  8354. }
  8355. return box;
  8356. };
  8357. /**
  8358. * Gets or sets the scroll of the canvas.
  8359. *
  8360. * @param {Object} [delta] the new scroll to apply.
  8361. *
  8362. * @param {number} [delta.dx]
  8363. * @param {number} [delta.dy]
  8364. */
  8365. Canvas.prototype.scroll = function(delta) {
  8366. var node = this._viewport;
  8367. var matrix = node.getCTM();
  8368. if (delta) {
  8369. this._changeViewbox(function() {
  8370. delta = assign({ dx: 0, dy: 0 }, delta || {});
  8371. matrix = this._svg.createSVGMatrix().translate(delta.dx, delta.dy).multiply(matrix);
  8372. setCTM(node, matrix);
  8373. });
  8374. }
  8375. return { x: matrix.e, y: matrix.f };
  8376. };
  8377. /**
  8378. * Scrolls the viewbox to contain the given element.
  8379. * Optionally specify a padding to be applied to the edges.
  8380. *
  8381. * @param {Object|String} [element] the element to scroll to.
  8382. * @param {Object|Number} [padding=100] the padding to be applied. Can also specify top, bottom, left and right.
  8383. *
  8384. */
  8385. Canvas.prototype.scrollToElement = function(element, padding) {
  8386. var defaultPadding = 100;
  8387. if (typeof element === 'string') {
  8388. element = this._elementRegistry.get(element);
  8389. }
  8390. // set to correct rootElement
  8391. var rootElement = this.findRoot(element);
  8392. if (rootElement !== this.getRootElement()) {
  8393. this.setRootElement(rootElement);
  8394. }
  8395. if (!padding) {
  8396. padding = {};
  8397. }
  8398. if (typeof padding === 'number') {
  8399. defaultPadding = padding;
  8400. }
  8401. padding = {
  8402. top: padding.top || defaultPadding,
  8403. right: padding.right || defaultPadding,
  8404. bottom: padding.bottom || defaultPadding,
  8405. left: padding.left || defaultPadding
  8406. };
  8407. var elementBounds = getBBox(element),
  8408. elementTrbl = asTRBL(elementBounds),
  8409. viewboxBounds = this.viewbox(),
  8410. zoom = this.zoom(),
  8411. dx, dy;
  8412. // shrink viewboxBounds with padding
  8413. viewboxBounds.y += padding.top / zoom;
  8414. viewboxBounds.x += padding.left / zoom;
  8415. viewboxBounds.width -= (padding.right + padding.left) / zoom;
  8416. viewboxBounds.height -= (padding.bottom + padding.top) / zoom;
  8417. var viewboxTrbl = asTRBL(viewboxBounds);
  8418. var canFit = elementBounds.width < viewboxBounds.width && elementBounds.height < viewboxBounds.height;
  8419. if (!canFit) {
  8420. // top-left when element can't fit
  8421. dx = elementBounds.x - viewboxBounds.x;
  8422. dy = elementBounds.y - viewboxBounds.y;
  8423. } else {
  8424. var dRight = Math.max(0, elementTrbl.right - viewboxTrbl.right),
  8425. dLeft = Math.min(0, elementTrbl.left - viewboxTrbl.left),
  8426. dBottom = Math.max(0, elementTrbl.bottom - viewboxTrbl.bottom),
  8427. dTop = Math.min(0, elementTrbl.top - viewboxTrbl.top);
  8428. dx = dRight || dLeft;
  8429. dy = dBottom || dTop;
  8430. }
  8431. this.scroll({ dx: -dx * zoom, dy: -dy * zoom });
  8432. };
  8433. /**
  8434. * Gets or sets the current zoom of the canvas, optionally zooming
  8435. * to the specified position.
  8436. *
  8437. * The getter may return a cached zoom level. Call it with `false` as
  8438. * the first argument to force recomputation of the current level.
  8439. *
  8440. * @param {string|number} [newScale] the new zoom level, either a number, i.e. 0.9,
  8441. * or `fit-viewport` to adjust the size to fit the current viewport
  8442. * @param {string|Point} [center] the reference point { x: .., y: ..} to zoom to, 'auto' to zoom into mid or null
  8443. *
  8444. * @return {number} the current scale
  8445. */
  8446. Canvas.prototype.zoom = function(newScale, center) {
  8447. if (!newScale) {
  8448. return this.viewbox(newScale).scale;
  8449. }
  8450. if (newScale === 'fit-viewport') {
  8451. return this._fitViewport(center);
  8452. }
  8453. var outer,
  8454. matrix;
  8455. this._changeViewbox(function() {
  8456. if (typeof center !== 'object') {
  8457. outer = this.viewbox().outer;
  8458. center = {
  8459. x: outer.width / 2,
  8460. y: outer.height / 2
  8461. };
  8462. }
  8463. matrix = this._setZoom(newScale, center);
  8464. });
  8465. return round(matrix.a, 1000);
  8466. };
  8467. function setCTM(node, m) {
  8468. var mstr = 'matrix(' + m.a + ',' + m.b + ',' + m.c + ',' + m.d + ',' + m.e + ',' + m.f + ')';
  8469. node.setAttribute('transform', mstr);
  8470. }
  8471. Canvas.prototype._fitViewport = function(center) {
  8472. var vbox = this.viewbox(),
  8473. outer = vbox.outer,
  8474. inner = vbox.inner,
  8475. newScale,
  8476. newViewbox;
  8477. // display the complete diagram without zooming in.
  8478. // instead of relying on internal zoom, we perform a
  8479. // hard reset on the canvas viewbox to realize this
  8480. //
  8481. // if diagram does not need to be zoomed in, we focus it around
  8482. // the diagram origin instead
  8483. if (inner.x >= 0 &&
  8484. inner.y >= 0 &&
  8485. inner.x + inner.width <= outer.width &&
  8486. inner.y + inner.height <= outer.height &&
  8487. !center) {
  8488. newViewbox = {
  8489. x: 0,
  8490. y: 0,
  8491. width: Math.max(inner.width + inner.x, outer.width),
  8492. height: Math.max(inner.height + inner.y, outer.height)
  8493. };
  8494. } else {
  8495. newScale = Math.min(1, outer.width / inner.width, outer.height / inner.height);
  8496. newViewbox = {
  8497. x: inner.x + (center ? inner.width / 2 - outer.width / newScale / 2 : 0),
  8498. y: inner.y + (center ? inner.height / 2 - outer.height / newScale / 2 : 0),
  8499. width: outer.width / newScale,
  8500. height: outer.height / newScale
  8501. };
  8502. }
  8503. this.viewbox(newViewbox);
  8504. return this.viewbox(false).scale;
  8505. };
  8506. Canvas.prototype._setZoom = function(scale, center) {
  8507. var svg = this._svg,
  8508. viewport = this._viewport;
  8509. var matrix = svg.createSVGMatrix();
  8510. var point = svg.createSVGPoint();
  8511. var centerPoint,
  8512. originalPoint,
  8513. currentMatrix,
  8514. scaleMatrix,
  8515. newMatrix;
  8516. currentMatrix = viewport.getCTM();
  8517. var currentScale = currentMatrix.a;
  8518. if (center) {
  8519. centerPoint = assign(point, center);
  8520. // revert applied viewport transformations
  8521. originalPoint = centerPoint.matrixTransform(currentMatrix.inverse());
  8522. // create scale matrix
  8523. scaleMatrix = matrix
  8524. .translate(originalPoint.x, originalPoint.y)
  8525. .scale(1 / currentScale * scale)
  8526. .translate(-originalPoint.x, -originalPoint.y);
  8527. newMatrix = currentMatrix.multiply(scaleMatrix);
  8528. } else {
  8529. newMatrix = matrix.scale(scale);
  8530. }
  8531. setCTM(this._viewport, newMatrix);
  8532. return newMatrix;
  8533. };
  8534. /**
  8535. * Returns the size of the canvas
  8536. *
  8537. * @return {Dimensions}
  8538. */
  8539. Canvas.prototype.getSize = function() {
  8540. return {
  8541. width: this._container.clientWidth,
  8542. height: this._container.clientHeight
  8543. };
  8544. };
  8545. /**
  8546. * Return the absolute bounding box for the given element
  8547. *
  8548. * The absolute bounding box may be used to display overlays in the
  8549. * callers (browser) coordinate system rather than the zoomed in/out
  8550. * canvas coordinates.
  8551. *
  8552. * @param {ElementDescriptor} element
  8553. * @return {Bounds} the absolute bounding box
  8554. */
  8555. Canvas.prototype.getAbsoluteBBox = function(element) {
  8556. var vbox = this.viewbox();
  8557. var bbox;
  8558. // connection
  8559. // use svg bbox
  8560. if (element.waypoints) {
  8561. var gfx = this.getGraphics(element);
  8562. bbox = gfx.getBBox();
  8563. }
  8564. // shapes
  8565. // use data
  8566. else {
  8567. bbox = element;
  8568. }
  8569. var x = bbox.x * vbox.scale - vbox.x * vbox.scale;
  8570. var y = bbox.y * vbox.scale - vbox.y * vbox.scale;
  8571. var width = bbox.width * vbox.scale;
  8572. var height = bbox.height * vbox.scale;
  8573. return {
  8574. x: x,
  8575. y: y,
  8576. width: width,
  8577. height: height
  8578. };
  8579. };
  8580. /**
  8581. * Fires an event in order other modules can react to the
  8582. * canvas resizing
  8583. */
  8584. Canvas.prototype.resized = function() {
  8585. // force recomputation of view box
  8586. delete this._cachedViewbox;
  8587. this._eventBus.fire('canvas.resized');
  8588. };
  8589. var ELEMENT_ID = 'data-element-id';
  8590. /**
  8591. * @class
  8592. *
  8593. * A registry that keeps track of all shapes in the diagram.
  8594. */
  8595. function ElementRegistry(eventBus) {
  8596. this._elements = {};
  8597. this._eventBus = eventBus;
  8598. }
  8599. ElementRegistry.$inject = [ 'eventBus' ];
  8600. /**
  8601. * Register a pair of (element, gfx, (secondaryGfx)).
  8602. *
  8603. * @param {djs.model.Base} element
  8604. * @param {SVGElement} gfx
  8605. * @param {SVGElement} [secondaryGfx] optional other element to register, too
  8606. */
  8607. ElementRegistry.prototype.add = function(element, gfx, secondaryGfx) {
  8608. var id = element.id;
  8609. this._validateId(id);
  8610. // associate dom node with element
  8611. attr$1(gfx, ELEMENT_ID, id);
  8612. if (secondaryGfx) {
  8613. attr$1(secondaryGfx, ELEMENT_ID, id);
  8614. }
  8615. this._elements[id] = { element: element, gfx: gfx, secondaryGfx: secondaryGfx };
  8616. };
  8617. /**
  8618. * Removes an element from the registry.
  8619. *
  8620. * @param {djs.model.Base} element
  8621. */
  8622. ElementRegistry.prototype.remove = function(element) {
  8623. var elements = this._elements,
  8624. id = element.id || element,
  8625. container = id && elements[id];
  8626. if (container) {
  8627. // unset element id on gfx
  8628. attr$1(container.gfx, ELEMENT_ID, '');
  8629. if (container.secondaryGfx) {
  8630. attr$1(container.secondaryGfx, ELEMENT_ID, '');
  8631. }
  8632. delete elements[id];
  8633. }
  8634. };
  8635. /**
  8636. * Update the id of an element
  8637. *
  8638. * @param {djs.model.Base} element
  8639. * @param {string} newId
  8640. */
  8641. ElementRegistry.prototype.updateId = function(element, newId) {
  8642. this._validateId(newId);
  8643. if (typeof element === 'string') {
  8644. element = this.get(element);
  8645. }
  8646. this._eventBus.fire('element.updateId', {
  8647. element: element,
  8648. newId: newId
  8649. });
  8650. var gfx = this.getGraphics(element),
  8651. secondaryGfx = this.getGraphics(element, true);
  8652. this.remove(element);
  8653. element.id = newId;
  8654. this.add(element, gfx, secondaryGfx);
  8655. };
  8656. /**
  8657. * Update the graphics of an element
  8658. *
  8659. * @param {djs.model.Base} element
  8660. * @param {SVGElement} gfx
  8661. * @param {boolean} [secondary=false] whether to update the secondary connected element
  8662. */
  8663. ElementRegistry.prototype.updateGraphics = function(filter, gfx, secondary) {
  8664. var id = filter.id || filter;
  8665. var container = this._elements[id];
  8666. if (secondary) {
  8667. container.secondaryGfx = gfx;
  8668. } else {
  8669. container.gfx = gfx;
  8670. }
  8671. if (gfx) {
  8672. attr$1(gfx, ELEMENT_ID, id);
  8673. }
  8674. return gfx;
  8675. };
  8676. /**
  8677. * Return the model element for a given id or graphics.
  8678. *
  8679. * @example
  8680. *
  8681. * elementRegistry.get('SomeElementId_1');
  8682. * elementRegistry.get(gfx);
  8683. *
  8684. *
  8685. * @param {string|SVGElement} filter for selecting the element
  8686. *
  8687. * @return {djs.model.Base}
  8688. */
  8689. ElementRegistry.prototype.get = function(filter) {
  8690. var id;
  8691. if (typeof filter === 'string') {
  8692. id = filter;
  8693. } else {
  8694. id = filter && attr$1(filter, ELEMENT_ID);
  8695. }
  8696. var container = this._elements[id];
  8697. return container && container.element;
  8698. };
  8699. /**
  8700. * Return all elements that match a given filter function.
  8701. *
  8702. * @param {Function} fn
  8703. *
  8704. * @return {Array<djs.model.Base>}
  8705. */
  8706. ElementRegistry.prototype.filter = function(fn) {
  8707. var filtered = [];
  8708. this.forEach(function(element, gfx) {
  8709. if (fn(element, gfx)) {
  8710. filtered.push(element);
  8711. }
  8712. });
  8713. return filtered;
  8714. };
  8715. /**
  8716. * Return the first element that satisfies the provided testing function.
  8717. *
  8718. * @param {Function} fn
  8719. *
  8720. * @return {djs.model.Base}
  8721. */
  8722. ElementRegistry.prototype.find = function(fn) {
  8723. var map = this._elements,
  8724. keys = Object.keys(map);
  8725. for (var i = 0; i < keys.length; i++) {
  8726. var id = keys[i],
  8727. container = map[id],
  8728. element = container.element,
  8729. gfx = container.gfx;
  8730. if (fn(element, gfx)) {
  8731. return element;
  8732. }
  8733. }
  8734. };
  8735. /**
  8736. * Return all rendered model elements.
  8737. *
  8738. * @return {Array<djs.model.Base>}
  8739. */
  8740. ElementRegistry.prototype.getAll = function() {
  8741. return this.filter(function(e) { return e; });
  8742. };
  8743. /**
  8744. * Iterate over all diagram elements.
  8745. *
  8746. * @param {Function} fn
  8747. */
  8748. ElementRegistry.prototype.forEach = function(fn) {
  8749. var map = this._elements;
  8750. Object.keys(map).forEach(function(id) {
  8751. var container = map[id],
  8752. element = container.element,
  8753. gfx = container.gfx;
  8754. return fn(element, gfx);
  8755. });
  8756. };
  8757. /**
  8758. * Return the graphical representation of an element or its id.
  8759. *
  8760. * @example
  8761. * elementRegistry.getGraphics('SomeElementId_1');
  8762. * elementRegistry.getGraphics(rootElement); // <g ...>
  8763. *
  8764. * elementRegistry.getGraphics(rootElement, true); // <svg ...>
  8765. *
  8766. *
  8767. * @param {string|djs.model.Base} filter
  8768. * @param {boolean} [secondary=false] whether to return the secondary connected element
  8769. *
  8770. * @return {SVGElement}
  8771. */
  8772. ElementRegistry.prototype.getGraphics = function(filter, secondary) {
  8773. var id = filter.id || filter;
  8774. var container = this._elements[id];
  8775. return container && (secondary ? container.secondaryGfx : container.gfx);
  8776. };
  8777. /**
  8778. * Validate the suitability of the given id and signals a problem
  8779. * with an exception.
  8780. *
  8781. * @param {string} id
  8782. *
  8783. * @throws {Error} if id is empty or already assigned
  8784. */
  8785. ElementRegistry.prototype._validateId = function(id) {
  8786. if (!id) {
  8787. throw new Error('element must have an id');
  8788. }
  8789. if (this._elements[id]) {
  8790. throw new Error('element with id ' + id + ' already added');
  8791. }
  8792. };
  8793. var objectRefs = {exports: {}};
  8794. var collection = {};
  8795. /**
  8796. * An empty collection stub. Use {@link RefsCollection.extend} to extend a
  8797. * collection with ref semantics.
  8798. *
  8799. * @class RefsCollection
  8800. */
  8801. /**
  8802. * Extends a collection with {@link Refs} aware methods
  8803. *
  8804. * @memberof RefsCollection
  8805. * @static
  8806. *
  8807. * @param {Array<Object>} collection
  8808. * @param {Refs} refs instance
  8809. * @param {Object} property represented by the collection
  8810. * @param {Object} target object the collection is attached to
  8811. *
  8812. * @return {RefsCollection<Object>} the extended array
  8813. */
  8814. function extend(collection, refs, property, target) {
  8815. var inverseProperty = property.inverse;
  8816. /**
  8817. * Removes the given element from the array and returns it.
  8818. *
  8819. * @method RefsCollection#remove
  8820. *
  8821. * @param {Object} element the element to remove
  8822. */
  8823. Object.defineProperty(collection, 'remove', {
  8824. value: function(element) {
  8825. var idx = this.indexOf(element);
  8826. if (idx !== -1) {
  8827. this.splice(idx, 1);
  8828. // unset inverse
  8829. refs.unset(element, inverseProperty, target);
  8830. }
  8831. return element;
  8832. }
  8833. });
  8834. /**
  8835. * Returns true if the collection contains the given element
  8836. *
  8837. * @method RefsCollection#contains
  8838. *
  8839. * @param {Object} element the element to check for
  8840. */
  8841. Object.defineProperty(collection, 'contains', {
  8842. value: function(element) {
  8843. return this.indexOf(element) !== -1;
  8844. }
  8845. });
  8846. /**
  8847. * Adds an element to the array, unless it exists already (set semantics).
  8848. *
  8849. * @method RefsCollection#add
  8850. *
  8851. * @param {Object} element the element to add
  8852. * @param {Number} optional index to add element to
  8853. * (possibly moving other elements around)
  8854. */
  8855. Object.defineProperty(collection, 'add', {
  8856. value: function(element, idx) {
  8857. var currentIdx = this.indexOf(element);
  8858. if (typeof idx === 'undefined') {
  8859. if (currentIdx !== -1) {
  8860. // element already in collection (!)
  8861. return;
  8862. }
  8863. // add to end of array, as no idx is specified
  8864. idx = this.length;
  8865. }
  8866. // handle already in collection
  8867. if (currentIdx !== -1) {
  8868. // remove element from currentIdx
  8869. this.splice(currentIdx, 1);
  8870. }
  8871. // add element at idx
  8872. this.splice(idx, 0, element);
  8873. if (currentIdx === -1) {
  8874. // set inverse, unless element was
  8875. // in collection already
  8876. refs.set(element, inverseProperty, target);
  8877. }
  8878. }
  8879. });
  8880. // a simple marker, identifying this element
  8881. // as being a refs collection
  8882. Object.defineProperty(collection, '__refs_collection', {
  8883. value: true
  8884. });
  8885. return collection;
  8886. }
  8887. function isExtended(collection) {
  8888. return collection.__refs_collection === true;
  8889. }
  8890. collection.extend = extend;
  8891. collection.isExtended = isExtended;
  8892. var Collection = collection;
  8893. function hasOwnProperty$1(e, property) {
  8894. return Object.prototype.hasOwnProperty.call(e, property.name || property);
  8895. }
  8896. function defineCollectionProperty(ref, property, target) {
  8897. var collection = Collection.extend(target[property.name] || [], ref, property, target);
  8898. Object.defineProperty(target, property.name, {
  8899. enumerable: property.enumerable,
  8900. value: collection
  8901. });
  8902. if (collection.length) {
  8903. collection.forEach(function(o) {
  8904. ref.set(o, property.inverse, target);
  8905. });
  8906. }
  8907. }
  8908. function defineProperty$1(ref, property, target) {
  8909. var inverseProperty = property.inverse;
  8910. var _value = target[property.name];
  8911. Object.defineProperty(target, property.name, {
  8912. configurable: property.configurable,
  8913. enumerable: property.enumerable,
  8914. get: function() {
  8915. return _value;
  8916. },
  8917. set: function(value) {
  8918. // return if we already performed all changes
  8919. if (value === _value) {
  8920. return;
  8921. }
  8922. var old = _value;
  8923. // temporary set null
  8924. _value = null;
  8925. if (old) {
  8926. ref.unset(old, inverseProperty, target);
  8927. }
  8928. // set new value
  8929. _value = value;
  8930. // set inverse value
  8931. ref.set(_value, inverseProperty, target);
  8932. }
  8933. });
  8934. }
  8935. /**
  8936. * Creates a new references object defining two inversly related
  8937. * attribute descriptors a and b.
  8938. *
  8939. * <p>
  8940. * When bound to an object using {@link Refs#bind} the references
  8941. * get activated and ensure that add and remove operations are applied
  8942. * reversely, too.
  8943. * </p>
  8944. *
  8945. * <p>
  8946. * For attributes represented as collections {@link Refs} provides the
  8947. * {@link RefsCollection#add}, {@link RefsCollection#remove} and {@link RefsCollection#contains} extensions
  8948. * that must be used to properly hook into the inverse change mechanism.
  8949. * </p>
  8950. *
  8951. * @class Refs
  8952. *
  8953. * @classdesc A bi-directional reference between two attributes.
  8954. *
  8955. * @param {Refs.AttributeDescriptor} a property descriptor
  8956. * @param {Refs.AttributeDescriptor} b property descriptor
  8957. *
  8958. * @example
  8959. *
  8960. * var refs = Refs({ name: 'wheels', collection: true, enumerable: true }, { name: 'car' });
  8961. *
  8962. * var car = { name: 'toyota' };
  8963. * var wheels = [{ pos: 'front-left' }, { pos: 'front-right' }];
  8964. *
  8965. * refs.bind(car, 'wheels');
  8966. *
  8967. * car.wheels // []
  8968. * car.wheels.add(wheels[0]);
  8969. * car.wheels.add(wheels[1]);
  8970. *
  8971. * car.wheels // [{ pos: 'front-left' }, { pos: 'front-right' }]
  8972. *
  8973. * wheels[0].car // { name: 'toyota' };
  8974. * car.wheels.remove(wheels[0]);
  8975. *
  8976. * wheels[0].car // undefined
  8977. */
  8978. function Refs$1(a, b) {
  8979. if (!(this instanceof Refs$1)) {
  8980. return new Refs$1(a, b);
  8981. }
  8982. // link
  8983. a.inverse = b;
  8984. b.inverse = a;
  8985. this.props = {};
  8986. this.props[a.name] = a;
  8987. this.props[b.name] = b;
  8988. }
  8989. /**
  8990. * Binds one side of a bi-directional reference to a
  8991. * target object.
  8992. *
  8993. * @memberOf Refs
  8994. *
  8995. * @param {Object} target
  8996. * @param {String} property
  8997. */
  8998. Refs$1.prototype.bind = function(target, property) {
  8999. if (typeof property === 'string') {
  9000. if (!this.props[property]) {
  9001. throw new Error('no property <' + property + '> in ref');
  9002. }
  9003. property = this.props[property];
  9004. }
  9005. if (property.collection) {
  9006. defineCollectionProperty(this, property, target);
  9007. } else {
  9008. defineProperty$1(this, property, target);
  9009. }
  9010. };
  9011. Refs$1.prototype.ensureRefsCollection = function(target, property) {
  9012. var collection = target[property.name];
  9013. if (!Collection.isExtended(collection)) {
  9014. defineCollectionProperty(this, property, target);
  9015. }
  9016. return collection;
  9017. };
  9018. Refs$1.prototype.ensureBound = function(target, property) {
  9019. if (!hasOwnProperty$1(target, property)) {
  9020. this.bind(target, property);
  9021. }
  9022. };
  9023. Refs$1.prototype.unset = function(target, property, value) {
  9024. if (target) {
  9025. this.ensureBound(target, property);
  9026. if (property.collection) {
  9027. this.ensureRefsCollection(target, property).remove(value);
  9028. } else {
  9029. target[property.name] = undefined;
  9030. }
  9031. }
  9032. };
  9033. Refs$1.prototype.set = function(target, property, value) {
  9034. if (target) {
  9035. this.ensureBound(target, property);
  9036. if (property.collection) {
  9037. this.ensureRefsCollection(target, property).add(value);
  9038. } else {
  9039. target[property.name] = value;
  9040. }
  9041. }
  9042. };
  9043. var refs = Refs$1;
  9044. objectRefs.exports = refs;
  9045. objectRefs.exports.Collection = collection;
  9046. var Refs = objectRefs.exports;
  9047. var parentRefs = new Refs({ name: 'children', enumerable: true, collection: true }, { name: 'parent' }),
  9048. labelRefs = new Refs({ name: 'labels', enumerable: true, collection: true }, { name: 'labelTarget' }),
  9049. attacherRefs = new Refs({ name: 'attachers', collection: true }, { name: 'host' }),
  9050. outgoingRefs = new Refs({ name: 'outgoing', collection: true }, { name: 'source' }),
  9051. incomingRefs = new Refs({ name: 'incoming', collection: true }, { name: 'target' });
  9052. /**
  9053. * @namespace djs.model
  9054. */
  9055. /**
  9056. * @memberOf djs.model
  9057. */
  9058. /**
  9059. * The basic graphical representation
  9060. *
  9061. * @class
  9062. *
  9063. * @abstract
  9064. */
  9065. function Base$1() {
  9066. /**
  9067. * The object that backs up the shape
  9068. *
  9069. * @name Base#businessObject
  9070. * @type Object
  9071. */
  9072. Object.defineProperty(this, 'businessObject', {
  9073. writable: true
  9074. });
  9075. /**
  9076. * Single label support, will mapped to multi label array
  9077. *
  9078. * @name Base#label
  9079. * @type Object
  9080. */
  9081. Object.defineProperty(this, 'label', {
  9082. get: function() {
  9083. return this.labels[0];
  9084. },
  9085. set: function(newLabel) {
  9086. var label = this.label,
  9087. labels = this.labels;
  9088. if (!newLabel && label) {
  9089. labels.remove(label);
  9090. } else {
  9091. labels.add(newLabel, 0);
  9092. }
  9093. }
  9094. });
  9095. /**
  9096. * The parent shape
  9097. *
  9098. * @name Base#parent
  9099. * @type Shape
  9100. */
  9101. parentRefs.bind(this, 'parent');
  9102. /**
  9103. * The list of labels
  9104. *
  9105. * @name Base#labels
  9106. * @type Label
  9107. */
  9108. labelRefs.bind(this, 'labels');
  9109. /**
  9110. * The list of outgoing connections
  9111. *
  9112. * @name Base#outgoing
  9113. * @type Array<Connection>
  9114. */
  9115. outgoingRefs.bind(this, 'outgoing');
  9116. /**
  9117. * The list of incoming connections
  9118. *
  9119. * @name Base#incoming
  9120. * @type Array<Connection>
  9121. */
  9122. incomingRefs.bind(this, 'incoming');
  9123. }
  9124. /**
  9125. * A graphical object
  9126. *
  9127. * @class
  9128. * @constructor
  9129. *
  9130. * @extends Base
  9131. */
  9132. function Shape() {
  9133. Base$1.call(this);
  9134. /**
  9135. * Indicates frame shapes
  9136. *
  9137. * @name Shape#isFrame
  9138. * @type boolean
  9139. */
  9140. /**
  9141. * The list of children
  9142. *
  9143. * @name Shape#children
  9144. * @type Array<Base>
  9145. */
  9146. parentRefs.bind(this, 'children');
  9147. /**
  9148. * @name Shape#host
  9149. * @type Shape
  9150. */
  9151. attacherRefs.bind(this, 'host');
  9152. /**
  9153. * @name Shape#attachers
  9154. * @type Shape
  9155. */
  9156. attacherRefs.bind(this, 'attachers');
  9157. }
  9158. e(Shape, Base$1);
  9159. /**
  9160. * A root graphical object
  9161. *
  9162. * @class
  9163. * @constructor
  9164. *
  9165. * @extends Shape
  9166. */
  9167. function Root() {
  9168. Shape.call(this);
  9169. }
  9170. e(Root, Shape);
  9171. /**
  9172. * A label for an element
  9173. *
  9174. * @class
  9175. * @constructor
  9176. *
  9177. * @extends Shape
  9178. */
  9179. function Label() {
  9180. Shape.call(this);
  9181. /**
  9182. * The labeled element
  9183. *
  9184. * @name Label#labelTarget
  9185. * @type Base
  9186. */
  9187. labelRefs.bind(this, 'labelTarget');
  9188. }
  9189. e(Label, Shape);
  9190. /**
  9191. * A connection between two elements
  9192. *
  9193. * @class
  9194. * @constructor
  9195. *
  9196. * @extends Base
  9197. */
  9198. function Connection() {
  9199. Base$1.call(this);
  9200. /**
  9201. * The element this connection originates from
  9202. *
  9203. * @name Connection#source
  9204. * @type Base
  9205. */
  9206. outgoingRefs.bind(this, 'source');
  9207. /**
  9208. * The element this connection points to
  9209. *
  9210. * @name Connection#target
  9211. * @type Base
  9212. */
  9213. incomingRefs.bind(this, 'target');
  9214. }
  9215. e(Connection, Base$1);
  9216. var types$6 = {
  9217. connection: Connection,
  9218. shape: Shape,
  9219. label: Label,
  9220. root: Root
  9221. };
  9222. /**
  9223. * Creates a new model element of the specified type
  9224. *
  9225. * @method create
  9226. *
  9227. * @example
  9228. *
  9229. * var shape1 = Model.create('shape', { x: 10, y: 10, width: 100, height: 100 });
  9230. * var shape2 = Model.create('shape', { x: 210, y: 210, width: 100, height: 100 });
  9231. *
  9232. * var connection = Model.create('connection', { waypoints: [ { x: 110, y: 55 }, {x: 210, y: 55 } ] });
  9233. *
  9234. * @param {string} type lower-cased model name
  9235. * @param {Object} attrs attributes to initialize the new model instance with
  9236. *
  9237. * @return {Base} the new model instance
  9238. */
  9239. function create(type, attrs) {
  9240. var Type = types$6[type];
  9241. if (!Type) {
  9242. throw new Error('unknown type: <' + type + '>');
  9243. }
  9244. return assign(new Type(), attrs);
  9245. }
  9246. /**
  9247. * A factory for diagram-js shapes
  9248. */
  9249. function ElementFactory() {
  9250. this._uid = 12;
  9251. }
  9252. ElementFactory.prototype.createRoot = function(attrs) {
  9253. return this.create('root', attrs);
  9254. };
  9255. ElementFactory.prototype.createLabel = function(attrs) {
  9256. return this.create('label', attrs);
  9257. };
  9258. ElementFactory.prototype.createShape = function(attrs) {
  9259. return this.create('shape', attrs);
  9260. };
  9261. ElementFactory.prototype.createConnection = function(attrs) {
  9262. return this.create('connection', attrs);
  9263. };
  9264. /**
  9265. * Create a model element with the given type and
  9266. * a number of pre-set attributes.
  9267. *
  9268. * @param {string} type
  9269. * @param {Object} attrs
  9270. * @return {djs.model.Base} the newly created model instance
  9271. */
  9272. ElementFactory.prototype.create = function(type, attrs) {
  9273. attrs = assign({}, attrs || {});
  9274. if (!attrs.id) {
  9275. attrs.id = type + '_' + (this._uid++);
  9276. }
  9277. return create(type, attrs);
  9278. };
  9279. var FN_REF = '__fn';
  9280. var DEFAULT_PRIORITY = 1000;
  9281. var slice = Array.prototype.slice;
  9282. /**
  9283. * A general purpose event bus.
  9284. *
  9285. * This component is used to communicate across a diagram instance.
  9286. * Other parts of a diagram can use it to listen to and broadcast events.
  9287. *
  9288. *
  9289. * ## Registering for Events
  9290. *
  9291. * The event bus provides the {@link EventBus#on} and {@link EventBus#once}
  9292. * methods to register for events. {@link EventBus#off} can be used to
  9293. * remove event registrations. Listeners receive an instance of {@link Event}
  9294. * as the first argument. It allows them to hook into the event execution.
  9295. *
  9296. * ```javascript
  9297. *
  9298. * // listen for event
  9299. * eventBus.on('foo', function(event) {
  9300. *
  9301. * // access event type
  9302. * event.type; // 'foo'
  9303. *
  9304. * // stop propagation to other listeners
  9305. * event.stopPropagation();
  9306. *
  9307. * // prevent event default
  9308. * event.preventDefault();
  9309. * });
  9310. *
  9311. * // listen for event with custom payload
  9312. * eventBus.on('bar', function(event, payload) {
  9313. * console.log(payload);
  9314. * });
  9315. *
  9316. * // listen for event returning value
  9317. * eventBus.on('foobar', function(event) {
  9318. *
  9319. * // stop event propagation + prevent default
  9320. * return false;
  9321. *
  9322. * // stop event propagation + return custom result
  9323. * return {
  9324. * complex: 'listening result'
  9325. * };
  9326. * });
  9327. *
  9328. *
  9329. * // listen with custom priority (default=1000, higher is better)
  9330. * eventBus.on('priorityfoo', 1500, function(event) {
  9331. * console.log('invoked first!');
  9332. * });
  9333. *
  9334. *
  9335. * // listen for event and pass the context (`this`)
  9336. * eventBus.on('foobar', function(event) {
  9337. * this.foo();
  9338. * }, this);
  9339. * ```
  9340. *
  9341. *
  9342. * ## Emitting Events
  9343. *
  9344. * Events can be emitted via the event bus using {@link EventBus#fire}.
  9345. *
  9346. * ```javascript
  9347. *
  9348. * // false indicates that the default action
  9349. * // was prevented by listeners
  9350. * if (eventBus.fire('foo') === false) {
  9351. * console.log('default has been prevented!');
  9352. * };
  9353. *
  9354. *
  9355. * // custom args + return value listener
  9356. * eventBus.on('sum', function(event, a, b) {
  9357. * return a + b;
  9358. * });
  9359. *
  9360. * // you can pass custom arguments + retrieve result values.
  9361. * var sum = eventBus.fire('sum', 1, 2);
  9362. * console.log(sum); // 3
  9363. * ```
  9364. */
  9365. function EventBus() {
  9366. this._listeners = {};
  9367. // cleanup on destroy on lowest priority to allow
  9368. // message passing until the bitter end
  9369. this.on('diagram.destroy', 1, this._destroy, this);
  9370. }
  9371. /**
  9372. * Register an event listener for events with the given name.
  9373. *
  9374. * The callback will be invoked with `event, ...additionalArguments`
  9375. * that have been passed to {@link EventBus#fire}.
  9376. *
  9377. * Returning false from a listener will prevent the events default action
  9378. * (if any is specified). To stop an event from being processed further in
  9379. * other listeners execute {@link Event#stopPropagation}.
  9380. *
  9381. * Returning anything but `undefined` from a listener will stop the listener propagation.
  9382. *
  9383. * @param {string|Array<string>} events
  9384. * @param {number} [priority=1000] the priority in which this listener is called, larger is higher
  9385. * @param {Function} callback
  9386. * @param {Object} [that] Pass context (`this`) to the callback
  9387. */
  9388. EventBus.prototype.on = function(events, priority, callback, that) {
  9389. events = isArray$2(events) ? events : [ events ];
  9390. if (isFunction(priority)) {
  9391. that = callback;
  9392. callback = priority;
  9393. priority = DEFAULT_PRIORITY;
  9394. }
  9395. if (!isNumber(priority)) {
  9396. throw new Error('priority must be a number');
  9397. }
  9398. var actualCallback = callback;
  9399. if (that) {
  9400. actualCallback = bind(callback, that);
  9401. // make sure we remember and are able to remove
  9402. // bound callbacks via {@link #off} using the original
  9403. // callback
  9404. actualCallback[FN_REF] = callback[FN_REF] || callback;
  9405. }
  9406. var self = this;
  9407. events.forEach(function(e) {
  9408. self._addListener(e, {
  9409. priority: priority,
  9410. callback: actualCallback,
  9411. next: null
  9412. });
  9413. });
  9414. };
  9415. /**
  9416. * Register an event listener that is executed only once.
  9417. *
  9418. * @param {string} event the event name to register for
  9419. * @param {number} [priority=1000] the priority in which this listener is called, larger is higher
  9420. * @param {Function} callback the callback to execute
  9421. * @param {Object} [that] Pass context (`this`) to the callback
  9422. */
  9423. EventBus.prototype.once = function(event, priority, callback, that) {
  9424. var self = this;
  9425. if (isFunction(priority)) {
  9426. that = callback;
  9427. callback = priority;
  9428. priority = DEFAULT_PRIORITY;
  9429. }
  9430. if (!isNumber(priority)) {
  9431. throw new Error('priority must be a number');
  9432. }
  9433. function wrappedCallback() {
  9434. wrappedCallback.__isTomb = true;
  9435. var result = callback.apply(that, arguments);
  9436. self.off(event, wrappedCallback);
  9437. return result;
  9438. }
  9439. // make sure we remember and are able to remove
  9440. // bound callbacks via {@link #off} using the original
  9441. // callback
  9442. wrappedCallback[FN_REF] = callback;
  9443. this.on(event, priority, wrappedCallback);
  9444. };
  9445. /**
  9446. * Removes event listeners by event and callback.
  9447. *
  9448. * If no callback is given, all listeners for a given event name are being removed.
  9449. *
  9450. * @param {string|Array<string>} events
  9451. * @param {Function} [callback]
  9452. */
  9453. EventBus.prototype.off = function(events, callback) {
  9454. events = isArray$2(events) ? events : [ events ];
  9455. var self = this;
  9456. events.forEach(function(event) {
  9457. self._removeListener(event, callback);
  9458. });
  9459. };
  9460. /**
  9461. * Create an EventBus event.
  9462. *
  9463. * @param {Object} data
  9464. *
  9465. * @return {Object} event, recognized by the eventBus
  9466. */
  9467. EventBus.prototype.createEvent = function(data) {
  9468. var event = new InternalEvent();
  9469. event.init(data);
  9470. return event;
  9471. };
  9472. /**
  9473. * Fires a named event.
  9474. *
  9475. * @example
  9476. *
  9477. * // fire event by name
  9478. * events.fire('foo');
  9479. *
  9480. * // fire event object with nested type
  9481. * var event = { type: 'foo' };
  9482. * events.fire(event);
  9483. *
  9484. * // fire event with explicit type
  9485. * var event = { x: 10, y: 20 };
  9486. * events.fire('element.moved', event);
  9487. *
  9488. * // pass additional arguments to the event
  9489. * events.on('foo', function(event, bar) {
  9490. * alert(bar);
  9491. * });
  9492. *
  9493. * events.fire({ type: 'foo' }, 'I am bar!');
  9494. *
  9495. * @param {string} [name] the optional event name
  9496. * @param {Object} [event] the event object
  9497. * @param {...Object} additional arguments to be passed to the callback functions
  9498. *
  9499. * @return {boolean} the events return value, if specified or false if the
  9500. * default action was prevented by listeners
  9501. */
  9502. EventBus.prototype.fire = function(type, data) {
  9503. var event,
  9504. firstListener,
  9505. returnValue,
  9506. args;
  9507. args = slice.call(arguments);
  9508. if (typeof type === 'object') {
  9509. data = type;
  9510. type = data.type;
  9511. }
  9512. if (!type) {
  9513. throw new Error('no event type specified');
  9514. }
  9515. firstListener = this._listeners[type];
  9516. if (!firstListener) {
  9517. return;
  9518. }
  9519. // we make sure we fire instances of our home made
  9520. // events here. We wrap them only once, though
  9521. if (data instanceof InternalEvent) {
  9522. // we are fine, we alread have an event
  9523. event = data;
  9524. } else {
  9525. event = this.createEvent(data);
  9526. }
  9527. // ensure we pass the event as the first parameter
  9528. args[0] = event;
  9529. // original event type (in case we delegate)
  9530. var originalType = event.type;
  9531. // update event type before delegation
  9532. if (type !== originalType) {
  9533. event.type = type;
  9534. }
  9535. try {
  9536. returnValue = this._invokeListeners(event, args, firstListener);
  9537. } finally {
  9538. // reset event type after delegation
  9539. if (type !== originalType) {
  9540. event.type = originalType;
  9541. }
  9542. }
  9543. // set the return value to false if the event default
  9544. // got prevented and no other return value exists
  9545. if (returnValue === undefined && event.defaultPrevented) {
  9546. returnValue = false;
  9547. }
  9548. return returnValue;
  9549. };
  9550. EventBus.prototype.handleError = function(error) {
  9551. return this.fire('error', { error: error }) === false;
  9552. };
  9553. EventBus.prototype._destroy = function() {
  9554. this._listeners = {};
  9555. };
  9556. EventBus.prototype._invokeListeners = function(event, args, listener) {
  9557. var returnValue;
  9558. while (listener) {
  9559. // handle stopped propagation
  9560. if (event.cancelBubble) {
  9561. break;
  9562. }
  9563. returnValue = this._invokeListener(event, args, listener);
  9564. listener = listener.next;
  9565. }
  9566. return returnValue;
  9567. };
  9568. EventBus.prototype._invokeListener = function(event, args, listener) {
  9569. var returnValue;
  9570. if (listener.callback.__isTomb) {
  9571. return returnValue;
  9572. }
  9573. try {
  9574. // returning false prevents the default action
  9575. returnValue = invokeFunction(listener.callback, args);
  9576. // stop propagation on return value
  9577. if (returnValue !== undefined) {
  9578. event.returnValue = returnValue;
  9579. event.stopPropagation();
  9580. }
  9581. // prevent default on return false
  9582. if (returnValue === false) {
  9583. event.preventDefault();
  9584. }
  9585. } catch (error) {
  9586. if (!this.handleError(error)) {
  9587. console.error('unhandled error in event listener', error);
  9588. throw error;
  9589. }
  9590. }
  9591. return returnValue;
  9592. };
  9593. /*
  9594. * Add new listener with a certain priority to the list
  9595. * of listeners (for the given event).
  9596. *
  9597. * The semantics of listener registration / listener execution are
  9598. * first register, first serve: New listeners will always be inserted
  9599. * after existing listeners with the same priority.
  9600. *
  9601. * Example: Inserting two listeners with priority 1000 and 1300
  9602. *
  9603. * * before: [ 1500, 1500, 1000, 1000 ]
  9604. * * after: [ 1500, 1500, (new=1300), 1000, 1000, (new=1000) ]
  9605. *
  9606. * @param {string} event
  9607. * @param {Object} listener { priority, callback }
  9608. */
  9609. EventBus.prototype._addListener = function(event, newListener) {
  9610. var listener = this._getListeners(event),
  9611. previousListener;
  9612. // no prior listeners
  9613. if (!listener) {
  9614. this._setListeners(event, newListener);
  9615. return;
  9616. }
  9617. // ensure we order listeners by priority from
  9618. // 0 (high) to n > 0 (low)
  9619. while (listener) {
  9620. if (listener.priority < newListener.priority) {
  9621. newListener.next = listener;
  9622. if (previousListener) {
  9623. previousListener.next = newListener;
  9624. } else {
  9625. this._setListeners(event, newListener);
  9626. }
  9627. return;
  9628. }
  9629. previousListener = listener;
  9630. listener = listener.next;
  9631. }
  9632. // add new listener to back
  9633. previousListener.next = newListener;
  9634. };
  9635. EventBus.prototype._getListeners = function(name) {
  9636. return this._listeners[name];
  9637. };
  9638. EventBus.prototype._setListeners = function(name, listener) {
  9639. this._listeners[name] = listener;
  9640. };
  9641. EventBus.prototype._removeListener = function(event, callback) {
  9642. var listener = this._getListeners(event),
  9643. nextListener,
  9644. previousListener,
  9645. listenerCallback;
  9646. if (!callback) {
  9647. // clear listeners
  9648. this._setListeners(event, null);
  9649. return;
  9650. }
  9651. while (listener) {
  9652. nextListener = listener.next;
  9653. listenerCallback = listener.callback;
  9654. if (listenerCallback === callback || listenerCallback[FN_REF] === callback) {
  9655. if (previousListener) {
  9656. previousListener.next = nextListener;
  9657. } else {
  9658. // new first listener
  9659. this._setListeners(event, nextListener);
  9660. }
  9661. }
  9662. previousListener = listener;
  9663. listener = nextListener;
  9664. }
  9665. };
  9666. /**
  9667. * A event that is emitted via the event bus.
  9668. */
  9669. function InternalEvent() { }
  9670. InternalEvent.prototype.stopPropagation = function() {
  9671. this.cancelBubble = true;
  9672. };
  9673. InternalEvent.prototype.preventDefault = function() {
  9674. this.defaultPrevented = true;
  9675. };
  9676. InternalEvent.prototype.init = function(data) {
  9677. assign(this, data || {});
  9678. };
  9679. /**
  9680. * Invoke function. Be fast...
  9681. *
  9682. * @param {Function} fn
  9683. * @param {Array<Object>} args
  9684. *
  9685. * @return {Any}
  9686. */
  9687. function invokeFunction(fn, args) {
  9688. return fn.apply(null, args);
  9689. }
  9690. /**
  9691. * SVGs for elements are generated by the {@link GraphicsFactory}.
  9692. *
  9693. * This utility gives quick access to the important semantic
  9694. * parts of an element.
  9695. */
  9696. /**
  9697. * Returns the visual part of a diagram element
  9698. *
  9699. * @param {Snap<SVGElement>} gfx
  9700. *
  9701. * @return {Snap<SVGElement>}
  9702. */
  9703. function getVisual(gfx) {
  9704. return gfx.childNodes[0];
  9705. }
  9706. /**
  9707. * Returns the children for a given diagram element.
  9708. *
  9709. * @param {Snap<SVGElement>} gfx
  9710. * @return {Snap<SVGElement>}
  9711. */
  9712. function getChildren(gfx) {
  9713. return gfx.parentNode.childNodes[1];
  9714. }
  9715. /**
  9716. * A factory that creates graphical elements
  9717. *
  9718. * @param {EventBus} eventBus
  9719. * @param {ElementRegistry} elementRegistry
  9720. */
  9721. function GraphicsFactory(eventBus, elementRegistry) {
  9722. this._eventBus = eventBus;
  9723. this._elementRegistry = elementRegistry;
  9724. }
  9725. GraphicsFactory.$inject = [ 'eventBus' , 'elementRegistry' ];
  9726. GraphicsFactory.prototype._getChildrenContainer = function(element) {
  9727. var gfx = this._elementRegistry.getGraphics(element);
  9728. var childrenGfx;
  9729. // root element
  9730. if (!element.parent) {
  9731. childrenGfx = gfx;
  9732. } else {
  9733. childrenGfx = getChildren(gfx);
  9734. if (!childrenGfx) {
  9735. childrenGfx = create$1('g');
  9736. classes$1(childrenGfx).add('djs-children');
  9737. append(gfx.parentNode, childrenGfx);
  9738. }
  9739. }
  9740. return childrenGfx;
  9741. };
  9742. /**
  9743. * Clears the graphical representation of the element and returns the
  9744. * cleared visual (the <g class="djs-visual" /> element).
  9745. */
  9746. GraphicsFactory.prototype._clear = function(gfx) {
  9747. var visual = getVisual(gfx);
  9748. clear(visual);
  9749. return visual;
  9750. };
  9751. /**
  9752. * Creates a gfx container for shapes and connections
  9753. *
  9754. * The layout is as follows:
  9755. *
  9756. * <g class="djs-group">
  9757. *
  9758. * <!-- the gfx -->
  9759. * <g class="djs-element djs-(shape|connection|frame)">
  9760. * <g class="djs-visual">
  9761. * <!-- the renderer draws in here -->
  9762. * </g>
  9763. *
  9764. * <!-- extensions (overlays, click box, ...) goes here
  9765. * </g>
  9766. *
  9767. * <!-- the gfx child nodes -->
  9768. * <g class="djs-children"></g>
  9769. * </g>
  9770. *
  9771. * @param {string} type the type of the element, i.e. shape | connection
  9772. * @param {SVGElement} [childrenGfx]
  9773. * @param {number} [parentIndex] position to create container in parent
  9774. * @param {boolean} [isFrame] is frame element
  9775. *
  9776. * @return {SVGElement}
  9777. */
  9778. GraphicsFactory.prototype._createContainer = function(
  9779. type, childrenGfx, parentIndex, isFrame
  9780. ) {
  9781. var outerGfx = create$1('g');
  9782. classes$1(outerGfx).add('djs-group');
  9783. // insert node at position
  9784. if (typeof parentIndex !== 'undefined') {
  9785. prependTo(outerGfx, childrenGfx, childrenGfx.childNodes[parentIndex]);
  9786. } else {
  9787. append(childrenGfx, outerGfx);
  9788. }
  9789. var gfx = create$1('g');
  9790. classes$1(gfx).add('djs-element');
  9791. classes$1(gfx).add('djs-' + type);
  9792. if (isFrame) {
  9793. classes$1(gfx).add('djs-frame');
  9794. }
  9795. append(outerGfx, gfx);
  9796. // create visual
  9797. var visual = create$1('g');
  9798. classes$1(visual).add('djs-visual');
  9799. append(gfx, visual);
  9800. return gfx;
  9801. };
  9802. GraphicsFactory.prototype.create = function(type, element, parentIndex) {
  9803. var childrenGfx = this._getChildrenContainer(element.parent);
  9804. return this._createContainer(type, childrenGfx, parentIndex, isFrameElement(element));
  9805. };
  9806. GraphicsFactory.prototype.updateContainments = function(elements) {
  9807. var self = this,
  9808. elementRegistry = this._elementRegistry,
  9809. parents;
  9810. parents = reduce(elements, function(map, e) {
  9811. if (e.parent) {
  9812. map[e.parent.id] = e.parent;
  9813. }
  9814. return map;
  9815. }, {});
  9816. // update all parents of changed and reorganized their children
  9817. // in the correct order (as indicated in our model)
  9818. forEach$1(parents, function(parent) {
  9819. var children = parent.children;
  9820. if (!children) {
  9821. return;
  9822. }
  9823. var childrenGfx = self._getChildrenContainer(parent);
  9824. forEach$1(children.slice().reverse(), function(child) {
  9825. var childGfx = elementRegistry.getGraphics(child);
  9826. prependTo(childGfx.parentNode, childrenGfx);
  9827. });
  9828. });
  9829. };
  9830. GraphicsFactory.prototype.drawShape = function(visual, element) {
  9831. var eventBus = this._eventBus;
  9832. return eventBus.fire('render.shape', { gfx: visual, element: element });
  9833. };
  9834. GraphicsFactory.prototype.getShapePath = function(element) {
  9835. var eventBus = this._eventBus;
  9836. return eventBus.fire('render.getShapePath', element);
  9837. };
  9838. GraphicsFactory.prototype.drawConnection = function(visual, element) {
  9839. var eventBus = this._eventBus;
  9840. return eventBus.fire('render.connection', { gfx: visual, element: element });
  9841. };
  9842. GraphicsFactory.prototype.getConnectionPath = function(waypoints) {
  9843. var eventBus = this._eventBus;
  9844. return eventBus.fire('render.getConnectionPath', waypoints);
  9845. };
  9846. GraphicsFactory.prototype.update = function(type, element, gfx) {
  9847. // do NOT update root element
  9848. if (!element.parent) {
  9849. return;
  9850. }
  9851. var visual = this._clear(gfx);
  9852. // redraw
  9853. if (type === 'shape') {
  9854. this.drawShape(visual, element);
  9855. // update positioning
  9856. translate$1(gfx, element.x, element.y);
  9857. } else
  9858. if (type === 'connection') {
  9859. this.drawConnection(visual, element);
  9860. } else {
  9861. throw new Error('unknown type: ' + type);
  9862. }
  9863. if (element.hidden) {
  9864. attr$1(gfx, 'display', 'none');
  9865. } else {
  9866. attr$1(gfx, 'display', 'block');
  9867. }
  9868. };
  9869. GraphicsFactory.prototype.remove = function(element) {
  9870. var gfx = this._elementRegistry.getGraphics(element);
  9871. // remove
  9872. remove$2(gfx.parentNode);
  9873. };
  9874. // helpers //////////
  9875. function prependTo(newNode, parentNode, siblingNode) {
  9876. var node = siblingNode || parentNode.firstChild;
  9877. // do not prepend node to itself to prevent IE from crashing
  9878. // https://github.com/bpmn-io/bpmn-js/issues/746
  9879. if (newNode === node) {
  9880. return;
  9881. }
  9882. parentNode.insertBefore(newNode, node);
  9883. }
  9884. var CoreModule = {
  9885. __depends__: [ DrawModule ],
  9886. __init__: [ 'canvas' ],
  9887. canvas: [ 'type', Canvas ],
  9888. elementRegistry: [ 'type', ElementRegistry ],
  9889. elementFactory: [ 'type', ElementFactory ],
  9890. eventBus: [ 'type', EventBus ],
  9891. graphicsFactory: [ 'type', GraphicsFactory ]
  9892. };
  9893. /**
  9894. * @typedef { import('didi').ModuleDeclaration } Module
  9895. */
  9896. /**
  9897. * Bootstrap an injector from a list of modules, instantiating a number of default components
  9898. *
  9899. * @param {Array<Module>} modules
  9900. *
  9901. * @return {Injector} a injector to use to access the components
  9902. */
  9903. function bootstrap(modules) {
  9904. var injector = new Injector(modules);
  9905. injector.init();
  9906. return injector;
  9907. }
  9908. /**
  9909. * Creates an injector from passed options.
  9910. *
  9911. * @param {Object} options
  9912. * @return {Injector}
  9913. */
  9914. function createInjector(options) {
  9915. options = options || {};
  9916. var configModule = {
  9917. 'config': [ 'value', options ]
  9918. };
  9919. var modules = [ configModule, CoreModule ].concat(options.modules || []);
  9920. return bootstrap(modules);
  9921. }
  9922. /**
  9923. * The main diagram-js entry point that bootstraps the diagram with the given
  9924. * configuration.
  9925. *
  9926. * To register extensions with the diagram, pass them as Array<Module> to the constructor.
  9927. *
  9928. * @class djs.Diagram
  9929. * @memberOf djs
  9930. * @constructor
  9931. *
  9932. * @example
  9933. *
  9934. * <caption>Creating a plug-in that logs whenever a shape is added to the canvas.</caption>
  9935. *
  9936. * // plug-in implemenentation
  9937. * function MyLoggingPlugin(eventBus) {
  9938. * eventBus.on('shape.added', function(event) {
  9939. * console.log('shape ', event.shape, ' was added to the diagram');
  9940. * });
  9941. * }
  9942. *
  9943. * // export as module
  9944. * export default {
  9945. * __init__: [ 'myLoggingPlugin' ],
  9946. * myLoggingPlugin: [ 'type', MyLoggingPlugin ]
  9947. * };
  9948. *
  9949. *
  9950. * // instantiate the diagram with the new plug-in
  9951. *
  9952. * import MyLoggingModule from 'path-to-my-logging-plugin';
  9953. *
  9954. * var diagram = new Diagram({
  9955. * modules: [
  9956. * MyLoggingModule
  9957. * ]
  9958. * });
  9959. *
  9960. * diagram.invoke([ 'canvas', function(canvas) {
  9961. * // add shape to drawing canvas
  9962. * canvas.addShape({ x: 10, y: 10 });
  9963. * });
  9964. *
  9965. * // 'shape ... was added to the diagram' logged to console
  9966. *
  9967. * @param {Object} options
  9968. * @param {Array<Module>} [options.modules] external modules to instantiate with the diagram
  9969. * @param {Injector} [injector] an (optional) injector to bootstrap the diagram with
  9970. */
  9971. function Diagram(options, injector) {
  9972. // create injector unless explicitly specified
  9973. this.injector = injector = injector || createInjector(options);
  9974. // API
  9975. /**
  9976. * Resolves a diagram service
  9977. *
  9978. * @method Diagram#get
  9979. *
  9980. * @param {string} name the name of the diagram service to be retrieved
  9981. * @param {boolean} [strict=true] if false, resolve missing services to null
  9982. */
  9983. this.get = injector.get;
  9984. /**
  9985. * Executes a function into which diagram services are injected
  9986. *
  9987. * @method Diagram#invoke
  9988. *
  9989. * @param {Function|Object[]} fn the function to resolve
  9990. * @param {Object} locals a number of locals to use to resolve certain dependencies
  9991. */
  9992. this.invoke = injector.invoke;
  9993. // init
  9994. // indicate via event
  9995. /**
  9996. * An event indicating that all plug-ins are loaded.
  9997. *
  9998. * Use this event to fire other events to interested plug-ins
  9999. *
  10000. * @memberOf Diagram
  10001. *
  10002. * @event diagram.init
  10003. *
  10004. * @example
  10005. *
  10006. * eventBus.on('diagram.init', function() {
  10007. * eventBus.fire('my-custom-event', { foo: 'BAR' });
  10008. * });
  10009. *
  10010. * @type {Object}
  10011. */
  10012. this.get('eventBus').fire('diagram.init');
  10013. }
  10014. /**
  10015. * Destroys the diagram
  10016. *
  10017. * @method Diagram#destroy
  10018. */
  10019. Diagram.prototype.destroy = function() {
  10020. this.get('eventBus').fire('diagram.destroy');
  10021. };
  10022. /**
  10023. * Clear the diagram, removing all contents.
  10024. */
  10025. Diagram.prototype.clear = function() {
  10026. this.get('eventBus').fire('diagram.clear');
  10027. };
  10028. /**
  10029. * Moddle base element.
  10030. */
  10031. function Base() { }
  10032. Base.prototype.get = function(name) {
  10033. return this.$model.properties.get(this, name);
  10034. };
  10035. Base.prototype.set = function(name, value) {
  10036. this.$model.properties.set(this, name, value);
  10037. };
  10038. /**
  10039. * A model element factory.
  10040. *
  10041. * @param {Moddle} model
  10042. * @param {Properties} properties
  10043. */
  10044. function Factory(model, properties) {
  10045. this.model = model;
  10046. this.properties = properties;
  10047. }
  10048. Factory.prototype.createType = function(descriptor) {
  10049. var model = this.model;
  10050. var props = this.properties,
  10051. prototype = Object.create(Base.prototype);
  10052. // initialize default values
  10053. forEach$1(descriptor.properties, function(p) {
  10054. if (!p.isMany && p.default !== undefined) {
  10055. prototype[p.name] = p.default;
  10056. }
  10057. });
  10058. props.defineModel(prototype, model);
  10059. props.defineDescriptor(prototype, descriptor);
  10060. var name = descriptor.ns.name;
  10061. /**
  10062. * The new type constructor
  10063. */
  10064. function ModdleElement(attrs) {
  10065. props.define(this, '$type', { value: name, enumerable: true });
  10066. props.define(this, '$attrs', { value: {} });
  10067. props.define(this, '$parent', { writable: true });
  10068. forEach$1(attrs, bind(function(val, key) {
  10069. this.set(key, val);
  10070. }, this));
  10071. }
  10072. ModdleElement.prototype = prototype;
  10073. ModdleElement.hasType = prototype.$instanceOf = this.model.hasType;
  10074. // static links
  10075. props.defineModel(ModdleElement, model);
  10076. props.defineDescriptor(ModdleElement, descriptor);
  10077. return ModdleElement;
  10078. };
  10079. /**
  10080. * Built-in moddle types
  10081. */
  10082. var BUILTINS = {
  10083. String: true,
  10084. Boolean: true,
  10085. Integer: true,
  10086. Real: true,
  10087. Element: true
  10088. };
  10089. /**
  10090. * Converters for built in types from string representations
  10091. */
  10092. var TYPE_CONVERTERS = {
  10093. String: function(s) { return s; },
  10094. Boolean: function(s) { return s === 'true'; },
  10095. Integer: function(s) { return parseInt(s, 10); },
  10096. Real: function(s) { return parseFloat(s); }
  10097. };
  10098. /**
  10099. * Convert a type to its real representation
  10100. */
  10101. function coerceType(type, value) {
  10102. var converter = TYPE_CONVERTERS[type];
  10103. if (converter) {
  10104. return converter(value);
  10105. } else {
  10106. return value;
  10107. }
  10108. }
  10109. /**
  10110. * Return whether the given type is built-in
  10111. */
  10112. function isBuiltIn(type) {
  10113. return !!BUILTINS[type];
  10114. }
  10115. /**
  10116. * Return whether the given type is simple
  10117. */
  10118. function isSimple(type) {
  10119. return !!TYPE_CONVERTERS[type];
  10120. }
  10121. /**
  10122. * Parses a namespaced attribute name of the form (ns:)localName to an object,
  10123. * given a default prefix to assume in case no explicit namespace is given.
  10124. *
  10125. * @param {String} name
  10126. * @param {String} [defaultPrefix] the default prefix to take, if none is present.
  10127. *
  10128. * @return {Object} the parsed name
  10129. */
  10130. function parseName(name, defaultPrefix) {
  10131. var parts = name.split(/:/),
  10132. localName, prefix;
  10133. // no prefix (i.e. only local name)
  10134. if (parts.length === 1) {
  10135. localName = name;
  10136. prefix = defaultPrefix;
  10137. } else
  10138. // prefix + local name
  10139. if (parts.length === 2) {
  10140. localName = parts[1];
  10141. prefix = parts[0];
  10142. } else {
  10143. throw new Error('expected <prefix:localName> or <localName>, got ' + name);
  10144. }
  10145. name = (prefix ? prefix + ':' : '') + localName;
  10146. return {
  10147. name: name,
  10148. prefix: prefix,
  10149. localName: localName
  10150. };
  10151. }
  10152. /**
  10153. * A utility to build element descriptors.
  10154. */
  10155. function DescriptorBuilder(nameNs) {
  10156. this.ns = nameNs;
  10157. this.name = nameNs.name;
  10158. this.allTypes = [];
  10159. this.allTypesByName = {};
  10160. this.properties = [];
  10161. this.propertiesByName = {};
  10162. }
  10163. DescriptorBuilder.prototype.build = function() {
  10164. return pick(this, [
  10165. 'ns',
  10166. 'name',
  10167. 'allTypes',
  10168. 'allTypesByName',
  10169. 'properties',
  10170. 'propertiesByName',
  10171. 'bodyProperty',
  10172. 'idProperty'
  10173. ]);
  10174. };
  10175. /**
  10176. * Add property at given index.
  10177. *
  10178. * @param {Object} p
  10179. * @param {Number} [idx]
  10180. * @param {Boolean} [validate=true]
  10181. */
  10182. DescriptorBuilder.prototype.addProperty = function(p, idx, validate) {
  10183. if (typeof idx === 'boolean') {
  10184. validate = idx;
  10185. idx = undefined;
  10186. }
  10187. this.addNamedProperty(p, validate !== false);
  10188. var properties = this.properties;
  10189. if (idx !== undefined) {
  10190. properties.splice(idx, 0, p);
  10191. } else {
  10192. properties.push(p);
  10193. }
  10194. };
  10195. DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty, replace) {
  10196. var oldNameNs = oldProperty.ns;
  10197. var props = this.properties,
  10198. propertiesByName = this.propertiesByName,
  10199. rename = oldProperty.name !== newProperty.name;
  10200. if (oldProperty.isId) {
  10201. if (!newProperty.isId) {
  10202. throw new Error(
  10203. 'property <' + newProperty.ns.name + '> must be id property ' +
  10204. 'to refine <' + oldProperty.ns.name + '>');
  10205. }
  10206. this.setIdProperty(newProperty, false);
  10207. }
  10208. if (oldProperty.isBody) {
  10209. if (!newProperty.isBody) {
  10210. throw new Error(
  10211. 'property <' + newProperty.ns.name + '> must be body property ' +
  10212. 'to refine <' + oldProperty.ns.name + '>');
  10213. }
  10214. // TODO: Check compatibility
  10215. this.setBodyProperty(newProperty, false);
  10216. }
  10217. // validate existence and get location of old property
  10218. var idx = props.indexOf(oldProperty);
  10219. if (idx === -1) {
  10220. throw new Error('property <' + oldNameNs.name + '> not found in property list');
  10221. }
  10222. // remove old property
  10223. props.splice(idx, 1);
  10224. // replacing the named property is intentional
  10225. //
  10226. // * validate only if this is a "rename" operation
  10227. // * add at specific index unless we "replace"
  10228. //
  10229. this.addProperty(newProperty, replace ? undefined : idx, rename);
  10230. // make new property available under old name
  10231. propertiesByName[oldNameNs.name] = propertiesByName[oldNameNs.localName] = newProperty;
  10232. };
  10233. DescriptorBuilder.prototype.redefineProperty = function(p, targetPropertyName, replace) {
  10234. var nsPrefix = p.ns.prefix;
  10235. var parts = targetPropertyName.split('#');
  10236. var name = parseName(parts[0], nsPrefix);
  10237. var attrName = parseName(parts[1], name.prefix).name;
  10238. var redefinedProperty = this.propertiesByName[attrName];
  10239. if (!redefinedProperty) {
  10240. throw new Error('refined property <' + attrName + '> not found');
  10241. } else {
  10242. this.replaceProperty(redefinedProperty, p, replace);
  10243. }
  10244. delete p.redefines;
  10245. };
  10246. DescriptorBuilder.prototype.addNamedProperty = function(p, validate) {
  10247. var ns = p.ns,
  10248. propsByName = this.propertiesByName;
  10249. if (validate) {
  10250. this.assertNotDefined(p, ns.name);
  10251. this.assertNotDefined(p, ns.localName);
  10252. }
  10253. propsByName[ns.name] = propsByName[ns.localName] = p;
  10254. };
  10255. DescriptorBuilder.prototype.removeNamedProperty = function(p) {
  10256. var ns = p.ns,
  10257. propsByName = this.propertiesByName;
  10258. delete propsByName[ns.name];
  10259. delete propsByName[ns.localName];
  10260. };
  10261. DescriptorBuilder.prototype.setBodyProperty = function(p, validate) {
  10262. if (validate && this.bodyProperty) {
  10263. throw new Error(
  10264. 'body property defined multiple times ' +
  10265. '(<' + this.bodyProperty.ns.name + '>, <' + p.ns.name + '>)');
  10266. }
  10267. this.bodyProperty = p;
  10268. };
  10269. DescriptorBuilder.prototype.setIdProperty = function(p, validate) {
  10270. if (validate && this.idProperty) {
  10271. throw new Error(
  10272. 'id property defined multiple times ' +
  10273. '(<' + this.idProperty.ns.name + '>, <' + p.ns.name + '>)');
  10274. }
  10275. this.idProperty = p;
  10276. };
  10277. DescriptorBuilder.prototype.assertNotDefined = function(p, name) {
  10278. var propertyName = p.name,
  10279. definedProperty = this.propertiesByName[propertyName];
  10280. if (definedProperty) {
  10281. throw new Error(
  10282. 'property <' + propertyName + '> already defined; ' +
  10283. 'override of <' + definedProperty.definedBy.ns.name + '#' + definedProperty.ns.name + '> by ' +
  10284. '<' + p.definedBy.ns.name + '#' + p.ns.name + '> not allowed without redefines');
  10285. }
  10286. };
  10287. DescriptorBuilder.prototype.hasProperty = function(name) {
  10288. return this.propertiesByName[name];
  10289. };
  10290. DescriptorBuilder.prototype.addTrait = function(t, inherited) {
  10291. var typesByName = this.allTypesByName,
  10292. types = this.allTypes;
  10293. var typeName = t.name;
  10294. if (typeName in typesByName) {
  10295. return;
  10296. }
  10297. forEach$1(t.properties, bind(function(p) {
  10298. // clone property to allow extensions
  10299. p = assign({}, p, {
  10300. name: p.ns.localName,
  10301. inherited: inherited
  10302. });
  10303. Object.defineProperty(p, 'definedBy', {
  10304. value: t
  10305. });
  10306. var replaces = p.replaces,
  10307. redefines = p.redefines;
  10308. // add replace/redefine support
  10309. if (replaces || redefines) {
  10310. this.redefineProperty(p, replaces || redefines, replaces);
  10311. } else {
  10312. if (p.isBody) {
  10313. this.setBodyProperty(p);
  10314. }
  10315. if (p.isId) {
  10316. this.setIdProperty(p);
  10317. }
  10318. this.addProperty(p);
  10319. }
  10320. }, this));
  10321. types.push(t);
  10322. typesByName[typeName] = t;
  10323. };
  10324. /**
  10325. * A registry of Moddle packages.
  10326. *
  10327. * @param {Array<Package>} packages
  10328. * @param {Properties} properties
  10329. */
  10330. function Registry(packages, properties) {
  10331. this.packageMap = {};
  10332. this.typeMap = {};
  10333. this.packages = [];
  10334. this.properties = properties;
  10335. forEach$1(packages, bind(this.registerPackage, this));
  10336. }
  10337. Registry.prototype.getPackage = function(uriOrPrefix) {
  10338. return this.packageMap[uriOrPrefix];
  10339. };
  10340. Registry.prototype.getPackages = function() {
  10341. return this.packages;
  10342. };
  10343. Registry.prototype.registerPackage = function(pkg) {
  10344. // copy package
  10345. pkg = assign({}, pkg);
  10346. var pkgMap = this.packageMap;
  10347. ensureAvailable(pkgMap, pkg, 'prefix');
  10348. ensureAvailable(pkgMap, pkg, 'uri');
  10349. // register types
  10350. forEach$1(pkg.types, bind(function(descriptor) {
  10351. this.registerType(descriptor, pkg);
  10352. }, this));
  10353. pkgMap[pkg.uri] = pkgMap[pkg.prefix] = pkg;
  10354. this.packages.push(pkg);
  10355. };
  10356. /**
  10357. * Register a type from a specific package with us
  10358. */
  10359. Registry.prototype.registerType = function(type, pkg) {
  10360. type = assign({}, type, {
  10361. superClass: (type.superClass || []).slice(),
  10362. extends: (type.extends || []).slice(),
  10363. properties: (type.properties || []).slice(),
  10364. meta: assign((type.meta || {}))
  10365. });
  10366. var ns = parseName(type.name, pkg.prefix),
  10367. name = ns.name,
  10368. propertiesByName = {};
  10369. // parse properties
  10370. forEach$1(type.properties, bind(function(p) {
  10371. // namespace property names
  10372. var propertyNs = parseName(p.name, ns.prefix),
  10373. propertyName = propertyNs.name;
  10374. // namespace property types
  10375. if (!isBuiltIn(p.type)) {
  10376. p.type = parseName(p.type, propertyNs.prefix).name;
  10377. }
  10378. assign(p, {
  10379. ns: propertyNs,
  10380. name: propertyName
  10381. });
  10382. propertiesByName[propertyName] = p;
  10383. }, this));
  10384. // update ns + name
  10385. assign(type, {
  10386. ns: ns,
  10387. name: name,
  10388. propertiesByName: propertiesByName
  10389. });
  10390. forEach$1(type.extends, bind(function(extendsName) {
  10391. var extended = this.typeMap[extendsName];
  10392. extended.traits = extended.traits || [];
  10393. extended.traits.push(name);
  10394. }, this));
  10395. // link to package
  10396. this.definePackage(type, pkg);
  10397. // register
  10398. this.typeMap[name] = type;
  10399. };
  10400. /**
  10401. * Traverse the type hierarchy from bottom to top,
  10402. * calling iterator with (type, inherited) for all elements in
  10403. * the inheritance chain.
  10404. *
  10405. * @param {Object} nsName
  10406. * @param {Function} iterator
  10407. * @param {Boolean} [trait=false]
  10408. */
  10409. Registry.prototype.mapTypes = function(nsName, iterator, trait) {
  10410. var type = isBuiltIn(nsName.name) ? { name: nsName.name } : this.typeMap[nsName.name];
  10411. var self = this;
  10412. /**
  10413. * Traverse the selected trait.
  10414. *
  10415. * @param {String} cls
  10416. */
  10417. function traverseTrait(cls) {
  10418. return traverseSuper(cls, true);
  10419. }
  10420. /**
  10421. * Traverse the selected super type or trait
  10422. *
  10423. * @param {String} cls
  10424. * @param {Boolean} [trait=false]
  10425. */
  10426. function traverseSuper(cls, trait) {
  10427. var parentNs = parseName(cls, isBuiltIn(cls) ? '' : nsName.prefix);
  10428. self.mapTypes(parentNs, iterator, trait);
  10429. }
  10430. if (!type) {
  10431. throw new Error('unknown type <' + nsName.name + '>');
  10432. }
  10433. forEach$1(type.superClass, trait ? traverseTrait : traverseSuper);
  10434. // call iterator with (type, inherited=!trait)
  10435. iterator(type, !trait);
  10436. forEach$1(type.traits, traverseTrait);
  10437. };
  10438. /**
  10439. * Returns the effective descriptor for a type.
  10440. *
  10441. * @param {String} type the namespaced name (ns:localName) of the type
  10442. *
  10443. * @return {Descriptor} the resulting effective descriptor
  10444. */
  10445. Registry.prototype.getEffectiveDescriptor = function(name) {
  10446. var nsName = parseName(name);
  10447. var builder = new DescriptorBuilder(nsName);
  10448. this.mapTypes(nsName, function(type, inherited) {
  10449. builder.addTrait(type, inherited);
  10450. });
  10451. var descriptor = builder.build();
  10452. // define package link
  10453. this.definePackage(descriptor, descriptor.allTypes[descriptor.allTypes.length - 1].$pkg);
  10454. return descriptor;
  10455. };
  10456. Registry.prototype.definePackage = function(target, pkg) {
  10457. this.properties.define(target, '$pkg', { value: pkg });
  10458. };
  10459. ///////// helpers ////////////////////////////
  10460. function ensureAvailable(packageMap, pkg, identifierKey) {
  10461. var value = pkg[identifierKey];
  10462. if (value in packageMap) {
  10463. throw new Error('package with ' + identifierKey + ' <' + value + '> already defined');
  10464. }
  10465. }
  10466. /**
  10467. * A utility that gets and sets properties of model elements.
  10468. *
  10469. * @param {Model} model
  10470. */
  10471. function Properties(model) {
  10472. this.model = model;
  10473. }
  10474. /**
  10475. * Sets a named property on the target element.
  10476. * If the value is undefined, the property gets deleted.
  10477. *
  10478. * @param {Object} target
  10479. * @param {String} name
  10480. * @param {Object} value
  10481. */
  10482. Properties.prototype.set = function(target, name, value) {
  10483. var property = this.model.getPropertyDescriptor(target, name);
  10484. var propertyName = property && property.name;
  10485. if (isUndefined(value)) {
  10486. // unset the property, if the specified value is undefined;
  10487. // delete from $attrs (for extensions) or the target itself
  10488. if (property) {
  10489. delete target[propertyName];
  10490. } else {
  10491. delete target.$attrs[name];
  10492. }
  10493. } else {
  10494. // set the property, defining well defined properties on the fly
  10495. // or simply updating them in target.$attrs (for extensions)
  10496. if (property) {
  10497. if (propertyName in target) {
  10498. target[propertyName] = value;
  10499. } else {
  10500. defineProperty(target, property, value);
  10501. }
  10502. } else {
  10503. target.$attrs[name] = value;
  10504. }
  10505. }
  10506. };
  10507. /**
  10508. * Returns the named property of the given element
  10509. *
  10510. * @param {Object} target
  10511. * @param {String} name
  10512. *
  10513. * @return {Object}
  10514. */
  10515. Properties.prototype.get = function(target, name) {
  10516. var property = this.model.getPropertyDescriptor(target, name);
  10517. if (!property) {
  10518. return target.$attrs[name];
  10519. }
  10520. var propertyName = property.name;
  10521. // check if access to collection property and lazily initialize it
  10522. if (!target[propertyName] && property.isMany) {
  10523. defineProperty(target, property, []);
  10524. }
  10525. return target[propertyName];
  10526. };
  10527. /**
  10528. * Define a property on the target element
  10529. *
  10530. * @param {Object} target
  10531. * @param {String} name
  10532. * @param {Object} options
  10533. */
  10534. Properties.prototype.define = function(target, name, options) {
  10535. Object.defineProperty(target, name, options);
  10536. };
  10537. /**
  10538. * Define the descriptor for an element
  10539. */
  10540. Properties.prototype.defineDescriptor = function(target, descriptor) {
  10541. this.define(target, '$descriptor', { value: descriptor });
  10542. };
  10543. /**
  10544. * Define the model for an element
  10545. */
  10546. Properties.prototype.defineModel = function(target, model) {
  10547. this.define(target, '$model', { value: model });
  10548. };
  10549. function isUndefined(val) {
  10550. return typeof val === 'undefined';
  10551. }
  10552. function defineProperty(target, property, value) {
  10553. Object.defineProperty(target, property.name, {
  10554. enumerable: !property.isReference,
  10555. writable: true,
  10556. value: value,
  10557. configurable: true
  10558. });
  10559. }
  10560. //// Moddle implementation /////////////////////////////////////////////////
  10561. /**
  10562. * @class Moddle
  10563. *
  10564. * A model that can be used to create elements of a specific type.
  10565. *
  10566. * @example
  10567. *
  10568. * var Moddle = require('moddle');
  10569. *
  10570. * var pkg = {
  10571. * name: 'mypackage',
  10572. * prefix: 'my',
  10573. * types: [
  10574. * { name: 'Root' }
  10575. * ]
  10576. * };
  10577. *
  10578. * var moddle = new Moddle([pkg]);
  10579. *
  10580. * @param {Array<Package>} packages the packages to contain
  10581. */
  10582. function Moddle(packages) {
  10583. this.properties = new Properties(this);
  10584. this.factory = new Factory(this, this.properties);
  10585. this.registry = new Registry(packages, this.properties);
  10586. this.typeCache = {};
  10587. }
  10588. /**
  10589. * Create an instance of the specified type.
  10590. *
  10591. * @method Moddle#create
  10592. *
  10593. * @example
  10594. *
  10595. * var foo = moddle.create('my:Foo');
  10596. * var bar = moddle.create('my:Bar', { id: 'BAR_1' });
  10597. *
  10598. * @param {String|Object} descriptor the type descriptor or name know to the model
  10599. * @param {Object} attrs a number of attributes to initialize the model instance with
  10600. * @return {Object} model instance
  10601. */
  10602. Moddle.prototype.create = function(descriptor, attrs) {
  10603. var Type = this.getType(descriptor);
  10604. if (!Type) {
  10605. throw new Error('unknown type <' + descriptor + '>');
  10606. }
  10607. return new Type(attrs);
  10608. };
  10609. /**
  10610. * Returns the type representing a given descriptor
  10611. *
  10612. * @method Moddle#getType
  10613. *
  10614. * @example
  10615. *
  10616. * var Foo = moddle.getType('my:Foo');
  10617. * var foo = new Foo({ 'id' : 'FOO_1' });
  10618. *
  10619. * @param {String|Object} descriptor the type descriptor or name know to the model
  10620. * @return {Object} the type representing the descriptor
  10621. */
  10622. Moddle.prototype.getType = function(descriptor) {
  10623. var cache = this.typeCache;
  10624. var name = isString(descriptor) ? descriptor : descriptor.ns.name;
  10625. var type = cache[name];
  10626. if (!type) {
  10627. descriptor = this.registry.getEffectiveDescriptor(name);
  10628. type = cache[name] = this.factory.createType(descriptor);
  10629. }
  10630. return type;
  10631. };
  10632. /**
  10633. * Creates an any-element type to be used within model instances.
  10634. *
  10635. * This can be used to create custom elements that lie outside the meta-model.
  10636. * The created element contains all the meta-data required to serialize it
  10637. * as part of meta-model elements.
  10638. *
  10639. * @method Moddle#createAny
  10640. *
  10641. * @example
  10642. *
  10643. * var foo = moddle.createAny('vendor:Foo', 'http://vendor', {
  10644. * value: 'bar'
  10645. * });
  10646. *
  10647. * var container = moddle.create('my:Container', 'http://my', {
  10648. * any: [ foo ]
  10649. * });
  10650. *
  10651. * // go ahead and serialize the stuff
  10652. *
  10653. *
  10654. * @param {String} name the name of the element
  10655. * @param {String} nsUri the namespace uri of the element
  10656. * @param {Object} [properties] a map of properties to initialize the instance with
  10657. * @return {Object} the any type instance
  10658. */
  10659. Moddle.prototype.createAny = function(name, nsUri, properties) {
  10660. var nameNs = parseName(name);
  10661. var element = {
  10662. $type: name,
  10663. $instanceOf: function(type) {
  10664. return type === this.$type;
  10665. }
  10666. };
  10667. var descriptor = {
  10668. name: name,
  10669. isGeneric: true,
  10670. ns: {
  10671. prefix: nameNs.prefix,
  10672. localName: nameNs.localName,
  10673. uri: nsUri
  10674. }
  10675. };
  10676. this.properties.defineDescriptor(element, descriptor);
  10677. this.properties.defineModel(element, this);
  10678. this.properties.define(element, '$parent', { enumerable: false, writable: true });
  10679. this.properties.define(element, '$instanceOf', { enumerable: false, writable: true });
  10680. forEach$1(properties, function(a, key) {
  10681. if (isObject(a) && a.value !== undefined) {
  10682. element[a.name] = a.value;
  10683. } else {
  10684. element[key] = a;
  10685. }
  10686. });
  10687. return element;
  10688. };
  10689. /**
  10690. * Returns a registered package by uri or prefix
  10691. *
  10692. * @return {Object} the package
  10693. */
  10694. Moddle.prototype.getPackage = function(uriOrPrefix) {
  10695. return this.registry.getPackage(uriOrPrefix);
  10696. };
  10697. /**
  10698. * Returns a snapshot of all known packages
  10699. *
  10700. * @return {Object} the package
  10701. */
  10702. Moddle.prototype.getPackages = function() {
  10703. return this.registry.getPackages();
  10704. };
  10705. /**
  10706. * Returns the descriptor for an element
  10707. */
  10708. Moddle.prototype.getElementDescriptor = function(element) {
  10709. return element.$descriptor;
  10710. };
  10711. /**
  10712. * Returns true if the given descriptor or instance
  10713. * represents the given type.
  10714. *
  10715. * May be applied to this, if element is omitted.
  10716. */
  10717. Moddle.prototype.hasType = function(element, type) {
  10718. if (type === undefined) {
  10719. type = element;
  10720. element = this;
  10721. }
  10722. var descriptor = element.$model.getElementDescriptor(element);
  10723. return (type in descriptor.allTypesByName);
  10724. };
  10725. /**
  10726. * Returns the descriptor of an elements named property
  10727. */
  10728. Moddle.prototype.getPropertyDescriptor = function(element, property) {
  10729. return this.getElementDescriptor(element).propertiesByName[property];
  10730. };
  10731. /**
  10732. * Returns a mapped type's descriptor
  10733. */
  10734. Moddle.prototype.getTypeDescriptor = function(type) {
  10735. return this.registry.typeMap[type];
  10736. };
  10737. var fromCharCode = String.fromCharCode;
  10738. var hasOwnProperty = Object.prototype.hasOwnProperty;
  10739. var ENTITY_PATTERN = /&#(\d+);|&#x([0-9a-f]+);|&(\w+);/ig;
  10740. var ENTITY_MAPPING = {
  10741. 'amp': '&',
  10742. 'apos': '\'',
  10743. 'gt': '>',
  10744. 'lt': '<',
  10745. 'quot': '"'
  10746. };
  10747. // map UPPERCASE variants of supported special chars
  10748. Object.keys(ENTITY_MAPPING).forEach(function(k) {
  10749. ENTITY_MAPPING[k.toUpperCase()] = ENTITY_MAPPING[k];
  10750. });
  10751. function replaceEntities(_, d, x, z) {
  10752. // reserved names, i.e. &nbsp;
  10753. if (z) {
  10754. if (hasOwnProperty.call(ENTITY_MAPPING, z)) {
  10755. return ENTITY_MAPPING[z];
  10756. } else {
  10757. // fall back to original value
  10758. return '&' + z + ';';
  10759. }
  10760. }
  10761. // decimal encoded char
  10762. if (d) {
  10763. return fromCharCode(d);
  10764. }
  10765. // hex encoded char
  10766. return fromCharCode(parseInt(x, 16));
  10767. }
  10768. /**
  10769. * A basic entity decoder that can decode a minimal
  10770. * sub-set of reserved names (&amp;) as well as
  10771. * hex (&#xaaf;) and decimal (&#1231;) encoded characters.
  10772. *
  10773. * @param {string} str
  10774. *
  10775. * @return {string} decoded string
  10776. */
  10777. function decodeEntities(s) {
  10778. if (s.length > 3 && s.indexOf('&') !== -1) {
  10779. return s.replace(ENTITY_PATTERN, replaceEntities);
  10780. }
  10781. return s;
  10782. }
  10783. var XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance';
  10784. var XSI_PREFIX = 'xsi';
  10785. var XSI_TYPE$1 = 'xsi:type';
  10786. var NON_WHITESPACE_OUTSIDE_ROOT_NODE = 'non-whitespace outside of root node';
  10787. function error$1(msg) {
  10788. return new Error(msg);
  10789. }
  10790. function missingNamespaceForPrefix(prefix) {
  10791. return 'missing namespace for prefix <' + prefix + '>';
  10792. }
  10793. function getter(getFn) {
  10794. return {
  10795. 'get': getFn,
  10796. 'enumerable': true
  10797. };
  10798. }
  10799. function cloneNsMatrix(nsMatrix) {
  10800. var clone = {}, key;
  10801. for (key in nsMatrix) {
  10802. clone[key] = nsMatrix[key];
  10803. }
  10804. return clone;
  10805. }
  10806. function uriPrefix(prefix) {
  10807. return prefix + '$uri';
  10808. }
  10809. function buildNsMatrix(nsUriToPrefix) {
  10810. var nsMatrix = {},
  10811. uri,
  10812. prefix;
  10813. for (uri in nsUriToPrefix) {
  10814. prefix = nsUriToPrefix[uri];
  10815. nsMatrix[prefix] = prefix;
  10816. nsMatrix[uriPrefix(prefix)] = uri;
  10817. }
  10818. return nsMatrix;
  10819. }
  10820. function noopGetContext() {
  10821. return { 'line': 0, 'column': 0 };
  10822. }
  10823. function throwFunc(err) {
  10824. throw err;
  10825. }
  10826. /**
  10827. * Creates a new parser with the given options.
  10828. *
  10829. * @constructor
  10830. *
  10831. * @param {!Object<string, ?>=} options
  10832. */
  10833. function Parser(options) {
  10834. if (!this) {
  10835. return new Parser(options);
  10836. }
  10837. var proxy = options && options['proxy'];
  10838. var onText,
  10839. onOpenTag,
  10840. onCloseTag,
  10841. onCDATA,
  10842. onError = throwFunc,
  10843. onWarning,
  10844. onComment,
  10845. onQuestion,
  10846. onAttention;
  10847. var getContext = noopGetContext;
  10848. /**
  10849. * Do we need to parse the current elements attributes for namespaces?
  10850. *
  10851. * @type {boolean}
  10852. */
  10853. var maybeNS = false;
  10854. /**
  10855. * Do we process namespaces at all?
  10856. *
  10857. * @type {boolean}
  10858. */
  10859. var isNamespace = false;
  10860. /**
  10861. * The caught error returned on parse end
  10862. *
  10863. * @type {Error}
  10864. */
  10865. var returnError = null;
  10866. /**
  10867. * Should we stop parsing?
  10868. *
  10869. * @type {boolean}
  10870. */
  10871. var parseStop = false;
  10872. /**
  10873. * A map of { uri: prefix } used by the parser.
  10874. *
  10875. * This map will ensure we can normalize prefixes during processing;
  10876. * for each uri, only one prefix will be exposed to the handlers.
  10877. *
  10878. * @type {!Object<string, string>}}
  10879. */
  10880. var nsUriToPrefix;
  10881. /**
  10882. * Handle parse error.
  10883. *
  10884. * @param {string|Error} err
  10885. */
  10886. function handleError(err) {
  10887. if (!(err instanceof Error)) {
  10888. err = error$1(err);
  10889. }
  10890. returnError = err;
  10891. onError(err, getContext);
  10892. }
  10893. /**
  10894. * Handle parse error.
  10895. *
  10896. * @param {string|Error} err
  10897. */
  10898. function handleWarning(err) {
  10899. if (!onWarning) {
  10900. return;
  10901. }
  10902. if (!(err instanceof Error)) {
  10903. err = error$1(err);
  10904. }
  10905. onWarning(err, getContext);
  10906. }
  10907. /**
  10908. * Register parse listener.
  10909. *
  10910. * @param {string} name
  10911. * @param {Function} cb
  10912. *
  10913. * @return {Parser}
  10914. */
  10915. this['on'] = function(name, cb) {
  10916. if (typeof cb !== 'function') {
  10917. throw error$1('required args <name, cb>');
  10918. }
  10919. switch (name) {
  10920. case 'openTag': onOpenTag = cb; break;
  10921. case 'text': onText = cb; break;
  10922. case 'closeTag': onCloseTag = cb; break;
  10923. case 'error': onError = cb; break;
  10924. case 'warn': onWarning = cb; break;
  10925. case 'cdata': onCDATA = cb; break;
  10926. case 'attention': onAttention = cb; break; // <!XXXXX zzzz="eeee">
  10927. case 'question': onQuestion = cb; break; // <? .... ?>
  10928. case 'comment': onComment = cb; break;
  10929. default:
  10930. throw error$1('unsupported event: ' + name);
  10931. }
  10932. return this;
  10933. };
  10934. /**
  10935. * Set the namespace to prefix mapping.
  10936. *
  10937. * @example
  10938. *
  10939. * parser.ns({
  10940. * 'http://foo': 'foo',
  10941. * 'http://bar': 'bar'
  10942. * });
  10943. *
  10944. * @param {!Object<string, string>} nsMap
  10945. *
  10946. * @return {Parser}
  10947. */
  10948. this['ns'] = function(nsMap) {
  10949. if (typeof nsMap === 'undefined') {
  10950. nsMap = {};
  10951. }
  10952. if (typeof nsMap !== 'object') {
  10953. throw error$1('required args <nsMap={}>');
  10954. }
  10955. var _nsUriToPrefix = {}, k;
  10956. for (k in nsMap) {
  10957. _nsUriToPrefix[k] = nsMap[k];
  10958. }
  10959. // FORCE default mapping for schema instance
  10960. _nsUriToPrefix[XSI_URI] = XSI_PREFIX;
  10961. isNamespace = true;
  10962. nsUriToPrefix = _nsUriToPrefix;
  10963. return this;
  10964. };
  10965. /**
  10966. * Parse xml string.
  10967. *
  10968. * @param {string} xml
  10969. *
  10970. * @return {Error} returnError, if not thrown
  10971. */
  10972. this['parse'] = function(xml) {
  10973. if (typeof xml !== 'string') {
  10974. throw error$1('required args <xml=string>');
  10975. }
  10976. returnError = null;
  10977. parse(xml);
  10978. getContext = noopGetContext;
  10979. parseStop = false;
  10980. return returnError;
  10981. };
  10982. /**
  10983. * Stop parsing.
  10984. */
  10985. this['stop'] = function() {
  10986. parseStop = true;
  10987. };
  10988. /**
  10989. * Parse string, invoking configured listeners on element.
  10990. *
  10991. * @param {string} xml
  10992. */
  10993. function parse(xml) {
  10994. var nsMatrixStack = isNamespace ? [] : null,
  10995. nsMatrix = isNamespace ? buildNsMatrix(nsUriToPrefix) : null,
  10996. _nsMatrix,
  10997. nodeStack = [],
  10998. anonymousNsCount = 0,
  10999. tagStart = false,
  11000. tagEnd = false,
  11001. i = 0, j = 0,
  11002. x, y, q, w, v,
  11003. xmlns,
  11004. elementName,
  11005. _elementName,
  11006. elementProxy
  11007. ;
  11008. var attrsString = '',
  11009. attrsStart = 0,
  11010. cachedAttrs // false = parsed with errors, null = needs parsing
  11011. ;
  11012. /**
  11013. * Parse attributes on demand and returns the parsed attributes.
  11014. *
  11015. * Return semantics: (1) `false` on attribute parse error,
  11016. * (2) object hash on extracted attrs.
  11017. *
  11018. * @return {boolean|Object}
  11019. */
  11020. function getAttrs() {
  11021. if (cachedAttrs !== null) {
  11022. return cachedAttrs;
  11023. }
  11024. var nsUri,
  11025. nsUriPrefix,
  11026. nsName,
  11027. defaultAlias = isNamespace && nsMatrix['xmlns'],
  11028. attrList = isNamespace && maybeNS ? [] : null,
  11029. i = attrsStart,
  11030. s = attrsString,
  11031. l = s.length,
  11032. hasNewMatrix,
  11033. newalias,
  11034. value,
  11035. alias,
  11036. name,
  11037. attrs = {},
  11038. seenAttrs = {},
  11039. skipAttr,
  11040. w,
  11041. j;
  11042. parseAttr:
  11043. for (; i < l; i++) {
  11044. skipAttr = false;
  11045. w = s.charCodeAt(i);
  11046. if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE={ \f\n\r\t\v}
  11047. continue;
  11048. }
  11049. // wait for non whitespace character
  11050. if (w < 65 || w > 122 || (w > 90 && w < 97)) {
  11051. if (w !== 95 && w !== 58) { // char 95"_" 58":"
  11052. handleWarning('illegal first char attribute name');
  11053. skipAttr = true;
  11054. }
  11055. }
  11056. // parse attribute name
  11057. for (j = i + 1; j < l; j++) {
  11058. w = s.charCodeAt(j);
  11059. if (
  11060. w > 96 && w < 123 ||
  11061. w > 64 && w < 91 ||
  11062. w > 47 && w < 59 ||
  11063. w === 46 || // '.'
  11064. w === 45 || // '-'
  11065. w === 95 // '_'
  11066. ) {
  11067. continue;
  11068. }
  11069. // unexpected whitespace
  11070. if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
  11071. handleWarning('missing attribute value');
  11072. i = j;
  11073. continue parseAttr;
  11074. }
  11075. // expected "="
  11076. if (w === 61) { // "=" == 61
  11077. break;
  11078. }
  11079. handleWarning('illegal attribute name char');
  11080. skipAttr = true;
  11081. }
  11082. name = s.substring(i, j);
  11083. if (name === 'xmlns:xmlns') {
  11084. handleWarning('illegal declaration of xmlns');
  11085. skipAttr = true;
  11086. }
  11087. w = s.charCodeAt(j + 1);
  11088. if (w === 34) { // '"'
  11089. j = s.indexOf('"', i = j + 2);
  11090. if (j === -1) {
  11091. j = s.indexOf('\'', i);
  11092. if (j !== -1) {
  11093. handleWarning('attribute value quote missmatch');
  11094. skipAttr = true;
  11095. }
  11096. }
  11097. } else if (w === 39) { // "'"
  11098. j = s.indexOf('\'', i = j + 2);
  11099. if (j === -1) {
  11100. j = s.indexOf('"', i);
  11101. if (j !== -1) {
  11102. handleWarning('attribute value quote missmatch');
  11103. skipAttr = true;
  11104. }
  11105. }
  11106. } else {
  11107. handleWarning('missing attribute value quotes');
  11108. skipAttr = true;
  11109. // skip to next space
  11110. for (j = j + 1; j < l; j++) {
  11111. w = s.charCodeAt(j + 1);
  11112. if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
  11113. break;
  11114. }
  11115. }
  11116. }
  11117. if (j === -1) {
  11118. handleWarning('missing closing quotes');
  11119. j = l;
  11120. skipAttr = true;
  11121. }
  11122. if (!skipAttr) {
  11123. value = s.substring(i, j);
  11124. }
  11125. i = j;
  11126. // ensure SPACE follows attribute
  11127. // skip illegal content otherwise
  11128. // example a="b"c
  11129. for (; j + 1 < l; j++) {
  11130. w = s.charCodeAt(j + 1);
  11131. if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
  11132. break;
  11133. }
  11134. // FIRST ILLEGAL CHAR
  11135. if (i === j) {
  11136. handleWarning('illegal character after attribute end');
  11137. skipAttr = true;
  11138. }
  11139. }
  11140. // advance cursor to next attribute
  11141. i = j + 1;
  11142. if (skipAttr) {
  11143. continue parseAttr;
  11144. }
  11145. // check attribute re-declaration
  11146. if (name in seenAttrs) {
  11147. handleWarning('attribute <' + name + '> already defined');
  11148. continue;
  11149. }
  11150. seenAttrs[name] = true;
  11151. if (!isNamespace) {
  11152. attrs[name] = value;
  11153. continue;
  11154. }
  11155. // try to extract namespace information
  11156. if (maybeNS) {
  11157. newalias = (
  11158. name === 'xmlns'
  11159. ? 'xmlns'
  11160. : (name.charCodeAt(0) === 120 && name.substr(0, 6) === 'xmlns:')
  11161. ? name.substr(6)
  11162. : null
  11163. );
  11164. // handle xmlns(:alias) assignment
  11165. if (newalias !== null) {
  11166. nsUri = decodeEntities(value);
  11167. nsUriPrefix = uriPrefix(newalias);
  11168. alias = nsUriToPrefix[nsUri];
  11169. if (!alias) {
  11170. // no prefix defined or prefix collision
  11171. if (
  11172. (newalias === 'xmlns') ||
  11173. (nsUriPrefix in nsMatrix && nsMatrix[nsUriPrefix] !== nsUri)
  11174. ) {
  11175. // alocate free ns prefix
  11176. do {
  11177. alias = 'ns' + (anonymousNsCount++);
  11178. } while (typeof nsMatrix[alias] !== 'undefined');
  11179. } else {
  11180. alias = newalias;
  11181. }
  11182. nsUriToPrefix[nsUri] = alias;
  11183. }
  11184. if (nsMatrix[newalias] !== alias) {
  11185. if (!hasNewMatrix) {
  11186. nsMatrix = cloneNsMatrix(nsMatrix);
  11187. hasNewMatrix = true;
  11188. }
  11189. nsMatrix[newalias] = alias;
  11190. if (newalias === 'xmlns') {
  11191. nsMatrix[uriPrefix(alias)] = nsUri;
  11192. defaultAlias = alias;
  11193. }
  11194. nsMatrix[nsUriPrefix] = nsUri;
  11195. }
  11196. // expose xmlns(:asd)="..." in attributes
  11197. attrs[name] = value;
  11198. continue;
  11199. }
  11200. // collect attributes until all namespace
  11201. // declarations are processed
  11202. attrList.push(name, value);
  11203. continue;
  11204. } /** end if (maybeNs) */
  11205. // handle attributes on element without
  11206. // namespace declarations
  11207. w = name.indexOf(':');
  11208. if (w === -1) {
  11209. attrs[name] = value;
  11210. continue;
  11211. }
  11212. // normalize ns attribute name
  11213. if (!(nsName = nsMatrix[name.substring(0, w)])) {
  11214. handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
  11215. continue;
  11216. }
  11217. name = defaultAlias === nsName
  11218. ? name.substr(w + 1)
  11219. : nsName + name.substr(w);
  11220. // end: normalize ns attribute name
  11221. // normalize xsi:type ns attribute value
  11222. if (name === XSI_TYPE$1) {
  11223. w = value.indexOf(':');
  11224. if (w !== -1) {
  11225. nsName = value.substring(0, w);
  11226. // handle default prefixes, i.e. xs:String gracefully
  11227. nsName = nsMatrix[nsName] || nsName;
  11228. value = nsName + value.substring(w);
  11229. } else {
  11230. value = defaultAlias + ':' + value;
  11231. }
  11232. }
  11233. // end: normalize xsi:type ns attribute value
  11234. attrs[name] = value;
  11235. }
  11236. // handle deferred, possibly namespaced attributes
  11237. if (maybeNS) {
  11238. // normalize captured attributes
  11239. for (i = 0, l = attrList.length; i < l; i++) {
  11240. name = attrList[i++];
  11241. value = attrList[i];
  11242. w = name.indexOf(':');
  11243. if (w !== -1) {
  11244. // normalize ns attribute name
  11245. if (!(nsName = nsMatrix[name.substring(0, w)])) {
  11246. handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
  11247. continue;
  11248. }
  11249. name = defaultAlias === nsName
  11250. ? name.substr(w + 1)
  11251. : nsName + name.substr(w);
  11252. // end: normalize ns attribute name
  11253. // normalize xsi:type ns attribute value
  11254. if (name === XSI_TYPE$1) {
  11255. w = value.indexOf(':');
  11256. if (w !== -1) {
  11257. nsName = value.substring(0, w);
  11258. // handle default prefixes, i.e. xs:String gracefully
  11259. nsName = nsMatrix[nsName] || nsName;
  11260. value = nsName + value.substring(w);
  11261. } else {
  11262. value = defaultAlias + ':' + value;
  11263. }
  11264. }
  11265. // end: normalize xsi:type ns attribute value
  11266. }
  11267. attrs[name] = value;
  11268. }
  11269. // end: normalize captured attributes
  11270. }
  11271. return cachedAttrs = attrs;
  11272. }
  11273. /**
  11274. * Extract the parse context { line, column, part }
  11275. * from the current parser position.
  11276. *
  11277. * @return {Object} parse context
  11278. */
  11279. function getParseContext() {
  11280. var splitsRe = /(\r\n|\r|\n)/g;
  11281. var line = 0;
  11282. var column = 0;
  11283. var startOfLine = 0;
  11284. var endOfLine = j;
  11285. var match;
  11286. var data;
  11287. while (i >= startOfLine) {
  11288. match = splitsRe.exec(xml);
  11289. if (!match) {
  11290. break;
  11291. }
  11292. // end of line = (break idx + break chars)
  11293. endOfLine = match[0].length + match.index;
  11294. if (endOfLine > i) {
  11295. break;
  11296. }
  11297. // advance to next line
  11298. line += 1;
  11299. startOfLine = endOfLine;
  11300. }
  11301. // EOF errors
  11302. if (i == -1) {
  11303. column = endOfLine;
  11304. data = xml.substring(j);
  11305. } else
  11306. // start errors
  11307. if (j === 0) {
  11308. data = xml.substring(j, i);
  11309. }
  11310. // other errors
  11311. else {
  11312. column = i - startOfLine;
  11313. data = (j == -1 ? xml.substring(i) : xml.substring(i, j + 1));
  11314. }
  11315. return {
  11316. 'data': data,
  11317. 'line': line,
  11318. 'column': column
  11319. };
  11320. }
  11321. getContext = getParseContext;
  11322. if (proxy) {
  11323. elementProxy = Object.create({}, {
  11324. 'name': getter(function() {
  11325. return elementName;
  11326. }),
  11327. 'originalName': getter(function() {
  11328. return _elementName;
  11329. }),
  11330. 'attrs': getter(getAttrs),
  11331. 'ns': getter(function() {
  11332. return nsMatrix;
  11333. })
  11334. });
  11335. }
  11336. // actual parse logic
  11337. while (j !== -1) {
  11338. if (xml.charCodeAt(j) === 60) { // "<"
  11339. i = j;
  11340. } else {
  11341. i = xml.indexOf('<', j);
  11342. }
  11343. // parse end
  11344. if (i === -1) {
  11345. if (nodeStack.length) {
  11346. return handleError('unexpected end of file');
  11347. }
  11348. if (j === 0) {
  11349. return handleError('missing start tag');
  11350. }
  11351. if (j < xml.length) {
  11352. if (xml.substring(j).trim()) {
  11353. handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
  11354. }
  11355. }
  11356. return;
  11357. }
  11358. // parse text
  11359. if (j !== i) {
  11360. if (nodeStack.length) {
  11361. if (onText) {
  11362. onText(xml.substring(j, i), decodeEntities, getContext);
  11363. if (parseStop) {
  11364. return;
  11365. }
  11366. }
  11367. } else {
  11368. if (xml.substring(j, i).trim()) {
  11369. handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
  11370. if (parseStop) {
  11371. return;
  11372. }
  11373. }
  11374. }
  11375. }
  11376. w = xml.charCodeAt(i+1);
  11377. // parse comments + CDATA
  11378. if (w === 33) { // "!"
  11379. q = xml.charCodeAt(i+2);
  11380. // CDATA section
  11381. if (q === 91 && xml.substr(i + 3, 6) === 'CDATA[') { // 91 == "["
  11382. j = xml.indexOf(']]>', i);
  11383. if (j === -1) {
  11384. return handleError('unclosed cdata');
  11385. }
  11386. if (onCDATA) {
  11387. onCDATA(xml.substring(i + 9, j), getContext);
  11388. if (parseStop) {
  11389. return;
  11390. }
  11391. }
  11392. j += 3;
  11393. continue;
  11394. }
  11395. // comment
  11396. if (q === 45 && xml.charCodeAt(i + 3) === 45) { // 45 == "-"
  11397. j = xml.indexOf('-->', i);
  11398. if (j === -1) {
  11399. return handleError('unclosed comment');
  11400. }
  11401. if (onComment) {
  11402. onComment(xml.substring(i + 4, j), decodeEntities, getContext);
  11403. if (parseStop) {
  11404. return;
  11405. }
  11406. }
  11407. j += 3;
  11408. continue;
  11409. }
  11410. }
  11411. // parse question <? ... ?>
  11412. if (w === 63) { // "?"
  11413. j = xml.indexOf('?>', i);
  11414. if (j === -1) {
  11415. return handleError('unclosed question');
  11416. }
  11417. if (onQuestion) {
  11418. onQuestion(xml.substring(i, j + 2), getContext);
  11419. if (parseStop) {
  11420. return;
  11421. }
  11422. }
  11423. j += 2;
  11424. continue;
  11425. }
  11426. // find matching closing tag for attention or standard tags
  11427. // for that we must skip through attribute values
  11428. // (enclosed in single or double quotes)
  11429. for (x = i + 1; ; x++) {
  11430. v = xml.charCodeAt(x);
  11431. if (isNaN(v)) {
  11432. j = -1;
  11433. return handleError('unclosed tag');
  11434. }
  11435. // [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
  11436. // skips the quoted string
  11437. // (double quotes) does not appear in a literal enclosed by (double quotes)
  11438. // (single quote) does not appear in a literal enclosed by (single quote)
  11439. if (v === 34) { // '"'
  11440. q = xml.indexOf('"', x + 1);
  11441. x = q !== -1 ? q : x;
  11442. } else if (v === 39) { // "'"
  11443. q = xml.indexOf("'", x + 1);
  11444. x = q !== -1 ? q : x;
  11445. } else if (v === 62) { // '>'
  11446. j = x;
  11447. break;
  11448. }
  11449. }
  11450. // parse attention <! ...>
  11451. // previously comment and CDATA have already been parsed
  11452. if (w === 33) { // "!"
  11453. if (onAttention) {
  11454. onAttention(xml.substring(i, j + 1), decodeEntities, getContext);
  11455. if (parseStop) {
  11456. return;
  11457. }
  11458. }
  11459. j += 1;
  11460. continue;
  11461. }
  11462. // don't process attributes;
  11463. // there are none
  11464. cachedAttrs = {};
  11465. // if (xml.charCodeAt(i+1) === 47) { // </...
  11466. if (w === 47) { // </...
  11467. tagStart = false;
  11468. tagEnd = true;
  11469. if (!nodeStack.length) {
  11470. return handleError('missing open tag');
  11471. }
  11472. // verify open <-> close tag match
  11473. x = elementName = nodeStack.pop();
  11474. q = i + 2 + x.length;
  11475. if (xml.substring(i + 2, q) !== x) {
  11476. return handleError('closing tag mismatch');
  11477. }
  11478. // verify chars in close tag
  11479. for (; q < j; q++) {
  11480. w = xml.charCodeAt(q);
  11481. if (w === 32 || (w > 8 && w < 14)) { // \f\n\r\t\v space
  11482. continue;
  11483. }
  11484. return handleError('close tag');
  11485. }
  11486. } else {
  11487. if (xml.charCodeAt(j - 1) === 47) { // .../>
  11488. x = elementName = xml.substring(i + 1, j - 1);
  11489. tagStart = true;
  11490. tagEnd = true;
  11491. } else {
  11492. x = elementName = xml.substring(i + 1, j);
  11493. tagStart = true;
  11494. tagEnd = false;
  11495. }
  11496. if (!(w > 96 && w < 123 || w > 64 && w < 91 || w === 95 || w === 58)) { // char 95"_" 58":"
  11497. return handleError('illegal first char nodeName');
  11498. }
  11499. for (q = 1, y = x.length; q < y; q++) {
  11500. w = x.charCodeAt(q);
  11501. if (w > 96 && w < 123 || w > 64 && w < 91 || w > 47 && w < 59 || w === 45 || w === 95 || w == 46) {
  11502. continue;
  11503. }
  11504. if (w === 32 || (w < 14 && w > 8)) { // \f\n\r\t\v space
  11505. elementName = x.substring(0, q);
  11506. // maybe there are attributes
  11507. cachedAttrs = null;
  11508. break;
  11509. }
  11510. return handleError('invalid nodeName');
  11511. }
  11512. if (!tagEnd) {
  11513. nodeStack.push(elementName);
  11514. }
  11515. }
  11516. if (isNamespace) {
  11517. _nsMatrix = nsMatrix;
  11518. if (tagStart) {
  11519. // remember old namespace
  11520. // unless we're self-closing
  11521. if (!tagEnd) {
  11522. nsMatrixStack.push(_nsMatrix);
  11523. }
  11524. if (cachedAttrs === null) {
  11525. // quick check, whether there may be namespace
  11526. // declarations on the node; if that is the case
  11527. // we need to eagerly parse the node attributes
  11528. if ((maybeNS = x.indexOf('xmlns', q) !== -1)) {
  11529. attrsStart = q;
  11530. attrsString = x;
  11531. getAttrs();
  11532. maybeNS = false;
  11533. }
  11534. }
  11535. }
  11536. _elementName = elementName;
  11537. w = elementName.indexOf(':');
  11538. if (w !== -1) {
  11539. xmlns = nsMatrix[elementName.substring(0, w)];
  11540. // prefix given; namespace must exist
  11541. if (!xmlns) {
  11542. return handleError('missing namespace on <' + _elementName + '>');
  11543. }
  11544. elementName = elementName.substr(w + 1);
  11545. } else {
  11546. xmlns = nsMatrix['xmlns'];
  11547. // if no default namespace is defined,
  11548. // we'll import the element as anonymous.
  11549. //
  11550. // it is up to users to correct that to the document defined
  11551. // targetNamespace, or whatever their undersanding of the
  11552. // XML spec mandates.
  11553. }
  11554. // adjust namespace prefixs as configured
  11555. if (xmlns) {
  11556. elementName = xmlns + ':' + elementName;
  11557. }
  11558. }
  11559. if (tagStart) {
  11560. attrsStart = q;
  11561. attrsString = x;
  11562. if (onOpenTag) {
  11563. if (proxy) {
  11564. onOpenTag(elementProxy, decodeEntities, tagEnd, getContext);
  11565. } else {
  11566. onOpenTag(elementName, getAttrs, decodeEntities, tagEnd, getContext);
  11567. }
  11568. if (parseStop) {
  11569. return;
  11570. }
  11571. }
  11572. }
  11573. if (tagEnd) {
  11574. if (onCloseTag) {
  11575. onCloseTag(proxy ? elementProxy : elementName, decodeEntities, tagStart, getContext);
  11576. if (parseStop) {
  11577. return;
  11578. }
  11579. }
  11580. // restore old namespace
  11581. if (isNamespace) {
  11582. if (!tagStart) {
  11583. nsMatrix = nsMatrixStack.pop();
  11584. } else {
  11585. nsMatrix = _nsMatrix;
  11586. }
  11587. }
  11588. }
  11589. j += 1;
  11590. }
  11591. } /** end parse */
  11592. }
  11593. function hasLowerCaseAlias(pkg) {
  11594. return pkg.xml && pkg.xml.tagAlias === 'lowerCase';
  11595. }
  11596. var DEFAULT_NS_MAP = {
  11597. 'xsi': 'http://www.w3.org/2001/XMLSchema-instance',
  11598. 'xml': 'http://www.w3.org/XML/1998/namespace'
  11599. };
  11600. var XSI_TYPE = 'xsi:type';
  11601. function serializeFormat(element) {
  11602. return element.xml && element.xml.serialize;
  11603. }
  11604. function serializeAsType(element) {
  11605. return serializeFormat(element) === XSI_TYPE;
  11606. }
  11607. function serializeAsProperty(element) {
  11608. return serializeFormat(element) === 'property';
  11609. }
  11610. function capitalize(str) {
  11611. return str.charAt(0).toUpperCase() + str.slice(1);
  11612. }
  11613. function aliasToName(aliasNs, pkg) {
  11614. if (!hasLowerCaseAlias(pkg)) {
  11615. return aliasNs.name;
  11616. }
  11617. return aliasNs.prefix + ':' + capitalize(aliasNs.localName);
  11618. }
  11619. function prefixedToName(nameNs, pkg) {
  11620. var name = nameNs.name,
  11621. localName = nameNs.localName;
  11622. var typePrefix = pkg.xml && pkg.xml.typePrefix;
  11623. if (typePrefix && localName.indexOf(typePrefix) === 0) {
  11624. return nameNs.prefix + ':' + localName.slice(typePrefix.length);
  11625. } else {
  11626. return name;
  11627. }
  11628. }
  11629. function normalizeXsiTypeName(name, model) {
  11630. var nameNs = parseName(name);
  11631. var pkg = model.getPackage(nameNs.prefix);
  11632. return prefixedToName(nameNs, pkg);
  11633. }
  11634. function error(message) {
  11635. return new Error(message);
  11636. }
  11637. /**
  11638. * Get the moddle descriptor for a given instance or type.
  11639. *
  11640. * @param {ModdleElement|Function} element
  11641. *
  11642. * @return {Object} the moddle descriptor
  11643. */
  11644. function getModdleDescriptor(element) {
  11645. return element.$descriptor;
  11646. }
  11647. /**
  11648. * A parse context.
  11649. *
  11650. * @class
  11651. *
  11652. * @param {Object} options
  11653. * @param {ElementHandler} options.rootHandler the root handler for parsing a document
  11654. * @param {boolean} [options.lax=false] whether or not to ignore invalid elements
  11655. */
  11656. function Context(options) {
  11657. /**
  11658. * @property {ElementHandler} rootHandler
  11659. */
  11660. /**
  11661. * @property {Boolean} lax
  11662. */
  11663. assign(this, options);
  11664. this.elementsById = {};
  11665. this.references = [];
  11666. this.warnings = [];
  11667. /**
  11668. * Add an unresolved reference.
  11669. *
  11670. * @param {Object} reference
  11671. */
  11672. this.addReference = function(reference) {
  11673. this.references.push(reference);
  11674. };
  11675. /**
  11676. * Add a processed element.
  11677. *
  11678. * @param {ModdleElement} element
  11679. */
  11680. this.addElement = function(element) {
  11681. if (!element) {
  11682. throw error('expected element');
  11683. }
  11684. var elementsById = this.elementsById;
  11685. var descriptor = getModdleDescriptor(element);
  11686. var idProperty = descriptor.idProperty,
  11687. id;
  11688. if (idProperty) {
  11689. id = element.get(idProperty.name);
  11690. if (id) {
  11691. // for QName validation as per http://www.w3.org/TR/REC-xml/#NT-NameChar
  11692. if (!/^([a-z][\w-.]*:)?[a-z_][\w-.]*$/i.test(id)) {
  11693. throw new Error('illegal ID <' + id + '>');
  11694. }
  11695. if (elementsById[id]) {
  11696. throw error('duplicate ID <' + id + '>');
  11697. }
  11698. elementsById[id] = element;
  11699. }
  11700. }
  11701. };
  11702. /**
  11703. * Add an import warning.
  11704. *
  11705. * @param {Object} warning
  11706. * @param {String} warning.message
  11707. * @param {Error} [warning.error]
  11708. */
  11709. this.addWarning = function(warning) {
  11710. this.warnings.push(warning);
  11711. };
  11712. }
  11713. function BaseHandler() {}
  11714. BaseHandler.prototype.handleEnd = function() {};
  11715. BaseHandler.prototype.handleText = function() {};
  11716. BaseHandler.prototype.handleNode = function() {};
  11717. /**
  11718. * A simple pass through handler that does nothing except for
  11719. * ignoring all input it receives.
  11720. *
  11721. * This is used to ignore unknown elements and
  11722. * attributes.
  11723. */
  11724. function NoopHandler() { }
  11725. NoopHandler.prototype = Object.create(BaseHandler.prototype);
  11726. NoopHandler.prototype.handleNode = function() {
  11727. return this;
  11728. };
  11729. function BodyHandler() {}
  11730. BodyHandler.prototype = Object.create(BaseHandler.prototype);
  11731. BodyHandler.prototype.handleText = function(text) {
  11732. this.body = (this.body || '') + text;
  11733. };
  11734. function ReferenceHandler(property, context) {
  11735. this.property = property;
  11736. this.context = context;
  11737. }
  11738. ReferenceHandler.prototype = Object.create(BodyHandler.prototype);
  11739. ReferenceHandler.prototype.handleNode = function(node) {
  11740. if (this.element) {
  11741. throw error('expected no sub nodes');
  11742. } else {
  11743. this.element = this.createReference(node);
  11744. }
  11745. return this;
  11746. };
  11747. ReferenceHandler.prototype.handleEnd = function() {
  11748. this.element.id = this.body;
  11749. };
  11750. ReferenceHandler.prototype.createReference = function(node) {
  11751. return {
  11752. property: this.property.ns.name,
  11753. id: ''
  11754. };
  11755. };
  11756. function ValueHandler(propertyDesc, element) {
  11757. this.element = element;
  11758. this.propertyDesc = propertyDesc;
  11759. }
  11760. ValueHandler.prototype = Object.create(BodyHandler.prototype);
  11761. ValueHandler.prototype.handleEnd = function() {
  11762. var value = this.body || '',
  11763. element = this.element,
  11764. propertyDesc = this.propertyDesc;
  11765. value = coerceType(propertyDesc.type, value);
  11766. if (propertyDesc.isMany) {
  11767. element.get(propertyDesc.name).push(value);
  11768. } else {
  11769. element.set(propertyDesc.name, value);
  11770. }
  11771. };
  11772. function BaseElementHandler() {}
  11773. BaseElementHandler.prototype = Object.create(BodyHandler.prototype);
  11774. BaseElementHandler.prototype.handleNode = function(node) {
  11775. var parser = this,
  11776. element = this.element;
  11777. if (!element) {
  11778. element = this.element = this.createElement(node);
  11779. this.context.addElement(element);
  11780. } else {
  11781. parser = this.handleChild(node);
  11782. }
  11783. return parser;
  11784. };
  11785. /**
  11786. * @class Reader.ElementHandler
  11787. *
  11788. */
  11789. function ElementHandler(model, typeName, context) {
  11790. this.model = model;
  11791. this.type = model.getType(typeName);
  11792. this.context = context;
  11793. }
  11794. ElementHandler.prototype = Object.create(BaseElementHandler.prototype);
  11795. ElementHandler.prototype.addReference = function(reference) {
  11796. this.context.addReference(reference);
  11797. };
  11798. ElementHandler.prototype.handleText = function(text) {
  11799. var element = this.element,
  11800. descriptor = getModdleDescriptor(element),
  11801. bodyProperty = descriptor.bodyProperty;
  11802. if (!bodyProperty) {
  11803. throw error('unexpected body text <' + text + '>');
  11804. }
  11805. BodyHandler.prototype.handleText.call(this, text);
  11806. };
  11807. ElementHandler.prototype.handleEnd = function() {
  11808. var value = this.body,
  11809. element = this.element,
  11810. descriptor = getModdleDescriptor(element),
  11811. bodyProperty = descriptor.bodyProperty;
  11812. if (bodyProperty && value !== undefined) {
  11813. value = coerceType(bodyProperty.type, value);
  11814. element.set(bodyProperty.name, value);
  11815. }
  11816. };
  11817. /**
  11818. * Create an instance of the model from the given node.
  11819. *
  11820. * @param {Element} node the xml node
  11821. */
  11822. ElementHandler.prototype.createElement = function(node) {
  11823. var attributes = node.attributes,
  11824. Type = this.type,
  11825. descriptor = getModdleDescriptor(Type),
  11826. context = this.context,
  11827. instance = new Type({}),
  11828. model = this.model,
  11829. propNameNs;
  11830. forEach$1(attributes, function(value, name) {
  11831. var prop = descriptor.propertiesByName[name],
  11832. values;
  11833. if (prop && prop.isReference) {
  11834. if (!prop.isMany) {
  11835. context.addReference({
  11836. element: instance,
  11837. property: prop.ns.name,
  11838. id: value
  11839. });
  11840. } else {
  11841. // IDREFS: parse references as whitespace-separated list
  11842. values = value.split(' ');
  11843. forEach$1(values, function(v) {
  11844. context.addReference({
  11845. element: instance,
  11846. property: prop.ns.name,
  11847. id: v
  11848. });
  11849. });
  11850. }
  11851. } else {
  11852. if (prop) {
  11853. value = coerceType(prop.type, value);
  11854. } else
  11855. if (name !== 'xmlns') {
  11856. propNameNs = parseName(name, descriptor.ns.prefix);
  11857. // check whether attribute is defined in a well-known namespace
  11858. // if that is the case we emit a warning to indicate potential misuse
  11859. if (model.getPackage(propNameNs.prefix)) {
  11860. context.addWarning({
  11861. message: 'unknown attribute <' + name + '>',
  11862. element: instance,
  11863. property: name,
  11864. value: value
  11865. });
  11866. }
  11867. }
  11868. instance.set(name, value);
  11869. }
  11870. });
  11871. return instance;
  11872. };
  11873. ElementHandler.prototype.getPropertyForNode = function(node) {
  11874. var name = node.name;
  11875. var nameNs = parseName(name);
  11876. var type = this.type,
  11877. model = this.model,
  11878. descriptor = getModdleDescriptor(type);
  11879. var propertyName = nameNs.name,
  11880. property = descriptor.propertiesByName[propertyName],
  11881. elementTypeName,
  11882. elementType;
  11883. // search for properties by name first
  11884. if (property && !property.isAttr) {
  11885. if (serializeAsType(property)) {
  11886. elementTypeName = node.attributes[XSI_TYPE];
  11887. // xsi type is optional, if it does not exists the
  11888. // default type is assumed
  11889. if (elementTypeName) {
  11890. // take possible type prefixes from XML
  11891. // into account, i.e.: xsi:type="t{ActualType}"
  11892. elementTypeName = normalizeXsiTypeName(elementTypeName, model);
  11893. elementType = model.getType(elementTypeName);
  11894. return assign({}, property, {
  11895. effectiveType: getModdleDescriptor(elementType).name
  11896. });
  11897. }
  11898. }
  11899. // search for properties by name first
  11900. return property;
  11901. }
  11902. var pkg = model.getPackage(nameNs.prefix);
  11903. if (pkg) {
  11904. elementTypeName = aliasToName(nameNs, pkg);
  11905. elementType = model.getType(elementTypeName);
  11906. // search for collection members later
  11907. property = find(descriptor.properties, function(p) {
  11908. return !p.isVirtual && !p.isReference && !p.isAttribute && elementType.hasType(p.type);
  11909. });
  11910. if (property) {
  11911. return assign({}, property, {
  11912. effectiveType: getModdleDescriptor(elementType).name
  11913. });
  11914. }
  11915. } else {
  11916. // parse unknown element (maybe extension)
  11917. property = find(descriptor.properties, function(p) {
  11918. return !p.isReference && !p.isAttribute && p.type === 'Element';
  11919. });
  11920. if (property) {
  11921. return property;
  11922. }
  11923. }
  11924. throw error('unrecognized element <' + nameNs.name + '>');
  11925. };
  11926. ElementHandler.prototype.toString = function() {
  11927. return 'ElementDescriptor[' + getModdleDescriptor(this.type).name + ']';
  11928. };
  11929. ElementHandler.prototype.valueHandler = function(propertyDesc, element) {
  11930. return new ValueHandler(propertyDesc, element);
  11931. };
  11932. ElementHandler.prototype.referenceHandler = function(propertyDesc) {
  11933. return new ReferenceHandler(propertyDesc, this.context);
  11934. };
  11935. ElementHandler.prototype.handler = function(type) {
  11936. if (type === 'Element') {
  11937. return new GenericElementHandler(this.model, type, this.context);
  11938. } else {
  11939. return new ElementHandler(this.model, type, this.context);
  11940. }
  11941. };
  11942. /**
  11943. * Handle the child element parsing
  11944. *
  11945. * @param {Element} node the xml node
  11946. */
  11947. ElementHandler.prototype.handleChild = function(node) {
  11948. var propertyDesc, type, element, childHandler;
  11949. propertyDesc = this.getPropertyForNode(node);
  11950. element = this.element;
  11951. type = propertyDesc.effectiveType || propertyDesc.type;
  11952. if (isSimple(type)) {
  11953. return this.valueHandler(propertyDesc, element);
  11954. }
  11955. if (propertyDesc.isReference) {
  11956. childHandler = this.referenceHandler(propertyDesc).handleNode(node);
  11957. } else {
  11958. childHandler = this.handler(type).handleNode(node);
  11959. }
  11960. var newElement = childHandler.element;
  11961. // child handles may decide to skip elements
  11962. // by not returning anything
  11963. if (newElement !== undefined) {
  11964. if (propertyDesc.isMany) {
  11965. element.get(propertyDesc.name).push(newElement);
  11966. } else {
  11967. element.set(propertyDesc.name, newElement);
  11968. }
  11969. if (propertyDesc.isReference) {
  11970. assign(newElement, {
  11971. element: element
  11972. });
  11973. this.context.addReference(newElement);
  11974. } else {
  11975. // establish child -> parent relationship
  11976. newElement.$parent = element;
  11977. }
  11978. }
  11979. return childHandler;
  11980. };
  11981. /**
  11982. * An element handler that performs special validation
  11983. * to ensure the node it gets initialized with matches
  11984. * the handlers type (namespace wise).
  11985. *
  11986. * @param {Moddle} model
  11987. * @param {String} typeName
  11988. * @param {Context} context
  11989. */
  11990. function RootElementHandler(model, typeName, context) {
  11991. ElementHandler.call(this, model, typeName, context);
  11992. }
  11993. RootElementHandler.prototype = Object.create(ElementHandler.prototype);
  11994. RootElementHandler.prototype.createElement = function(node) {
  11995. var name = node.name,
  11996. nameNs = parseName(name),
  11997. model = this.model,
  11998. type = this.type,
  11999. pkg = model.getPackage(nameNs.prefix),
  12000. typeName = pkg && aliasToName(nameNs, pkg) || name;
  12001. // verify the correct namespace if we parse
  12002. // the first element in the handler tree
  12003. //
  12004. // this ensures we don't mistakenly import wrong namespace elements
  12005. if (!type.hasType(typeName)) {
  12006. throw error('unexpected element <' + node.originalName + '>');
  12007. }
  12008. return ElementHandler.prototype.createElement.call(this, node);
  12009. };
  12010. function GenericElementHandler(model, typeName, context) {
  12011. this.model = model;
  12012. this.context = context;
  12013. }
  12014. GenericElementHandler.prototype = Object.create(BaseElementHandler.prototype);
  12015. GenericElementHandler.prototype.createElement = function(node) {
  12016. var name = node.name,
  12017. ns = parseName(name),
  12018. prefix = ns.prefix,
  12019. uri = node.ns[prefix + '$uri'],
  12020. attributes = node.attributes;
  12021. return this.model.createAny(name, uri, attributes);
  12022. };
  12023. GenericElementHandler.prototype.handleChild = function(node) {
  12024. var handler = new GenericElementHandler(this.model, 'Element', this.context).handleNode(node),
  12025. element = this.element;
  12026. var newElement = handler.element,
  12027. children;
  12028. if (newElement !== undefined) {
  12029. children = element.$children = element.$children || [];
  12030. children.push(newElement);
  12031. // establish child -> parent relationship
  12032. newElement.$parent = element;
  12033. }
  12034. return handler;
  12035. };
  12036. GenericElementHandler.prototype.handleEnd = function() {
  12037. if (this.body) {
  12038. this.element.$body = this.body;
  12039. }
  12040. };
  12041. /**
  12042. * A reader for a meta-model
  12043. *
  12044. * @param {Object} options
  12045. * @param {Model} options.model used to read xml files
  12046. * @param {Boolean} options.lax whether to make parse errors warnings
  12047. */
  12048. function Reader(options) {
  12049. if (options instanceof Moddle) {
  12050. options = {
  12051. model: options
  12052. };
  12053. }
  12054. assign(this, { lax: false }, options);
  12055. }
  12056. /**
  12057. * The fromXML result.
  12058. *
  12059. * @typedef {Object} ParseResult
  12060. *
  12061. * @property {ModdleElement} rootElement
  12062. * @property {Array<Object>} references
  12063. * @property {Array<Error>} warnings
  12064. * @property {Object} elementsById - a mapping containing each ID -> ModdleElement
  12065. */
  12066. /**
  12067. * The fromXML result.
  12068. *
  12069. * @typedef {Error} ParseError
  12070. *
  12071. * @property {Array<Error>} warnings
  12072. */
  12073. /**
  12074. * Parse the given XML into a moddle document tree.
  12075. *
  12076. * @param {String} xml
  12077. * @param {ElementHandler|Object} options or rootHandler
  12078. *
  12079. * @returns {Promise<ParseResult, ParseError>}
  12080. */
  12081. Reader.prototype.fromXML = function(xml, options, done) {
  12082. var rootHandler = options.rootHandler;
  12083. if (options instanceof ElementHandler) {
  12084. // root handler passed via (xml, { rootHandler: ElementHandler }, ...)
  12085. rootHandler = options;
  12086. options = {};
  12087. } else {
  12088. if (typeof options === 'string') {
  12089. // rootHandler passed via (xml, 'someString', ...)
  12090. rootHandler = this.handler(options);
  12091. options = {};
  12092. } else if (typeof rootHandler === 'string') {
  12093. // rootHandler passed via (xml, { rootHandler: 'someString' }, ...)
  12094. rootHandler = this.handler(rootHandler);
  12095. }
  12096. }
  12097. var model = this.model,
  12098. lax = this.lax;
  12099. var context = new Context(assign({}, options, { rootHandler: rootHandler })),
  12100. parser = new Parser({ proxy: true }),
  12101. stack = createStack();
  12102. rootHandler.context = context;
  12103. // push root handler
  12104. stack.push(rootHandler);
  12105. /**
  12106. * Handle error.
  12107. *
  12108. * @param {Error} err
  12109. * @param {Function} getContext
  12110. * @param {boolean} lax
  12111. *
  12112. * @return {boolean} true if handled
  12113. */
  12114. function handleError(err, getContext, lax) {
  12115. var ctx = getContext();
  12116. var line = ctx.line,
  12117. column = ctx.column,
  12118. data = ctx.data;
  12119. // we receive the full context data here,
  12120. // for elements trim down the information
  12121. // to the tag name, only
  12122. if (data.charAt(0) === '<' && data.indexOf(' ') !== -1) {
  12123. data = data.slice(0, data.indexOf(' ')) + '>';
  12124. }
  12125. var message =
  12126. 'unparsable content ' + (data ? data + ' ' : '') + 'detected\n\t' +
  12127. 'line: ' + line + '\n\t' +
  12128. 'column: ' + column + '\n\t' +
  12129. 'nested error: ' + err.message;
  12130. if (lax) {
  12131. context.addWarning({
  12132. message: message,
  12133. error: err
  12134. });
  12135. return true;
  12136. } else {
  12137. throw error(message);
  12138. }
  12139. }
  12140. function handleWarning(err, getContext) {
  12141. // just like handling errors in <lax=true> mode
  12142. return handleError(err, getContext, true);
  12143. }
  12144. /**
  12145. * Resolve collected references on parse end.
  12146. */
  12147. function resolveReferences() {
  12148. var elementsById = context.elementsById;
  12149. var references = context.references;
  12150. var i, r;
  12151. for (i = 0; (r = references[i]); i++) {
  12152. var element = r.element;
  12153. var reference = elementsById[r.id];
  12154. var property = getModdleDescriptor(element).propertiesByName[r.property];
  12155. if (!reference) {
  12156. context.addWarning({
  12157. message: 'unresolved reference <' + r.id + '>',
  12158. element: r.element,
  12159. property: r.property,
  12160. value: r.id
  12161. });
  12162. }
  12163. if (property.isMany) {
  12164. var collection = element.get(property.name),
  12165. idx = collection.indexOf(r);
  12166. // we replace an existing place holder (idx != -1) or
  12167. // append to the collection instead
  12168. if (idx === -1) {
  12169. idx = collection.length;
  12170. }
  12171. if (!reference) {
  12172. // remove unresolvable reference
  12173. collection.splice(idx, 1);
  12174. } else {
  12175. // add or update reference in collection
  12176. collection[idx] = reference;
  12177. }
  12178. } else {
  12179. element.set(property.name, reference);
  12180. }
  12181. }
  12182. }
  12183. function handleClose() {
  12184. stack.pop().handleEnd();
  12185. }
  12186. var PREAMBLE_START_PATTERN = /^<\?xml /i;
  12187. var ENCODING_PATTERN = / encoding="([^"]+)"/i;
  12188. var UTF_8_PATTERN = /^utf-8$/i;
  12189. function handleQuestion(question) {
  12190. if (!PREAMBLE_START_PATTERN.test(question)) {
  12191. return;
  12192. }
  12193. var match = ENCODING_PATTERN.exec(question);
  12194. var encoding = match && match[1];
  12195. if (!encoding || UTF_8_PATTERN.test(encoding)) {
  12196. return;
  12197. }
  12198. context.addWarning({
  12199. message:
  12200. 'unsupported document encoding <' + encoding + '>, ' +
  12201. 'falling back to UTF-8'
  12202. });
  12203. }
  12204. function handleOpen(node, getContext) {
  12205. var handler = stack.peek();
  12206. try {
  12207. stack.push(handler.handleNode(node));
  12208. } catch (err) {
  12209. if (handleError(err, getContext, lax)) {
  12210. stack.push(new NoopHandler());
  12211. }
  12212. }
  12213. }
  12214. function handleCData(text, getContext) {
  12215. try {
  12216. stack.peek().handleText(text);
  12217. } catch (err) {
  12218. handleWarning(err, getContext);
  12219. }
  12220. }
  12221. function handleText(text, getContext) {
  12222. // strip whitespace only nodes, i.e. before
  12223. // <!CDATA[ ... ]> sections and in between tags
  12224. if (!text.trim()) {
  12225. return;
  12226. }
  12227. handleCData(text, getContext);
  12228. }
  12229. var uriMap = model.getPackages().reduce(function(uriMap, p) {
  12230. uriMap[p.uri] = p.prefix;
  12231. return uriMap;
  12232. }, {
  12233. 'http://www.w3.org/XML/1998/namespace': 'xml' // add default xml ns
  12234. });
  12235. parser
  12236. .ns(uriMap)
  12237. .on('openTag', function(obj, decodeStr, selfClosing, getContext) {
  12238. // gracefully handle unparsable attributes (attrs=false)
  12239. var attrs = obj.attrs || {};
  12240. var decodedAttrs = Object.keys(attrs).reduce(function(d, key) {
  12241. var value = decodeStr(attrs[key]);
  12242. d[key] = value;
  12243. return d;
  12244. }, {});
  12245. var node = {
  12246. name: obj.name,
  12247. originalName: obj.originalName,
  12248. attributes: decodedAttrs,
  12249. ns: obj.ns
  12250. };
  12251. handleOpen(node, getContext);
  12252. })
  12253. .on('question', handleQuestion)
  12254. .on('closeTag', handleClose)
  12255. .on('cdata', handleCData)
  12256. .on('text', function(text, decodeEntities, getContext) {
  12257. handleText(decodeEntities(text), getContext);
  12258. })
  12259. .on('error', handleError)
  12260. .on('warn', handleWarning);
  12261. // async XML parsing to make sure the execution environment
  12262. // (node or brower) is kept responsive and that certain optimization
  12263. // strategies can kick in.
  12264. return new Promise(function(resolve, reject) {
  12265. var err;
  12266. try {
  12267. parser.parse(xml);
  12268. resolveReferences();
  12269. } catch (e) {
  12270. err = e;
  12271. }
  12272. var rootElement = rootHandler.element;
  12273. if (!err && !rootElement) {
  12274. err = error('failed to parse document as <' + rootHandler.type.$descriptor.name + '>');
  12275. }
  12276. var warnings = context.warnings;
  12277. var references = context.references;
  12278. var elementsById = context.elementsById;
  12279. if (err) {
  12280. err.warnings = warnings;
  12281. return reject(err);
  12282. } else {
  12283. return resolve({
  12284. rootElement: rootElement,
  12285. elementsById: elementsById,
  12286. references: references,
  12287. warnings: warnings
  12288. });
  12289. }
  12290. });
  12291. };
  12292. Reader.prototype.handler = function(name) {
  12293. return new RootElementHandler(this.model, name);
  12294. };
  12295. // helpers //////////////////////////
  12296. function createStack() {
  12297. var stack = [];
  12298. Object.defineProperty(stack, 'peek', {
  12299. value: function() {
  12300. return this[this.length - 1];
  12301. }
  12302. });
  12303. return stack;
  12304. }
  12305. var XML_PREAMBLE = '<?xml version="1.0" encoding="UTF-8"?>\n';
  12306. var ESCAPE_ATTR_CHARS = /<|>|'|"|&|\n\r|\n/g;
  12307. var ESCAPE_CHARS = /<|>|&/g;
  12308. function Namespaces(parent) {
  12309. var prefixMap = {};
  12310. var uriMap = {};
  12311. var used = {};
  12312. var wellknown = [];
  12313. var custom = [];
  12314. // API
  12315. this.byUri = function(uri) {
  12316. return uriMap[uri] || (
  12317. parent && parent.byUri(uri)
  12318. );
  12319. };
  12320. this.add = function(ns, isWellknown) {
  12321. uriMap[ns.uri] = ns;
  12322. if (isWellknown) {
  12323. wellknown.push(ns);
  12324. } else {
  12325. custom.push(ns);
  12326. }
  12327. this.mapPrefix(ns.prefix, ns.uri);
  12328. };
  12329. this.uriByPrefix = function(prefix) {
  12330. return prefixMap[prefix || 'xmlns'];
  12331. };
  12332. this.mapPrefix = function(prefix, uri) {
  12333. prefixMap[prefix || 'xmlns'] = uri;
  12334. };
  12335. this.getNSKey = function(ns) {
  12336. return (ns.prefix !== undefined) ? (ns.uri + '|' + ns.prefix) : ns.uri;
  12337. };
  12338. this.logUsed = function(ns) {
  12339. var uri = ns.uri;
  12340. var nsKey = this.getNSKey(ns);
  12341. used[nsKey] = this.byUri(uri);
  12342. // Inform parent recursively about the usage of this NS
  12343. if (parent) {
  12344. parent.logUsed(ns);
  12345. }
  12346. };
  12347. this.getUsed = function(ns) {
  12348. function isUsed(ns) {
  12349. var nsKey = self.getNSKey(ns);
  12350. return used[nsKey];
  12351. }
  12352. var self = this;
  12353. var allNs = [].concat(wellknown, custom);
  12354. return allNs.filter(isUsed);
  12355. };
  12356. }
  12357. function lower(string) {
  12358. return string.charAt(0).toLowerCase() + string.slice(1);
  12359. }
  12360. function nameToAlias(name, pkg) {
  12361. if (hasLowerCaseAlias(pkg)) {
  12362. return lower(name);
  12363. } else {
  12364. return name;
  12365. }
  12366. }
  12367. function inherits(ctor, superCtor) {
  12368. ctor.super_ = superCtor;
  12369. ctor.prototype = Object.create(superCtor.prototype, {
  12370. constructor: {
  12371. value: ctor,
  12372. enumerable: false,
  12373. writable: true,
  12374. configurable: true
  12375. }
  12376. });
  12377. }
  12378. function nsName(ns) {
  12379. if (isString(ns)) {
  12380. return ns;
  12381. } else {
  12382. return (ns.prefix ? ns.prefix + ':' : '') + ns.localName;
  12383. }
  12384. }
  12385. function getNsAttrs(namespaces) {
  12386. return namespaces.getUsed().filter(function(ns) {
  12387. // do not serialize built in <xml> namespace
  12388. return ns.prefix !== 'xml';
  12389. }).map(function(ns) {
  12390. var name = 'xmlns' + (ns.prefix ? ':' + ns.prefix : '');
  12391. return { name: name, value: ns.uri };
  12392. });
  12393. }
  12394. function getElementNs(ns, descriptor) {
  12395. if (descriptor.isGeneric) {
  12396. return assign({ localName: descriptor.ns.localName }, ns);
  12397. } else {
  12398. return assign({ localName: nameToAlias(descriptor.ns.localName, descriptor.$pkg) }, ns);
  12399. }
  12400. }
  12401. function getPropertyNs(ns, descriptor) {
  12402. return assign({ localName: descriptor.ns.localName }, ns);
  12403. }
  12404. function getSerializableProperties(element) {
  12405. var descriptor = element.$descriptor;
  12406. return filter(descriptor.properties, function(p) {
  12407. var name = p.name;
  12408. if (p.isVirtual) {
  12409. return false;
  12410. }
  12411. // do not serialize defaults
  12412. if (!has$1(element, name)) {
  12413. return false;
  12414. }
  12415. var value = element[name];
  12416. // do not serialize default equals
  12417. if (value === p.default) {
  12418. return false;
  12419. }
  12420. // do not serialize null properties
  12421. if (value === null) {
  12422. return false;
  12423. }
  12424. return p.isMany ? value.length : true;
  12425. });
  12426. }
  12427. var ESCAPE_ATTR_MAP = {
  12428. '\n': '#10',
  12429. '\n\r': '#10',
  12430. '"': '#34',
  12431. '\'': '#39',
  12432. '<': '#60',
  12433. '>': '#62',
  12434. '&': '#38'
  12435. };
  12436. var ESCAPE_MAP = {
  12437. '<': 'lt',
  12438. '>': 'gt',
  12439. '&': 'amp'
  12440. };
  12441. function escape(str, charPattern, replaceMap) {
  12442. // ensure we are handling strings here
  12443. str = isString(str) ? str : '' + str;
  12444. return str.replace(charPattern, function(s) {
  12445. return '&' + replaceMap[s] + ';';
  12446. });
  12447. }
  12448. /**
  12449. * Escape a string attribute to not contain any bad values (line breaks, '"', ...)
  12450. *
  12451. * @param {String} str the string to escape
  12452. * @return {String} the escaped string
  12453. */
  12454. function escapeAttr(str) {
  12455. return escape(str, ESCAPE_ATTR_CHARS, ESCAPE_ATTR_MAP);
  12456. }
  12457. function escapeBody(str) {
  12458. return escape(str, ESCAPE_CHARS, ESCAPE_MAP);
  12459. }
  12460. function filterAttributes(props) {
  12461. return filter(props, function(p) { return p.isAttr; });
  12462. }
  12463. function filterContained(props) {
  12464. return filter(props, function(p) { return !p.isAttr; });
  12465. }
  12466. function ReferenceSerializer(tagName) {
  12467. this.tagName = tagName;
  12468. }
  12469. ReferenceSerializer.prototype.build = function(element) {
  12470. this.element = element;
  12471. return this;
  12472. };
  12473. ReferenceSerializer.prototype.serializeTo = function(writer) {
  12474. writer
  12475. .appendIndent()
  12476. .append('<' + this.tagName + '>' + this.element.id + '</' + this.tagName + '>')
  12477. .appendNewLine();
  12478. };
  12479. function BodySerializer() {}
  12480. BodySerializer.prototype.serializeValue =
  12481. BodySerializer.prototype.serializeTo = function(writer) {
  12482. writer.append(
  12483. this.escape
  12484. ? escapeBody(this.value)
  12485. : this.value
  12486. );
  12487. };
  12488. BodySerializer.prototype.build = function(prop, value) {
  12489. this.value = value;
  12490. if (prop.type === 'String' && value.search(ESCAPE_CHARS) !== -1) {
  12491. this.escape = true;
  12492. }
  12493. return this;
  12494. };
  12495. function ValueSerializer(tagName) {
  12496. this.tagName = tagName;
  12497. }
  12498. inherits(ValueSerializer, BodySerializer);
  12499. ValueSerializer.prototype.serializeTo = function(writer) {
  12500. writer
  12501. .appendIndent()
  12502. .append('<' + this.tagName + '>');
  12503. this.serializeValue(writer);
  12504. writer
  12505. .append('</' + this.tagName + '>')
  12506. .appendNewLine();
  12507. };
  12508. function ElementSerializer(parent, propertyDescriptor) {
  12509. this.body = [];
  12510. this.attrs = [];
  12511. this.parent = parent;
  12512. this.propertyDescriptor = propertyDescriptor;
  12513. }
  12514. ElementSerializer.prototype.build = function(element) {
  12515. this.element = element;
  12516. var elementDescriptor = element.$descriptor,
  12517. propertyDescriptor = this.propertyDescriptor;
  12518. var otherAttrs,
  12519. properties;
  12520. var isGeneric = elementDescriptor.isGeneric;
  12521. if (isGeneric) {
  12522. otherAttrs = this.parseGeneric(element);
  12523. } else {
  12524. otherAttrs = this.parseNsAttributes(element);
  12525. }
  12526. if (propertyDescriptor) {
  12527. this.ns = this.nsPropertyTagName(propertyDescriptor);
  12528. } else {
  12529. this.ns = this.nsTagName(elementDescriptor);
  12530. }
  12531. // compute tag name
  12532. this.tagName = this.addTagName(this.ns);
  12533. if (!isGeneric) {
  12534. properties = getSerializableProperties(element);
  12535. this.parseAttributes(filterAttributes(properties));
  12536. this.parseContainments(filterContained(properties));
  12537. }
  12538. this.parseGenericAttributes(element, otherAttrs);
  12539. return this;
  12540. };
  12541. ElementSerializer.prototype.nsTagName = function(descriptor) {
  12542. var effectiveNs = this.logNamespaceUsed(descriptor.ns);
  12543. return getElementNs(effectiveNs, descriptor);
  12544. };
  12545. ElementSerializer.prototype.nsPropertyTagName = function(descriptor) {
  12546. var effectiveNs = this.logNamespaceUsed(descriptor.ns);
  12547. return getPropertyNs(effectiveNs, descriptor);
  12548. };
  12549. ElementSerializer.prototype.isLocalNs = function(ns) {
  12550. return ns.uri === this.ns.uri;
  12551. };
  12552. /**
  12553. * Get the actual ns attribute name for the given element.
  12554. *
  12555. * @param {Object} element
  12556. * @param {Boolean} [element.inherited=false]
  12557. *
  12558. * @return {Object} nsName
  12559. */
  12560. ElementSerializer.prototype.nsAttributeName = function(element) {
  12561. var ns;
  12562. if (isString(element)) {
  12563. ns = parseName(element);
  12564. } else {
  12565. ns = element.ns;
  12566. }
  12567. // return just local name for inherited attributes
  12568. if (element.inherited) {
  12569. return { localName: ns.localName };
  12570. }
  12571. // parse + log effective ns
  12572. var effectiveNs = this.logNamespaceUsed(ns);
  12573. // LOG ACTUAL namespace use
  12574. this.getNamespaces().logUsed(effectiveNs);
  12575. // strip prefix if same namespace like parent
  12576. if (this.isLocalNs(effectiveNs)) {
  12577. return { localName: ns.localName };
  12578. } else {
  12579. return assign({ localName: ns.localName }, effectiveNs);
  12580. }
  12581. };
  12582. ElementSerializer.prototype.parseGeneric = function(element) {
  12583. var self = this,
  12584. body = this.body;
  12585. var attributes = [];
  12586. forEach$1(element, function(val, key) {
  12587. var nonNsAttr;
  12588. if (key === '$body') {
  12589. body.push(new BodySerializer().build({ type: 'String' }, val));
  12590. } else
  12591. if (key === '$children') {
  12592. forEach$1(val, function(child) {
  12593. body.push(new ElementSerializer(self).build(child));
  12594. });
  12595. } else
  12596. if (key.indexOf('$') !== 0) {
  12597. nonNsAttr = self.parseNsAttribute(element, key, val);
  12598. if (nonNsAttr) {
  12599. attributes.push({ name: key, value: val });
  12600. }
  12601. }
  12602. });
  12603. return attributes;
  12604. };
  12605. ElementSerializer.prototype.parseNsAttribute = function(element, name, value) {
  12606. var model = element.$model;
  12607. var nameNs = parseName(name);
  12608. var ns;
  12609. // parse xmlns:foo="http://foo.bar"
  12610. if (nameNs.prefix === 'xmlns') {
  12611. ns = { prefix: nameNs.localName, uri: value };
  12612. }
  12613. // parse xmlns="http://foo.bar"
  12614. if (!nameNs.prefix && nameNs.localName === 'xmlns') {
  12615. ns = { uri: value };
  12616. }
  12617. if (!ns) {
  12618. return {
  12619. name: name,
  12620. value: value
  12621. };
  12622. }
  12623. if (model && model.getPackage(value)) {
  12624. // register well known namespace
  12625. this.logNamespace(ns, true, true);
  12626. } else {
  12627. // log custom namespace directly as used
  12628. var actualNs = this.logNamespaceUsed(ns, true);
  12629. this.getNamespaces().logUsed(actualNs);
  12630. }
  12631. };
  12632. /**
  12633. * Parse namespaces and return a list of left over generic attributes
  12634. *
  12635. * @param {Object} element
  12636. * @return {Array<Object>}
  12637. */
  12638. ElementSerializer.prototype.parseNsAttributes = function(element, attrs) {
  12639. var self = this;
  12640. var genericAttrs = element.$attrs;
  12641. var attributes = [];
  12642. // parse namespace attributes first
  12643. // and log them. push non namespace attributes to a list
  12644. // and process them later
  12645. forEach$1(genericAttrs, function(value, name) {
  12646. var nonNsAttr = self.parseNsAttribute(element, name, value);
  12647. if (nonNsAttr) {
  12648. attributes.push(nonNsAttr);
  12649. }
  12650. });
  12651. return attributes;
  12652. };
  12653. ElementSerializer.prototype.parseGenericAttributes = function(element, attributes) {
  12654. var self = this;
  12655. forEach$1(attributes, function(attr) {
  12656. // do not serialize xsi:type attribute
  12657. // it is set manually based on the actual implementation type
  12658. if (attr.name === XSI_TYPE) {
  12659. return;
  12660. }
  12661. try {
  12662. self.addAttribute(self.nsAttributeName(attr.name), attr.value);
  12663. } catch (e) {
  12664. console.warn(
  12665. 'missing namespace information for ',
  12666. attr.name, '=', attr.value, 'on', element,
  12667. e);
  12668. }
  12669. });
  12670. };
  12671. ElementSerializer.prototype.parseContainments = function(properties) {
  12672. var self = this,
  12673. body = this.body,
  12674. element = this.element;
  12675. forEach$1(properties, function(p) {
  12676. var value = element.get(p.name),
  12677. isReference = p.isReference,
  12678. isMany = p.isMany;
  12679. if (!isMany) {
  12680. value = [ value ];
  12681. }
  12682. if (p.isBody) {
  12683. body.push(new BodySerializer().build(p, value[0]));
  12684. } else
  12685. if (isSimple(p.type)) {
  12686. forEach$1(value, function(v) {
  12687. body.push(new ValueSerializer(self.addTagName(self.nsPropertyTagName(p))).build(p, v));
  12688. });
  12689. } else
  12690. if (isReference) {
  12691. forEach$1(value, function(v) {
  12692. body.push(new ReferenceSerializer(self.addTagName(self.nsPropertyTagName(p))).build(v));
  12693. });
  12694. } else {
  12695. // allow serialization via type
  12696. // rather than element name
  12697. var asType = serializeAsType(p),
  12698. asProperty = serializeAsProperty(p);
  12699. forEach$1(value, function(v) {
  12700. var serializer;
  12701. if (asType) {
  12702. serializer = new TypeSerializer(self, p);
  12703. } else
  12704. if (asProperty) {
  12705. serializer = new ElementSerializer(self, p);
  12706. } else {
  12707. serializer = new ElementSerializer(self);
  12708. }
  12709. body.push(serializer.build(v));
  12710. });
  12711. }
  12712. });
  12713. };
  12714. ElementSerializer.prototype.getNamespaces = function(local) {
  12715. var namespaces = this.namespaces,
  12716. parent = this.parent,
  12717. parentNamespaces;
  12718. if (!namespaces) {
  12719. parentNamespaces = parent && parent.getNamespaces();
  12720. if (local || !parentNamespaces) {
  12721. this.namespaces = namespaces = new Namespaces(parentNamespaces);
  12722. } else {
  12723. namespaces = parentNamespaces;
  12724. }
  12725. }
  12726. return namespaces;
  12727. };
  12728. ElementSerializer.prototype.logNamespace = function(ns, wellknown, local) {
  12729. var namespaces = this.getNamespaces(local);
  12730. var nsUri = ns.uri,
  12731. nsPrefix = ns.prefix;
  12732. var existing = namespaces.byUri(nsUri);
  12733. if (!existing || local) {
  12734. namespaces.add(ns, wellknown);
  12735. }
  12736. namespaces.mapPrefix(nsPrefix, nsUri);
  12737. return ns;
  12738. };
  12739. ElementSerializer.prototype.logNamespaceUsed = function(ns, local) {
  12740. var element = this.element,
  12741. model = element.$model,
  12742. namespaces = this.getNamespaces(local);
  12743. // ns may be
  12744. //
  12745. // * prefix only
  12746. // * prefix:uri
  12747. // * localName only
  12748. var prefix = ns.prefix,
  12749. uri = ns.uri,
  12750. newPrefix, idx,
  12751. wellknownUri;
  12752. // handle anonymous namespaces (elementForm=unqualified), cf. #23
  12753. if (!prefix && !uri) {
  12754. return { localName: ns.localName };
  12755. }
  12756. wellknownUri = DEFAULT_NS_MAP[prefix] || model && (model.getPackage(prefix) || {}).uri;
  12757. uri = uri || wellknownUri || namespaces.uriByPrefix(prefix);
  12758. if (!uri) {
  12759. throw new Error('no namespace uri given for prefix <' + prefix + '>');
  12760. }
  12761. ns = namespaces.byUri(uri);
  12762. if (!ns) {
  12763. newPrefix = prefix;
  12764. idx = 1;
  12765. // find a prefix that is not mapped yet
  12766. while (namespaces.uriByPrefix(newPrefix)) {
  12767. newPrefix = prefix + '_' + idx++;
  12768. }
  12769. ns = this.logNamespace({ prefix: newPrefix, uri: uri }, wellknownUri === uri);
  12770. }
  12771. if (prefix) {
  12772. namespaces.mapPrefix(prefix, uri);
  12773. }
  12774. return ns;
  12775. };
  12776. ElementSerializer.prototype.parseAttributes = function(properties) {
  12777. var self = this,
  12778. element = this.element;
  12779. forEach$1(properties, function(p) {
  12780. var value = element.get(p.name);
  12781. if (p.isReference) {
  12782. if (!p.isMany) {
  12783. value = value.id;
  12784. }
  12785. else {
  12786. var values = [];
  12787. forEach$1(value, function(v) {
  12788. values.push(v.id);
  12789. });
  12790. // IDREFS is a whitespace-separated list of references.
  12791. value = values.join(' ');
  12792. }
  12793. }
  12794. self.addAttribute(self.nsAttributeName(p), value);
  12795. });
  12796. };
  12797. ElementSerializer.prototype.addTagName = function(nsTagName) {
  12798. var actualNs = this.logNamespaceUsed(nsTagName);
  12799. this.getNamespaces().logUsed(actualNs);
  12800. return nsName(nsTagName);
  12801. };
  12802. ElementSerializer.prototype.addAttribute = function(name, value) {
  12803. var attrs = this.attrs;
  12804. if (isString(value)) {
  12805. value = escapeAttr(value);
  12806. }
  12807. attrs.push({ name: name, value: value });
  12808. };
  12809. ElementSerializer.prototype.serializeAttributes = function(writer) {
  12810. var attrs = this.attrs,
  12811. namespaces = this.namespaces;
  12812. if (namespaces) {
  12813. attrs = getNsAttrs(namespaces).concat(attrs);
  12814. }
  12815. forEach$1(attrs, function(a) {
  12816. writer
  12817. .append(' ')
  12818. .append(nsName(a.name)).append('="').append(a.value).append('"');
  12819. });
  12820. };
  12821. ElementSerializer.prototype.serializeTo = function(writer) {
  12822. var firstBody = this.body[0],
  12823. indent = firstBody && firstBody.constructor !== BodySerializer;
  12824. writer
  12825. .appendIndent()
  12826. .append('<' + this.tagName);
  12827. this.serializeAttributes(writer);
  12828. writer.append(firstBody ? '>' : ' />');
  12829. if (firstBody) {
  12830. if (indent) {
  12831. writer
  12832. .appendNewLine()
  12833. .indent();
  12834. }
  12835. forEach$1(this.body, function(b) {
  12836. b.serializeTo(writer);
  12837. });
  12838. if (indent) {
  12839. writer
  12840. .unindent()
  12841. .appendIndent();
  12842. }
  12843. writer.append('</' + this.tagName + '>');
  12844. }
  12845. writer.appendNewLine();
  12846. };
  12847. /**
  12848. * A serializer for types that handles serialization of data types
  12849. */
  12850. function TypeSerializer(parent, propertyDescriptor) {
  12851. ElementSerializer.call(this, parent, propertyDescriptor);
  12852. }
  12853. inherits(TypeSerializer, ElementSerializer);
  12854. TypeSerializer.prototype.parseNsAttributes = function(element) {
  12855. // extracted attributes
  12856. var attributes = ElementSerializer.prototype.parseNsAttributes.call(this, element);
  12857. var descriptor = element.$descriptor;
  12858. // only serialize xsi:type if necessary
  12859. if (descriptor.name === this.propertyDescriptor.type) {
  12860. return attributes;
  12861. }
  12862. var typeNs = this.typeNs = this.nsTagName(descriptor);
  12863. this.getNamespaces().logUsed(this.typeNs);
  12864. // add xsi:type attribute to represent the elements
  12865. // actual type
  12866. var pkg = element.$model.getPackage(typeNs.uri),
  12867. typePrefix = (pkg.xml && pkg.xml.typePrefix) || '';
  12868. this.addAttribute(
  12869. this.nsAttributeName(XSI_TYPE),
  12870. (typeNs.prefix ? typeNs.prefix + ':' : '') + typePrefix + descriptor.ns.localName
  12871. );
  12872. return attributes;
  12873. };
  12874. TypeSerializer.prototype.isLocalNs = function(ns) {
  12875. return ns.uri === (this.typeNs || this.ns).uri;
  12876. };
  12877. function SavingWriter() {
  12878. this.value = '';
  12879. this.write = function(str) {
  12880. this.value += str;
  12881. };
  12882. }
  12883. function FormatingWriter(out, format) {
  12884. var indent = [''];
  12885. this.append = function(str) {
  12886. out.write(str);
  12887. return this;
  12888. };
  12889. this.appendNewLine = function() {
  12890. if (format) {
  12891. out.write('\n');
  12892. }
  12893. return this;
  12894. };
  12895. this.appendIndent = function() {
  12896. if (format) {
  12897. out.write(indent.join(' '));
  12898. }
  12899. return this;
  12900. };
  12901. this.indent = function() {
  12902. indent.push('');
  12903. return this;
  12904. };
  12905. this.unindent = function() {
  12906. indent.pop();
  12907. return this;
  12908. };
  12909. }
  12910. /**
  12911. * A writer for meta-model backed document trees
  12912. *
  12913. * @param {Object} options output options to pass into the writer
  12914. */
  12915. function Writer(options) {
  12916. options = assign({ format: false, preamble: true }, options || {});
  12917. function toXML(tree, writer) {
  12918. var internalWriter = writer || new SavingWriter();
  12919. var formatingWriter = new FormatingWriter(internalWriter, options.format);
  12920. if (options.preamble) {
  12921. formatingWriter.append(XML_PREAMBLE);
  12922. }
  12923. new ElementSerializer().build(tree).serializeTo(formatingWriter);
  12924. if (!writer) {
  12925. return internalWriter.value;
  12926. }
  12927. }
  12928. return {
  12929. toXML: toXML
  12930. };
  12931. }
  12932. /**
  12933. * A sub class of {@link Moddle} with support for import and export of BPMN 2.0 xml files.
  12934. *
  12935. * @class BpmnModdle
  12936. * @extends Moddle
  12937. *
  12938. * @param {Object|Array} packages to use for instantiating the model
  12939. * @param {Object} [options] additional options to pass over
  12940. */
  12941. function BpmnModdle(packages, options) {
  12942. Moddle.call(this, packages, options);
  12943. }
  12944. BpmnModdle.prototype = Object.create(Moddle.prototype);
  12945. /**
  12946. * The fromXML result.
  12947. *
  12948. * @typedef {Object} ParseResult
  12949. *
  12950. * @property {ModdleElement} rootElement
  12951. * @property {Array<Object>} references
  12952. * @property {Array<Error>} warnings
  12953. * @property {Object} elementsById - a mapping containing each ID -> ModdleElement
  12954. */
  12955. /**
  12956. * The fromXML error.
  12957. *
  12958. * @typedef {Error} ParseError
  12959. *
  12960. * @property {Array<Error>} warnings
  12961. */
  12962. /**
  12963. * Instantiates a BPMN model tree from a given xml string.
  12964. *
  12965. * @param {String} xmlStr
  12966. * @param {String} [typeName='bpmn:Definitions'] name of the root element
  12967. * @param {Object} [options] options to pass to the underlying reader
  12968. *
  12969. * @returns {Promise<ParseResult, ParseError>}
  12970. */
  12971. BpmnModdle.prototype.fromXML = function(xmlStr, typeName, options) {
  12972. if (!isString(typeName)) {
  12973. options = typeName;
  12974. typeName = 'bpmn:Definitions';
  12975. }
  12976. var reader = new Reader(assign({ model: this, lax: true }, options));
  12977. var rootHandler = reader.handler(typeName);
  12978. return reader.fromXML(xmlStr, rootHandler);
  12979. };
  12980. /**
  12981. * The toXML result.
  12982. *
  12983. * @typedef {Object} SerializationResult
  12984. *
  12985. * @property {String} xml
  12986. */
  12987. /**
  12988. * Serializes a BPMN 2.0 object tree to XML.
  12989. *
  12990. * @param {String} element the root element, typically an instance of `bpmn:Definitions`
  12991. * @param {Object} [options] to pass to the underlying writer
  12992. *
  12993. * @returns {Promise<SerializationResult, Error>}
  12994. */
  12995. BpmnModdle.prototype.toXML = function(element, options) {
  12996. var writer = new Writer(options);
  12997. return new Promise(function(resolve, reject) {
  12998. try {
  12999. var result = writer.toXML(element);
  13000. return resolve({
  13001. xml: result
  13002. });
  13003. } catch (err) {
  13004. return reject(err);
  13005. }
  13006. });
  13007. };
  13008. var name = "BPMN20";
  13009. var uri = "http://www.omg.org/spec/BPMN/20100524/MODEL";
  13010. var prefix = "bpmn";
  13011. var associations = [
  13012. ];
  13013. var types = [
  13014. {
  13015. name: "Interface",
  13016. superClass: [
  13017. "RootElement"
  13018. ],
  13019. properties: [
  13020. {
  13021. name: "name",
  13022. isAttr: true,
  13023. type: "String"
  13024. },
  13025. {
  13026. name: "operations",
  13027. type: "Operation",
  13028. isMany: true
  13029. },
  13030. {
  13031. name: "implementationRef",
  13032. isAttr: true,
  13033. type: "String"
  13034. }
  13035. ]
  13036. },
  13037. {
  13038. name: "Operation",
  13039. superClass: [
  13040. "BaseElement"
  13041. ],
  13042. properties: [
  13043. {
  13044. name: "name",
  13045. isAttr: true,
  13046. type: "String"
  13047. },
  13048. {
  13049. name: "inMessageRef",
  13050. type: "Message",
  13051. isReference: true
  13052. },
  13053. {
  13054. name: "outMessageRef",
  13055. type: "Message",
  13056. isReference: true
  13057. },
  13058. {
  13059. name: "errorRef",
  13060. type: "Error",
  13061. isMany: true,
  13062. isReference: true
  13063. },
  13064. {
  13065. name: "implementationRef",
  13066. isAttr: true,
  13067. type: "String"
  13068. }
  13069. ]
  13070. },
  13071. {
  13072. name: "EndPoint",
  13073. superClass: [
  13074. "RootElement"
  13075. ]
  13076. },
  13077. {
  13078. name: "Auditing",
  13079. superClass: [
  13080. "BaseElement"
  13081. ]
  13082. },
  13083. {
  13084. name: "GlobalTask",
  13085. superClass: [
  13086. "CallableElement"
  13087. ],
  13088. properties: [
  13089. {
  13090. name: "resources",
  13091. type: "ResourceRole",
  13092. isMany: true
  13093. }
  13094. ]
  13095. },
  13096. {
  13097. name: "Monitoring",
  13098. superClass: [
  13099. "BaseElement"
  13100. ]
  13101. },
  13102. {
  13103. name: "Performer",
  13104. superClass: [
  13105. "ResourceRole"
  13106. ]
  13107. },
  13108. {
  13109. name: "Process",
  13110. superClass: [
  13111. "FlowElementsContainer",
  13112. "CallableElement"
  13113. ],
  13114. properties: [
  13115. {
  13116. name: "processType",
  13117. type: "ProcessType",
  13118. isAttr: true
  13119. },
  13120. {
  13121. name: "isClosed",
  13122. isAttr: true,
  13123. type: "Boolean"
  13124. },
  13125. {
  13126. name: "auditing",
  13127. type: "Auditing"
  13128. },
  13129. {
  13130. name: "monitoring",
  13131. type: "Monitoring"
  13132. },
  13133. {
  13134. name: "properties",
  13135. type: "Property",
  13136. isMany: true
  13137. },
  13138. {
  13139. name: "laneSets",
  13140. isMany: true,
  13141. replaces: "FlowElementsContainer#laneSets",
  13142. type: "LaneSet"
  13143. },
  13144. {
  13145. name: "flowElements",
  13146. isMany: true,
  13147. replaces: "FlowElementsContainer#flowElements",
  13148. type: "FlowElement"
  13149. },
  13150. {
  13151. name: "artifacts",
  13152. type: "Artifact",
  13153. isMany: true
  13154. },
  13155. {
  13156. name: "resources",
  13157. type: "ResourceRole",
  13158. isMany: true
  13159. },
  13160. {
  13161. name: "correlationSubscriptions",
  13162. type: "CorrelationSubscription",
  13163. isMany: true
  13164. },
  13165. {
  13166. name: "supports",
  13167. type: "Process",
  13168. isMany: true,
  13169. isReference: true
  13170. },
  13171. {
  13172. name: "definitionalCollaborationRef",
  13173. type: "Collaboration",
  13174. isAttr: true,
  13175. isReference: true
  13176. },
  13177. {
  13178. name: "isExecutable",
  13179. isAttr: true,
  13180. type: "Boolean"
  13181. }
  13182. ]
  13183. },
  13184. {
  13185. name: "LaneSet",
  13186. superClass: [
  13187. "BaseElement"
  13188. ],
  13189. properties: [
  13190. {
  13191. name: "lanes",
  13192. type: "Lane",
  13193. isMany: true
  13194. },
  13195. {
  13196. name: "name",
  13197. isAttr: true,
  13198. type: "String"
  13199. }
  13200. ]
  13201. },
  13202. {
  13203. name: "Lane",
  13204. superClass: [
  13205. "BaseElement"
  13206. ],
  13207. properties: [
  13208. {
  13209. name: "name",
  13210. isAttr: true,
  13211. type: "String"
  13212. },
  13213. {
  13214. name: "partitionElementRef",
  13215. type: "BaseElement",
  13216. isAttr: true,
  13217. isReference: true
  13218. },
  13219. {
  13220. name: "partitionElement",
  13221. type: "BaseElement"
  13222. },
  13223. {
  13224. name: "flowNodeRef",
  13225. type: "FlowNode",
  13226. isMany: true,
  13227. isReference: true
  13228. },
  13229. {
  13230. name: "childLaneSet",
  13231. type: "LaneSet",
  13232. xml: {
  13233. serialize: "xsi:type"
  13234. }
  13235. }
  13236. ]
  13237. },
  13238. {
  13239. name: "GlobalManualTask",
  13240. superClass: [
  13241. "GlobalTask"
  13242. ]
  13243. },
  13244. {
  13245. name: "ManualTask",
  13246. superClass: [
  13247. "Task"
  13248. ]
  13249. },
  13250. {
  13251. name: "UserTask",
  13252. superClass: [
  13253. "Task"
  13254. ],
  13255. properties: [
  13256. {
  13257. name: "renderings",
  13258. type: "Rendering",
  13259. isMany: true
  13260. },
  13261. {
  13262. name: "implementation",
  13263. isAttr: true,
  13264. type: "String"
  13265. }
  13266. ]
  13267. },
  13268. {
  13269. name: "Rendering",
  13270. superClass: [
  13271. "BaseElement"
  13272. ]
  13273. },
  13274. {
  13275. name: "HumanPerformer",
  13276. superClass: [
  13277. "Performer"
  13278. ]
  13279. },
  13280. {
  13281. name: "PotentialOwner",
  13282. superClass: [
  13283. "HumanPerformer"
  13284. ]
  13285. },
  13286. {
  13287. name: "GlobalUserTask",
  13288. superClass: [
  13289. "GlobalTask"
  13290. ],
  13291. properties: [
  13292. {
  13293. name: "implementation",
  13294. isAttr: true,
  13295. type: "String"
  13296. },
  13297. {
  13298. name: "renderings",
  13299. type: "Rendering",
  13300. isMany: true
  13301. }
  13302. ]
  13303. },
  13304. {
  13305. name: "Gateway",
  13306. isAbstract: true,
  13307. superClass: [
  13308. "FlowNode"
  13309. ],
  13310. properties: [
  13311. {
  13312. name: "gatewayDirection",
  13313. type: "GatewayDirection",
  13314. "default": "Unspecified",
  13315. isAttr: true
  13316. }
  13317. ]
  13318. },
  13319. {
  13320. name: "EventBasedGateway",
  13321. superClass: [
  13322. "Gateway"
  13323. ],
  13324. properties: [
  13325. {
  13326. name: "instantiate",
  13327. "default": false,
  13328. isAttr: true,
  13329. type: "Boolean"
  13330. },
  13331. {
  13332. name: "eventGatewayType",
  13333. type: "EventBasedGatewayType",
  13334. isAttr: true,
  13335. "default": "Exclusive"
  13336. }
  13337. ]
  13338. },
  13339. {
  13340. name: "ComplexGateway",
  13341. superClass: [
  13342. "Gateway"
  13343. ],
  13344. properties: [
  13345. {
  13346. name: "activationCondition",
  13347. type: "Expression",
  13348. xml: {
  13349. serialize: "xsi:type"
  13350. }
  13351. },
  13352. {
  13353. name: "default",
  13354. type: "SequenceFlow",
  13355. isAttr: true,
  13356. isReference: true
  13357. }
  13358. ]
  13359. },
  13360. {
  13361. name: "ExclusiveGateway",
  13362. superClass: [
  13363. "Gateway"
  13364. ],
  13365. properties: [
  13366. {
  13367. name: "default",
  13368. type: "SequenceFlow",
  13369. isAttr: true,
  13370. isReference: true
  13371. }
  13372. ]
  13373. },
  13374. {
  13375. name: "InclusiveGateway",
  13376. superClass: [
  13377. "Gateway"
  13378. ],
  13379. properties: [
  13380. {
  13381. name: "default",
  13382. type: "SequenceFlow",
  13383. isAttr: true,
  13384. isReference: true
  13385. }
  13386. ]
  13387. },
  13388. {
  13389. name: "ParallelGateway",
  13390. superClass: [
  13391. "Gateway"
  13392. ]
  13393. },
  13394. {
  13395. name: "RootElement",
  13396. isAbstract: true,
  13397. superClass: [
  13398. "BaseElement"
  13399. ]
  13400. },
  13401. {
  13402. name: "Relationship",
  13403. superClass: [
  13404. "BaseElement"
  13405. ],
  13406. properties: [
  13407. {
  13408. name: "type",
  13409. isAttr: true,
  13410. type: "String"
  13411. },
  13412. {
  13413. name: "direction",
  13414. type: "RelationshipDirection",
  13415. isAttr: true
  13416. },
  13417. {
  13418. name: "source",
  13419. isMany: true,
  13420. isReference: true,
  13421. type: "Element"
  13422. },
  13423. {
  13424. name: "target",
  13425. isMany: true,
  13426. isReference: true,
  13427. type: "Element"
  13428. }
  13429. ]
  13430. },
  13431. {
  13432. name: "BaseElement",
  13433. isAbstract: true,
  13434. properties: [
  13435. {
  13436. name: "id",
  13437. isAttr: true,
  13438. type: "String",
  13439. isId: true
  13440. },
  13441. {
  13442. name: "documentation",
  13443. type: "Documentation",
  13444. isMany: true
  13445. },
  13446. {
  13447. name: "extensionDefinitions",
  13448. type: "ExtensionDefinition",
  13449. isMany: true,
  13450. isReference: true
  13451. },
  13452. {
  13453. name: "extensionElements",
  13454. type: "ExtensionElements"
  13455. }
  13456. ]
  13457. },
  13458. {
  13459. name: "Extension",
  13460. properties: [
  13461. {
  13462. name: "mustUnderstand",
  13463. "default": false,
  13464. isAttr: true,
  13465. type: "Boolean"
  13466. },
  13467. {
  13468. name: "definition",
  13469. type: "ExtensionDefinition",
  13470. isAttr: true,
  13471. isReference: true
  13472. }
  13473. ]
  13474. },
  13475. {
  13476. name: "ExtensionDefinition",
  13477. properties: [
  13478. {
  13479. name: "name",
  13480. isAttr: true,
  13481. type: "String"
  13482. },
  13483. {
  13484. name: "extensionAttributeDefinitions",
  13485. type: "ExtensionAttributeDefinition",
  13486. isMany: true
  13487. }
  13488. ]
  13489. },
  13490. {
  13491. name: "ExtensionAttributeDefinition",
  13492. properties: [
  13493. {
  13494. name: "name",
  13495. isAttr: true,
  13496. type: "String"
  13497. },
  13498. {
  13499. name: "type",
  13500. isAttr: true,
  13501. type: "String"
  13502. },
  13503. {
  13504. name: "isReference",
  13505. "default": false,
  13506. isAttr: true,
  13507. type: "Boolean"
  13508. },
  13509. {
  13510. name: "extensionDefinition",
  13511. type: "ExtensionDefinition",
  13512. isAttr: true,
  13513. isReference: true
  13514. }
  13515. ]
  13516. },
  13517. {
  13518. name: "ExtensionElements",
  13519. properties: [
  13520. {
  13521. name: "valueRef",
  13522. isAttr: true,
  13523. isReference: true,
  13524. type: "Element"
  13525. },
  13526. {
  13527. name: "values",
  13528. type: "Element",
  13529. isMany: true
  13530. },
  13531. {
  13532. name: "extensionAttributeDefinition",
  13533. type: "ExtensionAttributeDefinition",
  13534. isAttr: true,
  13535. isReference: true
  13536. }
  13537. ]
  13538. },
  13539. {
  13540. name: "Documentation",
  13541. superClass: [
  13542. "BaseElement"
  13543. ],
  13544. properties: [
  13545. {
  13546. name: "text",
  13547. type: "String",
  13548. isBody: true
  13549. },
  13550. {
  13551. name: "textFormat",
  13552. "default": "text/plain",
  13553. isAttr: true,
  13554. type: "String"
  13555. }
  13556. ]
  13557. },
  13558. {
  13559. name: "Event",
  13560. isAbstract: true,
  13561. superClass: [
  13562. "FlowNode",
  13563. "InteractionNode"
  13564. ],
  13565. properties: [
  13566. {
  13567. name: "properties",
  13568. type: "Property",
  13569. isMany: true
  13570. }
  13571. ]
  13572. },
  13573. {
  13574. name: "IntermediateCatchEvent",
  13575. superClass: [
  13576. "CatchEvent"
  13577. ]
  13578. },
  13579. {
  13580. name: "IntermediateThrowEvent",
  13581. superClass: [
  13582. "ThrowEvent"
  13583. ]
  13584. },
  13585. {
  13586. name: "EndEvent",
  13587. superClass: [
  13588. "ThrowEvent"
  13589. ]
  13590. },
  13591. {
  13592. name: "StartEvent",
  13593. superClass: [
  13594. "CatchEvent"
  13595. ],
  13596. properties: [
  13597. {
  13598. name: "isInterrupting",
  13599. "default": true,
  13600. isAttr: true,
  13601. type: "Boolean"
  13602. }
  13603. ]
  13604. },
  13605. {
  13606. name: "ThrowEvent",
  13607. isAbstract: true,
  13608. superClass: [
  13609. "Event"
  13610. ],
  13611. properties: [
  13612. {
  13613. name: "dataInputs",
  13614. type: "DataInput",
  13615. isMany: true
  13616. },
  13617. {
  13618. name: "dataInputAssociations",
  13619. type: "DataInputAssociation",
  13620. isMany: true
  13621. },
  13622. {
  13623. name: "inputSet",
  13624. type: "InputSet"
  13625. },
  13626. {
  13627. name: "eventDefinitions",
  13628. type: "EventDefinition",
  13629. isMany: true
  13630. },
  13631. {
  13632. name: "eventDefinitionRef",
  13633. type: "EventDefinition",
  13634. isMany: true,
  13635. isReference: true
  13636. }
  13637. ]
  13638. },
  13639. {
  13640. name: "CatchEvent",
  13641. isAbstract: true,
  13642. superClass: [
  13643. "Event"
  13644. ],
  13645. properties: [
  13646. {
  13647. name: "parallelMultiple",
  13648. isAttr: true,
  13649. type: "Boolean",
  13650. "default": false
  13651. },
  13652. {
  13653. name: "dataOutputs",
  13654. type: "DataOutput",
  13655. isMany: true
  13656. },
  13657. {
  13658. name: "dataOutputAssociations",
  13659. type: "DataOutputAssociation",
  13660. isMany: true
  13661. },
  13662. {
  13663. name: "outputSet",
  13664. type: "OutputSet"
  13665. },
  13666. {
  13667. name: "eventDefinitions",
  13668. type: "EventDefinition",
  13669. isMany: true
  13670. },
  13671. {
  13672. name: "eventDefinitionRef",
  13673. type: "EventDefinition",
  13674. isMany: true,
  13675. isReference: true
  13676. }
  13677. ]
  13678. },
  13679. {
  13680. name: "BoundaryEvent",
  13681. superClass: [
  13682. "CatchEvent"
  13683. ],
  13684. properties: [
  13685. {
  13686. name: "cancelActivity",
  13687. "default": true,
  13688. isAttr: true,
  13689. type: "Boolean"
  13690. },
  13691. {
  13692. name: "attachedToRef",
  13693. type: "Activity",
  13694. isAttr: true,
  13695. isReference: true
  13696. }
  13697. ]
  13698. },
  13699. {
  13700. name: "EventDefinition",
  13701. isAbstract: true,
  13702. superClass: [
  13703. "RootElement"
  13704. ]
  13705. },
  13706. {
  13707. name: "CancelEventDefinition",
  13708. superClass: [
  13709. "EventDefinition"
  13710. ]
  13711. },
  13712. {
  13713. name: "ErrorEventDefinition",
  13714. superClass: [
  13715. "EventDefinition"
  13716. ],
  13717. properties: [
  13718. {
  13719. name: "errorRef",
  13720. type: "Error",
  13721. isAttr: true,
  13722. isReference: true
  13723. }
  13724. ]
  13725. },
  13726. {
  13727. name: "TerminateEventDefinition",
  13728. superClass: [
  13729. "EventDefinition"
  13730. ]
  13731. },
  13732. {
  13733. name: "EscalationEventDefinition",
  13734. superClass: [
  13735. "EventDefinition"
  13736. ],
  13737. properties: [
  13738. {
  13739. name: "escalationRef",
  13740. type: "Escalation",
  13741. isAttr: true,
  13742. isReference: true
  13743. }
  13744. ]
  13745. },
  13746. {
  13747. name: "Escalation",
  13748. properties: [
  13749. {
  13750. name: "structureRef",
  13751. type: "ItemDefinition",
  13752. isAttr: true,
  13753. isReference: true
  13754. },
  13755. {
  13756. name: "name",
  13757. isAttr: true,
  13758. type: "String"
  13759. },
  13760. {
  13761. name: "escalationCode",
  13762. isAttr: true,
  13763. type: "String"
  13764. }
  13765. ],
  13766. superClass: [
  13767. "RootElement"
  13768. ]
  13769. },
  13770. {
  13771. name: "CompensateEventDefinition",
  13772. superClass: [
  13773. "EventDefinition"
  13774. ],
  13775. properties: [
  13776. {
  13777. name: "waitForCompletion",
  13778. isAttr: true,
  13779. type: "Boolean",
  13780. "default": true
  13781. },
  13782. {
  13783. name: "activityRef",
  13784. type: "Activity",
  13785. isAttr: true,
  13786. isReference: true
  13787. }
  13788. ]
  13789. },
  13790. {
  13791. name: "TimerEventDefinition",
  13792. superClass: [
  13793. "EventDefinition"
  13794. ],
  13795. properties: [
  13796. {
  13797. name: "timeDate",
  13798. type: "Expression",
  13799. xml: {
  13800. serialize: "xsi:type"
  13801. }
  13802. },
  13803. {
  13804. name: "timeCycle",
  13805. type: "Expression",
  13806. xml: {
  13807. serialize: "xsi:type"
  13808. }
  13809. },
  13810. {
  13811. name: "timeDuration",
  13812. type: "Expression",
  13813. xml: {
  13814. serialize: "xsi:type"
  13815. }
  13816. }
  13817. ]
  13818. },
  13819. {
  13820. name: "LinkEventDefinition",
  13821. superClass: [
  13822. "EventDefinition"
  13823. ],
  13824. properties: [
  13825. {
  13826. name: "name",
  13827. isAttr: true,
  13828. type: "String"
  13829. },
  13830. {
  13831. name: "target",
  13832. type: "LinkEventDefinition",
  13833. isAttr: true,
  13834. isReference: true
  13835. },
  13836. {
  13837. name: "source",
  13838. type: "LinkEventDefinition",
  13839. isMany: true,
  13840. isReference: true
  13841. }
  13842. ]
  13843. },
  13844. {
  13845. name: "MessageEventDefinition",
  13846. superClass: [
  13847. "EventDefinition"
  13848. ],
  13849. properties: [
  13850. {
  13851. name: "messageRef",
  13852. type: "Message",
  13853. isAttr: true,
  13854. isReference: true
  13855. },
  13856. {
  13857. name: "operationRef",
  13858. type: "Operation",
  13859. isAttr: true,
  13860. isReference: true
  13861. }
  13862. ]
  13863. },
  13864. {
  13865. name: "ConditionalEventDefinition",
  13866. superClass: [
  13867. "EventDefinition"
  13868. ],
  13869. properties: [
  13870. {
  13871. name: "condition",
  13872. type: "Expression",
  13873. xml: {
  13874. serialize: "xsi:type"
  13875. }
  13876. }
  13877. ]
  13878. },
  13879. {
  13880. name: "SignalEventDefinition",
  13881. superClass: [
  13882. "EventDefinition"
  13883. ],
  13884. properties: [
  13885. {
  13886. name: "signalRef",
  13887. type: "Signal",
  13888. isAttr: true,
  13889. isReference: true
  13890. }
  13891. ]
  13892. },
  13893. {
  13894. name: "Signal",
  13895. superClass: [
  13896. "RootElement"
  13897. ],
  13898. properties: [
  13899. {
  13900. name: "structureRef",
  13901. type: "ItemDefinition",
  13902. isAttr: true,
  13903. isReference: true
  13904. },
  13905. {
  13906. name: "name",
  13907. isAttr: true,
  13908. type: "String"
  13909. }
  13910. ]
  13911. },
  13912. {
  13913. name: "ImplicitThrowEvent",
  13914. superClass: [
  13915. "ThrowEvent"
  13916. ]
  13917. },
  13918. {
  13919. name: "DataState",
  13920. superClass: [
  13921. "BaseElement"
  13922. ],
  13923. properties: [
  13924. {
  13925. name: "name",
  13926. isAttr: true,
  13927. type: "String"
  13928. }
  13929. ]
  13930. },
  13931. {
  13932. name: "ItemAwareElement",
  13933. superClass: [
  13934. "BaseElement"
  13935. ],
  13936. properties: [
  13937. {
  13938. name: "itemSubjectRef",
  13939. type: "ItemDefinition",
  13940. isAttr: true,
  13941. isReference: true
  13942. },
  13943. {
  13944. name: "dataState",
  13945. type: "DataState"
  13946. }
  13947. ]
  13948. },
  13949. {
  13950. name: "DataAssociation",
  13951. superClass: [
  13952. "BaseElement"
  13953. ],
  13954. properties: [
  13955. {
  13956. name: "sourceRef",
  13957. type: "ItemAwareElement",
  13958. isMany: true,
  13959. isReference: true
  13960. },
  13961. {
  13962. name: "targetRef",
  13963. type: "ItemAwareElement",
  13964. isReference: true
  13965. },
  13966. {
  13967. name: "transformation",
  13968. type: "FormalExpression",
  13969. xml: {
  13970. serialize: "property"
  13971. }
  13972. },
  13973. {
  13974. name: "assignment",
  13975. type: "Assignment",
  13976. isMany: true
  13977. }
  13978. ]
  13979. },
  13980. {
  13981. name: "DataInput",
  13982. superClass: [
  13983. "ItemAwareElement"
  13984. ],
  13985. properties: [
  13986. {
  13987. name: "name",
  13988. isAttr: true,
  13989. type: "String"
  13990. },
  13991. {
  13992. name: "isCollection",
  13993. "default": false,
  13994. isAttr: true,
  13995. type: "Boolean"
  13996. },
  13997. {
  13998. name: "inputSetRef",
  13999. type: "InputSet",
  14000. isMany: true,
  14001. isVirtual: true,
  14002. isReference: true
  14003. },
  14004. {
  14005. name: "inputSetWithOptional",
  14006. type: "InputSet",
  14007. isMany: true,
  14008. isVirtual: true,
  14009. isReference: true
  14010. },
  14011. {
  14012. name: "inputSetWithWhileExecuting",
  14013. type: "InputSet",
  14014. isMany: true,
  14015. isVirtual: true,
  14016. isReference: true
  14017. }
  14018. ]
  14019. },
  14020. {
  14021. name: "DataOutput",
  14022. superClass: [
  14023. "ItemAwareElement"
  14024. ],
  14025. properties: [
  14026. {
  14027. name: "name",
  14028. isAttr: true,
  14029. type: "String"
  14030. },
  14031. {
  14032. name: "isCollection",
  14033. "default": false,
  14034. isAttr: true,
  14035. type: "Boolean"
  14036. },
  14037. {
  14038. name: "outputSetRef",
  14039. type: "OutputSet",
  14040. isMany: true,
  14041. isVirtual: true,
  14042. isReference: true
  14043. },
  14044. {
  14045. name: "outputSetWithOptional",
  14046. type: "OutputSet",
  14047. isMany: true,
  14048. isVirtual: true,
  14049. isReference: true
  14050. },
  14051. {
  14052. name: "outputSetWithWhileExecuting",
  14053. type: "OutputSet",
  14054. isMany: true,
  14055. isVirtual: true,
  14056. isReference: true
  14057. }
  14058. ]
  14059. },
  14060. {
  14061. name: "InputSet",
  14062. superClass: [
  14063. "BaseElement"
  14064. ],
  14065. properties: [
  14066. {
  14067. name: "name",
  14068. isAttr: true,
  14069. type: "String"
  14070. },
  14071. {
  14072. name: "dataInputRefs",
  14073. type: "DataInput",
  14074. isMany: true,
  14075. isReference: true
  14076. },
  14077. {
  14078. name: "optionalInputRefs",
  14079. type: "DataInput",
  14080. isMany: true,
  14081. isReference: true
  14082. },
  14083. {
  14084. name: "whileExecutingInputRefs",
  14085. type: "DataInput",
  14086. isMany: true,
  14087. isReference: true
  14088. },
  14089. {
  14090. name: "outputSetRefs",
  14091. type: "OutputSet",
  14092. isMany: true,
  14093. isReference: true
  14094. }
  14095. ]
  14096. },
  14097. {
  14098. name: "OutputSet",
  14099. superClass: [
  14100. "BaseElement"
  14101. ],
  14102. properties: [
  14103. {
  14104. name: "dataOutputRefs",
  14105. type: "DataOutput",
  14106. isMany: true,
  14107. isReference: true
  14108. },
  14109. {
  14110. name: "name",
  14111. isAttr: true,
  14112. type: "String"
  14113. },
  14114. {
  14115. name: "inputSetRefs",
  14116. type: "InputSet",
  14117. isMany: true,
  14118. isReference: true
  14119. },
  14120. {
  14121. name: "optionalOutputRefs",
  14122. type: "DataOutput",
  14123. isMany: true,
  14124. isReference: true
  14125. },
  14126. {
  14127. name: "whileExecutingOutputRefs",
  14128. type: "DataOutput",
  14129. isMany: true,
  14130. isReference: true
  14131. }
  14132. ]
  14133. },
  14134. {
  14135. name: "Property",
  14136. superClass: [
  14137. "ItemAwareElement"
  14138. ],
  14139. properties: [
  14140. {
  14141. name: "name",
  14142. isAttr: true,
  14143. type: "String"
  14144. }
  14145. ]
  14146. },
  14147. {
  14148. name: "DataInputAssociation",
  14149. superClass: [
  14150. "DataAssociation"
  14151. ]
  14152. },
  14153. {
  14154. name: "DataOutputAssociation",
  14155. superClass: [
  14156. "DataAssociation"
  14157. ]
  14158. },
  14159. {
  14160. name: "InputOutputSpecification",
  14161. superClass: [
  14162. "BaseElement"
  14163. ],
  14164. properties: [
  14165. {
  14166. name: "dataInputs",
  14167. type: "DataInput",
  14168. isMany: true
  14169. },
  14170. {
  14171. name: "dataOutputs",
  14172. type: "DataOutput",
  14173. isMany: true
  14174. },
  14175. {
  14176. name: "inputSets",
  14177. type: "InputSet",
  14178. isMany: true
  14179. },
  14180. {
  14181. name: "outputSets",
  14182. type: "OutputSet",
  14183. isMany: true
  14184. }
  14185. ]
  14186. },
  14187. {
  14188. name: "DataObject",
  14189. superClass: [
  14190. "FlowElement",
  14191. "ItemAwareElement"
  14192. ],
  14193. properties: [
  14194. {
  14195. name: "isCollection",
  14196. "default": false,
  14197. isAttr: true,
  14198. type: "Boolean"
  14199. }
  14200. ]
  14201. },
  14202. {
  14203. name: "InputOutputBinding",
  14204. properties: [
  14205. {
  14206. name: "inputDataRef",
  14207. type: "InputSet",
  14208. isAttr: true,
  14209. isReference: true
  14210. },
  14211. {
  14212. name: "outputDataRef",
  14213. type: "OutputSet",
  14214. isAttr: true,
  14215. isReference: true
  14216. },
  14217. {
  14218. name: "operationRef",
  14219. type: "Operation",
  14220. isAttr: true,
  14221. isReference: true
  14222. }
  14223. ]
  14224. },
  14225. {
  14226. name: "Assignment",
  14227. superClass: [
  14228. "BaseElement"
  14229. ],
  14230. properties: [
  14231. {
  14232. name: "from",
  14233. type: "Expression",
  14234. xml: {
  14235. serialize: "xsi:type"
  14236. }
  14237. },
  14238. {
  14239. name: "to",
  14240. type: "Expression",
  14241. xml: {
  14242. serialize: "xsi:type"
  14243. }
  14244. }
  14245. ]
  14246. },
  14247. {
  14248. name: "DataStore",
  14249. superClass: [
  14250. "RootElement",
  14251. "ItemAwareElement"
  14252. ],
  14253. properties: [
  14254. {
  14255. name: "name",
  14256. isAttr: true,
  14257. type: "String"
  14258. },
  14259. {
  14260. name: "capacity",
  14261. isAttr: true,
  14262. type: "Integer"
  14263. },
  14264. {
  14265. name: "isUnlimited",
  14266. "default": true,
  14267. isAttr: true,
  14268. type: "Boolean"
  14269. }
  14270. ]
  14271. },
  14272. {
  14273. name: "DataStoreReference",
  14274. superClass: [
  14275. "ItemAwareElement",
  14276. "FlowElement"
  14277. ],
  14278. properties: [
  14279. {
  14280. name: "dataStoreRef",
  14281. type: "DataStore",
  14282. isAttr: true,
  14283. isReference: true
  14284. }
  14285. ]
  14286. },
  14287. {
  14288. name: "DataObjectReference",
  14289. superClass: [
  14290. "ItemAwareElement",
  14291. "FlowElement"
  14292. ],
  14293. properties: [
  14294. {
  14295. name: "dataObjectRef",
  14296. type: "DataObject",
  14297. isAttr: true,
  14298. isReference: true
  14299. }
  14300. ]
  14301. },
  14302. {
  14303. name: "ConversationLink",
  14304. superClass: [
  14305. "BaseElement"
  14306. ],
  14307. properties: [
  14308. {
  14309. name: "sourceRef",
  14310. type: "InteractionNode",
  14311. isAttr: true,
  14312. isReference: true
  14313. },
  14314. {
  14315. name: "targetRef",
  14316. type: "InteractionNode",
  14317. isAttr: true,
  14318. isReference: true
  14319. },
  14320. {
  14321. name: "name",
  14322. isAttr: true,
  14323. type: "String"
  14324. }
  14325. ]
  14326. },
  14327. {
  14328. name: "ConversationAssociation",
  14329. superClass: [
  14330. "BaseElement"
  14331. ],
  14332. properties: [
  14333. {
  14334. name: "innerConversationNodeRef",
  14335. type: "ConversationNode",
  14336. isAttr: true,
  14337. isReference: true
  14338. },
  14339. {
  14340. name: "outerConversationNodeRef",
  14341. type: "ConversationNode",
  14342. isAttr: true,
  14343. isReference: true
  14344. }
  14345. ]
  14346. },
  14347. {
  14348. name: "CallConversation",
  14349. superClass: [
  14350. "ConversationNode"
  14351. ],
  14352. properties: [
  14353. {
  14354. name: "calledCollaborationRef",
  14355. type: "Collaboration",
  14356. isAttr: true,
  14357. isReference: true
  14358. },
  14359. {
  14360. name: "participantAssociations",
  14361. type: "ParticipantAssociation",
  14362. isMany: true
  14363. }
  14364. ]
  14365. },
  14366. {
  14367. name: "Conversation",
  14368. superClass: [
  14369. "ConversationNode"
  14370. ]
  14371. },
  14372. {
  14373. name: "SubConversation",
  14374. superClass: [
  14375. "ConversationNode"
  14376. ],
  14377. properties: [
  14378. {
  14379. name: "conversationNodes",
  14380. type: "ConversationNode",
  14381. isMany: true
  14382. }
  14383. ]
  14384. },
  14385. {
  14386. name: "ConversationNode",
  14387. isAbstract: true,
  14388. superClass: [
  14389. "InteractionNode",
  14390. "BaseElement"
  14391. ],
  14392. properties: [
  14393. {
  14394. name: "name",
  14395. isAttr: true,
  14396. type: "String"
  14397. },
  14398. {
  14399. name: "participantRef",
  14400. type: "Participant",
  14401. isMany: true,
  14402. isReference: true
  14403. },
  14404. {
  14405. name: "messageFlowRefs",
  14406. type: "MessageFlow",
  14407. isMany: true,
  14408. isReference: true
  14409. },
  14410. {
  14411. name: "correlationKeys",
  14412. type: "CorrelationKey",
  14413. isMany: true
  14414. }
  14415. ]
  14416. },
  14417. {
  14418. name: "GlobalConversation",
  14419. superClass: [
  14420. "Collaboration"
  14421. ]
  14422. },
  14423. {
  14424. name: "PartnerEntity",
  14425. superClass: [
  14426. "RootElement"
  14427. ],
  14428. properties: [
  14429. {
  14430. name: "name",
  14431. isAttr: true,
  14432. type: "String"
  14433. },
  14434. {
  14435. name: "participantRef",
  14436. type: "Participant",
  14437. isMany: true,
  14438. isReference: true
  14439. }
  14440. ]
  14441. },
  14442. {
  14443. name: "PartnerRole",
  14444. superClass: [
  14445. "RootElement"
  14446. ],
  14447. properties: [
  14448. {
  14449. name: "name",
  14450. isAttr: true,
  14451. type: "String"
  14452. },
  14453. {
  14454. name: "participantRef",
  14455. type: "Participant",
  14456. isMany: true,
  14457. isReference: true
  14458. }
  14459. ]
  14460. },
  14461. {
  14462. name: "CorrelationProperty",
  14463. superClass: [
  14464. "RootElement"
  14465. ],
  14466. properties: [
  14467. {
  14468. name: "correlationPropertyRetrievalExpression",
  14469. type: "CorrelationPropertyRetrievalExpression",
  14470. isMany: true
  14471. },
  14472. {
  14473. name: "name",
  14474. isAttr: true,
  14475. type: "String"
  14476. },
  14477. {
  14478. name: "type",
  14479. type: "ItemDefinition",
  14480. isAttr: true,
  14481. isReference: true
  14482. }
  14483. ]
  14484. },
  14485. {
  14486. name: "Error",
  14487. superClass: [
  14488. "RootElement"
  14489. ],
  14490. properties: [
  14491. {
  14492. name: "structureRef",
  14493. type: "ItemDefinition",
  14494. isAttr: true,
  14495. isReference: true
  14496. },
  14497. {
  14498. name: "name",
  14499. isAttr: true,
  14500. type: "String"
  14501. },
  14502. {
  14503. name: "errorCode",
  14504. isAttr: true,
  14505. type: "String"
  14506. }
  14507. ]
  14508. },
  14509. {
  14510. name: "CorrelationKey",
  14511. superClass: [
  14512. "BaseElement"
  14513. ],
  14514. properties: [
  14515. {
  14516. name: "correlationPropertyRef",
  14517. type: "CorrelationProperty",
  14518. isMany: true,
  14519. isReference: true
  14520. },
  14521. {
  14522. name: "name",
  14523. isAttr: true,
  14524. type: "String"
  14525. }
  14526. ]
  14527. },
  14528. {
  14529. name: "Expression",
  14530. superClass: [
  14531. "BaseElement"
  14532. ],
  14533. isAbstract: false,
  14534. properties: [
  14535. {
  14536. name: "body",
  14537. isBody: true,
  14538. type: "String"
  14539. }
  14540. ]
  14541. },
  14542. {
  14543. name: "FormalExpression",
  14544. superClass: [
  14545. "Expression"
  14546. ],
  14547. properties: [
  14548. {
  14549. name: "language",
  14550. isAttr: true,
  14551. type: "String"
  14552. },
  14553. {
  14554. name: "evaluatesToTypeRef",
  14555. type: "ItemDefinition",
  14556. isAttr: true,
  14557. isReference: true
  14558. }
  14559. ]
  14560. },
  14561. {
  14562. name: "Message",
  14563. superClass: [
  14564. "RootElement"
  14565. ],
  14566. properties: [
  14567. {
  14568. name: "name",
  14569. isAttr: true,
  14570. type: "String"
  14571. },
  14572. {
  14573. name: "itemRef",
  14574. type: "ItemDefinition",
  14575. isAttr: true,
  14576. isReference: true
  14577. }
  14578. ]
  14579. },
  14580. {
  14581. name: "ItemDefinition",
  14582. superClass: [
  14583. "RootElement"
  14584. ],
  14585. properties: [
  14586. {
  14587. name: "itemKind",
  14588. type: "ItemKind",
  14589. isAttr: true
  14590. },
  14591. {
  14592. name: "structureRef",
  14593. isAttr: true,
  14594. type: "String"
  14595. },
  14596. {
  14597. name: "isCollection",
  14598. "default": false,
  14599. isAttr: true,
  14600. type: "Boolean"
  14601. },
  14602. {
  14603. name: "import",
  14604. type: "Import",
  14605. isAttr: true,
  14606. isReference: true
  14607. }
  14608. ]
  14609. },
  14610. {
  14611. name: "FlowElement",
  14612. isAbstract: true,
  14613. superClass: [
  14614. "BaseElement"
  14615. ],
  14616. properties: [
  14617. {
  14618. name: "name",
  14619. isAttr: true,
  14620. type: "String"
  14621. },
  14622. {
  14623. name: "auditing",
  14624. type: "Auditing"
  14625. },
  14626. {
  14627. name: "monitoring",
  14628. type: "Monitoring"
  14629. },
  14630. {
  14631. name: "categoryValueRef",
  14632. type: "CategoryValue",
  14633. isMany: true,
  14634. isReference: true
  14635. }
  14636. ]
  14637. },
  14638. {
  14639. name: "SequenceFlow",
  14640. superClass: [
  14641. "FlowElement"
  14642. ],
  14643. properties: [
  14644. {
  14645. name: "isImmediate",
  14646. isAttr: true,
  14647. type: "Boolean"
  14648. },
  14649. {
  14650. name: "conditionExpression",
  14651. type: "Expression",
  14652. xml: {
  14653. serialize: "xsi:type"
  14654. }
  14655. },
  14656. {
  14657. name: "sourceRef",
  14658. type: "FlowNode",
  14659. isAttr: true,
  14660. isReference: true
  14661. },
  14662. {
  14663. name: "targetRef",
  14664. type: "FlowNode",
  14665. isAttr: true,
  14666. isReference: true
  14667. }
  14668. ]
  14669. },
  14670. {
  14671. name: "FlowElementsContainer",
  14672. isAbstract: true,
  14673. superClass: [
  14674. "BaseElement"
  14675. ],
  14676. properties: [
  14677. {
  14678. name: "laneSets",
  14679. type: "LaneSet",
  14680. isMany: true
  14681. },
  14682. {
  14683. name: "flowElements",
  14684. type: "FlowElement",
  14685. isMany: true
  14686. }
  14687. ]
  14688. },
  14689. {
  14690. name: "CallableElement",
  14691. isAbstract: true,
  14692. superClass: [
  14693. "RootElement"
  14694. ],
  14695. properties: [
  14696. {
  14697. name: "name",
  14698. isAttr: true,
  14699. type: "String"
  14700. },
  14701. {
  14702. name: "ioSpecification",
  14703. type: "InputOutputSpecification",
  14704. xml: {
  14705. serialize: "property"
  14706. }
  14707. },
  14708. {
  14709. name: "supportedInterfaceRef",
  14710. type: "Interface",
  14711. isMany: true,
  14712. isReference: true
  14713. },
  14714. {
  14715. name: "ioBinding",
  14716. type: "InputOutputBinding",
  14717. isMany: true,
  14718. xml: {
  14719. serialize: "property"
  14720. }
  14721. }
  14722. ]
  14723. },
  14724. {
  14725. name: "FlowNode",
  14726. isAbstract: true,
  14727. superClass: [
  14728. "FlowElement"
  14729. ],
  14730. properties: [
  14731. {
  14732. name: "incoming",
  14733. type: "SequenceFlow",
  14734. isMany: true,
  14735. isReference: true
  14736. },
  14737. {
  14738. name: "outgoing",
  14739. type: "SequenceFlow",
  14740. isMany: true,
  14741. isReference: true
  14742. },
  14743. {
  14744. name: "lanes",
  14745. type: "Lane",
  14746. isMany: true,
  14747. isVirtual: true,
  14748. isReference: true
  14749. }
  14750. ]
  14751. },
  14752. {
  14753. name: "CorrelationPropertyRetrievalExpression",
  14754. superClass: [
  14755. "BaseElement"
  14756. ],
  14757. properties: [
  14758. {
  14759. name: "messagePath",
  14760. type: "FormalExpression"
  14761. },
  14762. {
  14763. name: "messageRef",
  14764. type: "Message",
  14765. isAttr: true,
  14766. isReference: true
  14767. }
  14768. ]
  14769. },
  14770. {
  14771. name: "CorrelationPropertyBinding",
  14772. superClass: [
  14773. "BaseElement"
  14774. ],
  14775. properties: [
  14776. {
  14777. name: "dataPath",
  14778. type: "FormalExpression"
  14779. },
  14780. {
  14781. name: "correlationPropertyRef",
  14782. type: "CorrelationProperty",
  14783. isAttr: true,
  14784. isReference: true
  14785. }
  14786. ]
  14787. },
  14788. {
  14789. name: "Resource",
  14790. superClass: [
  14791. "RootElement"
  14792. ],
  14793. properties: [
  14794. {
  14795. name: "name",
  14796. isAttr: true,
  14797. type: "String"
  14798. },
  14799. {
  14800. name: "resourceParameters",
  14801. type: "ResourceParameter",
  14802. isMany: true
  14803. }
  14804. ]
  14805. },
  14806. {
  14807. name: "ResourceParameter",
  14808. superClass: [
  14809. "BaseElement"
  14810. ],
  14811. properties: [
  14812. {
  14813. name: "name",
  14814. isAttr: true,
  14815. type: "String"
  14816. },
  14817. {
  14818. name: "isRequired",
  14819. isAttr: true,
  14820. type: "Boolean"
  14821. },
  14822. {
  14823. name: "type",
  14824. type: "ItemDefinition",
  14825. isAttr: true,
  14826. isReference: true
  14827. }
  14828. ]
  14829. },
  14830. {
  14831. name: "CorrelationSubscription",
  14832. superClass: [
  14833. "BaseElement"
  14834. ],
  14835. properties: [
  14836. {
  14837. name: "correlationKeyRef",
  14838. type: "CorrelationKey",
  14839. isAttr: true,
  14840. isReference: true
  14841. },
  14842. {
  14843. name: "correlationPropertyBinding",
  14844. type: "CorrelationPropertyBinding",
  14845. isMany: true
  14846. }
  14847. ]
  14848. },
  14849. {
  14850. name: "MessageFlow",
  14851. superClass: [
  14852. "BaseElement"
  14853. ],
  14854. properties: [
  14855. {
  14856. name: "name",
  14857. isAttr: true,
  14858. type: "String"
  14859. },
  14860. {
  14861. name: "sourceRef",
  14862. type: "InteractionNode",
  14863. isAttr: true,
  14864. isReference: true
  14865. },
  14866. {
  14867. name: "targetRef",
  14868. type: "InteractionNode",
  14869. isAttr: true,
  14870. isReference: true
  14871. },
  14872. {
  14873. name: "messageRef",
  14874. type: "Message",
  14875. isAttr: true,
  14876. isReference: true
  14877. }
  14878. ]
  14879. },
  14880. {
  14881. name: "MessageFlowAssociation",
  14882. superClass: [
  14883. "BaseElement"
  14884. ],
  14885. properties: [
  14886. {
  14887. name: "innerMessageFlowRef",
  14888. type: "MessageFlow",
  14889. isAttr: true,
  14890. isReference: true
  14891. },
  14892. {
  14893. name: "outerMessageFlowRef",
  14894. type: "MessageFlow",
  14895. isAttr: true,
  14896. isReference: true
  14897. }
  14898. ]
  14899. },
  14900. {
  14901. name: "InteractionNode",
  14902. isAbstract: true,
  14903. properties: [
  14904. {
  14905. name: "incomingConversationLinks",
  14906. type: "ConversationLink",
  14907. isMany: true,
  14908. isVirtual: true,
  14909. isReference: true
  14910. },
  14911. {
  14912. name: "outgoingConversationLinks",
  14913. type: "ConversationLink",
  14914. isMany: true,
  14915. isVirtual: true,
  14916. isReference: true
  14917. }
  14918. ]
  14919. },
  14920. {
  14921. name: "Participant",
  14922. superClass: [
  14923. "InteractionNode",
  14924. "BaseElement"
  14925. ],
  14926. properties: [
  14927. {
  14928. name: "name",
  14929. isAttr: true,
  14930. type: "String"
  14931. },
  14932. {
  14933. name: "interfaceRef",
  14934. type: "Interface",
  14935. isMany: true,
  14936. isReference: true
  14937. },
  14938. {
  14939. name: "participantMultiplicity",
  14940. type: "ParticipantMultiplicity"
  14941. },
  14942. {
  14943. name: "endPointRefs",
  14944. type: "EndPoint",
  14945. isMany: true,
  14946. isReference: true
  14947. },
  14948. {
  14949. name: "processRef",
  14950. type: "Process",
  14951. isAttr: true,
  14952. isReference: true
  14953. }
  14954. ]
  14955. },
  14956. {
  14957. name: "ParticipantAssociation",
  14958. superClass: [
  14959. "BaseElement"
  14960. ],
  14961. properties: [
  14962. {
  14963. name: "innerParticipantRef",
  14964. type: "Participant",
  14965. isAttr: true,
  14966. isReference: true
  14967. },
  14968. {
  14969. name: "outerParticipantRef",
  14970. type: "Participant",
  14971. isAttr: true,
  14972. isReference: true
  14973. }
  14974. ]
  14975. },
  14976. {
  14977. name: "ParticipantMultiplicity",
  14978. properties: [
  14979. {
  14980. name: "minimum",
  14981. "default": 0,
  14982. isAttr: true,
  14983. type: "Integer"
  14984. },
  14985. {
  14986. name: "maximum",
  14987. "default": 1,
  14988. isAttr: true,
  14989. type: "Integer"
  14990. }
  14991. ],
  14992. superClass: [
  14993. "BaseElement"
  14994. ]
  14995. },
  14996. {
  14997. name: "Collaboration",
  14998. superClass: [
  14999. "RootElement"
  15000. ],
  15001. properties: [
  15002. {
  15003. name: "name",
  15004. isAttr: true,
  15005. type: "String"
  15006. },
  15007. {
  15008. name: "isClosed",
  15009. isAttr: true,
  15010. type: "Boolean"
  15011. },
  15012. {
  15013. name: "participants",
  15014. type: "Participant",
  15015. isMany: true
  15016. },
  15017. {
  15018. name: "messageFlows",
  15019. type: "MessageFlow",
  15020. isMany: true
  15021. },
  15022. {
  15023. name: "artifacts",
  15024. type: "Artifact",
  15025. isMany: true
  15026. },
  15027. {
  15028. name: "conversations",
  15029. type: "ConversationNode",
  15030. isMany: true
  15031. },
  15032. {
  15033. name: "conversationAssociations",
  15034. type: "ConversationAssociation"
  15035. },
  15036. {
  15037. name: "participantAssociations",
  15038. type: "ParticipantAssociation",
  15039. isMany: true
  15040. },
  15041. {
  15042. name: "messageFlowAssociations",
  15043. type: "MessageFlowAssociation",
  15044. isMany: true
  15045. },
  15046. {
  15047. name: "correlationKeys",
  15048. type: "CorrelationKey",
  15049. isMany: true
  15050. },
  15051. {
  15052. name: "choreographyRef",
  15053. type: "Choreography",
  15054. isMany: true,
  15055. isReference: true
  15056. },
  15057. {
  15058. name: "conversationLinks",
  15059. type: "ConversationLink",
  15060. isMany: true
  15061. }
  15062. ]
  15063. },
  15064. {
  15065. name: "ChoreographyActivity",
  15066. isAbstract: true,
  15067. superClass: [
  15068. "FlowNode"
  15069. ],
  15070. properties: [
  15071. {
  15072. name: "participantRef",
  15073. type: "Participant",
  15074. isMany: true,
  15075. isReference: true
  15076. },
  15077. {
  15078. name: "initiatingParticipantRef",
  15079. type: "Participant",
  15080. isAttr: true,
  15081. isReference: true
  15082. },
  15083. {
  15084. name: "correlationKeys",
  15085. type: "CorrelationKey",
  15086. isMany: true
  15087. },
  15088. {
  15089. name: "loopType",
  15090. type: "ChoreographyLoopType",
  15091. "default": "None",
  15092. isAttr: true
  15093. }
  15094. ]
  15095. },
  15096. {
  15097. name: "CallChoreography",
  15098. superClass: [
  15099. "ChoreographyActivity"
  15100. ],
  15101. properties: [
  15102. {
  15103. name: "calledChoreographyRef",
  15104. type: "Choreography",
  15105. isAttr: true,
  15106. isReference: true
  15107. },
  15108. {
  15109. name: "participantAssociations",
  15110. type: "ParticipantAssociation",
  15111. isMany: true
  15112. }
  15113. ]
  15114. },
  15115. {
  15116. name: "SubChoreography",
  15117. superClass: [
  15118. "ChoreographyActivity",
  15119. "FlowElementsContainer"
  15120. ],
  15121. properties: [
  15122. {
  15123. name: "artifacts",
  15124. type: "Artifact",
  15125. isMany: true
  15126. }
  15127. ]
  15128. },
  15129. {
  15130. name: "ChoreographyTask",
  15131. superClass: [
  15132. "ChoreographyActivity"
  15133. ],
  15134. properties: [
  15135. {
  15136. name: "messageFlowRef",
  15137. type: "MessageFlow",
  15138. isMany: true,
  15139. isReference: true
  15140. }
  15141. ]
  15142. },
  15143. {
  15144. name: "Choreography",
  15145. superClass: [
  15146. "Collaboration",
  15147. "FlowElementsContainer"
  15148. ]
  15149. },
  15150. {
  15151. name: "GlobalChoreographyTask",
  15152. superClass: [
  15153. "Choreography"
  15154. ],
  15155. properties: [
  15156. {
  15157. name: "initiatingParticipantRef",
  15158. type: "Participant",
  15159. isAttr: true,
  15160. isReference: true
  15161. }
  15162. ]
  15163. },
  15164. {
  15165. name: "TextAnnotation",
  15166. superClass: [
  15167. "Artifact"
  15168. ],
  15169. properties: [
  15170. {
  15171. name: "text",
  15172. type: "String"
  15173. },
  15174. {
  15175. name: "textFormat",
  15176. "default": "text/plain",
  15177. isAttr: true,
  15178. type: "String"
  15179. }
  15180. ]
  15181. },
  15182. {
  15183. name: "Group",
  15184. superClass: [
  15185. "Artifact"
  15186. ],
  15187. properties: [
  15188. {
  15189. name: "categoryValueRef",
  15190. type: "CategoryValue",
  15191. isAttr: true,
  15192. isReference: true
  15193. }
  15194. ]
  15195. },
  15196. {
  15197. name: "Association",
  15198. superClass: [
  15199. "Artifact"
  15200. ],
  15201. properties: [
  15202. {
  15203. name: "associationDirection",
  15204. type: "AssociationDirection",
  15205. isAttr: true
  15206. },
  15207. {
  15208. name: "sourceRef",
  15209. type: "BaseElement",
  15210. isAttr: true,
  15211. isReference: true
  15212. },
  15213. {
  15214. name: "targetRef",
  15215. type: "BaseElement",
  15216. isAttr: true,
  15217. isReference: true
  15218. }
  15219. ]
  15220. },
  15221. {
  15222. name: "Category",
  15223. superClass: [
  15224. "RootElement"
  15225. ],
  15226. properties: [
  15227. {
  15228. name: "categoryValue",
  15229. type: "CategoryValue",
  15230. isMany: true
  15231. },
  15232. {
  15233. name: "name",
  15234. isAttr: true,
  15235. type: "String"
  15236. }
  15237. ]
  15238. },
  15239. {
  15240. name: "Artifact",
  15241. isAbstract: true,
  15242. superClass: [
  15243. "BaseElement"
  15244. ]
  15245. },
  15246. {
  15247. name: "CategoryValue",
  15248. superClass: [
  15249. "BaseElement"
  15250. ],
  15251. properties: [
  15252. {
  15253. name: "categorizedFlowElements",
  15254. type: "FlowElement",
  15255. isMany: true,
  15256. isVirtual: true,
  15257. isReference: true
  15258. },
  15259. {
  15260. name: "value",
  15261. isAttr: true,
  15262. type: "String"
  15263. }
  15264. ]
  15265. },
  15266. {
  15267. name: "Activity",
  15268. isAbstract: true,
  15269. superClass: [
  15270. "FlowNode"
  15271. ],
  15272. properties: [
  15273. {
  15274. name: "isForCompensation",
  15275. "default": false,
  15276. isAttr: true,
  15277. type: "Boolean"
  15278. },
  15279. {
  15280. name: "default",
  15281. type: "SequenceFlow",
  15282. isAttr: true,
  15283. isReference: true
  15284. },
  15285. {
  15286. name: "ioSpecification",
  15287. type: "InputOutputSpecification",
  15288. xml: {
  15289. serialize: "property"
  15290. }
  15291. },
  15292. {
  15293. name: "boundaryEventRefs",
  15294. type: "BoundaryEvent",
  15295. isMany: true,
  15296. isReference: true
  15297. },
  15298. {
  15299. name: "properties",
  15300. type: "Property",
  15301. isMany: true
  15302. },
  15303. {
  15304. name: "dataInputAssociations",
  15305. type: "DataInputAssociation",
  15306. isMany: true
  15307. },
  15308. {
  15309. name: "dataOutputAssociations",
  15310. type: "DataOutputAssociation",
  15311. isMany: true
  15312. },
  15313. {
  15314. name: "startQuantity",
  15315. "default": 1,
  15316. isAttr: true,
  15317. type: "Integer"
  15318. },
  15319. {
  15320. name: "resources",
  15321. type: "ResourceRole",
  15322. isMany: true
  15323. },
  15324. {
  15325. name: "completionQuantity",
  15326. "default": 1,
  15327. isAttr: true,
  15328. type: "Integer"
  15329. },
  15330. {
  15331. name: "loopCharacteristics",
  15332. type: "LoopCharacteristics"
  15333. }
  15334. ]
  15335. },
  15336. {
  15337. name: "ServiceTask",
  15338. superClass: [
  15339. "Task"
  15340. ],
  15341. properties: [
  15342. {
  15343. name: "implementation",
  15344. isAttr: true,
  15345. type: "String"
  15346. },
  15347. {
  15348. name: "operationRef",
  15349. type: "Operation",
  15350. isAttr: true,
  15351. isReference: true
  15352. }
  15353. ]
  15354. },
  15355. {
  15356. name: "SubProcess",
  15357. superClass: [
  15358. "Activity",
  15359. "FlowElementsContainer",
  15360. "InteractionNode"
  15361. ],
  15362. properties: [
  15363. {
  15364. name: "triggeredByEvent",
  15365. "default": false,
  15366. isAttr: true,
  15367. type: "Boolean"
  15368. },
  15369. {
  15370. name: "artifacts",
  15371. type: "Artifact",
  15372. isMany: true
  15373. }
  15374. ]
  15375. },
  15376. {
  15377. name: "LoopCharacteristics",
  15378. isAbstract: true,
  15379. superClass: [
  15380. "BaseElement"
  15381. ]
  15382. },
  15383. {
  15384. name: "MultiInstanceLoopCharacteristics",
  15385. superClass: [
  15386. "LoopCharacteristics"
  15387. ],
  15388. properties: [
  15389. {
  15390. name: "isSequential",
  15391. "default": false,
  15392. isAttr: true,
  15393. type: "Boolean"
  15394. },
  15395. {
  15396. name: "behavior",
  15397. type: "MultiInstanceBehavior",
  15398. "default": "All",
  15399. isAttr: true
  15400. },
  15401. {
  15402. name: "loopCardinality",
  15403. type: "Expression",
  15404. xml: {
  15405. serialize: "xsi:type"
  15406. }
  15407. },
  15408. {
  15409. name: "loopDataInputRef",
  15410. type: "ItemAwareElement",
  15411. isReference: true
  15412. },
  15413. {
  15414. name: "loopDataOutputRef",
  15415. type: "ItemAwareElement",
  15416. isReference: true
  15417. },
  15418. {
  15419. name: "inputDataItem",
  15420. type: "DataInput",
  15421. xml: {
  15422. serialize: "property"
  15423. }
  15424. },
  15425. {
  15426. name: "outputDataItem",
  15427. type: "DataOutput",
  15428. xml: {
  15429. serialize: "property"
  15430. }
  15431. },
  15432. {
  15433. name: "complexBehaviorDefinition",
  15434. type: "ComplexBehaviorDefinition",
  15435. isMany: true
  15436. },
  15437. {
  15438. name: "completionCondition",
  15439. type: "Expression",
  15440. xml: {
  15441. serialize: "xsi:type"
  15442. }
  15443. },
  15444. {
  15445. name: "oneBehaviorEventRef",
  15446. type: "EventDefinition",
  15447. isAttr: true,
  15448. isReference: true
  15449. },
  15450. {
  15451. name: "noneBehaviorEventRef",
  15452. type: "EventDefinition",
  15453. isAttr: true,
  15454. isReference: true
  15455. }
  15456. ]
  15457. },
  15458. {
  15459. name: "StandardLoopCharacteristics",
  15460. superClass: [
  15461. "LoopCharacteristics"
  15462. ],
  15463. properties: [
  15464. {
  15465. name: "testBefore",
  15466. "default": false,
  15467. isAttr: true,
  15468. type: "Boolean"
  15469. },
  15470. {
  15471. name: "loopCondition",
  15472. type: "Expression",
  15473. xml: {
  15474. serialize: "xsi:type"
  15475. }
  15476. },
  15477. {
  15478. name: "loopMaximum",
  15479. type: "Integer",
  15480. isAttr: true
  15481. }
  15482. ]
  15483. },
  15484. {
  15485. name: "CallActivity",
  15486. superClass: [
  15487. "Activity",
  15488. "InteractionNode"
  15489. ],
  15490. properties: [
  15491. {
  15492. name: "calledElement",
  15493. type: "String",
  15494. isAttr: true
  15495. }
  15496. ]
  15497. },
  15498. {
  15499. name: "Task",
  15500. superClass: [
  15501. "Activity",
  15502. "InteractionNode"
  15503. ]
  15504. },
  15505. {
  15506. name: "SendTask",
  15507. superClass: [
  15508. "Task"
  15509. ],
  15510. properties: [
  15511. {
  15512. name: "implementation",
  15513. isAttr: true,
  15514. type: "String"
  15515. },
  15516. {
  15517. name: "operationRef",
  15518. type: "Operation",
  15519. isAttr: true,
  15520. isReference: true
  15521. },
  15522. {
  15523. name: "messageRef",
  15524. type: "Message",
  15525. isAttr: true,
  15526. isReference: true
  15527. }
  15528. ]
  15529. },
  15530. {
  15531. name: "ReceiveTask",
  15532. superClass: [
  15533. "Task"
  15534. ],
  15535. properties: [
  15536. {
  15537. name: "implementation",
  15538. isAttr: true,
  15539. type: "String"
  15540. },
  15541. {
  15542. name: "instantiate",
  15543. "default": false,
  15544. isAttr: true,
  15545. type: "Boolean"
  15546. },
  15547. {
  15548. name: "operationRef",
  15549. type: "Operation",
  15550. isAttr: true,
  15551. isReference: true
  15552. },
  15553. {
  15554. name: "messageRef",
  15555. type: "Message",
  15556. isAttr: true,
  15557. isReference: true
  15558. }
  15559. ]
  15560. },
  15561. {
  15562. name: "ScriptTask",
  15563. superClass: [
  15564. "Task"
  15565. ],
  15566. properties: [
  15567. {
  15568. name: "scriptFormat",
  15569. isAttr: true,
  15570. type: "String"
  15571. },
  15572. {
  15573. name: "script",
  15574. type: "String"
  15575. }
  15576. ]
  15577. },
  15578. {
  15579. name: "BusinessRuleTask",
  15580. superClass: [
  15581. "Task"
  15582. ],
  15583. properties: [
  15584. {
  15585. name: "implementation",
  15586. isAttr: true,
  15587. type: "String"
  15588. }
  15589. ]
  15590. },
  15591. {
  15592. name: "AdHocSubProcess",
  15593. superClass: [
  15594. "SubProcess"
  15595. ],
  15596. properties: [
  15597. {
  15598. name: "completionCondition",
  15599. type: "Expression",
  15600. xml: {
  15601. serialize: "xsi:type"
  15602. }
  15603. },
  15604. {
  15605. name: "ordering",
  15606. type: "AdHocOrdering",
  15607. isAttr: true
  15608. },
  15609. {
  15610. name: "cancelRemainingInstances",
  15611. "default": true,
  15612. isAttr: true,
  15613. type: "Boolean"
  15614. }
  15615. ]
  15616. },
  15617. {
  15618. name: "Transaction",
  15619. superClass: [
  15620. "SubProcess"
  15621. ],
  15622. properties: [
  15623. {
  15624. name: "protocol",
  15625. isAttr: true,
  15626. type: "String"
  15627. },
  15628. {
  15629. name: "method",
  15630. isAttr: true,
  15631. type: "String"
  15632. }
  15633. ]
  15634. },
  15635. {
  15636. name: "GlobalScriptTask",
  15637. superClass: [
  15638. "GlobalTask"
  15639. ],
  15640. properties: [
  15641. {
  15642. name: "scriptLanguage",
  15643. isAttr: true,
  15644. type: "String"
  15645. },
  15646. {
  15647. name: "script",
  15648. isAttr: true,
  15649. type: "String"
  15650. }
  15651. ]
  15652. },
  15653. {
  15654. name: "GlobalBusinessRuleTask",
  15655. superClass: [
  15656. "GlobalTask"
  15657. ],
  15658. properties: [
  15659. {
  15660. name: "implementation",
  15661. isAttr: true,
  15662. type: "String"
  15663. }
  15664. ]
  15665. },
  15666. {
  15667. name: "ComplexBehaviorDefinition",
  15668. superClass: [
  15669. "BaseElement"
  15670. ],
  15671. properties: [
  15672. {
  15673. name: "condition",
  15674. type: "FormalExpression"
  15675. },
  15676. {
  15677. name: "event",
  15678. type: "ImplicitThrowEvent"
  15679. }
  15680. ]
  15681. },
  15682. {
  15683. name: "ResourceRole",
  15684. superClass: [
  15685. "BaseElement"
  15686. ],
  15687. properties: [
  15688. {
  15689. name: "resourceRef",
  15690. type: "Resource",
  15691. isReference: true
  15692. },
  15693. {
  15694. name: "resourceParameterBindings",
  15695. type: "ResourceParameterBinding",
  15696. isMany: true
  15697. },
  15698. {
  15699. name: "resourceAssignmentExpression",
  15700. type: "ResourceAssignmentExpression"
  15701. },
  15702. {
  15703. name: "name",
  15704. isAttr: true,
  15705. type: "String"
  15706. }
  15707. ]
  15708. },
  15709. {
  15710. name: "ResourceParameterBinding",
  15711. properties: [
  15712. {
  15713. name: "expression",
  15714. type: "Expression",
  15715. xml: {
  15716. serialize: "xsi:type"
  15717. }
  15718. },
  15719. {
  15720. name: "parameterRef",
  15721. type: "ResourceParameter",
  15722. isAttr: true,
  15723. isReference: true
  15724. }
  15725. ],
  15726. superClass: [
  15727. "BaseElement"
  15728. ]
  15729. },
  15730. {
  15731. name: "ResourceAssignmentExpression",
  15732. properties: [
  15733. {
  15734. name: "expression",
  15735. type: "Expression",
  15736. xml: {
  15737. serialize: "xsi:type"
  15738. }
  15739. }
  15740. ],
  15741. superClass: [
  15742. "BaseElement"
  15743. ]
  15744. },
  15745. {
  15746. name: "Import",
  15747. properties: [
  15748. {
  15749. name: "importType",
  15750. isAttr: true,
  15751. type: "String"
  15752. },
  15753. {
  15754. name: "location",
  15755. isAttr: true,
  15756. type: "String"
  15757. },
  15758. {
  15759. name: "namespace",
  15760. isAttr: true,
  15761. type: "String"
  15762. }
  15763. ]
  15764. },
  15765. {
  15766. name: "Definitions",
  15767. superClass: [
  15768. "BaseElement"
  15769. ],
  15770. properties: [
  15771. {
  15772. name: "name",
  15773. isAttr: true,
  15774. type: "String"
  15775. },
  15776. {
  15777. name: "targetNamespace",
  15778. isAttr: true,
  15779. type: "String"
  15780. },
  15781. {
  15782. name: "expressionLanguage",
  15783. "default": "http://www.w3.org/1999/XPath",
  15784. isAttr: true,
  15785. type: "String"
  15786. },
  15787. {
  15788. name: "typeLanguage",
  15789. "default": "http://www.w3.org/2001/XMLSchema",
  15790. isAttr: true,
  15791. type: "String"
  15792. },
  15793. {
  15794. name: "imports",
  15795. type: "Import",
  15796. isMany: true
  15797. },
  15798. {
  15799. name: "extensions",
  15800. type: "Extension",
  15801. isMany: true
  15802. },
  15803. {
  15804. name: "rootElements",
  15805. type: "RootElement",
  15806. isMany: true
  15807. },
  15808. {
  15809. name: "diagrams",
  15810. isMany: true,
  15811. type: "bpmndi:BPMNDiagram"
  15812. },
  15813. {
  15814. name: "exporter",
  15815. isAttr: true,
  15816. type: "String"
  15817. },
  15818. {
  15819. name: "relationships",
  15820. type: "Relationship",
  15821. isMany: true
  15822. },
  15823. {
  15824. name: "exporterVersion",
  15825. isAttr: true,
  15826. type: "String"
  15827. }
  15828. ]
  15829. }
  15830. ];
  15831. var enumerations = [
  15832. {
  15833. name: "ProcessType",
  15834. literalValues: [
  15835. {
  15836. name: "None"
  15837. },
  15838. {
  15839. name: "Public"
  15840. },
  15841. {
  15842. name: "Private"
  15843. }
  15844. ]
  15845. },
  15846. {
  15847. name: "GatewayDirection",
  15848. literalValues: [
  15849. {
  15850. name: "Unspecified"
  15851. },
  15852. {
  15853. name: "Converging"
  15854. },
  15855. {
  15856. name: "Diverging"
  15857. },
  15858. {
  15859. name: "Mixed"
  15860. }
  15861. ]
  15862. },
  15863. {
  15864. name: "EventBasedGatewayType",
  15865. literalValues: [
  15866. {
  15867. name: "Parallel"
  15868. },
  15869. {
  15870. name: "Exclusive"
  15871. }
  15872. ]
  15873. },
  15874. {
  15875. name: "RelationshipDirection",
  15876. literalValues: [
  15877. {
  15878. name: "None"
  15879. },
  15880. {
  15881. name: "Forward"
  15882. },
  15883. {
  15884. name: "Backward"
  15885. },
  15886. {
  15887. name: "Both"
  15888. }
  15889. ]
  15890. },
  15891. {
  15892. name: "ItemKind",
  15893. literalValues: [
  15894. {
  15895. name: "Physical"
  15896. },
  15897. {
  15898. name: "Information"
  15899. }
  15900. ]
  15901. },
  15902. {
  15903. name: "ChoreographyLoopType",
  15904. literalValues: [
  15905. {
  15906. name: "None"
  15907. },
  15908. {
  15909. name: "Standard"
  15910. },
  15911. {
  15912. name: "MultiInstanceSequential"
  15913. },
  15914. {
  15915. name: "MultiInstanceParallel"
  15916. }
  15917. ]
  15918. },
  15919. {
  15920. name: "AssociationDirection",
  15921. literalValues: [
  15922. {
  15923. name: "None"
  15924. },
  15925. {
  15926. name: "One"
  15927. },
  15928. {
  15929. name: "Both"
  15930. }
  15931. ]
  15932. },
  15933. {
  15934. name: "MultiInstanceBehavior",
  15935. literalValues: [
  15936. {
  15937. name: "None"
  15938. },
  15939. {
  15940. name: "One"
  15941. },
  15942. {
  15943. name: "All"
  15944. },
  15945. {
  15946. name: "Complex"
  15947. }
  15948. ]
  15949. },
  15950. {
  15951. name: "AdHocOrdering",
  15952. literalValues: [
  15953. {
  15954. name: "Parallel"
  15955. },
  15956. {
  15957. name: "Sequential"
  15958. }
  15959. ]
  15960. }
  15961. ];
  15962. var xml = {
  15963. tagAlias: "lowerCase",
  15964. typePrefix: "t"
  15965. };
  15966. var BpmnPackage = {
  15967. name: name,
  15968. uri: uri,
  15969. prefix: prefix,
  15970. associations: associations,
  15971. types: types,
  15972. enumerations: enumerations,
  15973. xml: xml
  15974. };
  15975. var name$1 = "BPMNDI";
  15976. var uri$1 = "http://www.omg.org/spec/BPMN/20100524/DI";
  15977. var prefix$1 = "bpmndi";
  15978. var types$1 = [
  15979. {
  15980. name: "BPMNDiagram",
  15981. properties: [
  15982. {
  15983. name: "plane",
  15984. type: "BPMNPlane",
  15985. redefines: "di:Diagram#rootElement"
  15986. },
  15987. {
  15988. name: "labelStyle",
  15989. type: "BPMNLabelStyle",
  15990. isMany: true
  15991. }
  15992. ],
  15993. superClass: [
  15994. "di:Diagram"
  15995. ]
  15996. },
  15997. {
  15998. name: "BPMNPlane",
  15999. properties: [
  16000. {
  16001. name: "bpmnElement",
  16002. isAttr: true,
  16003. isReference: true,
  16004. type: "bpmn:BaseElement",
  16005. redefines: "di:DiagramElement#modelElement"
  16006. }
  16007. ],
  16008. superClass: [
  16009. "di:Plane"
  16010. ]
  16011. },
  16012. {
  16013. name: "BPMNShape",
  16014. properties: [
  16015. {
  16016. name: "bpmnElement",
  16017. isAttr: true,
  16018. isReference: true,
  16019. type: "bpmn:BaseElement",
  16020. redefines: "di:DiagramElement#modelElement"
  16021. },
  16022. {
  16023. name: "isHorizontal",
  16024. isAttr: true,
  16025. type: "Boolean"
  16026. },
  16027. {
  16028. name: "isExpanded",
  16029. isAttr: true,
  16030. type: "Boolean"
  16031. },
  16032. {
  16033. name: "isMarkerVisible",
  16034. isAttr: true,
  16035. type: "Boolean"
  16036. },
  16037. {
  16038. name: "label",
  16039. type: "BPMNLabel"
  16040. },
  16041. {
  16042. name: "isMessageVisible",
  16043. isAttr: true,
  16044. type: "Boolean"
  16045. },
  16046. {
  16047. name: "participantBandKind",
  16048. type: "ParticipantBandKind",
  16049. isAttr: true
  16050. },
  16051. {
  16052. name: "choreographyActivityShape",
  16053. type: "BPMNShape",
  16054. isAttr: true,
  16055. isReference: true
  16056. }
  16057. ],
  16058. superClass: [
  16059. "di:LabeledShape"
  16060. ]
  16061. },
  16062. {
  16063. name: "BPMNEdge",
  16064. properties: [
  16065. {
  16066. name: "label",
  16067. type: "BPMNLabel"
  16068. },
  16069. {
  16070. name: "bpmnElement",
  16071. isAttr: true,
  16072. isReference: true,
  16073. type: "bpmn:BaseElement",
  16074. redefines: "di:DiagramElement#modelElement"
  16075. },
  16076. {
  16077. name: "sourceElement",
  16078. isAttr: true,
  16079. isReference: true,
  16080. type: "di:DiagramElement",
  16081. redefines: "di:Edge#source"
  16082. },
  16083. {
  16084. name: "targetElement",
  16085. isAttr: true,
  16086. isReference: true,
  16087. type: "di:DiagramElement",
  16088. redefines: "di:Edge#target"
  16089. },
  16090. {
  16091. name: "messageVisibleKind",
  16092. type: "MessageVisibleKind",
  16093. isAttr: true,
  16094. "default": "initiating"
  16095. }
  16096. ],
  16097. superClass: [
  16098. "di:LabeledEdge"
  16099. ]
  16100. },
  16101. {
  16102. name: "BPMNLabel",
  16103. properties: [
  16104. {
  16105. name: "labelStyle",
  16106. type: "BPMNLabelStyle",
  16107. isAttr: true,
  16108. isReference: true,
  16109. redefines: "di:DiagramElement#style"
  16110. }
  16111. ],
  16112. superClass: [
  16113. "di:Label"
  16114. ]
  16115. },
  16116. {
  16117. name: "BPMNLabelStyle",
  16118. properties: [
  16119. {
  16120. name: "font",
  16121. type: "dc:Font"
  16122. }
  16123. ],
  16124. superClass: [
  16125. "di:Style"
  16126. ]
  16127. }
  16128. ];
  16129. var enumerations$1 = [
  16130. {
  16131. name: "ParticipantBandKind",
  16132. literalValues: [
  16133. {
  16134. name: "top_initiating"
  16135. },
  16136. {
  16137. name: "middle_initiating"
  16138. },
  16139. {
  16140. name: "bottom_initiating"
  16141. },
  16142. {
  16143. name: "top_non_initiating"
  16144. },
  16145. {
  16146. name: "middle_non_initiating"
  16147. },
  16148. {
  16149. name: "bottom_non_initiating"
  16150. }
  16151. ]
  16152. },
  16153. {
  16154. name: "MessageVisibleKind",
  16155. literalValues: [
  16156. {
  16157. name: "initiating"
  16158. },
  16159. {
  16160. name: "non_initiating"
  16161. }
  16162. ]
  16163. }
  16164. ];
  16165. var associations$1 = [
  16166. ];
  16167. var BpmnDiPackage = {
  16168. name: name$1,
  16169. uri: uri$1,
  16170. prefix: prefix$1,
  16171. types: types$1,
  16172. enumerations: enumerations$1,
  16173. associations: associations$1
  16174. };
  16175. var name$2 = "DC";
  16176. var uri$2 = "http://www.omg.org/spec/DD/20100524/DC";
  16177. var prefix$2 = "dc";
  16178. var types$2 = [
  16179. {
  16180. name: "Boolean"
  16181. },
  16182. {
  16183. name: "Integer"
  16184. },
  16185. {
  16186. name: "Real"
  16187. },
  16188. {
  16189. name: "String"
  16190. },
  16191. {
  16192. name: "Font",
  16193. properties: [
  16194. {
  16195. name: "name",
  16196. type: "String",
  16197. isAttr: true
  16198. },
  16199. {
  16200. name: "size",
  16201. type: "Real",
  16202. isAttr: true
  16203. },
  16204. {
  16205. name: "isBold",
  16206. type: "Boolean",
  16207. isAttr: true
  16208. },
  16209. {
  16210. name: "isItalic",
  16211. type: "Boolean",
  16212. isAttr: true
  16213. },
  16214. {
  16215. name: "isUnderline",
  16216. type: "Boolean",
  16217. isAttr: true
  16218. },
  16219. {
  16220. name: "isStrikeThrough",
  16221. type: "Boolean",
  16222. isAttr: true
  16223. }
  16224. ]
  16225. },
  16226. {
  16227. name: "Point",
  16228. properties: [
  16229. {
  16230. name: "x",
  16231. type: "Real",
  16232. "default": "0",
  16233. isAttr: true
  16234. },
  16235. {
  16236. name: "y",
  16237. type: "Real",
  16238. "default": "0",
  16239. isAttr: true
  16240. }
  16241. ]
  16242. },
  16243. {
  16244. name: "Bounds",
  16245. properties: [
  16246. {
  16247. name: "x",
  16248. type: "Real",
  16249. "default": "0",
  16250. isAttr: true
  16251. },
  16252. {
  16253. name: "y",
  16254. type: "Real",
  16255. "default": "0",
  16256. isAttr: true
  16257. },
  16258. {
  16259. name: "width",
  16260. type: "Real",
  16261. isAttr: true
  16262. },
  16263. {
  16264. name: "height",
  16265. type: "Real",
  16266. isAttr: true
  16267. }
  16268. ]
  16269. }
  16270. ];
  16271. var associations$2 = [
  16272. ];
  16273. var DcPackage = {
  16274. name: name$2,
  16275. uri: uri$2,
  16276. prefix: prefix$2,
  16277. types: types$2,
  16278. associations: associations$2
  16279. };
  16280. var name$3 = "DI";
  16281. var uri$3 = "http://www.omg.org/spec/DD/20100524/DI";
  16282. var prefix$3 = "di";
  16283. var types$3 = [
  16284. {
  16285. name: "DiagramElement",
  16286. isAbstract: true,
  16287. properties: [
  16288. {
  16289. name: "id",
  16290. isAttr: true,
  16291. isId: true,
  16292. type: "String"
  16293. },
  16294. {
  16295. name: "extension",
  16296. type: "Extension"
  16297. },
  16298. {
  16299. name: "owningDiagram",
  16300. type: "Diagram",
  16301. isReadOnly: true,
  16302. isVirtual: true,
  16303. isReference: true
  16304. },
  16305. {
  16306. name: "owningElement",
  16307. type: "DiagramElement",
  16308. isReadOnly: true,
  16309. isVirtual: true,
  16310. isReference: true
  16311. },
  16312. {
  16313. name: "modelElement",
  16314. isReadOnly: true,
  16315. isVirtual: true,
  16316. isReference: true,
  16317. type: "Element"
  16318. },
  16319. {
  16320. name: "style",
  16321. type: "Style",
  16322. isReadOnly: true,
  16323. isVirtual: true,
  16324. isReference: true
  16325. },
  16326. {
  16327. name: "ownedElement",
  16328. type: "DiagramElement",
  16329. isReadOnly: true,
  16330. isMany: true,
  16331. isVirtual: true
  16332. }
  16333. ]
  16334. },
  16335. {
  16336. name: "Node",
  16337. isAbstract: true,
  16338. superClass: [
  16339. "DiagramElement"
  16340. ]
  16341. },
  16342. {
  16343. name: "Edge",
  16344. isAbstract: true,
  16345. superClass: [
  16346. "DiagramElement"
  16347. ],
  16348. properties: [
  16349. {
  16350. name: "source",
  16351. type: "DiagramElement",
  16352. isReadOnly: true,
  16353. isVirtual: true,
  16354. isReference: true
  16355. },
  16356. {
  16357. name: "target",
  16358. type: "DiagramElement",
  16359. isReadOnly: true,
  16360. isVirtual: true,
  16361. isReference: true
  16362. },
  16363. {
  16364. name: "waypoint",
  16365. isUnique: false,
  16366. isMany: true,
  16367. type: "dc:Point",
  16368. xml: {
  16369. serialize: "xsi:type"
  16370. }
  16371. }
  16372. ]
  16373. },
  16374. {
  16375. name: "Diagram",
  16376. isAbstract: true,
  16377. properties: [
  16378. {
  16379. name: "id",
  16380. isAttr: true,
  16381. isId: true,
  16382. type: "String"
  16383. },
  16384. {
  16385. name: "rootElement",
  16386. type: "DiagramElement",
  16387. isReadOnly: true,
  16388. isVirtual: true
  16389. },
  16390. {
  16391. name: "name",
  16392. isAttr: true,
  16393. type: "String"
  16394. },
  16395. {
  16396. name: "documentation",
  16397. isAttr: true,
  16398. type: "String"
  16399. },
  16400. {
  16401. name: "resolution",
  16402. isAttr: true,
  16403. type: "Real"
  16404. },
  16405. {
  16406. name: "ownedStyle",
  16407. type: "Style",
  16408. isReadOnly: true,
  16409. isMany: true,
  16410. isVirtual: true
  16411. }
  16412. ]
  16413. },
  16414. {
  16415. name: "Shape",
  16416. isAbstract: true,
  16417. superClass: [
  16418. "Node"
  16419. ],
  16420. properties: [
  16421. {
  16422. name: "bounds",
  16423. type: "dc:Bounds"
  16424. }
  16425. ]
  16426. },
  16427. {
  16428. name: "Plane",
  16429. isAbstract: true,
  16430. superClass: [
  16431. "Node"
  16432. ],
  16433. properties: [
  16434. {
  16435. name: "planeElement",
  16436. type: "DiagramElement",
  16437. subsettedProperty: "DiagramElement-ownedElement",
  16438. isMany: true
  16439. }
  16440. ]
  16441. },
  16442. {
  16443. name: "LabeledEdge",
  16444. isAbstract: true,
  16445. superClass: [
  16446. "Edge"
  16447. ],
  16448. properties: [
  16449. {
  16450. name: "ownedLabel",
  16451. type: "Label",
  16452. isReadOnly: true,
  16453. subsettedProperty: "DiagramElement-ownedElement",
  16454. isMany: true,
  16455. isVirtual: true
  16456. }
  16457. ]
  16458. },
  16459. {
  16460. name: "LabeledShape",
  16461. isAbstract: true,
  16462. superClass: [
  16463. "Shape"
  16464. ],
  16465. properties: [
  16466. {
  16467. name: "ownedLabel",
  16468. type: "Label",
  16469. isReadOnly: true,
  16470. subsettedProperty: "DiagramElement-ownedElement",
  16471. isMany: true,
  16472. isVirtual: true
  16473. }
  16474. ]
  16475. },
  16476. {
  16477. name: "Label",
  16478. isAbstract: true,
  16479. superClass: [
  16480. "Node"
  16481. ],
  16482. properties: [
  16483. {
  16484. name: "bounds",
  16485. type: "dc:Bounds"
  16486. }
  16487. ]
  16488. },
  16489. {
  16490. name: "Style",
  16491. isAbstract: true,
  16492. properties: [
  16493. {
  16494. name: "id",
  16495. isAttr: true,
  16496. isId: true,
  16497. type: "String"
  16498. }
  16499. ]
  16500. },
  16501. {
  16502. name: "Extension",
  16503. properties: [
  16504. {
  16505. name: "values",
  16506. isMany: true,
  16507. type: "Element"
  16508. }
  16509. ]
  16510. }
  16511. ];
  16512. var associations$3 = [
  16513. ];
  16514. var xml$1 = {
  16515. tagAlias: "lowerCase"
  16516. };
  16517. var DiPackage = {
  16518. name: name$3,
  16519. uri: uri$3,
  16520. prefix: prefix$3,
  16521. types: types$3,
  16522. associations: associations$3,
  16523. xml: xml$1
  16524. };
  16525. var name$4 = "bpmn.io colors for BPMN";
  16526. var uri$4 = "http://bpmn.io/schema/bpmn/biocolor/1.0";
  16527. var prefix$4 = "bioc";
  16528. var types$4 = [
  16529. {
  16530. name: "ColoredShape",
  16531. "extends": [
  16532. "bpmndi:BPMNShape"
  16533. ],
  16534. properties: [
  16535. {
  16536. name: "stroke",
  16537. isAttr: true,
  16538. type: "String"
  16539. },
  16540. {
  16541. name: "fill",
  16542. isAttr: true,
  16543. type: "String"
  16544. }
  16545. ]
  16546. },
  16547. {
  16548. name: "ColoredEdge",
  16549. "extends": [
  16550. "bpmndi:BPMNEdge"
  16551. ],
  16552. properties: [
  16553. {
  16554. name: "stroke",
  16555. isAttr: true,
  16556. type: "String"
  16557. },
  16558. {
  16559. name: "fill",
  16560. isAttr: true,
  16561. type: "String"
  16562. }
  16563. ]
  16564. }
  16565. ];
  16566. var enumerations$2 = [
  16567. ];
  16568. var associations$4 = [
  16569. ];
  16570. var BiocPackage = {
  16571. name: name$4,
  16572. uri: uri$4,
  16573. prefix: prefix$4,
  16574. types: types$4,
  16575. enumerations: enumerations$2,
  16576. associations: associations$4
  16577. };
  16578. var name$5 = "BPMN in Color";
  16579. var uri$5 = "http://www.omg.org/spec/BPMN/non-normative/color/1.0";
  16580. var prefix$5 = "color";
  16581. var types$5 = [
  16582. {
  16583. name: "ColoredLabel",
  16584. "extends": [
  16585. "bpmndi:BPMNLabel"
  16586. ],
  16587. properties: [
  16588. {
  16589. name: "color",
  16590. isAttr: true,
  16591. type: "String"
  16592. }
  16593. ]
  16594. },
  16595. {
  16596. name: "ColoredShape",
  16597. "extends": [
  16598. "bpmndi:BPMNShape"
  16599. ],
  16600. properties: [
  16601. {
  16602. name: "background-color",
  16603. isAttr: true,
  16604. type: "String"
  16605. },
  16606. {
  16607. name: "border-color",
  16608. isAttr: true,
  16609. type: "String"
  16610. }
  16611. ]
  16612. },
  16613. {
  16614. name: "ColoredEdge",
  16615. "extends": [
  16616. "bpmndi:BPMNEdge"
  16617. ],
  16618. properties: [
  16619. {
  16620. name: "border-color",
  16621. isAttr: true,
  16622. type: "String"
  16623. }
  16624. ]
  16625. }
  16626. ];
  16627. var enumerations$3 = [
  16628. ];
  16629. var associations$5 = [
  16630. ];
  16631. var BpmnInColorPackage = {
  16632. name: name$5,
  16633. uri: uri$5,
  16634. prefix: prefix$5,
  16635. types: types$5,
  16636. enumerations: enumerations$3,
  16637. associations: associations$5
  16638. };
  16639. var packages = {
  16640. bpmn: BpmnPackage,
  16641. bpmndi: BpmnDiPackage,
  16642. dc: DcPackage,
  16643. di: DiPackage,
  16644. bioc: BiocPackage,
  16645. color: BpmnInColorPackage
  16646. };
  16647. function simple(additionalPackages, options) {
  16648. var pks = assign({}, packages, additionalPackages);
  16649. return new BpmnModdle(pks, options);
  16650. }
  16651. // TODO(nikku): remove with future bpmn-js version
  16652. /**
  16653. * Wraps APIs to check:
  16654. *
  16655. * 1) If a callback is passed -> Warn users about callback deprecation.
  16656. * 2) If Promise class is implemented in current environment.
  16657. *
  16658. * @private
  16659. */
  16660. function wrapForCompatibility(api) {
  16661. return function() {
  16662. if (!window.Promise) {
  16663. throw new Error('Promises is not supported in this environment. Please polyfill Promise.');
  16664. }
  16665. var argLen = arguments.length;
  16666. if (argLen >= 1 && isFunction(arguments[argLen - 1])) {
  16667. var callback = arguments[argLen - 1];
  16668. console.warn(new Error(
  16669. 'Passing callbacks to ' + api.name + ' is deprecated and will be removed in a future major release. ' +
  16670. 'Please switch to promises: https://bpmn.io/l/moving-to-promises.html'
  16671. ));
  16672. var argsWithoutCallback = Array.prototype.slice.call(arguments, 0, -1);
  16673. api.apply(this, argsWithoutCallback).then(function(result) {
  16674. var firstKey = Object.keys(result)[0];
  16675. // The APIs we are wrapping all resolve a single item depending on the API.
  16676. // For instance, importXML resolves { warnings } and saveXML returns { xml }.
  16677. // That's why we can call the callback with the first item of result.
  16678. return callback(null, result[firstKey]);
  16679. // Passing a second paramter instead of catch because we don't want to
  16680. // catch errors thrown by callback().
  16681. }, function(err) {
  16682. return callback(err, err.warnings);
  16683. });
  16684. } else {
  16685. return api.apply(this, arguments);
  16686. }
  16687. };
  16688. }
  16689. // TODO(nikku): remove with future bpmn-js version
  16690. var DI_ERROR_MESSAGE = 'Tried to access di from the businessObject. The di is available through the diagram element only. For more information, see https://github.com/bpmn-io/bpmn-js/issues/1472';
  16691. function ensureCompatDiRef(businessObject) {
  16692. // bpmnElement can have multiple independent DIs
  16693. if (!has$1(businessObject, 'di')) {
  16694. Object.defineProperty(businessObject, 'di', {
  16695. get: function() {
  16696. throw new Error(DI_ERROR_MESSAGE);
  16697. }
  16698. });
  16699. }
  16700. }
  16701. /**
  16702. * Returns true if an element has the given meta-model type
  16703. *
  16704. * @param {ModdleElement} element
  16705. * @param {string} type
  16706. *
  16707. * @return {boolean}
  16708. */
  16709. function is(element, type) {
  16710. return element.$instanceOf(type);
  16711. }
  16712. /**
  16713. * Find a suitable display candidate for definitions where the DI does not
  16714. * correctly specify one.
  16715. */
  16716. function findDisplayCandidate(definitions) {
  16717. return find(definitions.rootElements, function(e) {
  16718. return is(e, 'bpmn:Process') || is(e, 'bpmn:Collaboration');
  16719. });
  16720. }
  16721. function BpmnTreeWalker(handler, translate) {
  16722. // list of containers already walked
  16723. var handledElements = {};
  16724. // list of elements to handle deferred to ensure
  16725. // prerequisites are drawn
  16726. var deferred = [];
  16727. var diMap = {};
  16728. // Helpers //////////////////////
  16729. function contextual(fn, ctx) {
  16730. return function(e) {
  16731. fn(e, ctx);
  16732. };
  16733. }
  16734. function handled(element) {
  16735. handledElements[element.id] = element;
  16736. }
  16737. function isHandled(element) {
  16738. return handledElements[element.id];
  16739. }
  16740. function visit(element, ctx) {
  16741. var gfx = element.gfx;
  16742. // avoid multiple rendering of elements
  16743. if (gfx) {
  16744. throw new Error(
  16745. translate('already rendered {element}', { element: elementToString(element) })
  16746. );
  16747. }
  16748. // call handler
  16749. return handler.element(element, diMap[element.id], ctx);
  16750. }
  16751. function visitRoot(element, diagram) {
  16752. return handler.root(element, diMap[element.id], diagram);
  16753. }
  16754. function visitIfDi(element, ctx) {
  16755. try {
  16756. var gfx = diMap[element.id] && visit(element, ctx);
  16757. handled(element);
  16758. return gfx;
  16759. } catch (e) {
  16760. logError(e.message, { element: element, error: e });
  16761. console.error(translate('failed to import {element}', { element: elementToString(element) }));
  16762. console.error(e);
  16763. }
  16764. }
  16765. function logError(message, context) {
  16766. handler.error(message, context);
  16767. }
  16768. // DI handling //////////////////////
  16769. function registerDi(di) {
  16770. var bpmnElement = di.bpmnElement;
  16771. if (bpmnElement) {
  16772. if (diMap[bpmnElement.id]) {
  16773. logError(
  16774. translate('multiple DI elements defined for {element}', {
  16775. element: elementToString(bpmnElement)
  16776. }),
  16777. { element: bpmnElement }
  16778. );
  16779. } else {
  16780. diMap[bpmnElement.id] = di;
  16781. ensureCompatDiRef(bpmnElement);
  16782. }
  16783. } else {
  16784. logError(
  16785. translate('no bpmnElement referenced in {element}', {
  16786. element: elementToString(di)
  16787. }),
  16788. { element: di }
  16789. );
  16790. }
  16791. }
  16792. function handleDiagram(diagram) {
  16793. handlePlane(diagram.plane);
  16794. }
  16795. function handlePlane(plane) {
  16796. registerDi(plane);
  16797. forEach$1(plane.planeElement, handlePlaneElement);
  16798. }
  16799. function handlePlaneElement(planeElement) {
  16800. registerDi(planeElement);
  16801. }
  16802. // Semantic handling //////////////////////
  16803. /**
  16804. * Handle definitions and return the rendered diagram (if any)
  16805. *
  16806. * @param {ModdleElement} definitions to walk and import
  16807. * @param {ModdleElement} [diagram] specific diagram to import and display
  16808. *
  16809. * @throws {Error} if no diagram to display could be found
  16810. */
  16811. function handleDefinitions(definitions, diagram) {
  16812. // make sure we walk the correct bpmnElement
  16813. var diagrams = definitions.diagrams;
  16814. if (diagram && diagrams.indexOf(diagram) === -1) {
  16815. throw new Error(translate('diagram not part of bpmn:Definitions'));
  16816. }
  16817. if (!diagram && diagrams && diagrams.length) {
  16818. diagram = diagrams[0];
  16819. }
  16820. // no diagram -> nothing to import
  16821. if (!diagram) {
  16822. throw new Error(translate('no diagram to display'));
  16823. }
  16824. // load DI from selected diagram only
  16825. diMap = {};
  16826. handleDiagram(diagram);
  16827. var plane = diagram.plane;
  16828. if (!plane) {
  16829. throw new Error(translate(
  16830. 'no plane for {element}',
  16831. { element: elementToString(diagram) }
  16832. ));
  16833. }
  16834. var rootElement = plane.bpmnElement;
  16835. // ensure we default to a suitable display candidate (process or collaboration),
  16836. // even if non is specified in DI
  16837. if (!rootElement) {
  16838. rootElement = findDisplayCandidate(definitions);
  16839. if (!rootElement) {
  16840. throw new Error(translate('no process or collaboration to display'));
  16841. } else {
  16842. logError(
  16843. translate('correcting missing bpmnElement on {plane} to {rootElement}', {
  16844. plane: elementToString(plane),
  16845. rootElement: elementToString(rootElement)
  16846. })
  16847. );
  16848. // correct DI on the fly
  16849. plane.bpmnElement = rootElement;
  16850. registerDi(plane);
  16851. }
  16852. }
  16853. var ctx = visitRoot(rootElement, plane);
  16854. if (is(rootElement, 'bpmn:Process') || is(rootElement, 'bpmn:SubProcess')) {
  16855. handleProcess(rootElement, ctx);
  16856. } else if (is(rootElement, 'bpmn:Collaboration')) {
  16857. handleCollaboration(rootElement, ctx);
  16858. // force drawing of everything not yet drawn that is part of the target DI
  16859. handleUnhandledProcesses(definitions.rootElements, ctx);
  16860. } else {
  16861. throw new Error(
  16862. translate('unsupported bpmnElement for {plane}: {rootElement}', {
  16863. plane: elementToString(plane),
  16864. rootElement: elementToString(rootElement)
  16865. })
  16866. );
  16867. }
  16868. // handle all deferred elements
  16869. handleDeferred();
  16870. }
  16871. function handleDeferred() {
  16872. var fn;
  16873. // drain deferred until empty
  16874. while (deferred.length) {
  16875. fn = deferred.shift();
  16876. fn();
  16877. }
  16878. }
  16879. function handleProcess(process, context) {
  16880. handleFlowElementsContainer(process, context);
  16881. handleIoSpecification(process.ioSpecification, context);
  16882. handleArtifacts(process.artifacts, context);
  16883. // log process handled
  16884. handled(process);
  16885. }
  16886. function handleUnhandledProcesses(rootElements, ctx) {
  16887. // walk through all processes that have not yet been drawn and draw them
  16888. // if they contain lanes with DI information.
  16889. // we do this to pass the free-floating lane test cases in the MIWG test suite
  16890. var processes = filter(rootElements, function(e) {
  16891. return !isHandled(e) && is(e, 'bpmn:Process') && e.laneSets;
  16892. });
  16893. processes.forEach(contextual(handleProcess, ctx));
  16894. }
  16895. function handleMessageFlow(messageFlow, context) {
  16896. visitIfDi(messageFlow, context);
  16897. }
  16898. function handleMessageFlows(messageFlows, context) {
  16899. forEach$1(messageFlows, contextual(handleMessageFlow, context));
  16900. }
  16901. function handleDataAssociation(association, context) {
  16902. visitIfDi(association, context);
  16903. }
  16904. function handleDataInput(dataInput, context) {
  16905. visitIfDi(dataInput, context);
  16906. }
  16907. function handleDataOutput(dataOutput, context) {
  16908. visitIfDi(dataOutput, context);
  16909. }
  16910. function handleArtifact(artifact, context) {
  16911. // bpmn:TextAnnotation
  16912. // bpmn:Group
  16913. // bpmn:Association
  16914. visitIfDi(artifact, context);
  16915. }
  16916. function handleArtifacts(artifacts, context) {
  16917. forEach$1(artifacts, function(e) {
  16918. if (is(e, 'bpmn:Association')) {
  16919. deferred.push(function() {
  16920. handleArtifact(e, context);
  16921. });
  16922. } else {
  16923. handleArtifact(e, context);
  16924. }
  16925. });
  16926. }
  16927. function handleIoSpecification(ioSpecification, context) {
  16928. if (!ioSpecification) {
  16929. return;
  16930. }
  16931. forEach$1(ioSpecification.dataInputs, contextual(handleDataInput, context));
  16932. forEach$1(ioSpecification.dataOutputs, contextual(handleDataOutput, context));
  16933. }
  16934. function handleSubProcess(subProcess, context) {
  16935. handleFlowElementsContainer(subProcess, context);
  16936. handleArtifacts(subProcess.artifacts, context);
  16937. }
  16938. function handleFlowNode(flowNode, context) {
  16939. var childCtx = visitIfDi(flowNode, context);
  16940. if (is(flowNode, 'bpmn:SubProcess')) {
  16941. handleSubProcess(flowNode, childCtx || context);
  16942. }
  16943. if (is(flowNode, 'bpmn:Activity')) {
  16944. handleIoSpecification(flowNode.ioSpecification, context);
  16945. }
  16946. // defer handling of associations
  16947. // affected types:
  16948. //
  16949. // * bpmn:Activity
  16950. // * bpmn:ThrowEvent
  16951. // * bpmn:CatchEvent
  16952. //
  16953. deferred.push(function() {
  16954. forEach$1(flowNode.dataInputAssociations, contextual(handleDataAssociation, context));
  16955. forEach$1(flowNode.dataOutputAssociations, contextual(handleDataAssociation, context));
  16956. });
  16957. }
  16958. function handleSequenceFlow(sequenceFlow, context) {
  16959. visitIfDi(sequenceFlow, context);
  16960. }
  16961. function handleDataElement(dataObject, context) {
  16962. visitIfDi(dataObject, context);
  16963. }
  16964. function handleLane(lane, context) {
  16965. deferred.push(function() {
  16966. var newContext = visitIfDi(lane, context);
  16967. if (lane.childLaneSet) {
  16968. handleLaneSet(lane.childLaneSet, newContext || context);
  16969. }
  16970. wireFlowNodeRefs(lane);
  16971. });
  16972. }
  16973. function handleLaneSet(laneSet, context) {
  16974. forEach$1(laneSet.lanes, contextual(handleLane, context));
  16975. }
  16976. function handleLaneSets(laneSets, context) {
  16977. forEach$1(laneSets, contextual(handleLaneSet, context));
  16978. }
  16979. function handleFlowElementsContainer(container, context) {
  16980. handleFlowElements(container.flowElements, context);
  16981. if (container.laneSets) {
  16982. handleLaneSets(container.laneSets, context);
  16983. }
  16984. }
  16985. function handleFlowElements(flowElements, context) {
  16986. forEach$1(flowElements, function(e) {
  16987. if (is(e, 'bpmn:SequenceFlow')) {
  16988. deferred.push(function() {
  16989. handleSequenceFlow(e, context);
  16990. });
  16991. } else if (is(e, 'bpmn:BoundaryEvent')) {
  16992. deferred.unshift(function() {
  16993. handleFlowNode(e, context);
  16994. });
  16995. } else if (is(e, 'bpmn:FlowNode')) {
  16996. handleFlowNode(e, context);
  16997. } else if (is(e, 'bpmn:DataObject')) ; else if (is(e, 'bpmn:DataStoreReference')) {
  16998. handleDataElement(e, context);
  16999. } else if (is(e, 'bpmn:DataObjectReference')) {
  17000. handleDataElement(e, context);
  17001. } else {
  17002. logError(
  17003. translate('unrecognized flowElement {element} in context {context}', {
  17004. element: elementToString(e),
  17005. context: (context ? elementToString(context.businessObject) : 'null')
  17006. }),
  17007. { element: e, context: context }
  17008. );
  17009. }
  17010. });
  17011. }
  17012. function handleParticipant(participant, context) {
  17013. var newCtx = visitIfDi(participant, context);
  17014. var process = participant.processRef;
  17015. if (process) {
  17016. handleProcess(process, newCtx || context);
  17017. }
  17018. }
  17019. function handleCollaboration(collaboration, context) {
  17020. forEach$1(collaboration.participants, contextual(handleParticipant, context));
  17021. handleArtifacts(collaboration.artifacts, context);
  17022. // handle message flows latest in the process
  17023. deferred.push(function() {
  17024. handleMessageFlows(collaboration.messageFlows, context);
  17025. });
  17026. }
  17027. function wireFlowNodeRefs(lane) {
  17028. // wire the virtual flowNodeRefs <-> relationship
  17029. forEach$1(lane.flowNodeRef, function(flowNode) {
  17030. var lanes = flowNode.get('lanes');
  17031. if (lanes) {
  17032. lanes.push(lane);
  17033. }
  17034. });
  17035. }
  17036. // API //////////////////////
  17037. return {
  17038. handleDeferred: handleDeferred,
  17039. handleDefinitions: handleDefinitions,
  17040. handleSubProcess: handleSubProcess,
  17041. registerDi: registerDi
  17042. };
  17043. }
  17044. /**
  17045. * The importBpmnDiagram result.
  17046. *
  17047. * @typedef {Object} ImportBPMNDiagramResult
  17048. *
  17049. * @property {Array<string>} warnings
  17050. */
  17051. /**
  17052. * The importBpmnDiagram error.
  17053. *
  17054. * @typedef {Error} ImportBPMNDiagramError
  17055. *
  17056. * @property {Array<string>} warnings
  17057. */
  17058. /**
  17059. * Import the definitions into a diagram.
  17060. *
  17061. * Errors and warnings are reported through the specified callback.
  17062. *
  17063. * @param {djs.Diagram} diagram
  17064. * @param {ModdleElement<Definitions>} definitions
  17065. * @param {ModdleElement<BPMNDiagram>} [bpmnDiagram] the diagram to be rendered
  17066. * (if not provided, the first one will be rendered)
  17067. *
  17068. * Returns {Promise<ImportBPMNDiagramResult, ImportBPMNDiagramError>}
  17069. */
  17070. function importBpmnDiagram(diagram, definitions, bpmnDiagram) {
  17071. var importer,
  17072. eventBus,
  17073. translate,
  17074. canvas;
  17075. var error,
  17076. warnings = [];
  17077. /**
  17078. * Walk the diagram semantically, importing (=drawing)
  17079. * all elements you encounter.
  17080. *
  17081. * @param {ModdleElement<Definitions>} definitions
  17082. * @param {ModdleElement<BPMNDiagram>} bpmnDiagram
  17083. */
  17084. function render(definitions, bpmnDiagram) {
  17085. var visitor = {
  17086. root: function(element, di) {
  17087. return importer.add(element, di);
  17088. },
  17089. element: function(element, di, parentShape) {
  17090. return importer.add(element, di, parentShape);
  17091. },
  17092. error: function(message, context) {
  17093. warnings.push({ message: message, context: context });
  17094. }
  17095. };
  17096. var walker = new BpmnTreeWalker(visitor, translate);
  17097. bpmnDiagram = bpmnDiagram || (definitions.diagrams && definitions.diagrams[0]);
  17098. var diagramsToImport = getDiagramsToImport(definitions, bpmnDiagram);
  17099. if (!diagramsToImport) {
  17100. throw new Error(translate('no diagram to display'));
  17101. }
  17102. // traverse BPMN 2.0 document model,
  17103. // starting at definitions
  17104. forEach$1(diagramsToImport, function(diagram) {
  17105. walker.handleDefinitions(definitions, diagram);
  17106. });
  17107. var rootId = bpmnDiagram.plane.bpmnElement.id;
  17108. // we do need to account for different ways we create root elements
  17109. // each nested imported <root> do have the `_plane` suffix, while
  17110. // the root <root> is found under the business object ID
  17111. canvas.setRootElement(
  17112. canvas.findRoot(rootId + '_plane') || canvas.findRoot(rootId)
  17113. );
  17114. }
  17115. return new Promise(function(resolve, reject) {
  17116. try {
  17117. importer = diagram.get('bpmnImporter');
  17118. eventBus = diagram.get('eventBus');
  17119. translate = diagram.get('translate');
  17120. canvas = diagram.get('canvas');
  17121. eventBus.fire('import.render.start', { definitions: definitions });
  17122. render(definitions, bpmnDiagram);
  17123. eventBus.fire('import.render.complete', {
  17124. error: error,
  17125. warnings: warnings
  17126. });
  17127. return resolve({ warnings: warnings });
  17128. } catch (e) {
  17129. e.warnings = warnings;
  17130. return reject(e);
  17131. }
  17132. });
  17133. }
  17134. /**
  17135. * Returns all diagrams in the same hierarchy as the requested diagram.
  17136. * Includes all parent and sub process diagrams.
  17137. *
  17138. * @param {Array} definitions
  17139. * @param {Object} bpmnDiagram
  17140. *
  17141. * @returns {Array<Object>}
  17142. */
  17143. function getDiagramsToImport(definitions, bpmnDiagram) {
  17144. if (!bpmnDiagram) {
  17145. return;
  17146. }
  17147. var bpmnElement = bpmnDiagram.plane.bpmnElement,
  17148. rootElement = bpmnElement;
  17149. if (!is$1(bpmnElement, 'bpmn:Process') && !is$1(bpmnElement, 'bpmn:Collaboration')) {
  17150. rootElement = findRootProcess(bpmnElement);
  17151. }
  17152. // in case the process is part of a collaboration, the plane references the
  17153. // collaboration, not the process
  17154. var collaboration;
  17155. if (is$1(rootElement, 'bpmn:Collaboration')) {
  17156. collaboration = rootElement;
  17157. } else {
  17158. collaboration = find(definitions.rootElements, function(element) {
  17159. if (!is$1(element, 'bpmn:Collaboration')) {
  17160. return;
  17161. }
  17162. return find(element.participants, function(participant) {
  17163. return participant.processRef === rootElement;
  17164. });
  17165. });
  17166. }
  17167. var rootElements = [ rootElement ];
  17168. // all collaboration processes can contain sub-diagrams
  17169. if (collaboration) {
  17170. rootElements = map(collaboration.participants, function(participant) {
  17171. return participant.processRef;
  17172. });
  17173. rootElements.push(collaboration);
  17174. }
  17175. var allChildren = selfAndAllFlowElements(rootElements);
  17176. // if we have multiple diagrams referencing the same element, we
  17177. // use the first in the file
  17178. var diagramsToImport = [ bpmnDiagram ];
  17179. var handledElements = [ bpmnElement ];
  17180. forEach$1(definitions.diagrams, function(diagram) {
  17181. var businessObject = diagram.plane.bpmnElement;
  17182. if (
  17183. allChildren.indexOf(businessObject) !== -1 &&
  17184. handledElements.indexOf(businessObject) === -1
  17185. ) {
  17186. diagramsToImport.push(diagram);
  17187. handledElements.push(businessObject);
  17188. }
  17189. });
  17190. return diagramsToImport;
  17191. }
  17192. function selfAndAllFlowElements(elements) {
  17193. var result = [];
  17194. forEach$1(elements, function(element) {
  17195. if (!element) {
  17196. return;
  17197. }
  17198. result.push(element);
  17199. result = result.concat(selfAndAllFlowElements(element.flowElements));
  17200. });
  17201. return result;
  17202. }
  17203. function findRootProcess(element) {
  17204. var parent = element;
  17205. while (parent) {
  17206. if (is$1(parent, 'bpmn:Process')) {
  17207. return parent;
  17208. }
  17209. parent = parent.$parent;
  17210. }
  17211. }
  17212. /**
  17213. * This file must not be changed or exchanged.
  17214. *
  17215. * @see http://bpmn.io/license for more information.
  17216. */
  17217. // inlined ../../resources/logo.svg
  17218. var BPMNIO_LOGO_SVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 14.02 5.57" width="53" height="21"><path fill="currentColor" d="M1.88.92v.14c0 .41-.13.68-.4.8.33.14.46.44.46.86v.33c0 .61-.33.95-.95.95H0V0h.95c.65 0 .93.3.93.92zM.63.57v1.06h.24c.24 0 .38-.1.38-.43V.98c0-.28-.1-.4-.32-.4zm0 1.63v1.22h.36c.2 0 .32-.1.32-.39v-.35c0-.37-.12-.48-.4-.48H.63zM4.18.99v.52c0 .64-.31.98-.94.98h-.3V4h-.62V0h.92c.63 0 .94.35.94.99zM2.94.57v1.35h.3c.2 0 .3-.09.3-.37v-.6c0-.29-.1-.38-.3-.38h-.3zm2.89 2.27L6.25 0h.88v4h-.6V1.12L6.1 3.99h-.6l-.46-2.82v2.82h-.55V0h.87zM8.14 1.1V4h-.56V0h.79L9 2.4V0h.56v4h-.64zm2.49 2.29v.6h-.6v-.6zM12.12 1c0-.63.33-1 .95-1 .61 0 .95.37.95 1v2.04c0 .64-.34 1-.95 1-.62 0-.95-.37-.95-1zm.62 2.08c0 .28.13.39.33.39s.32-.1.32-.4V.98c0-.29-.12-.4-.32-.4s-.33.11-.33.4z"/><path fill="currentColor" d="M0 4.53h14.02v1.04H0zM11.08 0h.63v.62h-.63zm.63 4V1h-.63v2.98z"/></svg>';
  17219. var BPMNIO_IMG = BPMNIO_LOGO_SVG;
  17220. var LOGO_STYLES = {
  17221. verticalAlign: 'middle'
  17222. };
  17223. var LINK_STYLES = {
  17224. 'color': '#404040'
  17225. };
  17226. var LIGHTBOX_STYLES = {
  17227. 'zIndex': '1001',
  17228. 'position': 'fixed',
  17229. 'top': '0',
  17230. 'left': '0',
  17231. 'right': '0',
  17232. 'bottom': '0'
  17233. };
  17234. var BACKDROP_STYLES = {
  17235. 'width': '100%',
  17236. 'height': '100%',
  17237. 'background': 'rgba(40,40,40,0.2)'
  17238. };
  17239. var NOTICE_STYLES = {
  17240. 'position': 'absolute',
  17241. 'left': '50%',
  17242. 'top': '40%',
  17243. 'transform': 'translate(-50%)',
  17244. 'width': '260px',
  17245. 'padding': '10px',
  17246. 'background': 'white',
  17247. 'boxShadow': '0 1px 4px rgba(0,0,0,0.3)',
  17248. 'fontFamily': 'Helvetica, Arial, sans-serif',
  17249. 'fontSize': '14px',
  17250. 'display': 'flex',
  17251. 'lineHeight': '1.3'
  17252. };
  17253. var LIGHTBOX_MARKUP =
  17254. '<div class="bjs-powered-by-lightbox">' +
  17255. '<div class="backdrop"></div>' +
  17256. '<div class="notice">' +
  17257. '<a href="https://bpmn.io" target="_blank" rel="noopener" class="link">' +
  17258. BPMNIO_IMG +
  17259. '</a>' +
  17260. '<span>' +
  17261. 'Web-based tooling for BPMN, DMN and CMMN diagrams ' +
  17262. 'powered by <a href="https://bpmn.io" target="_blank" rel="noopener">bpmn.io</a>.' +
  17263. '</span>' +
  17264. '</div>' +
  17265. '</div>';
  17266. var lightbox;
  17267. function createLightbox() {
  17268. lightbox = domify(LIGHTBOX_MARKUP);
  17269. assign$1(lightbox, LIGHTBOX_STYLES);
  17270. assign$1(query('svg', lightbox), LOGO_STYLES);
  17271. assign$1(query('.backdrop', lightbox), BACKDROP_STYLES);
  17272. assign$1(query('.notice', lightbox), NOTICE_STYLES);
  17273. assign$1(query('.link', lightbox), LINK_STYLES, {
  17274. 'margin': '15px 20px 15px 10px',
  17275. 'alignSelf': 'center'
  17276. });
  17277. }
  17278. function open() {
  17279. if (!lightbox) {
  17280. createLightbox();
  17281. delegate.bind(lightbox, '.backdrop', 'click', function(event) {
  17282. document.body.removeChild(lightbox);
  17283. });
  17284. }
  17285. document.body.appendChild(lightbox);
  17286. }
  17287. /**
  17288. * The code in the <project-logo></project-logo> area
  17289. * must not be changed.
  17290. *
  17291. * @see http://bpmn.io/license for more information.
  17292. */
  17293. /**
  17294. * A base viewer for BPMN 2.0 diagrams.
  17295. *
  17296. * Have a look at {@link Viewer}, {@link NavigatedViewer} or {@link Modeler} for
  17297. * bundles that include actual features.
  17298. *
  17299. * @param {Object} [options] configuration options to pass to the viewer
  17300. * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
  17301. * @param {string|number} [options.width] the width of the viewer
  17302. * @param {string|number} [options.height] the height of the viewer
  17303. * @param {Object} [options.moddleExtensions] extension packages to provide
  17304. * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
  17305. * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
  17306. */
  17307. function BaseViewer(options) {
  17308. options = assign({}, DEFAULT_OPTIONS, options);
  17309. this._moddle = this._createModdle(options);
  17310. this._container = this._createContainer(options);
  17311. /* <project-logo> */
  17312. addProjectLogo(this._container);
  17313. /* </project-logo> */
  17314. this._init(this._container, this._moddle, options);
  17315. }
  17316. e(BaseViewer, Diagram);
  17317. /**
  17318. * The importXML result.
  17319. *
  17320. * @typedef {Object} ImportXMLResult
  17321. *
  17322. * @property {Array<string>} warnings
  17323. */
  17324. /**
  17325. * The importXML error.
  17326. *
  17327. * @typedef {Error} ImportXMLError
  17328. *
  17329. * @property {Array<string>} warnings
  17330. */
  17331. /**
  17332. * Parse and render a BPMN 2.0 diagram.
  17333. *
  17334. * Once finished the viewer reports back the result to the
  17335. * provided callback function with (err, warnings).
  17336. *
  17337. * ## Life-Cycle Events
  17338. *
  17339. * During import the viewer will fire life-cycle events:
  17340. *
  17341. * * import.parse.start (about to read model from xml)
  17342. * * import.parse.complete (model read; may have worked or not)
  17343. * * import.render.start (graphical import start)
  17344. * * import.render.complete (graphical import finished)
  17345. * * import.done (everything done)
  17346. *
  17347. * You can use these events to hook into the life-cycle.
  17348. *
  17349. * @param {string} xml the BPMN 2.0 xml
  17350. * @param {ModdleElement<BPMNDiagram>|string} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
  17351. *
  17352. * Returns {Promise<ImportXMLResult, ImportXMLError>}
  17353. */
  17354. BaseViewer.prototype.importXML = wrapForCompatibility(function importXML(xml, bpmnDiagram) {
  17355. var self = this;
  17356. function ParseCompleteEvent(data) {
  17357. var event = self.get('eventBus').createEvent(data);
  17358. // TODO(nikku): remove with future bpmn-js version
  17359. Object.defineProperty(event, 'context', {
  17360. enumerable: true,
  17361. get: function() {
  17362. console.warn(new Error(
  17363. 'import.parse.complete <context> is deprecated ' +
  17364. 'and will be removed in future library versions'
  17365. ));
  17366. return {
  17367. warnings: data.warnings,
  17368. references: data.references,
  17369. elementsById: data.elementsById
  17370. };
  17371. }
  17372. });
  17373. return event;
  17374. }
  17375. return new Promise(function(resolve, reject) {
  17376. // hook in pre-parse listeners +
  17377. // allow xml manipulation
  17378. xml = self._emit('import.parse.start', { xml: xml }) || xml;
  17379. self._moddle.fromXML(xml, 'bpmn:Definitions').then(function(result) {
  17380. var definitions = result.rootElement;
  17381. var references = result.references;
  17382. var parseWarnings = result.warnings;
  17383. var elementsById = result.elementsById;
  17384. // hook in post parse listeners +
  17385. // allow definitions manipulation
  17386. definitions = self._emit('import.parse.complete', ParseCompleteEvent({
  17387. error: null,
  17388. definitions: definitions,
  17389. elementsById: elementsById,
  17390. references: references,
  17391. warnings: parseWarnings
  17392. })) || definitions;
  17393. self.importDefinitions(definitions, bpmnDiagram).then(function(result) {
  17394. var allWarnings = [].concat(parseWarnings, result.warnings || []);
  17395. self._emit('import.done', { error: null, warnings: allWarnings });
  17396. return resolve({ warnings: allWarnings });
  17397. }).catch(function(err) {
  17398. var allWarnings = [].concat(parseWarnings, err.warnings || []);
  17399. self._emit('import.done', { error: err, warnings: allWarnings });
  17400. return reject(addWarningsToError(err, allWarnings));
  17401. });
  17402. }).catch(function(err) {
  17403. self._emit('import.parse.complete', {
  17404. error: err
  17405. });
  17406. err = checkValidationError(err);
  17407. self._emit('import.done', { error: err, warnings: err.warnings });
  17408. return reject(err);
  17409. });
  17410. });
  17411. });
  17412. /**
  17413. * The importDefinitions result.
  17414. *
  17415. * @typedef {Object} ImportDefinitionsResult
  17416. *
  17417. * @property {Array<string>} warnings
  17418. */
  17419. /**
  17420. * The importDefinitions error.
  17421. *
  17422. * @typedef {Error} ImportDefinitionsError
  17423. *
  17424. * @property {Array<string>} warnings
  17425. */
  17426. /**
  17427. * Import parsed definitions and render a BPMN 2.0 diagram.
  17428. *
  17429. * Once finished the viewer reports back the result to the
  17430. * provided callback function with (err, warnings).
  17431. *
  17432. * ## Life-Cycle Events
  17433. *
  17434. * During import the viewer will fire life-cycle events:
  17435. *
  17436. * * import.render.start (graphical import start)
  17437. * * import.render.complete (graphical import finished)
  17438. *
  17439. * You can use these events to hook into the life-cycle.
  17440. *
  17441. * @param {ModdleElement<Definitions>} definitions parsed BPMN 2.0 definitions
  17442. * @param {ModdleElement<BPMNDiagram>|string} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
  17443. *
  17444. * Returns {Promise<ImportDefinitionsResult, ImportDefinitionsError>}
  17445. */
  17446. BaseViewer.prototype.importDefinitions = wrapForCompatibility(function importDefinitions(definitions, bpmnDiagram) {
  17447. var self = this;
  17448. return new Promise(function(resolve, reject) {
  17449. self._setDefinitions(definitions);
  17450. self.open(bpmnDiagram).then(function(result) {
  17451. var warnings = result.warnings;
  17452. return resolve({ warnings: warnings });
  17453. }).catch(function(err) {
  17454. return reject(err);
  17455. });
  17456. });
  17457. });
  17458. /**
  17459. * The open result.
  17460. *
  17461. * @typedef {Object} OpenResult
  17462. *
  17463. * @property {Array<string>} warnings
  17464. */
  17465. /**
  17466. * The open error.
  17467. *
  17468. * @typedef {Error} OpenError
  17469. *
  17470. * @property {Array<string>} warnings
  17471. */
  17472. /**
  17473. * Open diagram of previously imported XML.
  17474. *
  17475. * Once finished the viewer reports back the result to the
  17476. * provided callback function with (err, warnings).
  17477. *
  17478. * ## Life-Cycle Events
  17479. *
  17480. * During switch the viewer will fire life-cycle events:
  17481. *
  17482. * * import.render.start (graphical import start)
  17483. * * import.render.complete (graphical import finished)
  17484. *
  17485. * You can use these events to hook into the life-cycle.
  17486. *
  17487. * @param {string|ModdleElement<BPMNDiagram>} [bpmnDiagramOrId] id or the diagram to open
  17488. *
  17489. * Returns {Promise<OpenResult, OpenError>}
  17490. */
  17491. BaseViewer.prototype.open = wrapForCompatibility(function open(bpmnDiagramOrId) {
  17492. var definitions = this._definitions;
  17493. var bpmnDiagram = bpmnDiagramOrId;
  17494. var self = this;
  17495. return new Promise(function(resolve, reject) {
  17496. if (!definitions) {
  17497. var err1 = new Error('no XML imported');
  17498. return reject(addWarningsToError(err1, []));
  17499. }
  17500. if (typeof bpmnDiagramOrId === 'string') {
  17501. bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId);
  17502. if (!bpmnDiagram) {
  17503. var err2 = new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found');
  17504. return reject(addWarningsToError(err2, []));
  17505. }
  17506. }
  17507. // clear existing rendered diagram
  17508. // catch synchronous exceptions during #clear()
  17509. try {
  17510. self.clear();
  17511. } catch (error) {
  17512. return reject(addWarningsToError(error, []));
  17513. }
  17514. // perform graphical import
  17515. importBpmnDiagram(self, definitions, bpmnDiagram).then(function(result) {
  17516. var warnings = result.warnings;
  17517. return resolve({ warnings: warnings });
  17518. }).catch(function(err) {
  17519. return reject(err);
  17520. });
  17521. });
  17522. });
  17523. /**
  17524. * The saveXML result.
  17525. *
  17526. * @typedef {Object} SaveXMLResult
  17527. *
  17528. * @property {string} xml
  17529. */
  17530. /**
  17531. * Export the currently displayed BPMN 2.0 diagram as
  17532. * a BPMN 2.0 XML document.
  17533. *
  17534. * ## Life-Cycle Events
  17535. *
  17536. * During XML saving the viewer will fire life-cycle events:
  17537. *
  17538. * * saveXML.start (before serialization)
  17539. * * saveXML.serialized (after xml generation)
  17540. * * saveXML.done (everything done)
  17541. *
  17542. * You can use these events to hook into the life-cycle.
  17543. *
  17544. * @param {Object} [options] export options
  17545. * @param {boolean} [options.format=false] output formatted XML
  17546. * @param {boolean} [options.preamble=true] output preamble
  17547. *
  17548. * Returns {Promise<SaveXMLResult, Error>}
  17549. */
  17550. BaseViewer.prototype.saveXML = wrapForCompatibility(function saveXML(options) {
  17551. options = options || {};
  17552. var self = this;
  17553. var definitions = this._definitions;
  17554. return new Promise(function(resolve) {
  17555. if (!definitions) {
  17556. return resolve({
  17557. error: new Error('no definitions loaded')
  17558. });
  17559. }
  17560. // allow to fiddle around with definitions
  17561. definitions = self._emit('saveXML.start', {
  17562. definitions: definitions
  17563. }) || definitions;
  17564. self._moddle.toXML(definitions, options).then(function(result) {
  17565. var xml = result.xml;
  17566. xml = self._emit('saveXML.serialized', {
  17567. xml: xml
  17568. }) || xml;
  17569. return resolve({
  17570. xml: xml
  17571. });
  17572. });
  17573. }).catch(function(error) {
  17574. return { error: error };
  17575. }).then(function(result) {
  17576. self._emit('saveXML.done', result);
  17577. var error = result.error;
  17578. if (error) {
  17579. return Promise.reject(error);
  17580. }
  17581. return result;
  17582. });
  17583. });
  17584. /**
  17585. * The saveSVG result.
  17586. *
  17587. * @typedef {Object} SaveSVGResult
  17588. *
  17589. * @property {string} svg
  17590. */
  17591. /**
  17592. * Export the currently displayed BPMN 2.0 diagram as
  17593. * an SVG image.
  17594. *
  17595. * ## Life-Cycle Events
  17596. *
  17597. * During SVG saving the viewer will fire life-cycle events:
  17598. *
  17599. * * saveSVG.start (before serialization)
  17600. * * saveSVG.done (everything done)
  17601. *
  17602. * You can use these events to hook into the life-cycle.
  17603. *
  17604. * @param {Object} [options]
  17605. *
  17606. * Returns {Promise<SaveSVGResult, Error>}
  17607. */
  17608. BaseViewer.prototype.saveSVG = wrapForCompatibility(function saveSVG(options) {
  17609. var self = this;
  17610. return new Promise(function(resolve, reject) {
  17611. self._emit('saveSVG.start');
  17612. var svg, err;
  17613. try {
  17614. var canvas = self.get('canvas');
  17615. var contentNode = canvas.getActiveLayer(),
  17616. defsNode = query('defs', canvas._svg);
  17617. var contents = innerSVG(contentNode),
  17618. defs = defsNode ? '<defs>' + innerSVG(defsNode) + '</defs>' : '';
  17619. var bbox = contentNode.getBBox();
  17620. svg =
  17621. '<?xml version="1.0" encoding="utf-8"?>\n' +
  17622. '<!-- created with bpmn-js / http://bpmn.io -->\n' +
  17623. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
  17624. '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
  17625. 'width="' + bbox.width + '" height="' + bbox.height + '" ' +
  17626. 'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
  17627. defs + contents +
  17628. '</svg>';
  17629. } catch (e) {
  17630. err = e;
  17631. }
  17632. self._emit('saveSVG.done', {
  17633. error: err,
  17634. svg: svg
  17635. });
  17636. if (!err) {
  17637. return resolve({ svg: svg });
  17638. }
  17639. return reject(err);
  17640. });
  17641. });
  17642. /**
  17643. * Get a named diagram service.
  17644. *
  17645. * @example
  17646. *
  17647. * var elementRegistry = viewer.get('elementRegistry');
  17648. * var startEventShape = elementRegistry.get('StartEvent_1');
  17649. *
  17650. * @param {string} name
  17651. *
  17652. * @return {Object} diagram service instance
  17653. *
  17654. * @method BaseViewer#get
  17655. */
  17656. /**
  17657. * Invoke a function in the context of this viewer.
  17658. *
  17659. * @example
  17660. *
  17661. * viewer.invoke(function(elementRegistry) {
  17662. * var startEventShape = elementRegistry.get('StartEvent_1');
  17663. * });
  17664. *
  17665. * @param {Function} fn to be invoked
  17666. *
  17667. * @return {Object} the functions return value
  17668. *
  17669. * @method BaseViewer#invoke
  17670. */
  17671. BaseViewer.prototype._setDefinitions = function(definitions) {
  17672. this._definitions = definitions;
  17673. };
  17674. BaseViewer.prototype.getModules = function() {
  17675. return this._modules;
  17676. };
  17677. /**
  17678. * Remove all drawn elements from the viewer.
  17679. *
  17680. * After calling this method the viewer can still
  17681. * be reused for opening another diagram.
  17682. *
  17683. * @method BaseViewer#clear
  17684. */
  17685. BaseViewer.prototype.clear = function() {
  17686. if (!this.getDefinitions()) {
  17687. // no diagram to clear
  17688. return;
  17689. }
  17690. // remove drawn elements
  17691. Diagram.prototype.clear.call(this);
  17692. };
  17693. /**
  17694. * Destroy the viewer instance and remove all its
  17695. * remainders from the document tree.
  17696. */
  17697. BaseViewer.prototype.destroy = function() {
  17698. // diagram destroy
  17699. Diagram.prototype.destroy.call(this);
  17700. // dom detach
  17701. remove$1(this._container);
  17702. };
  17703. /**
  17704. * Register an event listener
  17705. *
  17706. * Remove a previously added listener via {@link #off(event, callback)}.
  17707. *
  17708. * @param {string} event
  17709. * @param {number} [priority]
  17710. * @param {Function} callback
  17711. * @param {Object} [that]
  17712. */
  17713. BaseViewer.prototype.on = function(event, priority, callback, target) {
  17714. return this.get('eventBus').on(event, priority, callback, target);
  17715. };
  17716. /**
  17717. * De-register an event listener
  17718. *
  17719. * @param {string} event
  17720. * @param {Function} callback
  17721. */
  17722. BaseViewer.prototype.off = function(event, callback) {
  17723. this.get('eventBus').off(event, callback);
  17724. };
  17725. BaseViewer.prototype.attachTo = function(parentNode) {
  17726. if (!parentNode) {
  17727. throw new Error('parentNode required');
  17728. }
  17729. // ensure we detach from the
  17730. // previous, old parent
  17731. this.detach();
  17732. // unwrap jQuery if provided
  17733. if (parentNode.get && parentNode.constructor.prototype.jquery) {
  17734. parentNode = parentNode.get(0);
  17735. }
  17736. if (typeof parentNode === 'string') {
  17737. parentNode = query(parentNode);
  17738. }
  17739. parentNode.appendChild(this._container);
  17740. this._emit('attach', {});
  17741. this.get('canvas').resized();
  17742. };
  17743. BaseViewer.prototype.getDefinitions = function() {
  17744. return this._definitions;
  17745. };
  17746. BaseViewer.prototype.detach = function() {
  17747. var container = this._container,
  17748. parentNode = container.parentNode;
  17749. if (!parentNode) {
  17750. return;
  17751. }
  17752. this._emit('detach', {});
  17753. parentNode.removeChild(container);
  17754. };
  17755. BaseViewer.prototype._init = function(container, moddle, options) {
  17756. var baseModules = options.modules || this.getModules(),
  17757. additionalModules = options.additionalModules || [],
  17758. staticModules = [
  17759. {
  17760. bpmnjs: [ 'value', this ],
  17761. moddle: [ 'value', moddle ]
  17762. }
  17763. ];
  17764. var diagramModules = [].concat(staticModules, baseModules, additionalModules);
  17765. var diagramOptions = assign(omit(options, [ 'additionalModules' ]), {
  17766. canvas: assign({}, options.canvas, { container: container }),
  17767. modules: diagramModules
  17768. });
  17769. // invoke diagram constructor
  17770. Diagram.call(this, diagramOptions);
  17771. if (options && options.container) {
  17772. this.attachTo(options.container);
  17773. }
  17774. };
  17775. /**
  17776. * Emit an event on the underlying {@link EventBus}
  17777. *
  17778. * @param {string} type
  17779. * @param {Object} event
  17780. *
  17781. * @return {Object} event processing result (if any)
  17782. */
  17783. BaseViewer.prototype._emit = function(type, event) {
  17784. return this.get('eventBus').fire(type, event);
  17785. };
  17786. BaseViewer.prototype._createContainer = function(options) {
  17787. var container = domify('<div class="bjs-container"></div>');
  17788. assign$1(container, {
  17789. width: ensureUnit(options.width),
  17790. height: ensureUnit(options.height),
  17791. position: options.position
  17792. });
  17793. return container;
  17794. };
  17795. BaseViewer.prototype._createModdle = function(options) {
  17796. var moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
  17797. return new simple(moddleOptions);
  17798. };
  17799. BaseViewer.prototype._modules = [];
  17800. // helpers ///////////////
  17801. function addWarningsToError(err, warningsAry) {
  17802. err.warnings = warningsAry;
  17803. return err;
  17804. }
  17805. function checkValidationError(err) {
  17806. // check if we can help the user by indicating wrong BPMN 2.0 xml
  17807. // (in case he or the exporting tool did not get that right)
  17808. var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
  17809. var match = pattern.exec(err.message);
  17810. if (match) {
  17811. err.message =
  17812. 'unparsable content <' + match[1] + '> detected; ' +
  17813. 'this may indicate an invalid BPMN 2.0 diagram file' + match[2];
  17814. }
  17815. return err;
  17816. }
  17817. var DEFAULT_OPTIONS = {
  17818. width: '100%',
  17819. height: '100%',
  17820. position: 'relative'
  17821. };
  17822. /**
  17823. * Ensure the passed argument is a proper unit (defaulting to px)
  17824. */
  17825. function ensureUnit(val) {
  17826. return val + (isNumber(val) ? 'px' : '');
  17827. }
  17828. /**
  17829. * Find BPMNDiagram in definitions by ID
  17830. *
  17831. * @param {ModdleElement<Definitions>} definitions
  17832. * @param {string} diagramId
  17833. *
  17834. * @return {ModdleElement<BPMNDiagram>|null}
  17835. */
  17836. function findBPMNDiagram(definitions, diagramId) {
  17837. if (!diagramId) {
  17838. return null;
  17839. }
  17840. return find(definitions.diagrams, function(element) {
  17841. return element.id === diagramId;
  17842. }) || null;
  17843. }
  17844. /**
  17845. * Adds the project logo to the diagram container as
  17846. * required by the bpmn.io license.
  17847. *
  17848. * @see http://bpmn.io/license
  17849. *
  17850. * @param {Element} container
  17851. */
  17852. function addProjectLogo(container) {
  17853. var img = BPMNIO_IMG;
  17854. var linkMarkup =
  17855. '<a href="http://bpmn.io" ' +
  17856. 'target="_blank" ' +
  17857. 'class="bjs-powered-by" ' +
  17858. 'title="Powered by bpmn.io" ' +
  17859. '>' +
  17860. img +
  17861. '</a>';
  17862. var linkElement = domify(linkMarkup);
  17863. assign$1(query('svg', linkElement), LOGO_STYLES);
  17864. assign$1(linkElement, LINK_STYLES, {
  17865. position: 'absolute',
  17866. bottom: '15px',
  17867. right: '15px',
  17868. zIndex: '100'
  17869. });
  17870. container.appendChild(linkElement);
  17871. componentEvent.bind(linkElement, 'click', function(event) {
  17872. open();
  17873. event.preventDefault();
  17874. });
  17875. }
  17876. /* </project-logo> */
  17877. /**
  17878. * A viewer for BPMN 2.0 diagrams.
  17879. *
  17880. * Have a look at {@link NavigatedViewer} or {@link Modeler} for bundles that include
  17881. * additional features.
  17882. *
  17883. *
  17884. * ## Extending the Viewer
  17885. *
  17886. * In order to extend the viewer pass extension modules to bootstrap via the
  17887. * `additionalModules` option. An extension module is an object that exposes
  17888. * named services.
  17889. *
  17890. * The following example depicts the integration of a simple
  17891. * logging component that integrates with interaction events:
  17892. *
  17893. *
  17894. * ```javascript
  17895. *
  17896. * // logging component
  17897. * function InteractionLogger(eventBus) {
  17898. * eventBus.on('element.hover', function(event) {
  17899. * console.log()
  17900. * })
  17901. * }
  17902. *
  17903. * InteractionLogger.$inject = [ 'eventBus' ]; // minification save
  17904. *
  17905. * // extension module
  17906. * var extensionModule = {
  17907. * __init__: [ 'interactionLogger' ],
  17908. * interactionLogger: [ 'type', InteractionLogger ]
  17909. * };
  17910. *
  17911. * // extend the viewer
  17912. * var bpmnViewer = new Viewer({ additionalModules: [ extensionModule ] });
  17913. * bpmnViewer.importXML(...);
  17914. * ```
  17915. *
  17916. * @param {Object} [options] configuration options to pass to the viewer
  17917. * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
  17918. * @param {string|number} [options.width] the width of the viewer
  17919. * @param {string|number} [options.height] the height of the viewer
  17920. * @param {Object} [options.moddleExtensions] extension packages to provide
  17921. * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
  17922. * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
  17923. */
  17924. function Viewer(options) {
  17925. BaseViewer.call(this, options);
  17926. }
  17927. e(Viewer, BaseViewer);
  17928. // modules the viewer is composed of
  17929. Viewer.prototype._modules = [
  17930. CoreModule$1,
  17931. TranslateModule,
  17932. SelectionModule,
  17933. OverlaysModule,
  17934. DrilldownModdule
  17935. ];
  17936. // default moddle extensions the viewer is composed of
  17937. Viewer.prototype._moddleExtensions = {};
  17938. return Viewer;
  17939. })));