bpmn-navigated-viewer.development.js 522 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591
  1. /*!
  2. * bpmn-js - bpmn-navigated-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$1(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$1(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 toPoint(event) {
  4796. if (event.pointers && event.pointers.length) {
  4797. event = event.pointers[0];
  4798. }
  4799. if (event.touches && event.touches.length) {
  4800. event = event.touches[0];
  4801. }
  4802. return event ? {
  4803. x: event.clientX,
  4804. y: event.clientY
  4805. } : null;
  4806. }
  4807. function isMac() {
  4808. return (/mac/i).test(navigator.platform);
  4809. }
  4810. function isButton(event, button) {
  4811. return (getOriginal(event) || event).button === button;
  4812. }
  4813. function isPrimaryButton(event) {
  4814. // button === 0 -> left áka primary mouse button
  4815. return isButton(event, 0);
  4816. }
  4817. function isAuxiliaryButton(event) {
  4818. // button === 1 -> auxiliary áka wheel button
  4819. return isButton(event, 1);
  4820. }
  4821. function hasPrimaryModifier(event) {
  4822. var originalEvent = getOriginal(event) || event;
  4823. if (!isPrimaryButton(event)) {
  4824. return false;
  4825. }
  4826. // Use cmd as primary modifier key for mac OS
  4827. if (isMac()) {
  4828. return originalEvent.metaKey;
  4829. } else {
  4830. return originalEvent.ctrlKey;
  4831. }
  4832. }
  4833. function hasSecondaryModifier(event) {
  4834. var originalEvent = getOriginal(event) || event;
  4835. return isPrimaryButton(event) && originalEvent.shiftKey;
  4836. }
  4837. function allowAll(event) { return true; }
  4838. function allowPrimaryAndAuxiliary(event) {
  4839. return isPrimaryButton(event) || isAuxiliaryButton(event);
  4840. }
  4841. var LOW_PRIORITY$4 = 500;
  4842. /**
  4843. * A plugin that provides interaction events for diagram elements.
  4844. *
  4845. * It emits the following events:
  4846. *
  4847. * * element.click
  4848. * * element.contextmenu
  4849. * * element.dblclick
  4850. * * element.hover
  4851. * * element.mousedown
  4852. * * element.mousemove
  4853. * * element.mouseup
  4854. * * element.out
  4855. *
  4856. * Each event is a tuple { element, gfx, originalEvent }.
  4857. *
  4858. * Canceling the event via Event#preventDefault()
  4859. * prevents the original DOM operation.
  4860. *
  4861. * @param {EventBus} eventBus
  4862. */
  4863. function InteractionEvents(eventBus, elementRegistry, styles) {
  4864. var self = this;
  4865. /**
  4866. * Fire an interaction event.
  4867. *
  4868. * @param {string} type local event name, e.g. element.click.
  4869. * @param {DOMEvent} event native event
  4870. * @param {djs.model.Base} [element] the diagram element to emit the event on;
  4871. * defaults to the event target
  4872. */
  4873. function fire(type, event, element) {
  4874. if (isIgnored(type, event)) {
  4875. return;
  4876. }
  4877. var target, gfx, returnValue;
  4878. if (!element) {
  4879. target = event.delegateTarget || event.target;
  4880. if (target) {
  4881. gfx = target;
  4882. element = elementRegistry.get(gfx);
  4883. }
  4884. } else {
  4885. gfx = elementRegistry.getGraphics(element);
  4886. }
  4887. if (!gfx || !element) {
  4888. return;
  4889. }
  4890. returnValue = eventBus.fire(type, {
  4891. element: element,
  4892. gfx: gfx,
  4893. originalEvent: event
  4894. });
  4895. if (returnValue === false) {
  4896. event.stopPropagation();
  4897. event.preventDefault();
  4898. }
  4899. }
  4900. // TODO(nikku): document this
  4901. var handlers = {};
  4902. function mouseHandler(localEventName) {
  4903. return handlers[localEventName];
  4904. }
  4905. function isIgnored(localEventName, event) {
  4906. var filter = ignoredFilters[localEventName] || isPrimaryButton;
  4907. // only react on left mouse button interactions
  4908. // except for interaction events that are enabled
  4909. // for secundary mouse button
  4910. return !filter(event);
  4911. }
  4912. var bindings = {
  4913. click: 'element.click',
  4914. contextmenu: 'element.contextmenu',
  4915. dblclick: 'element.dblclick',
  4916. mousedown: 'element.mousedown',
  4917. mousemove: 'element.mousemove',
  4918. mouseover: 'element.hover',
  4919. mouseout: 'element.out',
  4920. mouseup: 'element.mouseup',
  4921. };
  4922. var ignoredFilters = {
  4923. 'element.contextmenu': allowAll,
  4924. 'element.mousedown': allowPrimaryAndAuxiliary,
  4925. 'element.mouseup': allowPrimaryAndAuxiliary,
  4926. 'element.click': allowPrimaryAndAuxiliary,
  4927. 'element.dblclick': allowPrimaryAndAuxiliary
  4928. };
  4929. // manual event trigger //////////
  4930. /**
  4931. * Trigger an interaction event (based on a native dom event)
  4932. * on the target shape or connection.
  4933. *
  4934. * @param {string} eventName the name of the triggered DOM event
  4935. * @param {MouseEvent} event
  4936. * @param {djs.model.Base} targetElement
  4937. */
  4938. function triggerMouseEvent(eventName, event, targetElement) {
  4939. // i.e. element.mousedown...
  4940. var localEventName = bindings[eventName];
  4941. if (!localEventName) {
  4942. throw new Error('unmapped DOM event name <' + eventName + '>');
  4943. }
  4944. return fire(localEventName, event, targetElement);
  4945. }
  4946. var ELEMENT_SELECTOR = 'svg, .djs-element';
  4947. // event handling ///////
  4948. function registerEvent(node, event, localEvent, ignoredFilter) {
  4949. var handler = handlers[localEvent] = function(event) {
  4950. fire(localEvent, event);
  4951. };
  4952. if (ignoredFilter) {
  4953. ignoredFilters[localEvent] = ignoredFilter;
  4954. }
  4955. handler.$delegate = delegate.bind(node, ELEMENT_SELECTOR, event, handler);
  4956. }
  4957. function unregisterEvent(node, event, localEvent) {
  4958. var handler = mouseHandler(localEvent);
  4959. if (!handler) {
  4960. return;
  4961. }
  4962. delegate.unbind(node, event, handler.$delegate);
  4963. }
  4964. function registerEvents(svg) {
  4965. forEach$1(bindings, function(val, key) {
  4966. registerEvent(svg, key, val);
  4967. });
  4968. }
  4969. function unregisterEvents(svg) {
  4970. forEach$1(bindings, function(val, key) {
  4971. unregisterEvent(svg, key, val);
  4972. });
  4973. }
  4974. eventBus.on('canvas.destroy', function(event) {
  4975. unregisterEvents(event.svg);
  4976. });
  4977. eventBus.on('canvas.init', function(event) {
  4978. registerEvents(event.svg);
  4979. });
  4980. // hit box updating ////////////////
  4981. eventBus.on([ 'shape.added', 'connection.added' ], function(event) {
  4982. var element = event.element,
  4983. gfx = event.gfx;
  4984. eventBus.fire('interactionEvents.createHit', { element: element, gfx: gfx });
  4985. });
  4986. // Update djs-hit on change.
  4987. // A low priortity is necessary, because djs-hit of labels has to be updated
  4988. // after the label bounds have been updated in the renderer.
  4989. eventBus.on([
  4990. 'shape.changed',
  4991. 'connection.changed'
  4992. ], LOW_PRIORITY$4, function(event) {
  4993. var element = event.element,
  4994. gfx = event.gfx;
  4995. eventBus.fire('interactionEvents.updateHit', { element: element, gfx: gfx });
  4996. });
  4997. eventBus.on('interactionEvents.createHit', LOW_PRIORITY$4, function(event) {
  4998. var element = event.element,
  4999. gfx = event.gfx;
  5000. self.createDefaultHit(element, gfx);
  5001. });
  5002. eventBus.on('interactionEvents.updateHit', function(event) {
  5003. var element = event.element,
  5004. gfx = event.gfx;
  5005. self.updateDefaultHit(element, gfx);
  5006. });
  5007. // hit styles ////////////
  5008. var STROKE_HIT_STYLE = createHitStyle('djs-hit djs-hit-stroke');
  5009. var CLICK_STROKE_HIT_STYLE = createHitStyle('djs-hit djs-hit-click-stroke');
  5010. var ALL_HIT_STYLE = createHitStyle('djs-hit djs-hit-all');
  5011. var NO_MOVE_HIT_STYLE = createHitStyle('djs-hit djs-hit-no-move');
  5012. var HIT_TYPES = {
  5013. 'all': ALL_HIT_STYLE,
  5014. 'click-stroke': CLICK_STROKE_HIT_STYLE,
  5015. 'stroke': STROKE_HIT_STYLE,
  5016. 'no-move': NO_MOVE_HIT_STYLE
  5017. };
  5018. function createHitStyle(classNames, attrs) {
  5019. attrs = assign({
  5020. stroke: 'white',
  5021. strokeWidth: 15
  5022. }, attrs || {});
  5023. return styles.cls(classNames, [ 'no-fill', 'no-border' ], attrs);
  5024. }
  5025. // style helpers ///////////////
  5026. function applyStyle(hit, type) {
  5027. var attrs = HIT_TYPES[type];
  5028. if (!attrs) {
  5029. throw new Error('invalid hit type <' + type + '>');
  5030. }
  5031. attr$1(hit, attrs);
  5032. return hit;
  5033. }
  5034. function appendHit(gfx, hit) {
  5035. append(gfx, hit);
  5036. }
  5037. // API
  5038. /**
  5039. * Remove hints on the given graphics.
  5040. *
  5041. * @param {SVGElement} gfx
  5042. */
  5043. this.removeHits = function(gfx) {
  5044. var hits = all('.djs-hit', gfx);
  5045. forEach$1(hits, remove$2);
  5046. };
  5047. /**
  5048. * Create default hit for the given element.
  5049. *
  5050. * @param {djs.model.Base} element
  5051. * @param {SVGElement} gfx
  5052. *
  5053. * @return {SVGElement} created hit
  5054. */
  5055. this.createDefaultHit = function(element, gfx) {
  5056. var waypoints = element.waypoints,
  5057. isFrame = element.isFrame,
  5058. boxType;
  5059. if (waypoints) {
  5060. return this.createWaypointsHit(gfx, waypoints);
  5061. } else {
  5062. boxType = isFrame ? 'stroke' : 'all';
  5063. return this.createBoxHit(gfx, boxType, {
  5064. width: element.width,
  5065. height: element.height
  5066. });
  5067. }
  5068. };
  5069. /**
  5070. * Create hits for the given waypoints.
  5071. *
  5072. * @param {SVGElement} gfx
  5073. * @param {Array<Point>} waypoints
  5074. *
  5075. * @return {SVGElement}
  5076. */
  5077. this.createWaypointsHit = function(gfx, waypoints) {
  5078. var hit = createLine(waypoints);
  5079. applyStyle(hit, 'stroke');
  5080. appendHit(gfx, hit);
  5081. return hit;
  5082. };
  5083. /**
  5084. * Create hits for a box.
  5085. *
  5086. * @param {SVGElement} gfx
  5087. * @param {string} hitType
  5088. * @param {Object} attrs
  5089. *
  5090. * @return {SVGElement}
  5091. */
  5092. this.createBoxHit = function(gfx, type, attrs) {
  5093. attrs = assign({
  5094. x: 0,
  5095. y: 0
  5096. }, attrs);
  5097. var hit = create$1('rect');
  5098. applyStyle(hit, type);
  5099. attr$1(hit, attrs);
  5100. appendHit(gfx, hit);
  5101. return hit;
  5102. };
  5103. /**
  5104. * Update default hit of the element.
  5105. *
  5106. * @param {djs.model.Base} element
  5107. * @param {SVGElement} gfx
  5108. *
  5109. * @return {SVGElement} updated hit
  5110. */
  5111. this.updateDefaultHit = function(element, gfx) {
  5112. var hit = query('.djs-hit', gfx);
  5113. if (!hit) {
  5114. return;
  5115. }
  5116. if (element.waypoints) {
  5117. updateLine(hit, element.waypoints);
  5118. } else {
  5119. attr$1(hit, {
  5120. width: element.width,
  5121. height: element.height
  5122. });
  5123. }
  5124. return hit;
  5125. };
  5126. this.fire = fire;
  5127. this.triggerMouseEvent = triggerMouseEvent;
  5128. this.mouseHandler = mouseHandler;
  5129. this.registerEvent = registerEvent;
  5130. this.unregisterEvent = unregisterEvent;
  5131. }
  5132. InteractionEvents.$inject = [
  5133. 'eventBus',
  5134. 'elementRegistry',
  5135. 'styles'
  5136. ];
  5137. /**
  5138. * An event indicating that the mouse hovered over an element
  5139. *
  5140. * @event element.hover
  5141. *
  5142. * @type {Object}
  5143. * @property {djs.model.Base} element
  5144. * @property {SVGElement} gfx
  5145. * @property {Event} originalEvent
  5146. */
  5147. /**
  5148. * An event indicating that the mouse has left an element
  5149. *
  5150. * @event element.out
  5151. *
  5152. * @type {Object}
  5153. * @property {djs.model.Base} element
  5154. * @property {SVGElement} gfx
  5155. * @property {Event} originalEvent
  5156. */
  5157. /**
  5158. * An event indicating that the mouse has clicked an element
  5159. *
  5160. * @event element.click
  5161. *
  5162. * @type {Object}
  5163. * @property {djs.model.Base} element
  5164. * @property {SVGElement} gfx
  5165. * @property {Event} originalEvent
  5166. */
  5167. /**
  5168. * An event indicating that the mouse has double clicked an element
  5169. *
  5170. * @event element.dblclick
  5171. *
  5172. * @type {Object}
  5173. * @property {djs.model.Base} element
  5174. * @property {SVGElement} gfx
  5175. * @property {Event} originalEvent
  5176. */
  5177. /**
  5178. * An event indicating that the mouse has gone down on an element.
  5179. *
  5180. * @event element.mousedown
  5181. *
  5182. * @type {Object}
  5183. * @property {djs.model.Base} element
  5184. * @property {SVGElement} gfx
  5185. * @property {Event} originalEvent
  5186. */
  5187. /**
  5188. * An event indicating that the mouse has gone up on an element.
  5189. *
  5190. * @event element.mouseup
  5191. *
  5192. * @type {Object}
  5193. * @property {djs.model.Base} element
  5194. * @property {SVGElement} gfx
  5195. * @property {Event} originalEvent
  5196. */
  5197. /**
  5198. * An event indicating that the context menu action is triggered
  5199. * via mouse or touch controls.
  5200. *
  5201. * @event element.contextmenu
  5202. *
  5203. * @type {Object}
  5204. * @property {djs.model.Base} element
  5205. * @property {SVGElement} gfx
  5206. * @property {Event} originalEvent
  5207. */
  5208. var InteractionEventsModule = {
  5209. __init__: [ 'interactionEvents' ],
  5210. interactionEvents: [ 'type', InteractionEvents ]
  5211. };
  5212. /**
  5213. * Returns the surrounding bbox for all elements in
  5214. * the array or the element primitive.
  5215. *
  5216. * @param {Array<djs.model.Shape>|djs.model.Shape} elements
  5217. * @param {boolean} [stopRecursion=false]
  5218. *
  5219. * @return {Bounds}
  5220. */
  5221. function getBBox(elements, stopRecursion) {
  5222. stopRecursion = !!stopRecursion;
  5223. if (!isArray$2(elements)) {
  5224. elements = [ elements ];
  5225. }
  5226. var minX,
  5227. minY,
  5228. maxX,
  5229. maxY;
  5230. forEach$1(elements, function(element) {
  5231. // If element is a connection the bbox must be computed first
  5232. var bbox = element;
  5233. if (element.waypoints && !stopRecursion) {
  5234. bbox = getBBox(element.waypoints, true);
  5235. }
  5236. var x = bbox.x,
  5237. y = bbox.y,
  5238. height = bbox.height || 0,
  5239. width = bbox.width || 0;
  5240. if (x < minX || minX === undefined) {
  5241. minX = x;
  5242. }
  5243. if (y < minY || minY === undefined) {
  5244. minY = y;
  5245. }
  5246. if ((x + width) > maxX || maxX === undefined) {
  5247. maxX = x + width;
  5248. }
  5249. if ((y + height) > maxY || maxY === undefined) {
  5250. maxY = y + height;
  5251. }
  5252. });
  5253. return {
  5254. x: minX,
  5255. y: minY,
  5256. height: maxY - minY,
  5257. width: maxX - minX
  5258. };
  5259. }
  5260. function getType(element) {
  5261. if ('waypoints' in element) {
  5262. return 'connection';
  5263. }
  5264. if ('x' in element) {
  5265. return 'shape';
  5266. }
  5267. return 'root';
  5268. }
  5269. function isFrameElement(element) {
  5270. return !!(element && element.isFrame);
  5271. }
  5272. var LOW_PRIORITY$3 = 500;
  5273. /**
  5274. * @class
  5275. *
  5276. * A plugin that adds an outline to shapes and connections that may be activated and styled
  5277. * via CSS classes.
  5278. *
  5279. * @param {EventBus} eventBus
  5280. * @param {Styles} styles
  5281. * @param {ElementRegistry} elementRegistry
  5282. */
  5283. function Outline(eventBus, styles, elementRegistry) {
  5284. this.offset = 6;
  5285. var OUTLINE_STYLE = styles.cls('djs-outline', [ 'no-fill' ]);
  5286. var self = this;
  5287. function createOutline(gfx, bounds) {
  5288. var outline = create$1('rect');
  5289. attr$1(outline, assign({
  5290. x: 10,
  5291. y: 10,
  5292. rx: 3,
  5293. width: 100,
  5294. height: 100
  5295. }, OUTLINE_STYLE));
  5296. append(gfx, outline);
  5297. return outline;
  5298. }
  5299. // A low priortity is necessary, because outlines of labels have to be updated
  5300. // after the label bounds have been updated in the renderer.
  5301. eventBus.on([ 'shape.added', 'shape.changed' ], LOW_PRIORITY$3, function(event) {
  5302. var element = event.element,
  5303. gfx = event.gfx;
  5304. var outline = query('.djs-outline', gfx);
  5305. if (!outline) {
  5306. outline = createOutline(gfx);
  5307. }
  5308. self.updateShapeOutline(outline, element);
  5309. });
  5310. eventBus.on([ 'connection.added', 'connection.changed' ], function(event) {
  5311. var element = event.element,
  5312. gfx = event.gfx;
  5313. var outline = query('.djs-outline', gfx);
  5314. if (!outline) {
  5315. outline = createOutline(gfx);
  5316. }
  5317. self.updateConnectionOutline(outline, element);
  5318. });
  5319. }
  5320. /**
  5321. * Updates the outline of a shape respecting the dimension of the
  5322. * element and an outline offset.
  5323. *
  5324. * @param {SVGElement} outline
  5325. * @param {djs.model.Base} element
  5326. */
  5327. Outline.prototype.updateShapeOutline = function(outline, element) {
  5328. attr$1(outline, {
  5329. x: -this.offset,
  5330. y: -this.offset,
  5331. width: element.width + this.offset * 2,
  5332. height: element.height + this.offset * 2
  5333. });
  5334. };
  5335. /**
  5336. * Updates the outline of a connection respecting the bounding box of
  5337. * the connection and an outline offset.
  5338. *
  5339. * @param {SVGElement} outline
  5340. * @param {djs.model.Base} element
  5341. */
  5342. Outline.prototype.updateConnectionOutline = function(outline, connection) {
  5343. var bbox = getBBox(connection);
  5344. attr$1(outline, {
  5345. x: bbox.x - this.offset,
  5346. y: bbox.y - this.offset,
  5347. width: bbox.width + this.offset * 2,
  5348. height: bbox.height + this.offset * 2
  5349. });
  5350. };
  5351. Outline.$inject = [ 'eventBus', 'styles', 'elementRegistry' ];
  5352. var OutlineModule = {
  5353. __init__: [ 'outline' ],
  5354. outline: [ 'type', Outline ]
  5355. };
  5356. /**
  5357. * A service that offers the current selection in a diagram.
  5358. * Offers the api to control the selection, too.
  5359. *
  5360. * @class
  5361. *
  5362. * @param {EventBus} eventBus the event bus
  5363. */
  5364. function Selection(eventBus, canvas) {
  5365. this._eventBus = eventBus;
  5366. this._canvas = canvas;
  5367. this._selectedElements = [];
  5368. var self = this;
  5369. eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
  5370. var element = e.element;
  5371. self.deselect(element);
  5372. });
  5373. eventBus.on([ 'diagram.clear', 'root.set' ], function(e) {
  5374. self.select(null);
  5375. });
  5376. }
  5377. Selection.$inject = [ 'eventBus', 'canvas' ];
  5378. Selection.prototype.deselect = function(element) {
  5379. var selectedElements = this._selectedElements;
  5380. var idx = selectedElements.indexOf(element);
  5381. if (idx !== -1) {
  5382. var oldSelection = selectedElements.slice();
  5383. selectedElements.splice(idx, 1);
  5384. this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
  5385. }
  5386. };
  5387. Selection.prototype.get = function() {
  5388. return this._selectedElements;
  5389. };
  5390. Selection.prototype.isSelected = function(element) {
  5391. return this._selectedElements.indexOf(element) !== -1;
  5392. };
  5393. /**
  5394. * This method selects one or more elements on the diagram.
  5395. *
  5396. * By passing an additional add parameter you can decide whether or not the element(s)
  5397. * should be added to the already existing selection or not.
  5398. *
  5399. * @method Selection#select
  5400. *
  5401. * @param {Object|Object[]} elements element or array of elements to be selected
  5402. * @param {boolean} [add] whether the element(s) should be appended to the current selection, defaults to false
  5403. */
  5404. Selection.prototype.select = function(elements, add) {
  5405. var selectedElements = this._selectedElements,
  5406. oldSelection = selectedElements.slice();
  5407. if (!isArray$2(elements)) {
  5408. elements = elements ? [ elements ] : [];
  5409. }
  5410. var canvas = this._canvas;
  5411. var rootElement = canvas.getRootElement();
  5412. elements = elements.filter(function(element) {
  5413. var elementRoot = canvas.findRoot(element);
  5414. return rootElement === elementRoot;
  5415. });
  5416. // selection may be cleared by passing an empty array or null
  5417. // to the method
  5418. if (add) {
  5419. forEach$1(elements, function(element) {
  5420. if (selectedElements.indexOf(element) !== -1) {
  5421. // already selected
  5422. return;
  5423. } else {
  5424. selectedElements.push(element);
  5425. }
  5426. });
  5427. } else {
  5428. this._selectedElements = selectedElements = elements.slice();
  5429. }
  5430. this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
  5431. };
  5432. var MARKER_HOVER = 'hover',
  5433. MARKER_SELECTED = 'selected';
  5434. var SELECTION_OUTLINE_PADDING = 6;
  5435. /**
  5436. * A plugin that adds a visible selection UI to shapes and connections
  5437. * by appending the <code>hover</code> and <code>selected</code> classes to them.
  5438. *
  5439. * @class
  5440. *
  5441. * Makes elements selectable, too.
  5442. *
  5443. * @param {Canvas} canvas
  5444. * @param {EventBus} eventBus
  5445. */
  5446. function SelectionVisuals(canvas, eventBus, selection) {
  5447. this._canvas = canvas;
  5448. var self = this;
  5449. this._multiSelectionBox = null;
  5450. function addMarker(e, cls) {
  5451. canvas.addMarker(e, cls);
  5452. }
  5453. function removeMarker(e, cls) {
  5454. canvas.removeMarker(e, cls);
  5455. }
  5456. eventBus.on('element.hover', function(event) {
  5457. addMarker(event.element, MARKER_HOVER);
  5458. });
  5459. eventBus.on('element.out', function(event) {
  5460. removeMarker(event.element, MARKER_HOVER);
  5461. });
  5462. eventBus.on('selection.changed', function(event) {
  5463. function deselect(s) {
  5464. removeMarker(s, MARKER_SELECTED);
  5465. }
  5466. function select(s) {
  5467. addMarker(s, MARKER_SELECTED);
  5468. }
  5469. var oldSelection = event.oldSelection,
  5470. newSelection = event.newSelection;
  5471. forEach$1(oldSelection, function(e) {
  5472. if (newSelection.indexOf(e) === -1) {
  5473. deselect(e);
  5474. }
  5475. });
  5476. forEach$1(newSelection, function(e) {
  5477. if (oldSelection.indexOf(e) === -1) {
  5478. select(e);
  5479. }
  5480. });
  5481. self._updateSelectionOutline(newSelection);
  5482. });
  5483. eventBus.on('element.changed', function(event) {
  5484. if (selection.isSelected(event.element)) {
  5485. self._updateSelectionOutline(selection.get());
  5486. }
  5487. });
  5488. }
  5489. SelectionVisuals.$inject = [
  5490. 'canvas',
  5491. 'eventBus',
  5492. 'selection'
  5493. ];
  5494. SelectionVisuals.prototype._updateSelectionOutline = function(selection) {
  5495. var layer = this._canvas.getLayer('selectionOutline');
  5496. clear$1(layer);
  5497. var enabled = selection.length > 1;
  5498. var container = this._canvas.getContainer();
  5499. classes$1(container)[enabled ? 'add' : 'remove']('djs-multi-select');
  5500. if (!enabled) {
  5501. return;
  5502. }
  5503. var bBox = addSelectionOutlinePadding(getBBox(selection));
  5504. var rect = create$1('rect');
  5505. attr$1(rect, assign({
  5506. rx: 3
  5507. }, bBox));
  5508. classes$1(rect).add('djs-selection-outline');
  5509. append(layer, rect);
  5510. };
  5511. // helpers //////////
  5512. function addSelectionOutlinePadding(bBox) {
  5513. return {
  5514. x: bBox.x - SELECTION_OUTLINE_PADDING,
  5515. y: bBox.y - SELECTION_OUTLINE_PADDING,
  5516. width: bBox.width + SELECTION_OUTLINE_PADDING * 2,
  5517. height: bBox.height + SELECTION_OUTLINE_PADDING * 2
  5518. };
  5519. }
  5520. function SelectionBehavior(eventBus, selection, canvas, elementRegistry) {
  5521. // Select elements on create
  5522. eventBus.on('create.end', 500, function(event) {
  5523. var context = event.context,
  5524. canExecute = context.canExecute,
  5525. elements = context.elements,
  5526. hints = context.hints || {},
  5527. autoSelect = hints.autoSelect;
  5528. if (canExecute) {
  5529. if (autoSelect === false) {
  5530. // Select no elements
  5531. return;
  5532. }
  5533. if (isArray$2(autoSelect)) {
  5534. selection.select(autoSelect);
  5535. } else {
  5536. // Select all elements by default
  5537. selection.select(elements.filter(isShown));
  5538. }
  5539. }
  5540. });
  5541. // Select connection targets on connect
  5542. eventBus.on('connect.end', 500, function(event) {
  5543. var context = event.context,
  5544. connection = context.connection;
  5545. if (connection) {
  5546. selection.select(connection);
  5547. }
  5548. });
  5549. // Select shapes on move
  5550. eventBus.on('shape.move.end', 500, function(event) {
  5551. var previousSelection = event.previousSelection || [];
  5552. var shape = elementRegistry.get(event.context.shape.id);
  5553. // Always select main shape on move
  5554. var isSelected = find(previousSelection, function(selectedShape) {
  5555. return shape.id === selectedShape.id;
  5556. });
  5557. if (!isSelected) {
  5558. selection.select(shape);
  5559. }
  5560. });
  5561. // Select elements on click
  5562. eventBus.on('element.click', function(event) {
  5563. if (!isPrimaryButton(event)) {
  5564. return;
  5565. }
  5566. var element = event.element;
  5567. if (element === canvas.getRootElement()) {
  5568. element = null;
  5569. }
  5570. var isSelected = selection.isSelected(element),
  5571. isMultiSelect = selection.get().length > 1;
  5572. // Add to selection if CTRL or SHIFT pressed
  5573. var add = hasPrimaryModifier(event) || hasSecondaryModifier(event);
  5574. if (isSelected && isMultiSelect) {
  5575. if (add) {
  5576. // Deselect element
  5577. return selection.deselect(element);
  5578. } else {
  5579. // Select element only
  5580. return selection.select(element);
  5581. }
  5582. } else if (!isSelected) {
  5583. // Select element
  5584. selection.select(element, add);
  5585. } else {
  5586. // Deselect element
  5587. selection.deselect(element);
  5588. }
  5589. });
  5590. }
  5591. SelectionBehavior.$inject = [
  5592. 'eventBus',
  5593. 'selection',
  5594. 'canvas',
  5595. 'elementRegistry'
  5596. ];
  5597. function isShown(element) {
  5598. return !element.hidden;
  5599. }
  5600. var SelectionModule = {
  5601. __init__: [ 'selectionVisuals', 'selectionBehavior' ],
  5602. __depends__: [
  5603. InteractionEventsModule,
  5604. OutlineModule
  5605. ],
  5606. selection: [ 'type', Selection ],
  5607. selectionVisuals: [ 'type', SelectionVisuals ],
  5608. selectionBehavior: [ 'type', SelectionBehavior ]
  5609. };
  5610. /**
  5611. * Util that provides unique IDs.
  5612. *
  5613. * @class djs.util.IdGenerator
  5614. * @constructor
  5615. * @memberOf djs.util
  5616. *
  5617. * The ids can be customized via a given prefix and contain a random value to avoid collisions.
  5618. *
  5619. * @param {string} prefix a prefix to prepend to generated ids (for better readability)
  5620. */
  5621. function IdGenerator(prefix) {
  5622. this._counter = 0;
  5623. this._prefix = (prefix ? prefix + '-' : '') + Math.floor(Math.random() * 1000000000) + '-';
  5624. }
  5625. /**
  5626. * Returns a next unique ID.
  5627. *
  5628. * @method djs.util.IdGenerator#next
  5629. *
  5630. * @returns {string} the id
  5631. */
  5632. IdGenerator.prototype.next = function() {
  5633. return this._prefix + (++this._counter);
  5634. };
  5635. // document wide unique overlay ids
  5636. var ids = new IdGenerator('ov');
  5637. var LOW_PRIORITY$2 = 500;
  5638. /**
  5639. * A service that allows users to attach overlays to diagram elements.
  5640. *
  5641. * The overlay service will take care of overlay positioning during updates.
  5642. *
  5643. * @example
  5644. *
  5645. * // add a pink badge on the top left of the shape
  5646. * overlays.add(someShape, {
  5647. * position: {
  5648. * top: -5,
  5649. * left: -5
  5650. * },
  5651. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  5652. * });
  5653. *
  5654. * // or add via shape id
  5655. *
  5656. * overlays.add('some-element-id', {
  5657. * position: {
  5658. * top: -5,
  5659. * left: -5
  5660. * }
  5661. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  5662. * });
  5663. *
  5664. * // or add with optional type
  5665. *
  5666. * overlays.add(someShape, 'badge', {
  5667. * position: {
  5668. * top: -5,
  5669. * left: -5
  5670. * }
  5671. * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
  5672. * });
  5673. *
  5674. *
  5675. * // remove an overlay
  5676. *
  5677. * var id = overlays.add(...);
  5678. * overlays.remove(id);
  5679. *
  5680. *
  5681. * You may configure overlay defaults during tool by providing a `config` module
  5682. * with `overlays.defaults` as an entry:
  5683. *
  5684. * {
  5685. * overlays: {
  5686. * defaults: {
  5687. * show: {
  5688. * minZoom: 0.7,
  5689. * maxZoom: 5.0
  5690. * },
  5691. * scale: {
  5692. * min: 1
  5693. * }
  5694. * }
  5695. * }
  5696. *
  5697. * @param {Object} config
  5698. * @param {EventBus} eventBus
  5699. * @param {Canvas} canvas
  5700. * @param {ElementRegistry} elementRegistry
  5701. */
  5702. function Overlays(config, eventBus, canvas, elementRegistry) {
  5703. this._eventBus = eventBus;
  5704. this._canvas = canvas;
  5705. this._elementRegistry = elementRegistry;
  5706. this._ids = ids;
  5707. this._overlayDefaults = assign({
  5708. // no show constraints
  5709. show: null,
  5710. // always scale
  5711. scale: true
  5712. }, config && config.defaults);
  5713. /**
  5714. * Mapping overlayId -> overlay
  5715. */
  5716. this._overlays = {};
  5717. /**
  5718. * Mapping elementId -> overlay container
  5719. */
  5720. this._overlayContainers = [];
  5721. // root html element for all overlays
  5722. this._overlayRoot = createRoot(canvas.getContainer());
  5723. this._init();
  5724. }
  5725. Overlays.$inject = [
  5726. 'config.overlays',
  5727. 'eventBus',
  5728. 'canvas',
  5729. 'elementRegistry'
  5730. ];
  5731. /**
  5732. * Returns the overlay with the specified id or a list of overlays
  5733. * for an element with a given type.
  5734. *
  5735. * @example
  5736. *
  5737. * // return the single overlay with the given id
  5738. * overlays.get('some-id');
  5739. *
  5740. * // return all overlays for the shape
  5741. * overlays.get({ element: someShape });
  5742. *
  5743. * // return all overlays on shape with type 'badge'
  5744. * overlays.get({ element: someShape, type: 'badge' });
  5745. *
  5746. * // shape can also be specified as id
  5747. * overlays.get({ element: 'element-id', type: 'badge' });
  5748. *
  5749. *
  5750. * @param {Object} search
  5751. * @param {string} [search.id]
  5752. * @param {string|djs.model.Base} [search.element]
  5753. * @param {string} [search.type]
  5754. *
  5755. * @return {Object|Array<Object>} the overlay(s)
  5756. */
  5757. Overlays.prototype.get = function(search) {
  5758. if (isString(search)) {
  5759. search = { id: search };
  5760. }
  5761. if (isString(search.element)) {
  5762. search.element = this._elementRegistry.get(search.element);
  5763. }
  5764. if (search.element) {
  5765. var container = this._getOverlayContainer(search.element, true);
  5766. // return a list of overlays when searching by element (+type)
  5767. if (container) {
  5768. return search.type ? filter(container.overlays, matchPattern({ type: search.type })) : container.overlays.slice();
  5769. } else {
  5770. return [];
  5771. }
  5772. } else
  5773. if (search.type) {
  5774. return filter(this._overlays, matchPattern({ type: search.type }));
  5775. } else {
  5776. // return single element when searching by id
  5777. return search.id ? this._overlays[search.id] : null;
  5778. }
  5779. };
  5780. /**
  5781. * Adds a HTML overlay to an element.
  5782. *
  5783. * @param {string|djs.model.Base} element attach overlay to this shape
  5784. * @param {string} [type] optional type to assign to the overlay
  5785. * @param {Object} overlay the overlay configuration
  5786. *
  5787. * @param {string|DOMElement} overlay.html html element to use as an overlay
  5788. * @param {Object} [overlay.show] show configuration
  5789. * @param {number} [overlay.show.minZoom] minimal zoom level to show the overlay
  5790. * @param {number} [overlay.show.maxZoom] maximum zoom level to show the overlay
  5791. * @param {Object} overlay.position where to attach the overlay
  5792. * @param {number} [overlay.position.left] relative to element bbox left attachment
  5793. * @param {number} [overlay.position.top] relative to element bbox top attachment
  5794. * @param {number} [overlay.position.bottom] relative to element bbox bottom attachment
  5795. * @param {number} [overlay.position.right] relative to element bbox right attachment
  5796. * @param {boolean|Object} [overlay.scale=true] false to preserve the same size regardless of
  5797. * diagram zoom
  5798. * @param {number} [overlay.scale.min]
  5799. * @param {number} [overlay.scale.max]
  5800. *
  5801. * @return {string} id that may be used to reference the overlay for update or removal
  5802. */
  5803. Overlays.prototype.add = function(element, type, overlay) {
  5804. if (isObject(type)) {
  5805. overlay = type;
  5806. type = null;
  5807. }
  5808. if (!element.id) {
  5809. element = this._elementRegistry.get(element);
  5810. }
  5811. if (!overlay.position) {
  5812. throw new Error('must specifiy overlay position');
  5813. }
  5814. if (!overlay.html) {
  5815. throw new Error('must specifiy overlay html');
  5816. }
  5817. if (!element) {
  5818. throw new Error('invalid element specified');
  5819. }
  5820. var id = this._ids.next();
  5821. overlay = assign({}, this._overlayDefaults, overlay, {
  5822. id: id,
  5823. type: type,
  5824. element: element,
  5825. html: overlay.html
  5826. });
  5827. this._addOverlay(overlay);
  5828. return id;
  5829. };
  5830. /**
  5831. * Remove an overlay with the given id or all overlays matching the given filter.
  5832. *
  5833. * @see Overlays#get for filter options.
  5834. *
  5835. * @param {string|object} [filter]
  5836. */
  5837. Overlays.prototype.remove = function(filter) {
  5838. var overlays = this.get(filter) || [];
  5839. if (!isArray$2(overlays)) {
  5840. overlays = [ overlays ];
  5841. }
  5842. var self = this;
  5843. forEach$1(overlays, function(overlay) {
  5844. var container = self._getOverlayContainer(overlay.element, true);
  5845. if (overlay) {
  5846. remove$1(overlay.html);
  5847. remove$1(overlay.htmlContainer);
  5848. delete overlay.htmlContainer;
  5849. delete overlay.element;
  5850. delete self._overlays[overlay.id];
  5851. }
  5852. if (container) {
  5853. var idx = container.overlays.indexOf(overlay);
  5854. if (idx !== -1) {
  5855. container.overlays.splice(idx, 1);
  5856. }
  5857. }
  5858. });
  5859. };
  5860. Overlays.prototype.show = function() {
  5861. setVisible(this._overlayRoot);
  5862. };
  5863. Overlays.prototype.hide = function() {
  5864. setVisible(this._overlayRoot, false);
  5865. };
  5866. Overlays.prototype.clear = function() {
  5867. this._overlays = {};
  5868. this._overlayContainers = [];
  5869. clear(this._overlayRoot);
  5870. };
  5871. Overlays.prototype._updateOverlayContainer = function(container) {
  5872. var element = container.element,
  5873. html = container.html;
  5874. // update container left,top according to the elements x,y coordinates
  5875. // this ensures we can attach child elements relative to this container
  5876. var x = element.x,
  5877. y = element.y;
  5878. if (element.waypoints) {
  5879. var bbox = getBBox(element);
  5880. x = bbox.x;
  5881. y = bbox.y;
  5882. }
  5883. setPosition(html, x, y);
  5884. attr(container.html, 'data-container-id', element.id);
  5885. };
  5886. Overlays.prototype._updateOverlay = function(overlay) {
  5887. var position = overlay.position,
  5888. htmlContainer = overlay.htmlContainer,
  5889. element = overlay.element;
  5890. // update overlay html relative to shape because
  5891. // it is already positioned on the element
  5892. // update relative
  5893. var left = position.left,
  5894. top = position.top;
  5895. if (position.right !== undefined) {
  5896. var width;
  5897. if (element.waypoints) {
  5898. width = getBBox(element).width;
  5899. } else {
  5900. width = element.width;
  5901. }
  5902. left = position.right * -1 + width;
  5903. }
  5904. if (position.bottom !== undefined) {
  5905. var height;
  5906. if (element.waypoints) {
  5907. height = getBBox(element).height;
  5908. } else {
  5909. height = element.height;
  5910. }
  5911. top = position.bottom * -1 + height;
  5912. }
  5913. setPosition(htmlContainer, left || 0, top || 0);
  5914. this._updateOverlayVisibilty(overlay, this._canvas.viewbox());
  5915. };
  5916. Overlays.prototype._createOverlayContainer = function(element) {
  5917. var html = domify('<div class="djs-overlays" />');
  5918. assign$1(html, { position: 'absolute' });
  5919. this._overlayRoot.appendChild(html);
  5920. var container = {
  5921. html: html,
  5922. element: element,
  5923. overlays: []
  5924. };
  5925. this._updateOverlayContainer(container);
  5926. this._overlayContainers.push(container);
  5927. return container;
  5928. };
  5929. Overlays.prototype._updateRoot = function(viewbox) {
  5930. var scale = viewbox.scale || 1;
  5931. var matrix = 'matrix(' +
  5932. [
  5933. scale,
  5934. 0,
  5935. 0,
  5936. scale,
  5937. -1 * viewbox.x * scale,
  5938. -1 * viewbox.y * scale
  5939. ].join(',') +
  5940. ')';
  5941. setTransform(this._overlayRoot, matrix);
  5942. };
  5943. Overlays.prototype._getOverlayContainer = function(element, raw) {
  5944. var container = find(this._overlayContainers, function(c) {
  5945. return c.element === element;
  5946. });
  5947. if (!container && !raw) {
  5948. return this._createOverlayContainer(element);
  5949. }
  5950. return container;
  5951. };
  5952. Overlays.prototype._addOverlay = function(overlay) {
  5953. var id = overlay.id,
  5954. element = overlay.element,
  5955. html = overlay.html,
  5956. htmlContainer,
  5957. overlayContainer;
  5958. // unwrap jquery (for those who need it)
  5959. if (html.get && html.constructor.prototype.jquery) {
  5960. html = html.get(0);
  5961. }
  5962. // create proper html elements from
  5963. // overlay HTML strings
  5964. if (isString(html)) {
  5965. html = domify(html);
  5966. }
  5967. overlayContainer = this._getOverlayContainer(element);
  5968. htmlContainer = domify('<div class="djs-overlay" data-overlay-id="' + id + '">');
  5969. assign$1(htmlContainer, { position: 'absolute' });
  5970. htmlContainer.appendChild(html);
  5971. if (overlay.type) {
  5972. classes(htmlContainer).add('djs-overlay-' + overlay.type);
  5973. }
  5974. var elementRoot = this._canvas.findRoot(element);
  5975. var activeRoot = this._canvas.getRootElement();
  5976. setVisible(htmlContainer, elementRoot === activeRoot);
  5977. overlay.htmlContainer = htmlContainer;
  5978. overlayContainer.overlays.push(overlay);
  5979. overlayContainer.html.appendChild(htmlContainer);
  5980. this._overlays[id] = overlay;
  5981. this._updateOverlay(overlay);
  5982. this._updateOverlayVisibilty(overlay, this._canvas.viewbox());
  5983. };
  5984. Overlays.prototype._updateOverlayVisibilty = function(overlay, viewbox) {
  5985. var show = overlay.show,
  5986. rootElement = this._canvas.findRoot(overlay.element),
  5987. minZoom = show && show.minZoom,
  5988. maxZoom = show && show.maxZoom,
  5989. htmlContainer = overlay.htmlContainer,
  5990. activeRootElement = this._canvas.getRootElement(),
  5991. visible = true;
  5992. if (rootElement !== activeRootElement) {
  5993. visible = false;
  5994. } else if (show) {
  5995. if (
  5996. (isDefined(minZoom) && minZoom > viewbox.scale) ||
  5997. (isDefined(maxZoom) && maxZoom < viewbox.scale)
  5998. ) {
  5999. visible = false;
  6000. }
  6001. }
  6002. setVisible(htmlContainer, visible);
  6003. this._updateOverlayScale(overlay, viewbox);
  6004. };
  6005. Overlays.prototype._updateOverlayScale = function(overlay, viewbox) {
  6006. var shouldScale = overlay.scale,
  6007. minScale,
  6008. maxScale,
  6009. htmlContainer = overlay.htmlContainer;
  6010. var scale, transform = '';
  6011. if (shouldScale !== true) {
  6012. if (shouldScale === false) {
  6013. minScale = 1;
  6014. maxScale = 1;
  6015. } else {
  6016. minScale = shouldScale.min;
  6017. maxScale = shouldScale.max;
  6018. }
  6019. if (isDefined(minScale) && viewbox.scale < minScale) {
  6020. scale = (1 / viewbox.scale || 1) * minScale;
  6021. }
  6022. if (isDefined(maxScale) && viewbox.scale > maxScale) {
  6023. scale = (1 / viewbox.scale || 1) * maxScale;
  6024. }
  6025. }
  6026. if (isDefined(scale)) {
  6027. transform = 'scale(' + scale + ',' + scale + ')';
  6028. }
  6029. setTransform(htmlContainer, transform);
  6030. };
  6031. Overlays.prototype._updateOverlaysVisibilty = function(viewbox) {
  6032. var self = this;
  6033. forEach$1(this._overlays, function(overlay) {
  6034. self._updateOverlayVisibilty(overlay, viewbox);
  6035. });
  6036. };
  6037. Overlays.prototype._init = function() {
  6038. var eventBus = this._eventBus;
  6039. var self = this;
  6040. // scroll/zoom integration
  6041. function updateViewbox(viewbox) {
  6042. self._updateRoot(viewbox);
  6043. self._updateOverlaysVisibilty(viewbox);
  6044. self.show();
  6045. }
  6046. eventBus.on('canvas.viewbox.changing', function(event) {
  6047. self.hide();
  6048. });
  6049. eventBus.on('canvas.viewbox.changed', function(event) {
  6050. updateViewbox(event.viewbox);
  6051. });
  6052. // remove integration
  6053. eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
  6054. var element = e.element;
  6055. var overlays = self.get({ element: element });
  6056. forEach$1(overlays, function(o) {
  6057. self.remove(o.id);
  6058. });
  6059. var container = self._getOverlayContainer(element);
  6060. if (container) {
  6061. remove$1(container.html);
  6062. var i = self._overlayContainers.indexOf(container);
  6063. if (i !== -1) {
  6064. self._overlayContainers.splice(i, 1);
  6065. }
  6066. }
  6067. });
  6068. // move integration
  6069. eventBus.on('element.changed', LOW_PRIORITY$2, function(e) {
  6070. var element = e.element;
  6071. var container = self._getOverlayContainer(element, true);
  6072. if (container) {
  6073. forEach$1(container.overlays, function(overlay) {
  6074. self._updateOverlay(overlay);
  6075. });
  6076. self._updateOverlayContainer(container);
  6077. }
  6078. });
  6079. // marker integration, simply add them on the overlays as classes, too.
  6080. eventBus.on('element.marker.update', function(e) {
  6081. var container = self._getOverlayContainer(e.element, true);
  6082. if (container) {
  6083. classes(container.html)[e.add ? 'add' : 'remove'](e.marker);
  6084. }
  6085. });
  6086. eventBus.on('root.set', function() {
  6087. self._updateOverlaysVisibilty(self._canvas.viewbox());
  6088. });
  6089. // clear overlays with diagram
  6090. eventBus.on('diagram.clear', this.clear, this);
  6091. };
  6092. // helpers /////////////////////////////
  6093. function createRoot(parentNode) {
  6094. var root = domify(
  6095. '<div class="djs-overlay-container" />'
  6096. );
  6097. assign$1(root, {
  6098. position: 'absolute',
  6099. width: 0,
  6100. height: 0
  6101. });
  6102. parentNode.insertBefore(root, parentNode.firstChild);
  6103. return root;
  6104. }
  6105. function setPosition(el, x, y) {
  6106. assign$1(el, { left: x + 'px', top: y + 'px' });
  6107. }
  6108. /**
  6109. * Set element visible
  6110. *
  6111. * @param {DOMElement} el
  6112. * @param {boolean} [visible=true]
  6113. */
  6114. function setVisible(el, visible) {
  6115. el.style.display = visible === false ? 'none' : '';
  6116. }
  6117. function setTransform(el, transform) {
  6118. el.style['transform-origin'] = 'top left';
  6119. [ '', '-ms-', '-webkit-' ].forEach(function(prefix) {
  6120. el.style[prefix + 'transform'] = transform;
  6121. });
  6122. }
  6123. var OverlaysModule = {
  6124. __init__: [ 'overlays' ],
  6125. overlays: [ 'type', Overlays ]
  6126. };
  6127. /**
  6128. * Adds change support to the diagram, including
  6129. *
  6130. * <ul>
  6131. * <li>redrawing shapes and connections on change</li>
  6132. * </ul>
  6133. *
  6134. * @param {EventBus} eventBus
  6135. * @param {Canvas} canvas
  6136. * @param {ElementRegistry} elementRegistry
  6137. * @param {GraphicsFactory} graphicsFactory
  6138. */
  6139. function ChangeSupport(
  6140. eventBus, canvas, elementRegistry,
  6141. graphicsFactory) {
  6142. // redraw shapes / connections on change
  6143. eventBus.on('element.changed', function(event) {
  6144. var element = event.element;
  6145. // element might have been deleted and replaced by new element with same ID
  6146. // thus check for parent of element except for root element
  6147. if (element.parent || element === canvas.getRootElement()) {
  6148. event.gfx = elementRegistry.getGraphics(element);
  6149. }
  6150. // shape + gfx may have been deleted
  6151. if (!event.gfx) {
  6152. return;
  6153. }
  6154. eventBus.fire(getType(element) + '.changed', event);
  6155. });
  6156. eventBus.on('elements.changed', function(event) {
  6157. var elements = event.elements;
  6158. elements.forEach(function(e) {
  6159. eventBus.fire('element.changed', { element: e });
  6160. });
  6161. graphicsFactory.updateContainments(elements);
  6162. });
  6163. eventBus.on('shape.changed', function(event) {
  6164. graphicsFactory.update('shape', event.element, event.gfx);
  6165. });
  6166. eventBus.on('connection.changed', function(event) {
  6167. graphicsFactory.update('connection', event.element, event.gfx);
  6168. });
  6169. }
  6170. ChangeSupport.$inject = [
  6171. 'eventBus',
  6172. 'canvas',
  6173. 'elementRegistry',
  6174. 'graphicsFactory'
  6175. ];
  6176. var ChangeSupportModule = {
  6177. __init__: [ 'changeSupport' ],
  6178. changeSupport: [ 'type', ChangeSupport ]
  6179. };
  6180. var DEFAULT_PRIORITY$2 = 1000;
  6181. /**
  6182. * A utility that can be used to plug-in into the command execution for
  6183. * extension and/or validation.
  6184. *
  6185. * @param {EventBus} eventBus
  6186. *
  6187. * @example
  6188. *
  6189. * import inherits from 'inherits-browser';
  6190. *
  6191. * import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
  6192. *
  6193. * function CommandLogger(eventBus) {
  6194. * CommandInterceptor.call(this, eventBus);
  6195. *
  6196. * this.preExecute(function(event) {
  6197. * console.log('command pre-execute', event);
  6198. * });
  6199. * }
  6200. *
  6201. * inherits(CommandLogger, CommandInterceptor);
  6202. *
  6203. */
  6204. function CommandInterceptor(eventBus) {
  6205. this._eventBus = eventBus;
  6206. }
  6207. CommandInterceptor.$inject = [ 'eventBus' ];
  6208. function unwrapEvent(fn, that) {
  6209. return function(event) {
  6210. return fn.call(that || null, event.context, event.command, event);
  6211. };
  6212. }
  6213. /**
  6214. * Register an interceptor for a command execution
  6215. *
  6216. * @param {string|Array<string>} [events] list of commands to register on
  6217. * @param {string} [hook] command hook, i.e. preExecute, executed to listen on
  6218. * @param {number} [priority] the priority on which to hook into the execution
  6219. * @param {Function} handlerFn interceptor to be invoked with (event)
  6220. * @param {boolean} unwrap if true, unwrap the event and pass (context, command, event) to the
  6221. * listener instead
  6222. * @param {Object} [that] Pass context (`this`) to the handler function
  6223. */
  6224. CommandInterceptor.prototype.on = function(events, hook, priority, handlerFn, unwrap, that) {
  6225. if (isFunction(hook) || isNumber(hook)) {
  6226. that = unwrap;
  6227. unwrap = handlerFn;
  6228. handlerFn = priority;
  6229. priority = hook;
  6230. hook = null;
  6231. }
  6232. if (isFunction(priority)) {
  6233. that = unwrap;
  6234. unwrap = handlerFn;
  6235. handlerFn = priority;
  6236. priority = DEFAULT_PRIORITY$2;
  6237. }
  6238. if (isObject(unwrap)) {
  6239. that = unwrap;
  6240. unwrap = false;
  6241. }
  6242. if (!isFunction(handlerFn)) {
  6243. throw new Error('handlerFn must be a function');
  6244. }
  6245. if (!isArray$2(events)) {
  6246. events = [ events ];
  6247. }
  6248. var eventBus = this._eventBus;
  6249. forEach$1(events, function(event) {
  6250. // concat commandStack(.event)?(.hook)?
  6251. var fullEvent = [ 'commandStack', event, hook ].filter(function(e) { return e; }).join('.');
  6252. eventBus.on(fullEvent, priority, unwrap ? unwrapEvent(handlerFn, that) : handlerFn, that);
  6253. });
  6254. };
  6255. var hooks = [
  6256. 'canExecute',
  6257. 'preExecute',
  6258. 'preExecuted',
  6259. 'execute',
  6260. 'executed',
  6261. 'postExecute',
  6262. 'postExecuted',
  6263. 'revert',
  6264. 'reverted'
  6265. ];
  6266. /*
  6267. * Install hook shortcuts
  6268. *
  6269. * This will generate the CommandInterceptor#(preExecute|...|reverted) methods
  6270. * which will in term forward to CommandInterceptor#on.
  6271. */
  6272. forEach$1(hooks, function(hook) {
  6273. /**
  6274. * {canExecute|preExecute|preExecuted|execute|executed|postExecute|postExecuted|revert|reverted}
  6275. *
  6276. * A named hook for plugging into the command execution
  6277. *
  6278. * @param {string|Array<string>} [events] list of commands to register on
  6279. * @param {number} [priority] the priority on which to hook into the execution
  6280. * @param {Function} handlerFn interceptor to be invoked with (event)
  6281. * @param {boolean} [unwrap=false] if true, unwrap the event and pass (context, command, event) to the
  6282. * listener instead
  6283. * @param {Object} [that] Pass context (`this`) to the handler function
  6284. */
  6285. CommandInterceptor.prototype[hook] = function(events, priority, handlerFn, unwrap, that) {
  6286. if (isFunction(events) || isNumber(events)) {
  6287. that = unwrap;
  6288. unwrap = handlerFn;
  6289. handlerFn = priority;
  6290. priority = events;
  6291. events = null;
  6292. }
  6293. this.on(events, hook, priority, handlerFn, unwrap, that);
  6294. };
  6295. });
  6296. /**
  6297. * A modeling behavior that ensures we set the correct root element
  6298. * as we undo and redo commands.
  6299. *
  6300. * @param {Canvas} canvas
  6301. * @param {didi.Injector} injector
  6302. */
  6303. function RootElementsBehavior(canvas, injector) {
  6304. injector.invoke(CommandInterceptor, this);
  6305. this.executed(function(event) {
  6306. var context = event.context;
  6307. if (context.rootElement) {
  6308. canvas.setRootElement(context.rootElement);
  6309. } else {
  6310. context.rootElement = canvas.getRootElement();
  6311. }
  6312. });
  6313. this.revert(function(event) {
  6314. var context = event.context;
  6315. if (context.rootElement) {
  6316. canvas.setRootElement(context.rootElement);
  6317. }
  6318. });
  6319. }
  6320. e(RootElementsBehavior, CommandInterceptor);
  6321. RootElementsBehavior.$inject = [ 'canvas', 'injector' ];
  6322. var RootElementsModule = {
  6323. __init__: [ 'rootElementsBehavior' ],
  6324. rootElementsBehavior: [ 'type', RootElementsBehavior ]
  6325. };
  6326. var css_escape = {exports: {}};
  6327. /*! https://mths.be/cssescape v1.5.1 by @mathias | MIT license */
  6328. (function (module, exports) {
  6329. (function(root, factory) {
  6330. // https://github.com/umdjs/umd/blob/master/returnExports.js
  6331. {
  6332. // For Node.js.
  6333. module.exports = factory(root);
  6334. }
  6335. }(typeof commonjsGlobal != 'undefined' ? commonjsGlobal : commonjsGlobal, function(root) {
  6336. if (root.CSS && root.CSS.escape) {
  6337. return root.CSS.escape;
  6338. }
  6339. // https://drafts.csswg.org/cssom/#serialize-an-identifier
  6340. var cssEscape = function(value) {
  6341. if (arguments.length == 0) {
  6342. throw new TypeError('`CSS.escape` requires an argument.');
  6343. }
  6344. var string = String(value);
  6345. var length = string.length;
  6346. var index = -1;
  6347. var codeUnit;
  6348. var result = '';
  6349. var firstCodeUnit = string.charCodeAt(0);
  6350. while (++index < length) {
  6351. codeUnit = string.charCodeAt(index);
  6352. // Note: there’s no need to special-case astral symbols, surrogate
  6353. // pairs, or lone surrogates.
  6354. // If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
  6355. // (U+FFFD).
  6356. if (codeUnit == 0x0000) {
  6357. result += '\uFFFD';
  6358. continue;
  6359. }
  6360. if (
  6361. // If the character is in the range [\1-\1F] (U+0001 to U+001F) or is
  6362. // U+007F, […]
  6363. (codeUnit >= 0x0001 && codeUnit <= 0x001F) || codeUnit == 0x007F ||
  6364. // If the character is the first character and is in the range [0-9]
  6365. // (U+0030 to U+0039), […]
  6366. (index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039) ||
  6367. // If the character is the second character and is in the range [0-9]
  6368. // (U+0030 to U+0039) and the first character is a `-` (U+002D), […]
  6369. (
  6370. index == 1 &&
  6371. codeUnit >= 0x0030 && codeUnit <= 0x0039 &&
  6372. firstCodeUnit == 0x002D
  6373. )
  6374. ) {
  6375. // https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
  6376. result += '\\' + codeUnit.toString(16) + ' ';
  6377. continue;
  6378. }
  6379. if (
  6380. // If the character is the first character and is a `-` (U+002D), and
  6381. // there is no second character, […]
  6382. index == 0 &&
  6383. length == 1 &&
  6384. codeUnit == 0x002D
  6385. ) {
  6386. result += '\\' + string.charAt(index);
  6387. continue;
  6388. }
  6389. // If the character is not handled by one of the above rules and is
  6390. // greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
  6391. // is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
  6392. // U+005A), or [a-z] (U+0061 to U+007A), […]
  6393. if (
  6394. codeUnit >= 0x0080 ||
  6395. codeUnit == 0x002D ||
  6396. codeUnit == 0x005F ||
  6397. codeUnit >= 0x0030 && codeUnit <= 0x0039 ||
  6398. codeUnit >= 0x0041 && codeUnit <= 0x005A ||
  6399. codeUnit >= 0x0061 && codeUnit <= 0x007A
  6400. ) {
  6401. // the character itself
  6402. result += string.charAt(index);
  6403. continue;
  6404. }
  6405. // Otherwise, the escaped character.
  6406. // https://drafts.csswg.org/cssom/#escape-a-character
  6407. result += '\\' + string.charAt(index);
  6408. }
  6409. return result;
  6410. };
  6411. if (!root.CSS) {
  6412. root.CSS = {};
  6413. }
  6414. root.CSS.escape = cssEscape;
  6415. return cssEscape;
  6416. }));
  6417. }(css_escape));
  6418. var HTML_ESCAPE_MAP = {
  6419. '&': '&amp;',
  6420. '<': '&lt;',
  6421. '>': '&gt;',
  6422. '"': '&quot;',
  6423. '\'': '&#39;'
  6424. };
  6425. function escapeHTML(str) {
  6426. str = '' + str;
  6427. return str && str.replace(/[&<>"']/g, function(match) {
  6428. return HTML_ESCAPE_MAP[match];
  6429. });
  6430. }
  6431. var planeSuffix = '_plane';
  6432. /**
  6433. * Get plane ID for a primary shape.
  6434. *
  6435. * @param {djs.model.Base|ModdleElement} element
  6436. *
  6437. * @returns {String}
  6438. */
  6439. function getPlaneIdFromShape(element) {
  6440. var id = element.id;
  6441. if (is$1(element, 'bpmn:SubProcess')) {
  6442. return addPlaneSuffix(id);
  6443. }
  6444. return id;
  6445. }
  6446. function addPlaneSuffix(id) {
  6447. return id + planeSuffix;
  6448. }
  6449. var OPEN_CLASS = 'bjs-breadcrumbs-shown';
  6450. /**
  6451. * Adds overlays that allow switching planes on collapsed subprocesses.
  6452. *
  6453. * @param {eventBus} eventBus
  6454. * @param {elementRegistry} elementRegistry
  6455. * @param {overlays} overlays
  6456. * @param {canvas} canvas
  6457. */
  6458. function DrilldownBreadcrumbs(eventBus, elementRegistry, overlays, canvas) {
  6459. var breadcrumbs = domify('<ul class="bjs-breadcrumbs"></ul>');
  6460. var container = canvas.getContainer();
  6461. var containerClasses = classes(container);
  6462. container.appendChild(breadcrumbs);
  6463. var boParents = [];
  6464. // update breadcrumbs if name or ID of the primary shape changes
  6465. eventBus.on('element.changed', function(e) {
  6466. var shape = e.element,
  6467. bo = getBusinessObject(shape);
  6468. var isPresent = find(boParents, function(el) {
  6469. return el === bo;
  6470. });
  6471. if (!isPresent) {
  6472. return;
  6473. }
  6474. updateBreadcrumbs();
  6475. });
  6476. /**
  6477. * Updates the displayed breadcrumbs. If no element is provided, only the
  6478. * labels are updated.
  6479. *
  6480. * @param {djs.model.Base} [element]
  6481. */
  6482. function updateBreadcrumbs(element) {
  6483. if (element) {
  6484. boParents = getBoParentChain(element);
  6485. }
  6486. var path = boParents.map(function(parent) {
  6487. var title = escapeHTML(parent.name || parent.id);
  6488. var link = domify('<li><span class="bjs-crumb"><a title="' + title + '">' + title + '</a></span></li>');
  6489. var parentPlane = canvas.findRoot(getPlaneIdFromShape(parent)) || canvas.findRoot(parent.id);
  6490. // when the root is a collaboration, the process does not have a corresponding
  6491. // element in the elementRegisty. Instead, we search for the corresponding participant
  6492. if (!parentPlane && is$1(parent, 'bpmn:Process')) {
  6493. var participant = elementRegistry.find(function(element) {
  6494. var bo = getBusinessObject(element);
  6495. return bo && bo.processRef && bo.processRef === parent;
  6496. });
  6497. parentPlane = canvas.findRoot(participant.id);
  6498. }
  6499. link.addEventListener('click', function() {
  6500. canvas.setRootElement(parentPlane);
  6501. });
  6502. return link;
  6503. });
  6504. breadcrumbs.innerHTML = '';
  6505. // show breadcrumbs and expose state to .djs-container
  6506. var visible = path.length > 1;
  6507. containerClasses.toggle(OPEN_CLASS, visible);
  6508. path.forEach(function(el) {
  6509. breadcrumbs.appendChild(el);
  6510. });
  6511. }
  6512. eventBus.on('root.set', function(event) {
  6513. updateBreadcrumbs(event.element);
  6514. });
  6515. }
  6516. DrilldownBreadcrumbs.$inject = [ 'eventBus', 'elementRegistry', 'overlays', 'canvas' ];
  6517. // helpers //////////
  6518. /**
  6519. * Returns the parents for the element using the business object chain,
  6520. * starting with the root element.
  6521. *
  6522. * @param {djs.model.Shape} child
  6523. *
  6524. * @returns {Array<djs.model.Shape>} parents
  6525. */
  6526. function getBoParentChain(child) {
  6527. var bo = getBusinessObject(child);
  6528. var parents = [];
  6529. for (var element = bo; element; element = element.$parent) {
  6530. if (is$1(element, 'bpmn:SubProcess') || is$1(element, 'bpmn:Process')) {
  6531. parents.push(element);
  6532. }
  6533. }
  6534. return parents.reverse();
  6535. }
  6536. /**
  6537. * Move collapsed subprocesses into view when drilling down.
  6538. *
  6539. * Zoom and scroll are saved in a session.
  6540. *
  6541. * @param {eventBus} eventBus
  6542. * @param {canvas} canvas
  6543. */
  6544. function DrilldownCentering(eventBus, canvas) {
  6545. var currentRoot = null;
  6546. var positionMap = new Map();
  6547. eventBus.on('root.set', function(event) {
  6548. var newRoot = event.element;
  6549. var currentViewbox = canvas.viewbox();
  6550. var storedViewbox = positionMap.get(newRoot);
  6551. positionMap.set(currentRoot, {
  6552. x: currentViewbox.x,
  6553. y: currentViewbox.y,
  6554. zoom: currentViewbox.scale
  6555. });
  6556. currentRoot = newRoot;
  6557. // current root was replaced with a collaboration, we don't update the viewbox
  6558. if (is$1(newRoot, 'bpmn:Collaboration') && !storedViewbox) {
  6559. return;
  6560. }
  6561. storedViewbox = storedViewbox || { x: 0, y: 0, zoom: 1 };
  6562. var dx = (currentViewbox.x - storedViewbox.x) * currentViewbox.scale,
  6563. dy = (currentViewbox.y - storedViewbox.y) * currentViewbox.scale;
  6564. if (dx !== 0 || dy !== 0) {
  6565. canvas.scroll({
  6566. dx: dx,
  6567. dy: dy
  6568. });
  6569. }
  6570. if (storedViewbox.zoom !== currentViewbox.scale) {
  6571. canvas.zoom(storedViewbox.zoom, { x: 0, y: 0 });
  6572. }
  6573. });
  6574. eventBus.on('diagram.clear', function() {
  6575. positionMap.clear();
  6576. currentRoot = null;
  6577. });
  6578. }
  6579. DrilldownCentering.$inject = [ 'eventBus', 'canvas' ];
  6580. /**
  6581. * ES5 Map implementation. Works.
  6582. */
  6583. function Map() {
  6584. this._entries = [];
  6585. this.set = function(key, value) {
  6586. var found = false;
  6587. for (var k in this._entries) {
  6588. if (this._entries[k][0] === key) {
  6589. this._entries[k][1] = value;
  6590. found = true;
  6591. break;
  6592. }
  6593. }
  6594. if (!found) {
  6595. this._entries.push([ key, value ]);
  6596. }
  6597. };
  6598. this.get = function(key) {
  6599. for (var k in this._entries) {
  6600. if (this._entries[k][0] === key) {
  6601. return this._entries[k][1];
  6602. }
  6603. }
  6604. return null;
  6605. };
  6606. this.clear = function() {
  6607. this._entries.length = 0;
  6608. };
  6609. this.remove = function(key) {
  6610. var idx = -1;
  6611. for (var k in this._entries) {
  6612. if (this._entries[k][0] === key) {
  6613. idx = k;
  6614. break;
  6615. }
  6616. }
  6617. if (idx !== -1) {
  6618. this._entries.splice(idx, 1);
  6619. }
  6620. };
  6621. }
  6622. var DEFAULT_POSITION = {
  6623. x: 180,
  6624. y: 160
  6625. };
  6626. /**
  6627. * Hook into `import.render.start` and create new planes for diagrams with
  6628. * collapsed subprocesses and all dis on the same plane.
  6629. *
  6630. * @param {eventBus} eventBus
  6631. * @param {moddle} moddle
  6632. */
  6633. function SubprocessCompatibility(eventBus, moddle) {
  6634. this._eventBus = eventBus;
  6635. this._moddle = moddle;
  6636. var self = this;
  6637. eventBus.on('import.render.start', 1500, function(e, context) {
  6638. self.handleImport(context.definitions);
  6639. });
  6640. }
  6641. SubprocessCompatibility.prototype.handleImport = function(definitions) {
  6642. if (!definitions.diagrams) {
  6643. return;
  6644. }
  6645. var self = this;
  6646. this._definitions = definitions;
  6647. this._processToDiagramMap = {};
  6648. definitions.diagrams.forEach(function(diagram) {
  6649. if (!diagram.plane || !diagram.plane.bpmnElement) {
  6650. return;
  6651. }
  6652. self._processToDiagramMap[diagram.plane.bpmnElement.id] = diagram;
  6653. });
  6654. var newDiagrams = [];
  6655. definitions.diagrams.forEach(function(diagram) {
  6656. var createdDiagrams = self.createNewDiagrams(diagram.plane);
  6657. Array.prototype.push.apply(newDiagrams, createdDiagrams);
  6658. });
  6659. newDiagrams.forEach(function(diagram) {
  6660. self.movePlaneElementsToOrigin(diagram.plane);
  6661. });
  6662. };
  6663. /**
  6664. * Moves all DI elements from collapsed subprocesses to a new plane.
  6665. *
  6666. * @param {Object} plane
  6667. * @return {Array} new diagrams created for the collapsed subprocesses
  6668. */
  6669. SubprocessCompatibility.prototype.createNewDiagrams = function(plane) {
  6670. var self = this;
  6671. var collapsedElements = [];
  6672. var elementsToMove = [];
  6673. plane.get('planeElement').forEach(function(diElement) {
  6674. var bo = diElement.bpmnElement;
  6675. if (!bo) {
  6676. return;
  6677. }
  6678. var parent = bo.$parent;
  6679. if (is$1(bo, 'bpmn:SubProcess') && !diElement.isExpanded) {
  6680. collapsedElements.push(bo);
  6681. }
  6682. if (shouldMoveToPlane(bo, plane)) {
  6683. // don't change the array while we iterate over it
  6684. elementsToMove.push({ diElement: diElement, parent: parent });
  6685. }
  6686. });
  6687. var newDiagrams = [];
  6688. // create new planes for all collapsed subprocesses, even when they are empty
  6689. collapsedElements.forEach(function(element) {
  6690. if (!self._processToDiagramMap[element.id]) {
  6691. var diagram = self.createDiagram(element);
  6692. self._processToDiagramMap[element.id] = diagram;
  6693. newDiagrams.push(diagram);
  6694. }
  6695. });
  6696. elementsToMove.forEach(function(element) {
  6697. var diElement = element.diElement;
  6698. var parent = element.parent;
  6699. // parent is expanded, get nearest collapsed parent
  6700. while (parent && collapsedElements.indexOf(parent) === -1) {
  6701. parent = parent.$parent;
  6702. }
  6703. // false positive, all parents are expanded
  6704. if (!parent) {
  6705. return;
  6706. }
  6707. var diagram = self._processToDiagramMap[parent.id];
  6708. self.moveToDiPlane(diElement, diagram.plane);
  6709. });
  6710. return newDiagrams;
  6711. };
  6712. SubprocessCompatibility.prototype.movePlaneElementsToOrigin = function(plane) {
  6713. var elements = plane.get('planeElement');
  6714. // get bounding box of all elements
  6715. var planeBounds = getPlaneBounds(plane);
  6716. var offset = {
  6717. x: planeBounds.x - DEFAULT_POSITION.x,
  6718. y: planeBounds.y - DEFAULT_POSITION.y
  6719. };
  6720. elements.forEach(function(diElement) {
  6721. if (diElement.waypoint) {
  6722. diElement.waypoint.forEach(function(waypoint) {
  6723. waypoint.x = waypoint.x - offset.x;
  6724. waypoint.y = waypoint.y - offset.y;
  6725. });
  6726. } else if (diElement.bounds) {
  6727. diElement.bounds.x = diElement.bounds.x - offset.x;
  6728. diElement.bounds.y = diElement.bounds.y - offset.y;
  6729. }
  6730. });
  6731. };
  6732. SubprocessCompatibility.prototype.moveToDiPlane = function(diElement, newPlane) {
  6733. var containingDiagram = findRootDiagram(diElement);
  6734. // remove DI from old Plane and add it to the new one
  6735. var parentPlaneElement = containingDiagram.plane.get('planeElement');
  6736. parentPlaneElement.splice(parentPlaneElement.indexOf(diElement), 1);
  6737. newPlane.get('planeElement').push(diElement);
  6738. };
  6739. SubprocessCompatibility.prototype.createDiagram = function(bo) {
  6740. var plane = this._moddle.create('bpmndi:BPMNPlane', { bpmnElement: bo });
  6741. var diagram = this._moddle.create('bpmndi:BPMNDiagram', {
  6742. plane: plane
  6743. });
  6744. plane.$parent = diagram;
  6745. plane.bpmnElement = bo;
  6746. diagram.$parent = this._definitions;
  6747. this._definitions.diagrams.push(diagram);
  6748. return diagram;
  6749. };
  6750. SubprocessCompatibility.$inject = [ 'eventBus', 'moddle' ];
  6751. // helpers //////////////////////////
  6752. function findRootDiagram(element) {
  6753. if (is$1(element, 'bpmndi:BPMNDiagram')) {
  6754. return element;
  6755. } else {
  6756. return findRootDiagram(element.$parent);
  6757. }
  6758. }
  6759. function getPlaneBounds(plane) {
  6760. var planeTrbl = {
  6761. top: Infinity,
  6762. right: -Infinity,
  6763. bottom: -Infinity,
  6764. left: Infinity
  6765. };
  6766. plane.planeElement.forEach(function(element) {
  6767. if (!element.bounds) {
  6768. return;
  6769. }
  6770. var trbl = asTRBL(element.bounds);
  6771. planeTrbl.top = Math.min(trbl.top, planeTrbl.top);
  6772. planeTrbl.left = Math.min(trbl.left, planeTrbl.left);
  6773. });
  6774. return asBounds(planeTrbl);
  6775. }
  6776. function shouldMoveToPlane(bo, plane) {
  6777. var parent = bo.$parent;
  6778. // don't move elements that are already on the plane
  6779. if (!is$1(parent, 'bpmn:SubProcess') || parent === plane.bpmnElement) {
  6780. return false;
  6781. }
  6782. // dataAssociations are children of the subprocess but rendered on process level
  6783. // cf. https://github.com/bpmn-io/bpmn-js/issues/1619
  6784. if (isAny(bo, ['bpmn:DataInputAssociation', 'bpmn:DataOutputAssociation'])) {
  6785. return false;
  6786. }
  6787. return true;
  6788. }
  6789. var LOW_PRIORITY$1 = 250;
  6790. 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>';
  6791. var EMPTY_MARKER = 'bjs-drilldown-empty';
  6792. function DrilldownOverlayBehavior(
  6793. canvas, eventBus, elementRegistry, overlays
  6794. ) {
  6795. CommandInterceptor.call(this, eventBus);
  6796. this._canvas = canvas;
  6797. this._eventBus = eventBus;
  6798. this._elementRegistry = elementRegistry;
  6799. this._overlays = overlays;
  6800. var self = this;
  6801. this.executed('shape.toggleCollapse', LOW_PRIORITY$1, function(context) {
  6802. var shape = context.shape;
  6803. // Add overlay to the collapsed shape
  6804. if (self.canDrillDown(shape)) {
  6805. self.addOverlay(shape);
  6806. } else {
  6807. self.removeOverlay(shape);
  6808. }
  6809. }, true);
  6810. this.reverted('shape.toggleCollapse', LOW_PRIORITY$1, function(context) {
  6811. var shape = context.shape;
  6812. // Add overlay to the collapsed shape
  6813. if (self.canDrillDown(shape)) {
  6814. self.addOverlay(shape);
  6815. } else {
  6816. self.removeOverlay(shape);
  6817. }
  6818. }, true);
  6819. this.executed(['shape.create', 'shape.move', 'shape.delete'], LOW_PRIORITY$1,
  6820. function(context) {
  6821. var oldParent = context.oldParent,
  6822. newParent = context.newParent || context.parent,
  6823. shape = context.shape;
  6824. // Add overlay to the collapsed shape
  6825. if (self.canDrillDown(shape)) {
  6826. self.addOverlay(shape);
  6827. }
  6828. self.updateDrilldownOverlay(oldParent);
  6829. self.updateDrilldownOverlay(newParent);
  6830. self.updateDrilldownOverlay(shape);
  6831. }, true);
  6832. this.reverted(['shape.create', 'shape.move', 'shape.delete'], LOW_PRIORITY$1,
  6833. function(context) {
  6834. var oldParent = context.oldParent,
  6835. newParent = context.newParent || context.parent,
  6836. shape = context.shape;
  6837. // Add overlay to the collapsed shape
  6838. if (self.canDrillDown(shape)) {
  6839. self.addOverlay(shape);
  6840. }
  6841. self.updateDrilldownOverlay(oldParent);
  6842. self.updateDrilldownOverlay(newParent);
  6843. self.updateDrilldownOverlay(shape);
  6844. }, true);
  6845. eventBus.on('import.render.complete', function() {
  6846. elementRegistry.filter(function(e) {
  6847. return self.canDrillDown(e);
  6848. }).map(function(el) {
  6849. self.addOverlay(el);
  6850. });
  6851. });
  6852. }
  6853. e(DrilldownOverlayBehavior, CommandInterceptor);
  6854. DrilldownOverlayBehavior.prototype.updateDrilldownOverlay = function(shape) {
  6855. var canvas = this._canvas;
  6856. if (!shape) {
  6857. return;
  6858. }
  6859. var root = canvas.findRoot(shape);
  6860. if (root) {
  6861. this.updateOverlayVisibility(root);
  6862. }
  6863. };
  6864. DrilldownOverlayBehavior.prototype.canDrillDown = function(element) {
  6865. var canvas = this._canvas;
  6866. return is$1(element, 'bpmn:SubProcess') && canvas.findRoot(getPlaneIdFromShape(element));
  6867. };
  6868. /**
  6869. * Updates visibility of the drilldown overlay. If the plane has no elements,
  6870. * the drilldown will be only shown when the element is selected.
  6871. *
  6872. * @param {djs.model.Shape|djs.model.Root} element collapsed shape or root element
  6873. */
  6874. DrilldownOverlayBehavior.prototype.updateOverlayVisibility = function(element) {
  6875. var overlays = this._overlays;
  6876. var bo = element.businessObject;
  6877. var overlay = overlays.get({ element: bo.id, type: 'drilldown' })[0];
  6878. if (!overlay) {
  6879. return;
  6880. }
  6881. var hasContent = bo && bo.flowElements && bo.flowElements.length;
  6882. classes(overlay.html).toggle(EMPTY_MARKER, !hasContent);
  6883. };
  6884. /**
  6885. * Attaches a drilldown button to the given element. We assume that the plane has
  6886. * the same id as the element.
  6887. *
  6888. * @param {djs.model.Shape} element collapsed shape
  6889. */
  6890. DrilldownOverlayBehavior.prototype.addOverlay = function(element) {
  6891. var canvas = this._canvas;
  6892. var overlays = this._overlays;
  6893. var existingOverlays = overlays.get({ element: element, type: 'drilldown' });
  6894. if (existingOverlays.length) {
  6895. this.removeOverlay(element);
  6896. }
  6897. var button = domify('<button class="bjs-drilldown">' + ARROW_DOWN_SVG + '</button>');
  6898. button.addEventListener('click', function() {
  6899. canvas.setRootElement(canvas.findRoot(getPlaneIdFromShape(element)));
  6900. });
  6901. overlays.add(element, 'drilldown', {
  6902. position: {
  6903. bottom: -7,
  6904. right: -8
  6905. },
  6906. html: button
  6907. });
  6908. this.updateOverlayVisibility(element);
  6909. };
  6910. DrilldownOverlayBehavior.prototype.removeOverlay = function(element) {
  6911. var overlays = this._overlays;
  6912. overlays.remove({
  6913. element: element,
  6914. type: 'drilldown'
  6915. });
  6916. };
  6917. DrilldownOverlayBehavior.$inject = [
  6918. 'canvas',
  6919. 'eventBus',
  6920. 'elementRegistry',
  6921. 'overlays'
  6922. ];
  6923. var DrilldownModdule = {
  6924. __depends__: [ OverlaysModule, ChangeSupportModule, RootElementsModule ],
  6925. __init__: [ 'drilldownBreadcrumbs', 'drilldownOverlayBehavior', 'drilldownCentering', 'subprocessCompatibility'],
  6926. drilldownBreadcrumbs: [ 'type', DrilldownBreadcrumbs ],
  6927. drilldownCentering: [ 'type', DrilldownCentering ],
  6928. drilldownOverlayBehavior: [ 'type', DrilldownOverlayBehavior ],
  6929. subprocessCompatibility: [ 'type', SubprocessCompatibility ]
  6930. };
  6931. var CLASS_PATTERN = /^class /;
  6932. /**
  6933. * @param {function} fn
  6934. *
  6935. * @return {boolean}
  6936. */
  6937. function isClass(fn) {
  6938. return CLASS_PATTERN.test(fn.toString());
  6939. }
  6940. /**
  6941. * @param {any} obj
  6942. *
  6943. * @return {boolean}
  6944. */
  6945. function isArray(obj) {
  6946. return Object.prototype.toString.call(obj) === '[object Array]';
  6947. }
  6948. /**
  6949. * @param {any} obj
  6950. * @param {string} prop
  6951. *
  6952. * @return {boolean}
  6953. */
  6954. function hasOwnProp(obj, prop) {
  6955. return Object.prototype.hasOwnProperty.call(obj, prop);
  6956. }
  6957. /**
  6958. * @typedef {import('./index').InjectAnnotated } InjectAnnotated
  6959. */
  6960. /**
  6961. * @template T
  6962. *
  6963. * @params {[...string[], T] | ...string[], T} args
  6964. *
  6965. * @return {T & InjectAnnotated}
  6966. */
  6967. function annotate() {
  6968. var args = Array.prototype.slice.call(arguments);
  6969. if (args.length === 1 && isArray(args[0])) {
  6970. args = args[0];
  6971. }
  6972. var fn = args.pop();
  6973. fn.$inject = args;
  6974. return fn;
  6975. }
  6976. // Current limitations:
  6977. // - can't put into "function arg" comments
  6978. // function /* (no parenthesis like this) */ (){}
  6979. // function abc( /* xx (no parenthesis like this) */ a, b) {}
  6980. //
  6981. // Just put the comment before function or inside:
  6982. // /* (((this is fine))) */ function(a, b) {}
  6983. // function abc(a) { /* (((this is fine))) */}
  6984. //
  6985. // - can't reliably auto-annotate constructor; we'll match the
  6986. // first constructor(...) pattern found which may be the one
  6987. // of a nested class, too.
  6988. var CONSTRUCTOR_ARGS = /constructor\s*[^(]*\(\s*([^)]*)\)/m;
  6989. var FN_ARGS = /^(?:async\s+)?(?:function\s*[^(]*)?(?:\(\s*([^)]*)\)|(\w+))/m;
  6990. var FN_ARG = /\/\*([^*]*)\*\//m;
  6991. /**
  6992. * @param {unknown} fn
  6993. *
  6994. * @return {string[]}
  6995. */
  6996. function parseAnnotations(fn) {
  6997. if (typeof fn !== 'function') {
  6998. throw new Error('Cannot annotate "' + fn + '". Expected a function!');
  6999. }
  7000. var match = fn.toString().match(isClass(fn) ? CONSTRUCTOR_ARGS : FN_ARGS);
  7001. // may parse class without constructor
  7002. if (!match) {
  7003. return [];
  7004. }
  7005. var args = match[1] || match[2];
  7006. return args && args.split(',').map(function(arg) {
  7007. var argMatch = arg.match(FN_ARG);
  7008. return (argMatch && argMatch[1] || arg).trim();
  7009. }) || [];
  7010. }
  7011. /**
  7012. * @typedef { import('./index').ModuleDeclaration } ModuleDeclaration
  7013. * @typedef { import('./index').ModuleDefinition } ModuleDefinition
  7014. * @typedef { import('./index').InjectorContext } InjectorContext
  7015. */
  7016. /**
  7017. * Create a new injector with the given modules.
  7018. *
  7019. * @param {ModuleDefinition[]} modules
  7020. * @param {InjectorContext} [parent]
  7021. */
  7022. function Injector(modules, parent) {
  7023. parent = parent || {
  7024. get: function(name, strict) {
  7025. currentlyResolving.push(name);
  7026. if (strict === false) {
  7027. return null;
  7028. } else {
  7029. throw error('No provider for "' + name + '"!');
  7030. }
  7031. }
  7032. };
  7033. var currentlyResolving = [];
  7034. var providers = this._providers = Object.create(parent._providers || null);
  7035. var instances = this._instances = Object.create(null);
  7036. var self = instances.injector = this;
  7037. var error = function(msg) {
  7038. var stack = currentlyResolving.join(' -> ');
  7039. currentlyResolving.length = 0;
  7040. return new Error(stack ? msg + ' (Resolving: ' + stack + ')' : msg);
  7041. };
  7042. /**
  7043. * Return a named service.
  7044. *
  7045. * @param {string} name
  7046. * @param {boolean} [strict=true] if false, resolve missing services to null
  7047. *
  7048. * @return {any}
  7049. */
  7050. function get(name, strict) {
  7051. if (!providers[name] && name.indexOf('.') !== -1) {
  7052. var parts = name.split('.');
  7053. var pivot = get(parts.shift());
  7054. while (parts.length) {
  7055. pivot = pivot[parts.shift()];
  7056. }
  7057. return pivot;
  7058. }
  7059. if (hasOwnProp(instances, name)) {
  7060. return instances[name];
  7061. }
  7062. if (hasOwnProp(providers, name)) {
  7063. if (currentlyResolving.indexOf(name) !== -1) {
  7064. currentlyResolving.push(name);
  7065. throw error('Cannot resolve circular dependency!');
  7066. }
  7067. currentlyResolving.push(name);
  7068. instances[name] = providers[name][0](providers[name][1]);
  7069. currentlyResolving.pop();
  7070. return instances[name];
  7071. }
  7072. return parent.get(name, strict);
  7073. }
  7074. function fnDef(fn, locals) {
  7075. if (typeof locals === 'undefined') {
  7076. locals = {};
  7077. }
  7078. if (typeof fn !== 'function') {
  7079. if (isArray(fn)) {
  7080. fn = annotate(fn.slice());
  7081. } else {
  7082. throw new Error('Cannot invoke "' + fn + '". Expected a function!');
  7083. }
  7084. }
  7085. var inject = fn.$inject || parseAnnotations(fn);
  7086. var dependencies = inject.map(function(dep) {
  7087. if (hasOwnProp(locals, dep)) {
  7088. return locals[dep];
  7089. } else {
  7090. return get(dep);
  7091. }
  7092. });
  7093. return {
  7094. fn: fn,
  7095. dependencies: dependencies
  7096. };
  7097. }
  7098. function instantiate(Type) {
  7099. var def = fnDef(Type);
  7100. var fn = def.fn,
  7101. dependencies = def.dependencies;
  7102. // instantiate var args constructor
  7103. var Constructor = Function.prototype.bind.apply(fn, [ null ].concat(dependencies));
  7104. return new Constructor();
  7105. }
  7106. function invoke(func, context, locals) {
  7107. var def = fnDef(func, locals);
  7108. var fn = def.fn,
  7109. dependencies = def.dependencies;
  7110. return fn.apply(context, dependencies);
  7111. }
  7112. /**
  7113. * @param {Injector} childInjector
  7114. *
  7115. * @return {Function}
  7116. */
  7117. function createPrivateInjectorFactory(childInjector) {
  7118. return annotate(function(key) {
  7119. return childInjector.get(key);
  7120. });
  7121. }
  7122. /**
  7123. * @param {ModuleDefinition[]} modules
  7124. * @param {string[]} [forceNewInstances]
  7125. *
  7126. * @return {Injector}
  7127. */
  7128. function createChild(modules, forceNewInstances) {
  7129. if (forceNewInstances && forceNewInstances.length) {
  7130. var fromParentModule = Object.create(null);
  7131. var matchedScopes = Object.create(null);
  7132. var privateInjectorsCache = [];
  7133. var privateChildInjectors = [];
  7134. var privateChildFactories = [];
  7135. var provider;
  7136. var cacheIdx;
  7137. var privateChildInjector;
  7138. var privateChildInjectorFactory;
  7139. for (var name in providers) {
  7140. provider = providers[name];
  7141. if (forceNewInstances.indexOf(name) !== -1) {
  7142. if (provider[2] === 'private') {
  7143. cacheIdx = privateInjectorsCache.indexOf(provider[3]);
  7144. if (cacheIdx === -1) {
  7145. privateChildInjector = provider[3].createChild([], forceNewInstances);
  7146. privateChildInjectorFactory = createPrivateInjectorFactory(privateChildInjector);
  7147. privateInjectorsCache.push(provider[3]);
  7148. privateChildInjectors.push(privateChildInjector);
  7149. privateChildFactories.push(privateChildInjectorFactory);
  7150. fromParentModule[name] = [ privateChildInjectorFactory, name, 'private', privateChildInjector ];
  7151. } else {
  7152. fromParentModule[name] = [ privateChildFactories[cacheIdx], name, 'private', privateChildInjectors[cacheIdx] ];
  7153. }
  7154. } else {
  7155. fromParentModule[name] = [ provider[2], provider[1] ];
  7156. }
  7157. matchedScopes[name] = true;
  7158. }
  7159. if ((provider[2] === 'factory' || provider[2] === 'type') && provider[1].$scope) {
  7160. /* jshint -W083 */
  7161. forceNewInstances.forEach(function(scope) {
  7162. if (provider[1].$scope.indexOf(scope) !== -1) {
  7163. fromParentModule[name] = [ provider[2], provider[1] ];
  7164. matchedScopes[scope] = true;
  7165. }
  7166. });
  7167. }
  7168. }
  7169. forceNewInstances.forEach(function(scope) {
  7170. if (!matchedScopes[scope]) {
  7171. throw new Error('No provider for "' + scope + '". Cannot use provider from the parent!');
  7172. }
  7173. });
  7174. modules.unshift(fromParentModule);
  7175. }
  7176. return new Injector(modules, self);
  7177. }
  7178. var factoryMap = {
  7179. factory: invoke,
  7180. type: instantiate,
  7181. value: function(value) {
  7182. return value;
  7183. }
  7184. };
  7185. /**
  7186. * @param {ModuleDefinition} moduleDefinition
  7187. * @param {Injector} injector
  7188. */
  7189. function createInitializer(moduleDefinition, injector) {
  7190. var initializers = moduleDefinition.__init__ || [];
  7191. return function() {
  7192. initializers.forEach(function(initializer) {
  7193. try {
  7194. // eagerly resolve component (fn or string)
  7195. if (typeof initializer === 'string') {
  7196. injector.get(initializer);
  7197. } else {
  7198. injector.invoke(initializer);
  7199. }
  7200. } catch (error) {
  7201. if (typeof AggregateError !== 'undefined') {
  7202. throw new AggregateError([ error ], 'Failed to initialize!');
  7203. }
  7204. throw new Error('Failed to initialize! ' + error.message);
  7205. }
  7206. });
  7207. };
  7208. }
  7209. /**
  7210. * @param {ModuleDefinition} moduleDefinition
  7211. */
  7212. function loadModule(moduleDefinition) {
  7213. var moduleExports = moduleDefinition.__exports__;
  7214. // private module
  7215. if (moduleExports) {
  7216. var nestedModules = moduleDefinition.__modules__;
  7217. var clonedModule = Object.keys(moduleDefinition).reduce(function(clonedModule, key) {
  7218. if (key !== '__exports__' && key !== '__modules__' && key !== '__init__' && key !== '__depends__') {
  7219. clonedModule[key] = moduleDefinition[key];
  7220. }
  7221. return clonedModule;
  7222. }, Object.create(null));
  7223. var childModules = (nestedModules || []).concat(clonedModule);
  7224. var privateInjector = createChild(childModules);
  7225. var getFromPrivateInjector = annotate(function(key) {
  7226. return privateInjector.get(key);
  7227. });
  7228. moduleExports.forEach(function(key) {
  7229. providers[key] = [ getFromPrivateInjector, key, 'private', privateInjector ];
  7230. });
  7231. // ensure child injector initializes
  7232. var initializers = (moduleDefinition.__init__ || []).slice();
  7233. initializers.unshift(function() {
  7234. privateInjector.init();
  7235. });
  7236. moduleDefinition = Object.assign({}, moduleDefinition, {
  7237. __init__: initializers
  7238. });
  7239. return createInitializer(moduleDefinition, privateInjector);
  7240. }
  7241. // normal module
  7242. Object.keys(moduleDefinition).forEach(function(key) {
  7243. if (key === '__init__' || key === '__depends__') {
  7244. return;
  7245. }
  7246. if (moduleDefinition[key][2] === 'private') {
  7247. providers[key] = moduleDefinition[key];
  7248. return;
  7249. }
  7250. var type = moduleDefinition[key][0];
  7251. var value = moduleDefinition[key][1];
  7252. providers[key] = [ factoryMap[type], arrayUnwrap(type, value), type ];
  7253. });
  7254. return createInitializer(moduleDefinition, self);
  7255. }
  7256. /**
  7257. * @param {ModuleDefinition[]} moduleDefinitions
  7258. * @param {ModuleDefinition} moduleDefinition
  7259. *
  7260. * @return {ModuleDefinition[]}
  7261. */
  7262. function resolveDependencies(moduleDefinitions, moduleDefinition) {
  7263. if (moduleDefinitions.indexOf(moduleDefinition) !== -1) {
  7264. return moduleDefinitions;
  7265. }
  7266. moduleDefinitions = (moduleDefinition.__depends__ || []).reduce(resolveDependencies, moduleDefinitions);
  7267. if (moduleDefinitions.indexOf(moduleDefinition) !== -1) {
  7268. return moduleDefinitions;
  7269. }
  7270. return moduleDefinitions.concat(moduleDefinition);
  7271. }
  7272. /**
  7273. * @param {ModuleDefinition[]} moduleDefinitions
  7274. *
  7275. * @return { () => void } initializerFn
  7276. */
  7277. function bootstrap(moduleDefinitions) {
  7278. var initializers = moduleDefinitions
  7279. .reduce(resolveDependencies, [])
  7280. .map(loadModule);
  7281. var initialized = false;
  7282. return function() {
  7283. if (initialized) {
  7284. return;
  7285. }
  7286. initialized = true;
  7287. initializers.forEach(function(initializer) {
  7288. return initializer();
  7289. });
  7290. };
  7291. }
  7292. // public API
  7293. this.get = get;
  7294. this.invoke = invoke;
  7295. this.instantiate = instantiate;
  7296. this.createChild = createChild;
  7297. // setup
  7298. this.init = bootstrap(modules);
  7299. }
  7300. // helpers ///////////////
  7301. function arrayUnwrap(type, value) {
  7302. if (type !== 'value' && isArray(value)) {
  7303. value = annotate(value.slice());
  7304. }
  7305. return value;
  7306. }
  7307. // apply default renderer with lowest possible priority
  7308. // so that it only kicks in if noone else could render
  7309. var DEFAULT_RENDER_PRIORITY = 1;
  7310. /**
  7311. * The default renderer used for shapes and connections.
  7312. *
  7313. * @param {EventBus} eventBus
  7314. * @param {Styles} styles
  7315. */
  7316. function DefaultRenderer(eventBus, styles) {
  7317. //
  7318. BaseRenderer.call(this, eventBus, DEFAULT_RENDER_PRIORITY);
  7319. this.CONNECTION_STYLE = styles.style([ 'no-fill' ], { strokeWidth: 5, stroke: 'fuchsia' });
  7320. this.SHAPE_STYLE = styles.style({ fill: 'white', stroke: 'fuchsia', strokeWidth: 2 });
  7321. this.FRAME_STYLE = styles.style([ 'no-fill' ], { stroke: 'fuchsia', strokeDasharray: 4, strokeWidth: 2 });
  7322. }
  7323. e(DefaultRenderer, BaseRenderer);
  7324. DefaultRenderer.prototype.canRender = function() {
  7325. return true;
  7326. };
  7327. DefaultRenderer.prototype.drawShape = function drawShape(visuals, element, attrs) {
  7328. var rect = create$1('rect');
  7329. attr$1(rect, {
  7330. x: 0,
  7331. y: 0,
  7332. width: element.width || 0,
  7333. height: element.height || 0
  7334. });
  7335. if (isFrameElement(element)) {
  7336. attr$1(rect, assign({}, this.FRAME_STYLE, attrs || {}));
  7337. } else {
  7338. attr$1(rect, assign({}, this.SHAPE_STYLE, attrs || {}));
  7339. }
  7340. append(visuals, rect);
  7341. return rect;
  7342. };
  7343. DefaultRenderer.prototype.drawConnection = function drawConnection(visuals, connection, attrs) {
  7344. var line = createLine(connection.waypoints, assign({}, this.CONNECTION_STYLE, attrs || {}));
  7345. append(visuals, line);
  7346. return line;
  7347. };
  7348. DefaultRenderer.prototype.getShapePath = function getShapePath(shape) {
  7349. var x = shape.x,
  7350. y = shape.y,
  7351. width = shape.width,
  7352. height = shape.height;
  7353. var shapePath = [
  7354. [ 'M', x, y ],
  7355. [ 'l', width, 0 ],
  7356. [ 'l', 0, height ],
  7357. [ 'l', -width, 0 ],
  7358. [ 'z' ]
  7359. ];
  7360. return componentsToPath(shapePath);
  7361. };
  7362. DefaultRenderer.prototype.getConnectionPath = function getConnectionPath(connection) {
  7363. var waypoints = connection.waypoints;
  7364. var idx, point, connectionPath = [];
  7365. for (idx = 0; (point = waypoints[idx]); idx++) {
  7366. // take invisible docking into account
  7367. // when creating the path
  7368. point = point.original || point;
  7369. connectionPath.push([ idx === 0 ? 'M' : 'L', point.x, point.y ]);
  7370. }
  7371. return componentsToPath(connectionPath);
  7372. };
  7373. DefaultRenderer.$inject = [ 'eventBus', 'styles' ];
  7374. /**
  7375. * A component that manages shape styles
  7376. */
  7377. function Styles() {
  7378. var defaultTraits = {
  7379. 'no-fill': {
  7380. fill: 'none'
  7381. },
  7382. 'no-border': {
  7383. strokeOpacity: 0.0
  7384. },
  7385. 'no-events': {
  7386. pointerEvents: 'none'
  7387. }
  7388. };
  7389. var self = this;
  7390. /**
  7391. * Builds a style definition from a className, a list of traits and an object of additional attributes.
  7392. *
  7393. * @param {string} className
  7394. * @param {Array<string>} traits
  7395. * @param {Object} additionalAttrs
  7396. *
  7397. * @return {Object} the style defintion
  7398. */
  7399. this.cls = function(className, traits, additionalAttrs) {
  7400. var attrs = this.style(traits, additionalAttrs);
  7401. return assign(attrs, { 'class': className });
  7402. };
  7403. /**
  7404. * Builds a style definition from a list of traits and an object of additional attributes.
  7405. *
  7406. * @param {Array<string>} traits
  7407. * @param {Object} additionalAttrs
  7408. *
  7409. * @return {Object} the style defintion
  7410. */
  7411. this.style = function(traits, additionalAttrs) {
  7412. if (!isArray$2(traits) && !additionalAttrs) {
  7413. additionalAttrs = traits;
  7414. traits = [];
  7415. }
  7416. var attrs = reduce(traits, function(attrs, t) {
  7417. return assign(attrs, defaultTraits[t] || {});
  7418. }, {});
  7419. return additionalAttrs ? assign(attrs, additionalAttrs) : attrs;
  7420. };
  7421. this.computeStyle = function(custom, traits, defaultStyles) {
  7422. if (!isArray$2(traits)) {
  7423. defaultStyles = traits;
  7424. traits = [];
  7425. }
  7426. return self.style(traits || [], assign({}, defaultStyles, custom || {}));
  7427. };
  7428. }
  7429. var DrawModule = {
  7430. __init__: [ 'defaultRenderer' ],
  7431. defaultRenderer: [ 'type', DefaultRenderer ],
  7432. styles: [ 'type', Styles ]
  7433. };
  7434. /**
  7435. * Failsafe remove an element from a collection
  7436. *
  7437. * @param {Array<Object>} [collection]
  7438. * @param {Object} [element]
  7439. *
  7440. * @return {number} the previous index of the element
  7441. */
  7442. function remove(collection, element) {
  7443. if (!collection || !element) {
  7444. return -1;
  7445. }
  7446. var idx = collection.indexOf(element);
  7447. if (idx !== -1) {
  7448. collection.splice(idx, 1);
  7449. }
  7450. return idx;
  7451. }
  7452. /**
  7453. * Fail save add an element to the given connection, ensuring
  7454. * it does not yet exist.
  7455. *
  7456. * @param {Array<Object>} collection
  7457. * @param {Object} element
  7458. * @param {number} idx
  7459. */
  7460. function add(collection, element, idx) {
  7461. if (!collection || !element) {
  7462. return;
  7463. }
  7464. if (typeof idx !== 'number') {
  7465. idx = -1;
  7466. }
  7467. var currentIdx = collection.indexOf(element);
  7468. if (currentIdx !== -1) {
  7469. if (currentIdx === idx) {
  7470. // nothing to do, position has not changed
  7471. return;
  7472. } else {
  7473. if (idx !== -1) {
  7474. // remove from current position
  7475. collection.splice(currentIdx, 1);
  7476. } else {
  7477. // already exists in collection
  7478. return;
  7479. }
  7480. }
  7481. }
  7482. if (idx !== -1) {
  7483. // insert at specified position
  7484. collection.splice(idx, 0, element);
  7485. } else {
  7486. // push to end
  7487. collection.push(element);
  7488. }
  7489. }
  7490. function round(number, resolution) {
  7491. return Math.round(number * resolution) / resolution;
  7492. }
  7493. function ensurePx(number) {
  7494. return isNumber(number) ? number + 'px' : number;
  7495. }
  7496. function findRoot(element) {
  7497. while (element.parent) {
  7498. element = element.parent;
  7499. }
  7500. return element;
  7501. }
  7502. /**
  7503. * Creates a HTML container element for a SVG element with
  7504. * the given configuration
  7505. *
  7506. * @param {Object} options
  7507. * @return {HTMLElement} the container element
  7508. */
  7509. function createContainer(options) {
  7510. options = assign({}, { width: '100%', height: '100%' }, options);
  7511. var container = options.container || document.body;
  7512. // create a <div> around the svg element with the respective size
  7513. // this way we can always get the correct container size
  7514. // (this is impossible for <svg> elements at the moment)
  7515. var parent = document.createElement('div');
  7516. parent.setAttribute('class', 'djs-container');
  7517. assign$1(parent, {
  7518. position: 'relative',
  7519. overflow: 'hidden',
  7520. width: ensurePx(options.width),
  7521. height: ensurePx(options.height)
  7522. });
  7523. container.appendChild(parent);
  7524. return parent;
  7525. }
  7526. function createGroup(parent, cls, childIndex) {
  7527. var group = create$1('g');
  7528. classes$1(group).add(cls);
  7529. var index = childIndex !== undefined ? childIndex : parent.childNodes.length - 1;
  7530. // must ensure second argument is node or _null_
  7531. // cf. https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
  7532. parent.insertBefore(group, parent.childNodes[index] || null);
  7533. return group;
  7534. }
  7535. var BASE_LAYER = 'base';
  7536. // render plane contents behind utility layers
  7537. var PLANE_LAYER_INDEX = 0;
  7538. var UTILITY_LAYER_INDEX = 1;
  7539. var REQUIRED_MODEL_ATTRS = {
  7540. shape: [ 'x', 'y', 'width', 'height' ],
  7541. connection: [ 'waypoints' ]
  7542. };
  7543. /**
  7544. * The main drawing canvas.
  7545. *
  7546. * @class
  7547. * @constructor
  7548. *
  7549. * @emits Canvas#canvas.init
  7550. *
  7551. * @param {Object} config
  7552. * @param {EventBus} eventBus
  7553. * @param {GraphicsFactory} graphicsFactory
  7554. * @param {ElementRegistry} elementRegistry
  7555. */
  7556. function Canvas(config, eventBus, graphicsFactory, elementRegistry) {
  7557. this._eventBus = eventBus;
  7558. this._elementRegistry = elementRegistry;
  7559. this._graphicsFactory = graphicsFactory;
  7560. this._rootsIdx = 0;
  7561. this._layers = {};
  7562. this._planes = [];
  7563. this._rootElement = null;
  7564. this._init(config || {});
  7565. }
  7566. Canvas.$inject = [
  7567. 'config.canvas',
  7568. 'eventBus',
  7569. 'graphicsFactory',
  7570. 'elementRegistry'
  7571. ];
  7572. /**
  7573. * Creates a <svg> element that is wrapped into a <div>.
  7574. * This way we are always able to correctly figure out the size of the svg element
  7575. * by querying the parent node.
  7576. * (It is not possible to get the size of a svg element cross browser @ 2014-04-01)
  7577. * <div class="djs-container" style="width: {desired-width}, height: {desired-height}">
  7578. * <svg width="100%" height="100%">
  7579. * ...
  7580. * </svg>
  7581. * </div>
  7582. */
  7583. Canvas.prototype._init = function(config) {
  7584. var eventBus = this._eventBus;
  7585. // html container
  7586. var container = this._container = createContainer(config);
  7587. var svg = this._svg = create$1('svg');
  7588. attr$1(svg, { width: '100%', height: '100%' });
  7589. append(container, svg);
  7590. var viewport = this._viewport = createGroup(svg, 'viewport');
  7591. // debounce canvas.viewbox.changed events
  7592. // for smoother diagram interaction
  7593. if (config.deferUpdate !== false) {
  7594. this._viewboxChanged = debounce(bind(this._viewboxChanged, this), 300);
  7595. }
  7596. eventBus.on('diagram.init', function() {
  7597. /**
  7598. * An event indicating that the canvas is ready to be drawn on.
  7599. *
  7600. * @memberOf Canvas
  7601. *
  7602. * @event canvas.init
  7603. *
  7604. * @type {Object}
  7605. * @property {SVGElement} svg the created svg element
  7606. * @property {SVGElement} viewport the direct parent of diagram elements and shapes
  7607. */
  7608. eventBus.fire('canvas.init', {
  7609. svg: svg,
  7610. viewport: viewport
  7611. });
  7612. }, this);
  7613. // reset viewbox on shape changes to
  7614. // recompute the viewbox
  7615. eventBus.on([
  7616. 'shape.added',
  7617. 'connection.added',
  7618. 'shape.removed',
  7619. 'connection.removed',
  7620. 'elements.changed',
  7621. 'root.set'
  7622. ], function() {
  7623. delete this._cachedViewbox;
  7624. }, this);
  7625. eventBus.on('diagram.destroy', 500, this._destroy, this);
  7626. eventBus.on('diagram.clear', 500, this._clear, this);
  7627. };
  7628. Canvas.prototype._destroy = function(emit) {
  7629. this._eventBus.fire('canvas.destroy', {
  7630. svg: this._svg,
  7631. viewport: this._viewport
  7632. });
  7633. var parent = this._container.parentNode;
  7634. if (parent) {
  7635. parent.removeChild(this._container);
  7636. }
  7637. delete this._svg;
  7638. delete this._container;
  7639. delete this._layers;
  7640. delete this._planes;
  7641. delete this._rootElement;
  7642. delete this._viewport;
  7643. };
  7644. Canvas.prototype._clear = function() {
  7645. var self = this;
  7646. var allElements = this._elementRegistry.getAll();
  7647. // remove all elements
  7648. allElements.forEach(function(element) {
  7649. var type = getType(element);
  7650. if (type === 'root') {
  7651. self.removeRootElement(element);
  7652. } else {
  7653. self._removeElement(element, type);
  7654. }
  7655. });
  7656. // remove all planes
  7657. this._planes = [];
  7658. this._rootElement = null;
  7659. // force recomputation of view box
  7660. delete this._cachedViewbox;
  7661. };
  7662. /**
  7663. * Returns the default layer on which
  7664. * all elements are drawn.
  7665. *
  7666. * @returns {SVGElement}
  7667. */
  7668. Canvas.prototype.getDefaultLayer = function() {
  7669. return this.getLayer(BASE_LAYER, PLANE_LAYER_INDEX);
  7670. };
  7671. /**
  7672. * Returns a layer that is used to draw elements
  7673. * or annotations on it.
  7674. *
  7675. * Non-existing layers retrieved through this method
  7676. * will be created. During creation, the optional index
  7677. * may be used to create layers below or above existing layers.
  7678. * A layer with a certain index is always created above all
  7679. * existing layers with the same index.
  7680. *
  7681. * @param {string} name
  7682. * @param {number} index
  7683. *
  7684. * @returns {SVGElement}
  7685. */
  7686. Canvas.prototype.getLayer = function(name, index) {
  7687. if (!name) {
  7688. throw new Error('must specify a name');
  7689. }
  7690. var layer = this._layers[name];
  7691. if (!layer) {
  7692. layer = this._layers[name] = this._createLayer(name, index);
  7693. }
  7694. // throw an error if layer creation / retrival is
  7695. // requested on different index
  7696. if (typeof index !== 'undefined' && layer.index !== index) {
  7697. throw new Error('layer <' + name + '> already created at index <' + index + '>');
  7698. }
  7699. return layer.group;
  7700. };
  7701. /**
  7702. * For a given index, return the number of layers that have a higher index and
  7703. * are visible.
  7704. *
  7705. * This is used to determine the node a layer should be inserted at.
  7706. *
  7707. * @param {Number} index
  7708. * @returns {Number}
  7709. */
  7710. Canvas.prototype._getChildIndex = function(index) {
  7711. return reduce(this._layers, function(childIndex, layer) {
  7712. if (layer.visible && index >= layer.index) {
  7713. childIndex++;
  7714. }
  7715. return childIndex;
  7716. }, 0);
  7717. };
  7718. /**
  7719. * Creates a given layer and returns it.
  7720. *
  7721. * @param {string} name
  7722. * @param {number} [index=0]
  7723. *
  7724. * @return {Object} layer descriptor with { index, group: SVGGroup }
  7725. */
  7726. Canvas.prototype._createLayer = function(name, index) {
  7727. if (typeof index === 'undefined') {
  7728. index = UTILITY_LAYER_INDEX;
  7729. }
  7730. var childIndex = this._getChildIndex(index);
  7731. return {
  7732. group: createGroup(this._viewport, 'layer-' + name, childIndex),
  7733. index: index,
  7734. visible: true
  7735. };
  7736. };
  7737. /**
  7738. * Shows a given layer.
  7739. *
  7740. * @param {String} layer
  7741. * @returns {SVGElement}
  7742. */
  7743. Canvas.prototype.showLayer = function(name) {
  7744. if (!name) {
  7745. throw new Error('must specify a name');
  7746. }
  7747. var layer = this._layers[name];
  7748. if (!layer) {
  7749. throw new Error('layer <' + name + '> does not exist');
  7750. }
  7751. var viewport = this._viewport;
  7752. var group = layer.group;
  7753. var index = layer.index;
  7754. if (layer.visible) {
  7755. return group;
  7756. }
  7757. var childIndex = this._getChildIndex(index);
  7758. viewport.insertBefore(group, viewport.childNodes[childIndex] || null);
  7759. layer.visible = true;
  7760. return group;
  7761. };
  7762. /**
  7763. * Hides a given layer.
  7764. *
  7765. * @param {String} layer
  7766. * @returns {SVGElement}
  7767. */
  7768. Canvas.prototype.hideLayer = function(name) {
  7769. if (!name) {
  7770. throw new Error('must specify a name');
  7771. }
  7772. var layer = this._layers[name];
  7773. if (!layer) {
  7774. throw new Error('layer <' + name + '> does not exist');
  7775. }
  7776. var group = layer.group;
  7777. if (!layer.visible) {
  7778. return group;
  7779. }
  7780. remove$2(group);
  7781. layer.visible = false;
  7782. return group;
  7783. };
  7784. Canvas.prototype._removeLayer = function(name) {
  7785. var layer = this._layers[name];
  7786. if (layer) {
  7787. delete this._layers[name];
  7788. remove$2(layer.group);
  7789. }
  7790. };
  7791. /**
  7792. * Returns the currently active layer. Can be null.
  7793. *
  7794. * @returns {SVGElement|null}
  7795. */
  7796. Canvas.prototype.getActiveLayer = function() {
  7797. var plane = this._findPlaneForRoot(this.getRootElement());
  7798. if (!plane) {
  7799. return null;
  7800. }
  7801. return plane.layer;
  7802. };
  7803. /**
  7804. * Returns the plane which contains the given element.
  7805. *
  7806. * @param {string|djs.model.Base} element
  7807. *
  7808. * @return {djs.model.Base} root for element
  7809. */
  7810. Canvas.prototype.findRoot = function(element) {
  7811. if (typeof element === 'string') {
  7812. element = this._elementRegistry.get(element);
  7813. }
  7814. if (!element) {
  7815. return;
  7816. }
  7817. var plane = this._findPlaneForRoot(
  7818. findRoot(element)
  7819. ) || {};
  7820. return plane.rootElement;
  7821. };
  7822. /**
  7823. * Return a list of all root elements on the diagram.
  7824. *
  7825. * @return {djs.model.Root[]}
  7826. */
  7827. Canvas.prototype.getRootElements = function() {
  7828. return this._planes.map(function(plane) {
  7829. return plane.rootElement;
  7830. });
  7831. };
  7832. Canvas.prototype._findPlaneForRoot = function(rootElement) {
  7833. return find(this._planes, function(plane) {
  7834. return plane.rootElement === rootElement;
  7835. });
  7836. };
  7837. /**
  7838. * Returns the html element that encloses the
  7839. * drawing canvas.
  7840. *
  7841. * @return {DOMNode}
  7842. */
  7843. Canvas.prototype.getContainer = function() {
  7844. return this._container;
  7845. };
  7846. // markers //////////////////////
  7847. Canvas.prototype._updateMarker = function(element, marker, add) {
  7848. var container;
  7849. if (!element.id) {
  7850. element = this._elementRegistry.get(element);
  7851. }
  7852. // we need to access all
  7853. container = this._elementRegistry._elements[element.id];
  7854. if (!container) {
  7855. return;
  7856. }
  7857. forEach$1([ container.gfx, container.secondaryGfx ], function(gfx) {
  7858. if (gfx) {
  7859. // invoke either addClass or removeClass based on mode
  7860. if (add) {
  7861. classes$1(gfx).add(marker);
  7862. } else {
  7863. classes$1(gfx).remove(marker);
  7864. }
  7865. }
  7866. });
  7867. /**
  7868. * An event indicating that a marker has been updated for an element
  7869. *
  7870. * @event element.marker.update
  7871. * @type {Object}
  7872. * @property {djs.model.Element} element the shape
  7873. * @property {Object} gfx the graphical representation of the shape
  7874. * @property {string} marker
  7875. * @property {boolean} add true if the marker was added, false if it got removed
  7876. */
  7877. this._eventBus.fire('element.marker.update', { element: element, gfx: container.gfx, marker: marker, add: !!add });
  7878. };
  7879. /**
  7880. * Adds a marker to an element (basically a css class).
  7881. *
  7882. * Fires the element.marker.update event, making it possible to
  7883. * integrate extension into the marker life-cycle, too.
  7884. *
  7885. * @example
  7886. * canvas.addMarker('foo', 'some-marker');
  7887. *
  7888. * var fooGfx = canvas.getGraphics('foo');
  7889. *
  7890. * fooGfx; // <g class="... some-marker"> ... </g>
  7891. *
  7892. * @param {string|djs.model.Base} element
  7893. * @param {string} marker
  7894. */
  7895. Canvas.prototype.addMarker = function(element, marker) {
  7896. this._updateMarker(element, marker, true);
  7897. };
  7898. /**
  7899. * Remove a marker from an element.
  7900. *
  7901. * Fires the element.marker.update event, making it possible to
  7902. * integrate extension into the marker life-cycle, too.
  7903. *
  7904. * @param {string|djs.model.Base} element
  7905. * @param {string} marker
  7906. */
  7907. Canvas.prototype.removeMarker = function(element, marker) {
  7908. this._updateMarker(element, marker, false);
  7909. };
  7910. /**
  7911. * Check the existence of a marker on element.
  7912. *
  7913. * @param {string|djs.model.Base} element
  7914. * @param {string} marker
  7915. */
  7916. Canvas.prototype.hasMarker = function(element, marker) {
  7917. if (!element.id) {
  7918. element = this._elementRegistry.get(element);
  7919. }
  7920. var gfx = this.getGraphics(element);
  7921. return classes$1(gfx).has(marker);
  7922. };
  7923. /**
  7924. * Toggles a marker on an element.
  7925. *
  7926. * Fires the element.marker.update event, making it possible to
  7927. * integrate extension into the marker life-cycle, too.
  7928. *
  7929. * @param {string|djs.model.Base} element
  7930. * @param {string} marker
  7931. */
  7932. Canvas.prototype.toggleMarker = function(element, marker) {
  7933. if (this.hasMarker(element, marker)) {
  7934. this.removeMarker(element, marker);
  7935. } else {
  7936. this.addMarker(element, marker);
  7937. }
  7938. };
  7939. /**
  7940. * Returns the current root element.
  7941. *
  7942. * Supports two different modes for handling root elements:
  7943. *
  7944. * 1. if no root element has been added before, an implicit root will be added
  7945. * and returned. This is used in applications that don't require explicit
  7946. * root elements.
  7947. *
  7948. * 2. when root elements have been added before calling `getRootElement`,
  7949. * root elements can be null. This is used for applications that want to manage
  7950. * root elements themselves.
  7951. *
  7952. * @returns {Object|djs.model.Root|null} rootElement.
  7953. */
  7954. Canvas.prototype.getRootElement = function() {
  7955. var rootElement = this._rootElement;
  7956. // can return null if root elements are present but none was set yet
  7957. if (rootElement || this._planes.length) {
  7958. return rootElement;
  7959. }
  7960. return this.setRootElement(this.addRootElement(null));
  7961. };
  7962. /**
  7963. * Adds a given root element and returns it.
  7964. *
  7965. * @param {Object|djs.model.Root} rootElement
  7966. *
  7967. * @return {Object|djs.model.Root} rootElement
  7968. */
  7969. Canvas.prototype.addRootElement = function(rootElement) {
  7970. var idx = this._rootsIdx++;
  7971. if (!rootElement) {
  7972. rootElement = {
  7973. id: '__implicitroot_' + idx,
  7974. children: [],
  7975. isImplicit: true
  7976. };
  7977. }
  7978. var layerName = rootElement.layer = 'root-' + idx;
  7979. this._ensureValid('root', rootElement);
  7980. var layer = this.getLayer(layerName, PLANE_LAYER_INDEX);
  7981. this.hideLayer(layerName);
  7982. this._addRoot(rootElement, layer);
  7983. this._planes.push({
  7984. rootElement: rootElement,
  7985. layer: layer
  7986. });
  7987. return rootElement;
  7988. };
  7989. /**
  7990. * Removes a given rootElement and returns it.
  7991. *
  7992. * @param {djs.model.Root|String} rootElement
  7993. *
  7994. * @return {Object|djs.model.Root} rootElement
  7995. */
  7996. Canvas.prototype.removeRootElement = function(rootElement) {
  7997. if (typeof rootElement === 'string') {
  7998. rootElement = this._elementRegistry.get(rootElement);
  7999. }
  8000. var plane = this._findPlaneForRoot(rootElement);
  8001. if (!plane) {
  8002. return;
  8003. }
  8004. // hook up life-cycle events
  8005. this._removeRoot(rootElement);
  8006. // clean up layer
  8007. this._removeLayer(rootElement.layer);
  8008. // clean up plane
  8009. this._planes = this._planes.filter(function(plane) {
  8010. return plane.rootElement !== rootElement;
  8011. });
  8012. // clean up active root
  8013. if (this._rootElement === rootElement) {
  8014. this._rootElement = null;
  8015. }
  8016. return rootElement;
  8017. };
  8018. // root element handling //////////////////////
  8019. /**
  8020. * Sets a given element as the new root element for the canvas
  8021. * and returns the new root element.
  8022. *
  8023. * @param {Object|djs.model.Root} rootElement
  8024. *
  8025. * @return {Object|djs.model.Root} new root element
  8026. */
  8027. Canvas.prototype.setRootElement = function(rootElement, override) {
  8028. if (isDefined(override)) {
  8029. throw new Error('override not supported');
  8030. }
  8031. if (rootElement === this._rootElement) {
  8032. return;
  8033. }
  8034. var plane;
  8035. if (!rootElement) {
  8036. throw new Error('rootElement required');
  8037. }
  8038. plane = this._findPlaneForRoot(rootElement);
  8039. // give set add semantics for backwards compatibility
  8040. if (!plane) {
  8041. rootElement = this.addRootElement(rootElement);
  8042. }
  8043. this._setRoot(rootElement);
  8044. return rootElement;
  8045. };
  8046. Canvas.prototype._removeRoot = function(element) {
  8047. var elementRegistry = this._elementRegistry,
  8048. eventBus = this._eventBus;
  8049. // simulate element remove event sequence
  8050. eventBus.fire('root.remove', { element: element });
  8051. eventBus.fire('root.removed', { element: element });
  8052. elementRegistry.remove(element);
  8053. };
  8054. Canvas.prototype._addRoot = function(element, gfx) {
  8055. var elementRegistry = this._elementRegistry,
  8056. eventBus = this._eventBus;
  8057. // resemble element add event sequence
  8058. eventBus.fire('root.add', { element: element });
  8059. elementRegistry.add(element, gfx);
  8060. eventBus.fire('root.added', { element: element, gfx: gfx });
  8061. };
  8062. Canvas.prototype._setRoot = function(rootElement, layer) {
  8063. var currentRoot = this._rootElement;
  8064. if (currentRoot) {
  8065. // un-associate previous root element <svg>
  8066. this._elementRegistry.updateGraphics(currentRoot, null, true);
  8067. // hide previous layer
  8068. this.hideLayer(currentRoot.layer);
  8069. }
  8070. if (rootElement) {
  8071. if (!layer) {
  8072. layer = this._findPlaneForRoot(rootElement).layer;
  8073. }
  8074. // associate element with <svg>
  8075. this._elementRegistry.updateGraphics(rootElement, this._svg, true);
  8076. // show root layer
  8077. this.showLayer(rootElement.layer);
  8078. }
  8079. this._rootElement = rootElement;
  8080. this._eventBus.fire('root.set', { element: rootElement });
  8081. };
  8082. // add functionality //////////////////////
  8083. Canvas.prototype._ensureValid = function(type, element) {
  8084. if (!element.id) {
  8085. throw new Error('element must have an id');
  8086. }
  8087. if (this._elementRegistry.get(element.id)) {
  8088. throw new Error('element <' + element.id + '> already exists');
  8089. }
  8090. var requiredAttrs = REQUIRED_MODEL_ATTRS[type];
  8091. var valid = every(requiredAttrs, function(attr) {
  8092. return typeof element[attr] !== 'undefined';
  8093. });
  8094. if (!valid) {
  8095. throw new Error(
  8096. 'must supply { ' + requiredAttrs.join(', ') + ' } with ' + type);
  8097. }
  8098. };
  8099. Canvas.prototype._setParent = function(element, parent, parentIndex) {
  8100. add(parent.children, element, parentIndex);
  8101. element.parent = parent;
  8102. };
  8103. /**
  8104. * Adds an element to the canvas.
  8105. *
  8106. * This wires the parent <-> child relationship between the element and
  8107. * a explicitly specified parent or an implicit root element.
  8108. *
  8109. * During add it emits the events
  8110. *
  8111. * * <{type}.add> (element, parent)
  8112. * * <{type}.added> (element, gfx)
  8113. *
  8114. * Extensions may hook into these events to perform their magic.
  8115. *
  8116. * @param {string} type
  8117. * @param {Object|djs.model.Base} element
  8118. * @param {Object|djs.model.Base} [parent]
  8119. * @param {number} [parentIndex]
  8120. *
  8121. * @return {Object|djs.model.Base} the added element
  8122. */
  8123. Canvas.prototype._addElement = function(type, element, parent, parentIndex) {
  8124. parent = parent || this.getRootElement();
  8125. var eventBus = this._eventBus,
  8126. graphicsFactory = this._graphicsFactory;
  8127. this._ensureValid(type, element);
  8128. eventBus.fire(type + '.add', { element: element, parent: parent });
  8129. this._setParent(element, parent, parentIndex);
  8130. // create graphics
  8131. var gfx = graphicsFactory.create(type, element, parentIndex);
  8132. this._elementRegistry.add(element, gfx);
  8133. // update its visual
  8134. graphicsFactory.update(type, element, gfx);
  8135. eventBus.fire(type + '.added', { element: element, gfx: gfx });
  8136. return element;
  8137. };
  8138. /**
  8139. * Adds a shape to the canvas
  8140. *
  8141. * @param {Object|djs.model.Shape} shape to add to the diagram
  8142. * @param {djs.model.Base} [parent]
  8143. * @param {number} [parentIndex]
  8144. *
  8145. * @return {djs.model.Shape} the added shape
  8146. */
  8147. Canvas.prototype.addShape = function(shape, parent, parentIndex) {
  8148. return this._addElement('shape', shape, parent, parentIndex);
  8149. };
  8150. /**
  8151. * Adds a connection to the canvas
  8152. *
  8153. * @param {Object|djs.model.Connection} connection to add to the diagram
  8154. * @param {djs.model.Base} [parent]
  8155. * @param {number} [parentIndex]
  8156. *
  8157. * @return {djs.model.Connection} the added connection
  8158. */
  8159. Canvas.prototype.addConnection = function(connection, parent, parentIndex) {
  8160. return this._addElement('connection', connection, parent, parentIndex);
  8161. };
  8162. /**
  8163. * Internal remove element
  8164. */
  8165. Canvas.prototype._removeElement = function(element, type) {
  8166. var elementRegistry = this._elementRegistry,
  8167. graphicsFactory = this._graphicsFactory,
  8168. eventBus = this._eventBus;
  8169. element = elementRegistry.get(element.id || element);
  8170. if (!element) {
  8171. // element was removed already
  8172. return;
  8173. }
  8174. eventBus.fire(type + '.remove', { element: element });
  8175. graphicsFactory.remove(element);
  8176. // unset parent <-> child relationship
  8177. remove(element.parent && element.parent.children, element);
  8178. element.parent = null;
  8179. eventBus.fire(type + '.removed', { element: element });
  8180. elementRegistry.remove(element);
  8181. return element;
  8182. };
  8183. /**
  8184. * Removes a shape from the canvas
  8185. *
  8186. * @param {string|djs.model.Shape} shape or shape id to be removed
  8187. *
  8188. * @return {djs.model.Shape} the removed shape
  8189. */
  8190. Canvas.prototype.removeShape = function(shape) {
  8191. /**
  8192. * An event indicating that a shape is about to be removed from the canvas.
  8193. *
  8194. * @memberOf Canvas
  8195. *
  8196. * @event shape.remove
  8197. * @type {Object}
  8198. * @property {djs.model.Shape} element the shape descriptor
  8199. * @property {Object} gfx the graphical representation of the shape
  8200. */
  8201. /**
  8202. * An event indicating that a shape has been removed from the canvas.
  8203. *
  8204. * @memberOf Canvas
  8205. *
  8206. * @event shape.removed
  8207. * @type {Object}
  8208. * @property {djs.model.Shape} element the shape descriptor
  8209. * @property {Object} gfx the graphical representation of the shape
  8210. */
  8211. return this._removeElement(shape, 'shape');
  8212. };
  8213. /**
  8214. * Removes a connection from the canvas
  8215. *
  8216. * @param {string|djs.model.Connection} connection or connection id to be removed
  8217. *
  8218. * @return {djs.model.Connection} the removed connection
  8219. */
  8220. Canvas.prototype.removeConnection = function(connection) {
  8221. /**
  8222. * An event indicating that a connection is about to be removed from the canvas.
  8223. *
  8224. * @memberOf Canvas
  8225. *
  8226. * @event connection.remove
  8227. * @type {Object}
  8228. * @property {djs.model.Connection} element the connection descriptor
  8229. * @property {Object} gfx the graphical representation of the connection
  8230. */
  8231. /**
  8232. * An event indicating that a connection has been removed from the canvas.
  8233. *
  8234. * @memberOf Canvas
  8235. *
  8236. * @event connection.removed
  8237. * @type {Object}
  8238. * @property {djs.model.Connection} element the connection descriptor
  8239. * @property {Object} gfx the graphical representation of the connection
  8240. */
  8241. return this._removeElement(connection, 'connection');
  8242. };
  8243. /**
  8244. * Return the graphical object underlaying a certain diagram element
  8245. *
  8246. * @param {string|djs.model.Base} element descriptor of the element
  8247. * @param {boolean} [secondary=false] whether to return the secondary connected element
  8248. *
  8249. * @return {SVGElement}
  8250. */
  8251. Canvas.prototype.getGraphics = function(element, secondary) {
  8252. return this._elementRegistry.getGraphics(element, secondary);
  8253. };
  8254. /**
  8255. * Perform a viewbox update via a given change function.
  8256. *
  8257. * @param {Function} changeFn
  8258. */
  8259. Canvas.prototype._changeViewbox = function(changeFn) {
  8260. // notify others of the upcoming viewbox change
  8261. this._eventBus.fire('canvas.viewbox.changing');
  8262. // perform actual change
  8263. changeFn.apply(this);
  8264. // reset the cached viewbox so that
  8265. // a new get operation on viewbox or zoom
  8266. // triggers a viewbox re-computation
  8267. this._cachedViewbox = null;
  8268. // notify others of the change; this step
  8269. // may or may not be debounced
  8270. this._viewboxChanged();
  8271. };
  8272. Canvas.prototype._viewboxChanged = function() {
  8273. this._eventBus.fire('canvas.viewbox.changed', { viewbox: this.viewbox() });
  8274. };
  8275. /**
  8276. * Gets or sets the view box of the canvas, i.e. the
  8277. * area that is currently displayed.
  8278. *
  8279. * The getter may return a cached viewbox (if it is currently
  8280. * changing). To force a recomputation, pass `false` as the first argument.
  8281. *
  8282. * @example
  8283. *
  8284. * canvas.viewbox({ x: 100, y: 100, width: 500, height: 500 })
  8285. *
  8286. * // sets the visible area of the diagram to (100|100) -> (600|100)
  8287. * // and and scales it according to the diagram width
  8288. *
  8289. * var viewbox = canvas.viewbox(); // pass `false` to force recomputing the box.
  8290. *
  8291. * console.log(viewbox);
  8292. * // {
  8293. * // inner: Dimensions,
  8294. * // outer: Dimensions,
  8295. * // scale,
  8296. * // x, y,
  8297. * // width, height
  8298. * // }
  8299. *
  8300. * // if the current diagram is zoomed and scrolled, you may reset it to the
  8301. * // default zoom via this method, too:
  8302. *
  8303. * var zoomedAndScrolledViewbox = canvas.viewbox();
  8304. *
  8305. * canvas.viewbox({
  8306. * x: 0,
  8307. * y: 0,
  8308. * width: zoomedAndScrolledViewbox.outer.width,
  8309. * height: zoomedAndScrolledViewbox.outer.height
  8310. * });
  8311. *
  8312. * @param {Object} [box] the new view box to set
  8313. * @param {number} box.x the top left X coordinate of the canvas visible in view box
  8314. * @param {number} box.y the top left Y coordinate of the canvas visible in view box
  8315. * @param {number} box.width the visible width
  8316. * @param {number} box.height
  8317. *
  8318. * @return {Object} the current view box
  8319. */
  8320. Canvas.prototype.viewbox = function(box) {
  8321. if (box === undefined && this._cachedViewbox) {
  8322. return this._cachedViewbox;
  8323. }
  8324. var viewport = this._viewport,
  8325. innerBox,
  8326. outerBox = this.getSize(),
  8327. matrix,
  8328. activeLayer,
  8329. transform,
  8330. scale,
  8331. x, y;
  8332. if (!box) {
  8333. // compute the inner box based on the
  8334. // diagrams active layer. This allows us to exclude
  8335. // external components, such as overlays
  8336. activeLayer = this._rootElement ? this.getActiveLayer() : null;
  8337. innerBox = activeLayer && activeLayer.getBBox() || {};
  8338. transform = transform$1(viewport);
  8339. matrix = transform ? transform.matrix : createMatrix();
  8340. scale = round(matrix.a, 1000);
  8341. x = round(-matrix.e || 0, 1000);
  8342. y = round(-matrix.f || 0, 1000);
  8343. box = this._cachedViewbox = {
  8344. x: x ? x / scale : 0,
  8345. y: y ? y / scale : 0,
  8346. width: outerBox.width / scale,
  8347. height: outerBox.height / scale,
  8348. scale: scale,
  8349. inner: {
  8350. width: innerBox.width || 0,
  8351. height: innerBox.height || 0,
  8352. x: innerBox.x || 0,
  8353. y: innerBox.y || 0
  8354. },
  8355. outer: outerBox
  8356. };
  8357. return box;
  8358. } else {
  8359. this._changeViewbox(function() {
  8360. scale = Math.min(outerBox.width / box.width, outerBox.height / box.height);
  8361. var matrix = this._svg.createSVGMatrix()
  8362. .scale(scale)
  8363. .translate(-box.x, -box.y);
  8364. transform$1(viewport, matrix);
  8365. });
  8366. }
  8367. return box;
  8368. };
  8369. /**
  8370. * Gets or sets the scroll of the canvas.
  8371. *
  8372. * @param {Object} [delta] the new scroll to apply.
  8373. *
  8374. * @param {number} [delta.dx]
  8375. * @param {number} [delta.dy]
  8376. */
  8377. Canvas.prototype.scroll = function(delta) {
  8378. var node = this._viewport;
  8379. var matrix = node.getCTM();
  8380. if (delta) {
  8381. this._changeViewbox(function() {
  8382. delta = assign({ dx: 0, dy: 0 }, delta || {});
  8383. matrix = this._svg.createSVGMatrix().translate(delta.dx, delta.dy).multiply(matrix);
  8384. setCTM(node, matrix);
  8385. });
  8386. }
  8387. return { x: matrix.e, y: matrix.f };
  8388. };
  8389. /**
  8390. * Scrolls the viewbox to contain the given element.
  8391. * Optionally specify a padding to be applied to the edges.
  8392. *
  8393. * @param {Object|String} [element] the element to scroll to.
  8394. * @param {Object|Number} [padding=100] the padding to be applied. Can also specify top, bottom, left and right.
  8395. *
  8396. */
  8397. Canvas.prototype.scrollToElement = function(element, padding) {
  8398. var defaultPadding = 100;
  8399. if (typeof element === 'string') {
  8400. element = this._elementRegistry.get(element);
  8401. }
  8402. // set to correct rootElement
  8403. var rootElement = this.findRoot(element);
  8404. if (rootElement !== this.getRootElement()) {
  8405. this.setRootElement(rootElement);
  8406. }
  8407. if (!padding) {
  8408. padding = {};
  8409. }
  8410. if (typeof padding === 'number') {
  8411. defaultPadding = padding;
  8412. }
  8413. padding = {
  8414. top: padding.top || defaultPadding,
  8415. right: padding.right || defaultPadding,
  8416. bottom: padding.bottom || defaultPadding,
  8417. left: padding.left || defaultPadding
  8418. };
  8419. var elementBounds = getBBox(element),
  8420. elementTrbl = asTRBL(elementBounds),
  8421. viewboxBounds = this.viewbox(),
  8422. zoom = this.zoom(),
  8423. dx, dy;
  8424. // shrink viewboxBounds with padding
  8425. viewboxBounds.y += padding.top / zoom;
  8426. viewboxBounds.x += padding.left / zoom;
  8427. viewboxBounds.width -= (padding.right + padding.left) / zoom;
  8428. viewboxBounds.height -= (padding.bottom + padding.top) / zoom;
  8429. var viewboxTrbl = asTRBL(viewboxBounds);
  8430. var canFit = elementBounds.width < viewboxBounds.width && elementBounds.height < viewboxBounds.height;
  8431. if (!canFit) {
  8432. // top-left when element can't fit
  8433. dx = elementBounds.x - viewboxBounds.x;
  8434. dy = elementBounds.y - viewboxBounds.y;
  8435. } else {
  8436. var dRight = Math.max(0, elementTrbl.right - viewboxTrbl.right),
  8437. dLeft = Math.min(0, elementTrbl.left - viewboxTrbl.left),
  8438. dBottom = Math.max(0, elementTrbl.bottom - viewboxTrbl.bottom),
  8439. dTop = Math.min(0, elementTrbl.top - viewboxTrbl.top);
  8440. dx = dRight || dLeft;
  8441. dy = dBottom || dTop;
  8442. }
  8443. this.scroll({ dx: -dx * zoom, dy: -dy * zoom });
  8444. };
  8445. /**
  8446. * Gets or sets the current zoom of the canvas, optionally zooming
  8447. * to the specified position.
  8448. *
  8449. * The getter may return a cached zoom level. Call it with `false` as
  8450. * the first argument to force recomputation of the current level.
  8451. *
  8452. * @param {string|number} [newScale] the new zoom level, either a number, i.e. 0.9,
  8453. * or `fit-viewport` to adjust the size to fit the current viewport
  8454. * @param {string|Point} [center] the reference point { x: .., y: ..} to zoom to, 'auto' to zoom into mid or null
  8455. *
  8456. * @return {number} the current scale
  8457. */
  8458. Canvas.prototype.zoom = function(newScale, center) {
  8459. if (!newScale) {
  8460. return this.viewbox(newScale).scale;
  8461. }
  8462. if (newScale === 'fit-viewport') {
  8463. return this._fitViewport(center);
  8464. }
  8465. var outer,
  8466. matrix;
  8467. this._changeViewbox(function() {
  8468. if (typeof center !== 'object') {
  8469. outer = this.viewbox().outer;
  8470. center = {
  8471. x: outer.width / 2,
  8472. y: outer.height / 2
  8473. };
  8474. }
  8475. matrix = this._setZoom(newScale, center);
  8476. });
  8477. return round(matrix.a, 1000);
  8478. };
  8479. function setCTM(node, m) {
  8480. var mstr = 'matrix(' + m.a + ',' + m.b + ',' + m.c + ',' + m.d + ',' + m.e + ',' + m.f + ')';
  8481. node.setAttribute('transform', mstr);
  8482. }
  8483. Canvas.prototype._fitViewport = function(center) {
  8484. var vbox = this.viewbox(),
  8485. outer = vbox.outer,
  8486. inner = vbox.inner,
  8487. newScale,
  8488. newViewbox;
  8489. // display the complete diagram without zooming in.
  8490. // instead of relying on internal zoom, we perform a
  8491. // hard reset on the canvas viewbox to realize this
  8492. //
  8493. // if diagram does not need to be zoomed in, we focus it around
  8494. // the diagram origin instead
  8495. if (inner.x >= 0 &&
  8496. inner.y >= 0 &&
  8497. inner.x + inner.width <= outer.width &&
  8498. inner.y + inner.height <= outer.height &&
  8499. !center) {
  8500. newViewbox = {
  8501. x: 0,
  8502. y: 0,
  8503. width: Math.max(inner.width + inner.x, outer.width),
  8504. height: Math.max(inner.height + inner.y, outer.height)
  8505. };
  8506. } else {
  8507. newScale = Math.min(1, outer.width / inner.width, outer.height / inner.height);
  8508. newViewbox = {
  8509. x: inner.x + (center ? inner.width / 2 - outer.width / newScale / 2 : 0),
  8510. y: inner.y + (center ? inner.height / 2 - outer.height / newScale / 2 : 0),
  8511. width: outer.width / newScale,
  8512. height: outer.height / newScale
  8513. };
  8514. }
  8515. this.viewbox(newViewbox);
  8516. return this.viewbox(false).scale;
  8517. };
  8518. Canvas.prototype._setZoom = function(scale, center) {
  8519. var svg = this._svg,
  8520. viewport = this._viewport;
  8521. var matrix = svg.createSVGMatrix();
  8522. var point = svg.createSVGPoint();
  8523. var centerPoint,
  8524. originalPoint,
  8525. currentMatrix,
  8526. scaleMatrix,
  8527. newMatrix;
  8528. currentMatrix = viewport.getCTM();
  8529. var currentScale = currentMatrix.a;
  8530. if (center) {
  8531. centerPoint = assign(point, center);
  8532. // revert applied viewport transformations
  8533. originalPoint = centerPoint.matrixTransform(currentMatrix.inverse());
  8534. // create scale matrix
  8535. scaleMatrix = matrix
  8536. .translate(originalPoint.x, originalPoint.y)
  8537. .scale(1 / currentScale * scale)
  8538. .translate(-originalPoint.x, -originalPoint.y);
  8539. newMatrix = currentMatrix.multiply(scaleMatrix);
  8540. } else {
  8541. newMatrix = matrix.scale(scale);
  8542. }
  8543. setCTM(this._viewport, newMatrix);
  8544. return newMatrix;
  8545. };
  8546. /**
  8547. * Returns the size of the canvas
  8548. *
  8549. * @return {Dimensions}
  8550. */
  8551. Canvas.prototype.getSize = function() {
  8552. return {
  8553. width: this._container.clientWidth,
  8554. height: this._container.clientHeight
  8555. };
  8556. };
  8557. /**
  8558. * Return the absolute bounding box for the given element
  8559. *
  8560. * The absolute bounding box may be used to display overlays in the
  8561. * callers (browser) coordinate system rather than the zoomed in/out
  8562. * canvas coordinates.
  8563. *
  8564. * @param {ElementDescriptor} element
  8565. * @return {Bounds} the absolute bounding box
  8566. */
  8567. Canvas.prototype.getAbsoluteBBox = function(element) {
  8568. var vbox = this.viewbox();
  8569. var bbox;
  8570. // connection
  8571. // use svg bbox
  8572. if (element.waypoints) {
  8573. var gfx = this.getGraphics(element);
  8574. bbox = gfx.getBBox();
  8575. }
  8576. // shapes
  8577. // use data
  8578. else {
  8579. bbox = element;
  8580. }
  8581. var x = bbox.x * vbox.scale - vbox.x * vbox.scale;
  8582. var y = bbox.y * vbox.scale - vbox.y * vbox.scale;
  8583. var width = bbox.width * vbox.scale;
  8584. var height = bbox.height * vbox.scale;
  8585. return {
  8586. x: x,
  8587. y: y,
  8588. width: width,
  8589. height: height
  8590. };
  8591. };
  8592. /**
  8593. * Fires an event in order other modules can react to the
  8594. * canvas resizing
  8595. */
  8596. Canvas.prototype.resized = function() {
  8597. // force recomputation of view box
  8598. delete this._cachedViewbox;
  8599. this._eventBus.fire('canvas.resized');
  8600. };
  8601. var ELEMENT_ID = 'data-element-id';
  8602. /**
  8603. * @class
  8604. *
  8605. * A registry that keeps track of all shapes in the diagram.
  8606. */
  8607. function ElementRegistry(eventBus) {
  8608. this._elements = {};
  8609. this._eventBus = eventBus;
  8610. }
  8611. ElementRegistry.$inject = [ 'eventBus' ];
  8612. /**
  8613. * Register a pair of (element, gfx, (secondaryGfx)).
  8614. *
  8615. * @param {djs.model.Base} element
  8616. * @param {SVGElement} gfx
  8617. * @param {SVGElement} [secondaryGfx] optional other element to register, too
  8618. */
  8619. ElementRegistry.prototype.add = function(element, gfx, secondaryGfx) {
  8620. var id = element.id;
  8621. this._validateId(id);
  8622. // associate dom node with element
  8623. attr$1(gfx, ELEMENT_ID, id);
  8624. if (secondaryGfx) {
  8625. attr$1(secondaryGfx, ELEMENT_ID, id);
  8626. }
  8627. this._elements[id] = { element: element, gfx: gfx, secondaryGfx: secondaryGfx };
  8628. };
  8629. /**
  8630. * Removes an element from the registry.
  8631. *
  8632. * @param {djs.model.Base} element
  8633. */
  8634. ElementRegistry.prototype.remove = function(element) {
  8635. var elements = this._elements,
  8636. id = element.id || element,
  8637. container = id && elements[id];
  8638. if (container) {
  8639. // unset element id on gfx
  8640. attr$1(container.gfx, ELEMENT_ID, '');
  8641. if (container.secondaryGfx) {
  8642. attr$1(container.secondaryGfx, ELEMENT_ID, '');
  8643. }
  8644. delete elements[id];
  8645. }
  8646. };
  8647. /**
  8648. * Update the id of an element
  8649. *
  8650. * @param {djs.model.Base} element
  8651. * @param {string} newId
  8652. */
  8653. ElementRegistry.prototype.updateId = function(element, newId) {
  8654. this._validateId(newId);
  8655. if (typeof element === 'string') {
  8656. element = this.get(element);
  8657. }
  8658. this._eventBus.fire('element.updateId', {
  8659. element: element,
  8660. newId: newId
  8661. });
  8662. var gfx = this.getGraphics(element),
  8663. secondaryGfx = this.getGraphics(element, true);
  8664. this.remove(element);
  8665. element.id = newId;
  8666. this.add(element, gfx, secondaryGfx);
  8667. };
  8668. /**
  8669. * Update the graphics of an element
  8670. *
  8671. * @param {djs.model.Base} element
  8672. * @param {SVGElement} gfx
  8673. * @param {boolean} [secondary=false] whether to update the secondary connected element
  8674. */
  8675. ElementRegistry.prototype.updateGraphics = function(filter, gfx, secondary) {
  8676. var id = filter.id || filter;
  8677. var container = this._elements[id];
  8678. if (secondary) {
  8679. container.secondaryGfx = gfx;
  8680. } else {
  8681. container.gfx = gfx;
  8682. }
  8683. if (gfx) {
  8684. attr$1(gfx, ELEMENT_ID, id);
  8685. }
  8686. return gfx;
  8687. };
  8688. /**
  8689. * Return the model element for a given id or graphics.
  8690. *
  8691. * @example
  8692. *
  8693. * elementRegistry.get('SomeElementId_1');
  8694. * elementRegistry.get(gfx);
  8695. *
  8696. *
  8697. * @param {string|SVGElement} filter for selecting the element
  8698. *
  8699. * @return {djs.model.Base}
  8700. */
  8701. ElementRegistry.prototype.get = function(filter) {
  8702. var id;
  8703. if (typeof filter === 'string') {
  8704. id = filter;
  8705. } else {
  8706. id = filter && attr$1(filter, ELEMENT_ID);
  8707. }
  8708. var container = this._elements[id];
  8709. return container && container.element;
  8710. };
  8711. /**
  8712. * Return all elements that match a given filter function.
  8713. *
  8714. * @param {Function} fn
  8715. *
  8716. * @return {Array<djs.model.Base>}
  8717. */
  8718. ElementRegistry.prototype.filter = function(fn) {
  8719. var filtered = [];
  8720. this.forEach(function(element, gfx) {
  8721. if (fn(element, gfx)) {
  8722. filtered.push(element);
  8723. }
  8724. });
  8725. return filtered;
  8726. };
  8727. /**
  8728. * Return the first element that satisfies the provided testing function.
  8729. *
  8730. * @param {Function} fn
  8731. *
  8732. * @return {djs.model.Base}
  8733. */
  8734. ElementRegistry.prototype.find = function(fn) {
  8735. var map = this._elements,
  8736. keys = Object.keys(map);
  8737. for (var i = 0; i < keys.length; i++) {
  8738. var id = keys[i],
  8739. container = map[id],
  8740. element = container.element,
  8741. gfx = container.gfx;
  8742. if (fn(element, gfx)) {
  8743. return element;
  8744. }
  8745. }
  8746. };
  8747. /**
  8748. * Return all rendered model elements.
  8749. *
  8750. * @return {Array<djs.model.Base>}
  8751. */
  8752. ElementRegistry.prototype.getAll = function() {
  8753. return this.filter(function(e) { return e; });
  8754. };
  8755. /**
  8756. * Iterate over all diagram elements.
  8757. *
  8758. * @param {Function} fn
  8759. */
  8760. ElementRegistry.prototype.forEach = function(fn) {
  8761. var map = this._elements;
  8762. Object.keys(map).forEach(function(id) {
  8763. var container = map[id],
  8764. element = container.element,
  8765. gfx = container.gfx;
  8766. return fn(element, gfx);
  8767. });
  8768. };
  8769. /**
  8770. * Return the graphical representation of an element or its id.
  8771. *
  8772. * @example
  8773. * elementRegistry.getGraphics('SomeElementId_1');
  8774. * elementRegistry.getGraphics(rootElement); // <g ...>
  8775. *
  8776. * elementRegistry.getGraphics(rootElement, true); // <svg ...>
  8777. *
  8778. *
  8779. * @param {string|djs.model.Base} filter
  8780. * @param {boolean} [secondary=false] whether to return the secondary connected element
  8781. *
  8782. * @return {SVGElement}
  8783. */
  8784. ElementRegistry.prototype.getGraphics = function(filter, secondary) {
  8785. var id = filter.id || filter;
  8786. var container = this._elements[id];
  8787. return container && (secondary ? container.secondaryGfx : container.gfx);
  8788. };
  8789. /**
  8790. * Validate the suitability of the given id and signals a problem
  8791. * with an exception.
  8792. *
  8793. * @param {string} id
  8794. *
  8795. * @throws {Error} if id is empty or already assigned
  8796. */
  8797. ElementRegistry.prototype._validateId = function(id) {
  8798. if (!id) {
  8799. throw new Error('element must have an id');
  8800. }
  8801. if (this._elements[id]) {
  8802. throw new Error('element with id ' + id + ' already added');
  8803. }
  8804. };
  8805. var objectRefs = {exports: {}};
  8806. var collection = {};
  8807. /**
  8808. * An empty collection stub. Use {@link RefsCollection.extend} to extend a
  8809. * collection with ref semantics.
  8810. *
  8811. * @class RefsCollection
  8812. */
  8813. /**
  8814. * Extends a collection with {@link Refs} aware methods
  8815. *
  8816. * @memberof RefsCollection
  8817. * @static
  8818. *
  8819. * @param {Array<Object>} collection
  8820. * @param {Refs} refs instance
  8821. * @param {Object} property represented by the collection
  8822. * @param {Object} target object the collection is attached to
  8823. *
  8824. * @return {RefsCollection<Object>} the extended array
  8825. */
  8826. function extend(collection, refs, property, target) {
  8827. var inverseProperty = property.inverse;
  8828. /**
  8829. * Removes the given element from the array and returns it.
  8830. *
  8831. * @method RefsCollection#remove
  8832. *
  8833. * @param {Object} element the element to remove
  8834. */
  8835. Object.defineProperty(collection, 'remove', {
  8836. value: function(element) {
  8837. var idx = this.indexOf(element);
  8838. if (idx !== -1) {
  8839. this.splice(idx, 1);
  8840. // unset inverse
  8841. refs.unset(element, inverseProperty, target);
  8842. }
  8843. return element;
  8844. }
  8845. });
  8846. /**
  8847. * Returns true if the collection contains the given element
  8848. *
  8849. * @method RefsCollection#contains
  8850. *
  8851. * @param {Object} element the element to check for
  8852. */
  8853. Object.defineProperty(collection, 'contains', {
  8854. value: function(element) {
  8855. return this.indexOf(element) !== -1;
  8856. }
  8857. });
  8858. /**
  8859. * Adds an element to the array, unless it exists already (set semantics).
  8860. *
  8861. * @method RefsCollection#add
  8862. *
  8863. * @param {Object} element the element to add
  8864. * @param {Number} optional index to add element to
  8865. * (possibly moving other elements around)
  8866. */
  8867. Object.defineProperty(collection, 'add', {
  8868. value: function(element, idx) {
  8869. var currentIdx = this.indexOf(element);
  8870. if (typeof idx === 'undefined') {
  8871. if (currentIdx !== -1) {
  8872. // element already in collection (!)
  8873. return;
  8874. }
  8875. // add to end of array, as no idx is specified
  8876. idx = this.length;
  8877. }
  8878. // handle already in collection
  8879. if (currentIdx !== -1) {
  8880. // remove element from currentIdx
  8881. this.splice(currentIdx, 1);
  8882. }
  8883. // add element at idx
  8884. this.splice(idx, 0, element);
  8885. if (currentIdx === -1) {
  8886. // set inverse, unless element was
  8887. // in collection already
  8888. refs.set(element, inverseProperty, target);
  8889. }
  8890. }
  8891. });
  8892. // a simple marker, identifying this element
  8893. // as being a refs collection
  8894. Object.defineProperty(collection, '__refs_collection', {
  8895. value: true
  8896. });
  8897. return collection;
  8898. }
  8899. function isExtended(collection) {
  8900. return collection.__refs_collection === true;
  8901. }
  8902. collection.extend = extend;
  8903. collection.isExtended = isExtended;
  8904. var Collection = collection;
  8905. function hasOwnProperty$1(e, property) {
  8906. return Object.prototype.hasOwnProperty.call(e, property.name || property);
  8907. }
  8908. function defineCollectionProperty(ref, property, target) {
  8909. var collection = Collection.extend(target[property.name] || [], ref, property, target);
  8910. Object.defineProperty(target, property.name, {
  8911. enumerable: property.enumerable,
  8912. value: collection
  8913. });
  8914. if (collection.length) {
  8915. collection.forEach(function(o) {
  8916. ref.set(o, property.inverse, target);
  8917. });
  8918. }
  8919. }
  8920. function defineProperty$1(ref, property, target) {
  8921. var inverseProperty = property.inverse;
  8922. var _value = target[property.name];
  8923. Object.defineProperty(target, property.name, {
  8924. configurable: property.configurable,
  8925. enumerable: property.enumerable,
  8926. get: function() {
  8927. return _value;
  8928. },
  8929. set: function(value) {
  8930. // return if we already performed all changes
  8931. if (value === _value) {
  8932. return;
  8933. }
  8934. var old = _value;
  8935. // temporary set null
  8936. _value = null;
  8937. if (old) {
  8938. ref.unset(old, inverseProperty, target);
  8939. }
  8940. // set new value
  8941. _value = value;
  8942. // set inverse value
  8943. ref.set(_value, inverseProperty, target);
  8944. }
  8945. });
  8946. }
  8947. /**
  8948. * Creates a new references object defining two inversly related
  8949. * attribute descriptors a and b.
  8950. *
  8951. * <p>
  8952. * When bound to an object using {@link Refs#bind} the references
  8953. * get activated and ensure that add and remove operations are applied
  8954. * reversely, too.
  8955. * </p>
  8956. *
  8957. * <p>
  8958. * For attributes represented as collections {@link Refs} provides the
  8959. * {@link RefsCollection#add}, {@link RefsCollection#remove} and {@link RefsCollection#contains} extensions
  8960. * that must be used to properly hook into the inverse change mechanism.
  8961. * </p>
  8962. *
  8963. * @class Refs
  8964. *
  8965. * @classdesc A bi-directional reference between two attributes.
  8966. *
  8967. * @param {Refs.AttributeDescriptor} a property descriptor
  8968. * @param {Refs.AttributeDescriptor} b property descriptor
  8969. *
  8970. * @example
  8971. *
  8972. * var refs = Refs({ name: 'wheels', collection: true, enumerable: true }, { name: 'car' });
  8973. *
  8974. * var car = { name: 'toyota' };
  8975. * var wheels = [{ pos: 'front-left' }, { pos: 'front-right' }];
  8976. *
  8977. * refs.bind(car, 'wheels');
  8978. *
  8979. * car.wheels // []
  8980. * car.wheels.add(wheels[0]);
  8981. * car.wheels.add(wheels[1]);
  8982. *
  8983. * car.wheels // [{ pos: 'front-left' }, { pos: 'front-right' }]
  8984. *
  8985. * wheels[0].car // { name: 'toyota' };
  8986. * car.wheels.remove(wheels[0]);
  8987. *
  8988. * wheels[0].car // undefined
  8989. */
  8990. function Refs$1(a, b) {
  8991. if (!(this instanceof Refs$1)) {
  8992. return new Refs$1(a, b);
  8993. }
  8994. // link
  8995. a.inverse = b;
  8996. b.inverse = a;
  8997. this.props = {};
  8998. this.props[a.name] = a;
  8999. this.props[b.name] = b;
  9000. }
  9001. /**
  9002. * Binds one side of a bi-directional reference to a
  9003. * target object.
  9004. *
  9005. * @memberOf Refs
  9006. *
  9007. * @param {Object} target
  9008. * @param {String} property
  9009. */
  9010. Refs$1.prototype.bind = function(target, property) {
  9011. if (typeof property === 'string') {
  9012. if (!this.props[property]) {
  9013. throw new Error('no property <' + property + '> in ref');
  9014. }
  9015. property = this.props[property];
  9016. }
  9017. if (property.collection) {
  9018. defineCollectionProperty(this, property, target);
  9019. } else {
  9020. defineProperty$1(this, property, target);
  9021. }
  9022. };
  9023. Refs$1.prototype.ensureRefsCollection = function(target, property) {
  9024. var collection = target[property.name];
  9025. if (!Collection.isExtended(collection)) {
  9026. defineCollectionProperty(this, property, target);
  9027. }
  9028. return collection;
  9029. };
  9030. Refs$1.prototype.ensureBound = function(target, property) {
  9031. if (!hasOwnProperty$1(target, property)) {
  9032. this.bind(target, property);
  9033. }
  9034. };
  9035. Refs$1.prototype.unset = function(target, property, value) {
  9036. if (target) {
  9037. this.ensureBound(target, property);
  9038. if (property.collection) {
  9039. this.ensureRefsCollection(target, property).remove(value);
  9040. } else {
  9041. target[property.name] = undefined;
  9042. }
  9043. }
  9044. };
  9045. Refs$1.prototype.set = function(target, property, value) {
  9046. if (target) {
  9047. this.ensureBound(target, property);
  9048. if (property.collection) {
  9049. this.ensureRefsCollection(target, property).add(value);
  9050. } else {
  9051. target[property.name] = value;
  9052. }
  9053. }
  9054. };
  9055. var refs = Refs$1;
  9056. objectRefs.exports = refs;
  9057. objectRefs.exports.Collection = collection;
  9058. var Refs = objectRefs.exports;
  9059. var parentRefs = new Refs({ name: 'children', enumerable: true, collection: true }, { name: 'parent' }),
  9060. labelRefs = new Refs({ name: 'labels', enumerable: true, collection: true }, { name: 'labelTarget' }),
  9061. attacherRefs = new Refs({ name: 'attachers', collection: true }, { name: 'host' }),
  9062. outgoingRefs = new Refs({ name: 'outgoing', collection: true }, { name: 'source' }),
  9063. incomingRefs = new Refs({ name: 'incoming', collection: true }, { name: 'target' });
  9064. /**
  9065. * @namespace djs.model
  9066. */
  9067. /**
  9068. * @memberOf djs.model
  9069. */
  9070. /**
  9071. * The basic graphical representation
  9072. *
  9073. * @class
  9074. *
  9075. * @abstract
  9076. */
  9077. function Base$1() {
  9078. /**
  9079. * The object that backs up the shape
  9080. *
  9081. * @name Base#businessObject
  9082. * @type Object
  9083. */
  9084. Object.defineProperty(this, 'businessObject', {
  9085. writable: true
  9086. });
  9087. /**
  9088. * Single label support, will mapped to multi label array
  9089. *
  9090. * @name Base#label
  9091. * @type Object
  9092. */
  9093. Object.defineProperty(this, 'label', {
  9094. get: function() {
  9095. return this.labels[0];
  9096. },
  9097. set: function(newLabel) {
  9098. var label = this.label,
  9099. labels = this.labels;
  9100. if (!newLabel && label) {
  9101. labels.remove(label);
  9102. } else {
  9103. labels.add(newLabel, 0);
  9104. }
  9105. }
  9106. });
  9107. /**
  9108. * The parent shape
  9109. *
  9110. * @name Base#parent
  9111. * @type Shape
  9112. */
  9113. parentRefs.bind(this, 'parent');
  9114. /**
  9115. * The list of labels
  9116. *
  9117. * @name Base#labels
  9118. * @type Label
  9119. */
  9120. labelRefs.bind(this, 'labels');
  9121. /**
  9122. * The list of outgoing connections
  9123. *
  9124. * @name Base#outgoing
  9125. * @type Array<Connection>
  9126. */
  9127. outgoingRefs.bind(this, 'outgoing');
  9128. /**
  9129. * The list of incoming connections
  9130. *
  9131. * @name Base#incoming
  9132. * @type Array<Connection>
  9133. */
  9134. incomingRefs.bind(this, 'incoming');
  9135. }
  9136. /**
  9137. * A graphical object
  9138. *
  9139. * @class
  9140. * @constructor
  9141. *
  9142. * @extends Base
  9143. */
  9144. function Shape() {
  9145. Base$1.call(this);
  9146. /**
  9147. * Indicates frame shapes
  9148. *
  9149. * @name Shape#isFrame
  9150. * @type boolean
  9151. */
  9152. /**
  9153. * The list of children
  9154. *
  9155. * @name Shape#children
  9156. * @type Array<Base>
  9157. */
  9158. parentRefs.bind(this, 'children');
  9159. /**
  9160. * @name Shape#host
  9161. * @type Shape
  9162. */
  9163. attacherRefs.bind(this, 'host');
  9164. /**
  9165. * @name Shape#attachers
  9166. * @type Shape
  9167. */
  9168. attacherRefs.bind(this, 'attachers');
  9169. }
  9170. e(Shape, Base$1);
  9171. /**
  9172. * A root graphical object
  9173. *
  9174. * @class
  9175. * @constructor
  9176. *
  9177. * @extends Shape
  9178. */
  9179. function Root() {
  9180. Shape.call(this);
  9181. }
  9182. e(Root, Shape);
  9183. /**
  9184. * A label for an element
  9185. *
  9186. * @class
  9187. * @constructor
  9188. *
  9189. * @extends Shape
  9190. */
  9191. function Label() {
  9192. Shape.call(this);
  9193. /**
  9194. * The labeled element
  9195. *
  9196. * @name Label#labelTarget
  9197. * @type Base
  9198. */
  9199. labelRefs.bind(this, 'labelTarget');
  9200. }
  9201. e(Label, Shape);
  9202. /**
  9203. * A connection between two elements
  9204. *
  9205. * @class
  9206. * @constructor
  9207. *
  9208. * @extends Base
  9209. */
  9210. function Connection() {
  9211. Base$1.call(this);
  9212. /**
  9213. * The element this connection originates from
  9214. *
  9215. * @name Connection#source
  9216. * @type Base
  9217. */
  9218. outgoingRefs.bind(this, 'source');
  9219. /**
  9220. * The element this connection points to
  9221. *
  9222. * @name Connection#target
  9223. * @type Base
  9224. */
  9225. incomingRefs.bind(this, 'target');
  9226. }
  9227. e(Connection, Base$1);
  9228. var types$6 = {
  9229. connection: Connection,
  9230. shape: Shape,
  9231. label: Label,
  9232. root: Root
  9233. };
  9234. /**
  9235. * Creates a new model element of the specified type
  9236. *
  9237. * @method create
  9238. *
  9239. * @example
  9240. *
  9241. * var shape1 = Model.create('shape', { x: 10, y: 10, width: 100, height: 100 });
  9242. * var shape2 = Model.create('shape', { x: 210, y: 210, width: 100, height: 100 });
  9243. *
  9244. * var connection = Model.create('connection', { waypoints: [ { x: 110, y: 55 }, {x: 210, y: 55 } ] });
  9245. *
  9246. * @param {string} type lower-cased model name
  9247. * @param {Object} attrs attributes to initialize the new model instance with
  9248. *
  9249. * @return {Base} the new model instance
  9250. */
  9251. function create(type, attrs) {
  9252. var Type = types$6[type];
  9253. if (!Type) {
  9254. throw new Error('unknown type: <' + type + '>');
  9255. }
  9256. return assign(new Type(), attrs);
  9257. }
  9258. /**
  9259. * A factory for diagram-js shapes
  9260. */
  9261. function ElementFactory() {
  9262. this._uid = 12;
  9263. }
  9264. ElementFactory.prototype.createRoot = function(attrs) {
  9265. return this.create('root', attrs);
  9266. };
  9267. ElementFactory.prototype.createLabel = function(attrs) {
  9268. return this.create('label', attrs);
  9269. };
  9270. ElementFactory.prototype.createShape = function(attrs) {
  9271. return this.create('shape', attrs);
  9272. };
  9273. ElementFactory.prototype.createConnection = function(attrs) {
  9274. return this.create('connection', attrs);
  9275. };
  9276. /**
  9277. * Create a model element with the given type and
  9278. * a number of pre-set attributes.
  9279. *
  9280. * @param {string} type
  9281. * @param {Object} attrs
  9282. * @return {djs.model.Base} the newly created model instance
  9283. */
  9284. ElementFactory.prototype.create = function(type, attrs) {
  9285. attrs = assign({}, attrs || {});
  9286. if (!attrs.id) {
  9287. attrs.id = type + '_' + (this._uid++);
  9288. }
  9289. return create(type, attrs);
  9290. };
  9291. var FN_REF = '__fn';
  9292. var DEFAULT_PRIORITY$1 = 1000;
  9293. var slice = Array.prototype.slice;
  9294. /**
  9295. * A general purpose event bus.
  9296. *
  9297. * This component is used to communicate across a diagram instance.
  9298. * Other parts of a diagram can use it to listen to and broadcast events.
  9299. *
  9300. *
  9301. * ## Registering for Events
  9302. *
  9303. * The event bus provides the {@link EventBus#on} and {@link EventBus#once}
  9304. * methods to register for events. {@link EventBus#off} can be used to
  9305. * remove event registrations. Listeners receive an instance of {@link Event}
  9306. * as the first argument. It allows them to hook into the event execution.
  9307. *
  9308. * ```javascript
  9309. *
  9310. * // listen for event
  9311. * eventBus.on('foo', function(event) {
  9312. *
  9313. * // access event type
  9314. * event.type; // 'foo'
  9315. *
  9316. * // stop propagation to other listeners
  9317. * event.stopPropagation();
  9318. *
  9319. * // prevent event default
  9320. * event.preventDefault();
  9321. * });
  9322. *
  9323. * // listen for event with custom payload
  9324. * eventBus.on('bar', function(event, payload) {
  9325. * console.log(payload);
  9326. * });
  9327. *
  9328. * // listen for event returning value
  9329. * eventBus.on('foobar', function(event) {
  9330. *
  9331. * // stop event propagation + prevent default
  9332. * return false;
  9333. *
  9334. * // stop event propagation + return custom result
  9335. * return {
  9336. * complex: 'listening result'
  9337. * };
  9338. * });
  9339. *
  9340. *
  9341. * // listen with custom priority (default=1000, higher is better)
  9342. * eventBus.on('priorityfoo', 1500, function(event) {
  9343. * console.log('invoked first!');
  9344. * });
  9345. *
  9346. *
  9347. * // listen for event and pass the context (`this`)
  9348. * eventBus.on('foobar', function(event) {
  9349. * this.foo();
  9350. * }, this);
  9351. * ```
  9352. *
  9353. *
  9354. * ## Emitting Events
  9355. *
  9356. * Events can be emitted via the event bus using {@link EventBus#fire}.
  9357. *
  9358. * ```javascript
  9359. *
  9360. * // false indicates that the default action
  9361. * // was prevented by listeners
  9362. * if (eventBus.fire('foo') === false) {
  9363. * console.log('default has been prevented!');
  9364. * };
  9365. *
  9366. *
  9367. * // custom args + return value listener
  9368. * eventBus.on('sum', function(event, a, b) {
  9369. * return a + b;
  9370. * });
  9371. *
  9372. * // you can pass custom arguments + retrieve result values.
  9373. * var sum = eventBus.fire('sum', 1, 2);
  9374. * console.log(sum); // 3
  9375. * ```
  9376. */
  9377. function EventBus() {
  9378. this._listeners = {};
  9379. // cleanup on destroy on lowest priority to allow
  9380. // message passing until the bitter end
  9381. this.on('diagram.destroy', 1, this._destroy, this);
  9382. }
  9383. /**
  9384. * Register an event listener for events with the given name.
  9385. *
  9386. * The callback will be invoked with `event, ...additionalArguments`
  9387. * that have been passed to {@link EventBus#fire}.
  9388. *
  9389. * Returning false from a listener will prevent the events default action
  9390. * (if any is specified). To stop an event from being processed further in
  9391. * other listeners execute {@link Event#stopPropagation}.
  9392. *
  9393. * Returning anything but `undefined` from a listener will stop the listener propagation.
  9394. *
  9395. * @param {string|Array<string>} events
  9396. * @param {number} [priority=1000] the priority in which this listener is called, larger is higher
  9397. * @param {Function} callback
  9398. * @param {Object} [that] Pass context (`this`) to the callback
  9399. */
  9400. EventBus.prototype.on = function(events, priority, callback, that) {
  9401. events = isArray$2(events) ? events : [ events ];
  9402. if (isFunction(priority)) {
  9403. that = callback;
  9404. callback = priority;
  9405. priority = DEFAULT_PRIORITY$1;
  9406. }
  9407. if (!isNumber(priority)) {
  9408. throw new Error('priority must be a number');
  9409. }
  9410. var actualCallback = callback;
  9411. if (that) {
  9412. actualCallback = bind(callback, that);
  9413. // make sure we remember and are able to remove
  9414. // bound callbacks via {@link #off} using the original
  9415. // callback
  9416. actualCallback[FN_REF] = callback[FN_REF] || callback;
  9417. }
  9418. var self = this;
  9419. events.forEach(function(e) {
  9420. self._addListener(e, {
  9421. priority: priority,
  9422. callback: actualCallback,
  9423. next: null
  9424. });
  9425. });
  9426. };
  9427. /**
  9428. * Register an event listener that is executed only once.
  9429. *
  9430. * @param {string} event the event name to register for
  9431. * @param {number} [priority=1000] the priority in which this listener is called, larger is higher
  9432. * @param {Function} callback the callback to execute
  9433. * @param {Object} [that] Pass context (`this`) to the callback
  9434. */
  9435. EventBus.prototype.once = function(event, priority, callback, that) {
  9436. var self = this;
  9437. if (isFunction(priority)) {
  9438. that = callback;
  9439. callback = priority;
  9440. priority = DEFAULT_PRIORITY$1;
  9441. }
  9442. if (!isNumber(priority)) {
  9443. throw new Error('priority must be a number');
  9444. }
  9445. function wrappedCallback() {
  9446. wrappedCallback.__isTomb = true;
  9447. var result = callback.apply(that, arguments);
  9448. self.off(event, wrappedCallback);
  9449. return result;
  9450. }
  9451. // make sure we remember and are able to remove
  9452. // bound callbacks via {@link #off} using the original
  9453. // callback
  9454. wrappedCallback[FN_REF] = callback;
  9455. this.on(event, priority, wrappedCallback);
  9456. };
  9457. /**
  9458. * Removes event listeners by event and callback.
  9459. *
  9460. * If no callback is given, all listeners for a given event name are being removed.
  9461. *
  9462. * @param {string|Array<string>} events
  9463. * @param {Function} [callback]
  9464. */
  9465. EventBus.prototype.off = function(events, callback) {
  9466. events = isArray$2(events) ? events : [ events ];
  9467. var self = this;
  9468. events.forEach(function(event) {
  9469. self._removeListener(event, callback);
  9470. });
  9471. };
  9472. /**
  9473. * Create an EventBus event.
  9474. *
  9475. * @param {Object} data
  9476. *
  9477. * @return {Object} event, recognized by the eventBus
  9478. */
  9479. EventBus.prototype.createEvent = function(data) {
  9480. var event = new InternalEvent();
  9481. event.init(data);
  9482. return event;
  9483. };
  9484. /**
  9485. * Fires a named event.
  9486. *
  9487. * @example
  9488. *
  9489. * // fire event by name
  9490. * events.fire('foo');
  9491. *
  9492. * // fire event object with nested type
  9493. * var event = { type: 'foo' };
  9494. * events.fire(event);
  9495. *
  9496. * // fire event with explicit type
  9497. * var event = { x: 10, y: 20 };
  9498. * events.fire('element.moved', event);
  9499. *
  9500. * // pass additional arguments to the event
  9501. * events.on('foo', function(event, bar) {
  9502. * alert(bar);
  9503. * });
  9504. *
  9505. * events.fire({ type: 'foo' }, 'I am bar!');
  9506. *
  9507. * @param {string} [name] the optional event name
  9508. * @param {Object} [event] the event object
  9509. * @param {...Object} additional arguments to be passed to the callback functions
  9510. *
  9511. * @return {boolean} the events return value, if specified or false if the
  9512. * default action was prevented by listeners
  9513. */
  9514. EventBus.prototype.fire = function(type, data) {
  9515. var event,
  9516. firstListener,
  9517. returnValue,
  9518. args;
  9519. args = slice.call(arguments);
  9520. if (typeof type === 'object') {
  9521. data = type;
  9522. type = data.type;
  9523. }
  9524. if (!type) {
  9525. throw new Error('no event type specified');
  9526. }
  9527. firstListener = this._listeners[type];
  9528. if (!firstListener) {
  9529. return;
  9530. }
  9531. // we make sure we fire instances of our home made
  9532. // events here. We wrap them only once, though
  9533. if (data instanceof InternalEvent) {
  9534. // we are fine, we alread have an event
  9535. event = data;
  9536. } else {
  9537. event = this.createEvent(data);
  9538. }
  9539. // ensure we pass the event as the first parameter
  9540. args[0] = event;
  9541. // original event type (in case we delegate)
  9542. var originalType = event.type;
  9543. // update event type before delegation
  9544. if (type !== originalType) {
  9545. event.type = type;
  9546. }
  9547. try {
  9548. returnValue = this._invokeListeners(event, args, firstListener);
  9549. } finally {
  9550. // reset event type after delegation
  9551. if (type !== originalType) {
  9552. event.type = originalType;
  9553. }
  9554. }
  9555. // set the return value to false if the event default
  9556. // got prevented and no other return value exists
  9557. if (returnValue === undefined && event.defaultPrevented) {
  9558. returnValue = false;
  9559. }
  9560. return returnValue;
  9561. };
  9562. EventBus.prototype.handleError = function(error) {
  9563. return this.fire('error', { error: error }) === false;
  9564. };
  9565. EventBus.prototype._destroy = function() {
  9566. this._listeners = {};
  9567. };
  9568. EventBus.prototype._invokeListeners = function(event, args, listener) {
  9569. var returnValue;
  9570. while (listener) {
  9571. // handle stopped propagation
  9572. if (event.cancelBubble) {
  9573. break;
  9574. }
  9575. returnValue = this._invokeListener(event, args, listener);
  9576. listener = listener.next;
  9577. }
  9578. return returnValue;
  9579. };
  9580. EventBus.prototype._invokeListener = function(event, args, listener) {
  9581. var returnValue;
  9582. if (listener.callback.__isTomb) {
  9583. return returnValue;
  9584. }
  9585. try {
  9586. // returning false prevents the default action
  9587. returnValue = invokeFunction(listener.callback, args);
  9588. // stop propagation on return value
  9589. if (returnValue !== undefined) {
  9590. event.returnValue = returnValue;
  9591. event.stopPropagation();
  9592. }
  9593. // prevent default on return false
  9594. if (returnValue === false) {
  9595. event.preventDefault();
  9596. }
  9597. } catch (error) {
  9598. if (!this.handleError(error)) {
  9599. console.error('unhandled error in event listener', error);
  9600. throw error;
  9601. }
  9602. }
  9603. return returnValue;
  9604. };
  9605. /*
  9606. * Add new listener with a certain priority to the list
  9607. * of listeners (for the given event).
  9608. *
  9609. * The semantics of listener registration / listener execution are
  9610. * first register, first serve: New listeners will always be inserted
  9611. * after existing listeners with the same priority.
  9612. *
  9613. * Example: Inserting two listeners with priority 1000 and 1300
  9614. *
  9615. * * before: [ 1500, 1500, 1000, 1000 ]
  9616. * * after: [ 1500, 1500, (new=1300), 1000, 1000, (new=1000) ]
  9617. *
  9618. * @param {string} event
  9619. * @param {Object} listener { priority, callback }
  9620. */
  9621. EventBus.prototype._addListener = function(event, newListener) {
  9622. var listener = this._getListeners(event),
  9623. previousListener;
  9624. // no prior listeners
  9625. if (!listener) {
  9626. this._setListeners(event, newListener);
  9627. return;
  9628. }
  9629. // ensure we order listeners by priority from
  9630. // 0 (high) to n > 0 (low)
  9631. while (listener) {
  9632. if (listener.priority < newListener.priority) {
  9633. newListener.next = listener;
  9634. if (previousListener) {
  9635. previousListener.next = newListener;
  9636. } else {
  9637. this._setListeners(event, newListener);
  9638. }
  9639. return;
  9640. }
  9641. previousListener = listener;
  9642. listener = listener.next;
  9643. }
  9644. // add new listener to back
  9645. previousListener.next = newListener;
  9646. };
  9647. EventBus.prototype._getListeners = function(name) {
  9648. return this._listeners[name];
  9649. };
  9650. EventBus.prototype._setListeners = function(name, listener) {
  9651. this._listeners[name] = listener;
  9652. };
  9653. EventBus.prototype._removeListener = function(event, callback) {
  9654. var listener = this._getListeners(event),
  9655. nextListener,
  9656. previousListener,
  9657. listenerCallback;
  9658. if (!callback) {
  9659. // clear listeners
  9660. this._setListeners(event, null);
  9661. return;
  9662. }
  9663. while (listener) {
  9664. nextListener = listener.next;
  9665. listenerCallback = listener.callback;
  9666. if (listenerCallback === callback || listenerCallback[FN_REF] === callback) {
  9667. if (previousListener) {
  9668. previousListener.next = nextListener;
  9669. } else {
  9670. // new first listener
  9671. this._setListeners(event, nextListener);
  9672. }
  9673. }
  9674. previousListener = listener;
  9675. listener = nextListener;
  9676. }
  9677. };
  9678. /**
  9679. * A event that is emitted via the event bus.
  9680. */
  9681. function InternalEvent() { }
  9682. InternalEvent.prototype.stopPropagation = function() {
  9683. this.cancelBubble = true;
  9684. };
  9685. InternalEvent.prototype.preventDefault = function() {
  9686. this.defaultPrevented = true;
  9687. };
  9688. InternalEvent.prototype.init = function(data) {
  9689. assign(this, data || {});
  9690. };
  9691. /**
  9692. * Invoke function. Be fast...
  9693. *
  9694. * @param {Function} fn
  9695. * @param {Array<Object>} args
  9696. *
  9697. * @return {Any}
  9698. */
  9699. function invokeFunction(fn, args) {
  9700. return fn.apply(null, args);
  9701. }
  9702. /**
  9703. * SVGs for elements are generated by the {@link GraphicsFactory}.
  9704. *
  9705. * This utility gives quick access to the important semantic
  9706. * parts of an element.
  9707. */
  9708. /**
  9709. * Returns the visual part of a diagram element
  9710. *
  9711. * @param {Snap<SVGElement>} gfx
  9712. *
  9713. * @return {Snap<SVGElement>}
  9714. */
  9715. function getVisual(gfx) {
  9716. return gfx.childNodes[0];
  9717. }
  9718. /**
  9719. * Returns the children for a given diagram element.
  9720. *
  9721. * @param {Snap<SVGElement>} gfx
  9722. * @return {Snap<SVGElement>}
  9723. */
  9724. function getChildren(gfx) {
  9725. return gfx.parentNode.childNodes[1];
  9726. }
  9727. /**
  9728. * A factory that creates graphical elements
  9729. *
  9730. * @param {EventBus} eventBus
  9731. * @param {ElementRegistry} elementRegistry
  9732. */
  9733. function GraphicsFactory(eventBus, elementRegistry) {
  9734. this._eventBus = eventBus;
  9735. this._elementRegistry = elementRegistry;
  9736. }
  9737. GraphicsFactory.$inject = [ 'eventBus' , 'elementRegistry' ];
  9738. GraphicsFactory.prototype._getChildrenContainer = function(element) {
  9739. var gfx = this._elementRegistry.getGraphics(element);
  9740. var childrenGfx;
  9741. // root element
  9742. if (!element.parent) {
  9743. childrenGfx = gfx;
  9744. } else {
  9745. childrenGfx = getChildren(gfx);
  9746. if (!childrenGfx) {
  9747. childrenGfx = create$1('g');
  9748. classes$1(childrenGfx).add('djs-children');
  9749. append(gfx.parentNode, childrenGfx);
  9750. }
  9751. }
  9752. return childrenGfx;
  9753. };
  9754. /**
  9755. * Clears the graphical representation of the element and returns the
  9756. * cleared visual (the <g class="djs-visual" /> element).
  9757. */
  9758. GraphicsFactory.prototype._clear = function(gfx) {
  9759. var visual = getVisual(gfx);
  9760. clear(visual);
  9761. return visual;
  9762. };
  9763. /**
  9764. * Creates a gfx container for shapes and connections
  9765. *
  9766. * The layout is as follows:
  9767. *
  9768. * <g class="djs-group">
  9769. *
  9770. * <!-- the gfx -->
  9771. * <g class="djs-element djs-(shape|connection|frame)">
  9772. * <g class="djs-visual">
  9773. * <!-- the renderer draws in here -->
  9774. * </g>
  9775. *
  9776. * <!-- extensions (overlays, click box, ...) goes here
  9777. * </g>
  9778. *
  9779. * <!-- the gfx child nodes -->
  9780. * <g class="djs-children"></g>
  9781. * </g>
  9782. *
  9783. * @param {string} type the type of the element, i.e. shape | connection
  9784. * @param {SVGElement} [childrenGfx]
  9785. * @param {number} [parentIndex] position to create container in parent
  9786. * @param {boolean} [isFrame] is frame element
  9787. *
  9788. * @return {SVGElement}
  9789. */
  9790. GraphicsFactory.prototype._createContainer = function(
  9791. type, childrenGfx, parentIndex, isFrame
  9792. ) {
  9793. var outerGfx = create$1('g');
  9794. classes$1(outerGfx).add('djs-group');
  9795. // insert node at position
  9796. if (typeof parentIndex !== 'undefined') {
  9797. prependTo(outerGfx, childrenGfx, childrenGfx.childNodes[parentIndex]);
  9798. } else {
  9799. append(childrenGfx, outerGfx);
  9800. }
  9801. var gfx = create$1('g');
  9802. classes$1(gfx).add('djs-element');
  9803. classes$1(gfx).add('djs-' + type);
  9804. if (isFrame) {
  9805. classes$1(gfx).add('djs-frame');
  9806. }
  9807. append(outerGfx, gfx);
  9808. // create visual
  9809. var visual = create$1('g');
  9810. classes$1(visual).add('djs-visual');
  9811. append(gfx, visual);
  9812. return gfx;
  9813. };
  9814. GraphicsFactory.prototype.create = function(type, element, parentIndex) {
  9815. var childrenGfx = this._getChildrenContainer(element.parent);
  9816. return this._createContainer(type, childrenGfx, parentIndex, isFrameElement(element));
  9817. };
  9818. GraphicsFactory.prototype.updateContainments = function(elements) {
  9819. var self = this,
  9820. elementRegistry = this._elementRegistry,
  9821. parents;
  9822. parents = reduce(elements, function(map, e) {
  9823. if (e.parent) {
  9824. map[e.parent.id] = e.parent;
  9825. }
  9826. return map;
  9827. }, {});
  9828. // update all parents of changed and reorganized their children
  9829. // in the correct order (as indicated in our model)
  9830. forEach$1(parents, function(parent) {
  9831. var children = parent.children;
  9832. if (!children) {
  9833. return;
  9834. }
  9835. var childrenGfx = self._getChildrenContainer(parent);
  9836. forEach$1(children.slice().reverse(), function(child) {
  9837. var childGfx = elementRegistry.getGraphics(child);
  9838. prependTo(childGfx.parentNode, childrenGfx);
  9839. });
  9840. });
  9841. };
  9842. GraphicsFactory.prototype.drawShape = function(visual, element) {
  9843. var eventBus = this._eventBus;
  9844. return eventBus.fire('render.shape', { gfx: visual, element: element });
  9845. };
  9846. GraphicsFactory.prototype.getShapePath = function(element) {
  9847. var eventBus = this._eventBus;
  9848. return eventBus.fire('render.getShapePath', element);
  9849. };
  9850. GraphicsFactory.prototype.drawConnection = function(visual, element) {
  9851. var eventBus = this._eventBus;
  9852. return eventBus.fire('render.connection', { gfx: visual, element: element });
  9853. };
  9854. GraphicsFactory.prototype.getConnectionPath = function(waypoints) {
  9855. var eventBus = this._eventBus;
  9856. return eventBus.fire('render.getConnectionPath', waypoints);
  9857. };
  9858. GraphicsFactory.prototype.update = function(type, element, gfx) {
  9859. // do NOT update root element
  9860. if (!element.parent) {
  9861. return;
  9862. }
  9863. var visual = this._clear(gfx);
  9864. // redraw
  9865. if (type === 'shape') {
  9866. this.drawShape(visual, element);
  9867. // update positioning
  9868. translate$1(gfx, element.x, element.y);
  9869. } else
  9870. if (type === 'connection') {
  9871. this.drawConnection(visual, element);
  9872. } else {
  9873. throw new Error('unknown type: ' + type);
  9874. }
  9875. if (element.hidden) {
  9876. attr$1(gfx, 'display', 'none');
  9877. } else {
  9878. attr$1(gfx, 'display', 'block');
  9879. }
  9880. };
  9881. GraphicsFactory.prototype.remove = function(element) {
  9882. var gfx = this._elementRegistry.getGraphics(element);
  9883. // remove
  9884. remove$2(gfx.parentNode);
  9885. };
  9886. // helpers //////////
  9887. function prependTo(newNode, parentNode, siblingNode) {
  9888. var node = siblingNode || parentNode.firstChild;
  9889. // do not prepend node to itself to prevent IE from crashing
  9890. // https://github.com/bpmn-io/bpmn-js/issues/746
  9891. if (newNode === node) {
  9892. return;
  9893. }
  9894. parentNode.insertBefore(newNode, node);
  9895. }
  9896. var CoreModule = {
  9897. __depends__: [ DrawModule ],
  9898. __init__: [ 'canvas' ],
  9899. canvas: [ 'type', Canvas ],
  9900. elementRegistry: [ 'type', ElementRegistry ],
  9901. elementFactory: [ 'type', ElementFactory ],
  9902. eventBus: [ 'type', EventBus ],
  9903. graphicsFactory: [ 'type', GraphicsFactory ]
  9904. };
  9905. /**
  9906. * @typedef { import('didi').ModuleDeclaration } Module
  9907. */
  9908. /**
  9909. * Bootstrap an injector from a list of modules, instantiating a number of default components
  9910. *
  9911. * @param {Array<Module>} modules
  9912. *
  9913. * @return {Injector} a injector to use to access the components
  9914. */
  9915. function bootstrap(modules) {
  9916. var injector = new Injector(modules);
  9917. injector.init();
  9918. return injector;
  9919. }
  9920. /**
  9921. * Creates an injector from passed options.
  9922. *
  9923. * @param {Object} options
  9924. * @return {Injector}
  9925. */
  9926. function createInjector(options) {
  9927. options = options || {};
  9928. var configModule = {
  9929. 'config': [ 'value', options ]
  9930. };
  9931. var modules = [ configModule, CoreModule ].concat(options.modules || []);
  9932. return bootstrap(modules);
  9933. }
  9934. /**
  9935. * The main diagram-js entry point that bootstraps the diagram with the given
  9936. * configuration.
  9937. *
  9938. * To register extensions with the diagram, pass them as Array<Module> to the constructor.
  9939. *
  9940. * @class djs.Diagram
  9941. * @memberOf djs
  9942. * @constructor
  9943. *
  9944. * @example
  9945. *
  9946. * <caption>Creating a plug-in that logs whenever a shape is added to the canvas.</caption>
  9947. *
  9948. * // plug-in implemenentation
  9949. * function MyLoggingPlugin(eventBus) {
  9950. * eventBus.on('shape.added', function(event) {
  9951. * console.log('shape ', event.shape, ' was added to the diagram');
  9952. * });
  9953. * }
  9954. *
  9955. * // export as module
  9956. * export default {
  9957. * __init__: [ 'myLoggingPlugin' ],
  9958. * myLoggingPlugin: [ 'type', MyLoggingPlugin ]
  9959. * };
  9960. *
  9961. *
  9962. * // instantiate the diagram with the new plug-in
  9963. *
  9964. * import MyLoggingModule from 'path-to-my-logging-plugin';
  9965. *
  9966. * var diagram = new Diagram({
  9967. * modules: [
  9968. * MyLoggingModule
  9969. * ]
  9970. * });
  9971. *
  9972. * diagram.invoke([ 'canvas', function(canvas) {
  9973. * // add shape to drawing canvas
  9974. * canvas.addShape({ x: 10, y: 10 });
  9975. * });
  9976. *
  9977. * // 'shape ... was added to the diagram' logged to console
  9978. *
  9979. * @param {Object} options
  9980. * @param {Array<Module>} [options.modules] external modules to instantiate with the diagram
  9981. * @param {Injector} [injector] an (optional) injector to bootstrap the diagram with
  9982. */
  9983. function Diagram(options, injector) {
  9984. // create injector unless explicitly specified
  9985. this.injector = injector = injector || createInjector(options);
  9986. // API
  9987. /**
  9988. * Resolves a diagram service
  9989. *
  9990. * @method Diagram#get
  9991. *
  9992. * @param {string} name the name of the diagram service to be retrieved
  9993. * @param {boolean} [strict=true] if false, resolve missing services to null
  9994. */
  9995. this.get = injector.get;
  9996. /**
  9997. * Executes a function into which diagram services are injected
  9998. *
  9999. * @method Diagram#invoke
  10000. *
  10001. * @param {Function|Object[]} fn the function to resolve
  10002. * @param {Object} locals a number of locals to use to resolve certain dependencies
  10003. */
  10004. this.invoke = injector.invoke;
  10005. // init
  10006. // indicate via event
  10007. /**
  10008. * An event indicating that all plug-ins are loaded.
  10009. *
  10010. * Use this event to fire other events to interested plug-ins
  10011. *
  10012. * @memberOf Diagram
  10013. *
  10014. * @event diagram.init
  10015. *
  10016. * @example
  10017. *
  10018. * eventBus.on('diagram.init', function() {
  10019. * eventBus.fire('my-custom-event', { foo: 'BAR' });
  10020. * });
  10021. *
  10022. * @type {Object}
  10023. */
  10024. this.get('eventBus').fire('diagram.init');
  10025. }
  10026. /**
  10027. * Destroys the diagram
  10028. *
  10029. * @method Diagram#destroy
  10030. */
  10031. Diagram.prototype.destroy = function() {
  10032. this.get('eventBus').fire('diagram.destroy');
  10033. };
  10034. /**
  10035. * Clear the diagram, removing all contents.
  10036. */
  10037. Diagram.prototype.clear = function() {
  10038. this.get('eventBus').fire('diagram.clear');
  10039. };
  10040. /**
  10041. * Moddle base element.
  10042. */
  10043. function Base() { }
  10044. Base.prototype.get = function(name) {
  10045. return this.$model.properties.get(this, name);
  10046. };
  10047. Base.prototype.set = function(name, value) {
  10048. this.$model.properties.set(this, name, value);
  10049. };
  10050. /**
  10051. * A model element factory.
  10052. *
  10053. * @param {Moddle} model
  10054. * @param {Properties} properties
  10055. */
  10056. function Factory(model, properties) {
  10057. this.model = model;
  10058. this.properties = properties;
  10059. }
  10060. Factory.prototype.createType = function(descriptor) {
  10061. var model = this.model;
  10062. var props = this.properties,
  10063. prototype = Object.create(Base.prototype);
  10064. // initialize default values
  10065. forEach$1(descriptor.properties, function(p) {
  10066. if (!p.isMany && p.default !== undefined) {
  10067. prototype[p.name] = p.default;
  10068. }
  10069. });
  10070. props.defineModel(prototype, model);
  10071. props.defineDescriptor(prototype, descriptor);
  10072. var name = descriptor.ns.name;
  10073. /**
  10074. * The new type constructor
  10075. */
  10076. function ModdleElement(attrs) {
  10077. props.define(this, '$type', { value: name, enumerable: true });
  10078. props.define(this, '$attrs', { value: {} });
  10079. props.define(this, '$parent', { writable: true });
  10080. forEach$1(attrs, bind(function(val, key) {
  10081. this.set(key, val);
  10082. }, this));
  10083. }
  10084. ModdleElement.prototype = prototype;
  10085. ModdleElement.hasType = prototype.$instanceOf = this.model.hasType;
  10086. // static links
  10087. props.defineModel(ModdleElement, model);
  10088. props.defineDescriptor(ModdleElement, descriptor);
  10089. return ModdleElement;
  10090. };
  10091. /**
  10092. * Built-in moddle types
  10093. */
  10094. var BUILTINS = {
  10095. String: true,
  10096. Boolean: true,
  10097. Integer: true,
  10098. Real: true,
  10099. Element: true
  10100. };
  10101. /**
  10102. * Converters for built in types from string representations
  10103. */
  10104. var TYPE_CONVERTERS = {
  10105. String: function(s) { return s; },
  10106. Boolean: function(s) { return s === 'true'; },
  10107. Integer: function(s) { return parseInt(s, 10); },
  10108. Real: function(s) { return parseFloat(s); }
  10109. };
  10110. /**
  10111. * Convert a type to its real representation
  10112. */
  10113. function coerceType(type, value) {
  10114. var converter = TYPE_CONVERTERS[type];
  10115. if (converter) {
  10116. return converter(value);
  10117. } else {
  10118. return value;
  10119. }
  10120. }
  10121. /**
  10122. * Return whether the given type is built-in
  10123. */
  10124. function isBuiltIn(type) {
  10125. return !!BUILTINS[type];
  10126. }
  10127. /**
  10128. * Return whether the given type is simple
  10129. */
  10130. function isSimple(type) {
  10131. return !!TYPE_CONVERTERS[type];
  10132. }
  10133. /**
  10134. * Parses a namespaced attribute name of the form (ns:)localName to an object,
  10135. * given a default prefix to assume in case no explicit namespace is given.
  10136. *
  10137. * @param {String} name
  10138. * @param {String} [defaultPrefix] the default prefix to take, if none is present.
  10139. *
  10140. * @return {Object} the parsed name
  10141. */
  10142. function parseName(name, defaultPrefix) {
  10143. var parts = name.split(/:/),
  10144. localName, prefix;
  10145. // no prefix (i.e. only local name)
  10146. if (parts.length === 1) {
  10147. localName = name;
  10148. prefix = defaultPrefix;
  10149. } else
  10150. // prefix + local name
  10151. if (parts.length === 2) {
  10152. localName = parts[1];
  10153. prefix = parts[0];
  10154. } else {
  10155. throw new Error('expected <prefix:localName> or <localName>, got ' + name);
  10156. }
  10157. name = (prefix ? prefix + ':' : '') + localName;
  10158. return {
  10159. name: name,
  10160. prefix: prefix,
  10161. localName: localName
  10162. };
  10163. }
  10164. /**
  10165. * A utility to build element descriptors.
  10166. */
  10167. function DescriptorBuilder(nameNs) {
  10168. this.ns = nameNs;
  10169. this.name = nameNs.name;
  10170. this.allTypes = [];
  10171. this.allTypesByName = {};
  10172. this.properties = [];
  10173. this.propertiesByName = {};
  10174. }
  10175. DescriptorBuilder.prototype.build = function() {
  10176. return pick(this, [
  10177. 'ns',
  10178. 'name',
  10179. 'allTypes',
  10180. 'allTypesByName',
  10181. 'properties',
  10182. 'propertiesByName',
  10183. 'bodyProperty',
  10184. 'idProperty'
  10185. ]);
  10186. };
  10187. /**
  10188. * Add property at given index.
  10189. *
  10190. * @param {Object} p
  10191. * @param {Number} [idx]
  10192. * @param {Boolean} [validate=true]
  10193. */
  10194. DescriptorBuilder.prototype.addProperty = function(p, idx, validate) {
  10195. if (typeof idx === 'boolean') {
  10196. validate = idx;
  10197. idx = undefined;
  10198. }
  10199. this.addNamedProperty(p, validate !== false);
  10200. var properties = this.properties;
  10201. if (idx !== undefined) {
  10202. properties.splice(idx, 0, p);
  10203. } else {
  10204. properties.push(p);
  10205. }
  10206. };
  10207. DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty, replace) {
  10208. var oldNameNs = oldProperty.ns;
  10209. var props = this.properties,
  10210. propertiesByName = this.propertiesByName,
  10211. rename = oldProperty.name !== newProperty.name;
  10212. if (oldProperty.isId) {
  10213. if (!newProperty.isId) {
  10214. throw new Error(
  10215. 'property <' + newProperty.ns.name + '> must be id property ' +
  10216. 'to refine <' + oldProperty.ns.name + '>');
  10217. }
  10218. this.setIdProperty(newProperty, false);
  10219. }
  10220. if (oldProperty.isBody) {
  10221. if (!newProperty.isBody) {
  10222. throw new Error(
  10223. 'property <' + newProperty.ns.name + '> must be body property ' +
  10224. 'to refine <' + oldProperty.ns.name + '>');
  10225. }
  10226. // TODO: Check compatibility
  10227. this.setBodyProperty(newProperty, false);
  10228. }
  10229. // validate existence and get location of old property
  10230. var idx = props.indexOf(oldProperty);
  10231. if (idx === -1) {
  10232. throw new Error('property <' + oldNameNs.name + '> not found in property list');
  10233. }
  10234. // remove old property
  10235. props.splice(idx, 1);
  10236. // replacing the named property is intentional
  10237. //
  10238. // * validate only if this is a "rename" operation
  10239. // * add at specific index unless we "replace"
  10240. //
  10241. this.addProperty(newProperty, replace ? undefined : idx, rename);
  10242. // make new property available under old name
  10243. propertiesByName[oldNameNs.name] = propertiesByName[oldNameNs.localName] = newProperty;
  10244. };
  10245. DescriptorBuilder.prototype.redefineProperty = function(p, targetPropertyName, replace) {
  10246. var nsPrefix = p.ns.prefix;
  10247. var parts = targetPropertyName.split('#');
  10248. var name = parseName(parts[0], nsPrefix);
  10249. var attrName = parseName(parts[1], name.prefix).name;
  10250. var redefinedProperty = this.propertiesByName[attrName];
  10251. if (!redefinedProperty) {
  10252. throw new Error('refined property <' + attrName + '> not found');
  10253. } else {
  10254. this.replaceProperty(redefinedProperty, p, replace);
  10255. }
  10256. delete p.redefines;
  10257. };
  10258. DescriptorBuilder.prototype.addNamedProperty = function(p, validate) {
  10259. var ns = p.ns,
  10260. propsByName = this.propertiesByName;
  10261. if (validate) {
  10262. this.assertNotDefined(p, ns.name);
  10263. this.assertNotDefined(p, ns.localName);
  10264. }
  10265. propsByName[ns.name] = propsByName[ns.localName] = p;
  10266. };
  10267. DescriptorBuilder.prototype.removeNamedProperty = function(p) {
  10268. var ns = p.ns,
  10269. propsByName = this.propertiesByName;
  10270. delete propsByName[ns.name];
  10271. delete propsByName[ns.localName];
  10272. };
  10273. DescriptorBuilder.prototype.setBodyProperty = function(p, validate) {
  10274. if (validate && this.bodyProperty) {
  10275. throw new Error(
  10276. 'body property defined multiple times ' +
  10277. '(<' + this.bodyProperty.ns.name + '>, <' + p.ns.name + '>)');
  10278. }
  10279. this.bodyProperty = p;
  10280. };
  10281. DescriptorBuilder.prototype.setIdProperty = function(p, validate) {
  10282. if (validate && this.idProperty) {
  10283. throw new Error(
  10284. 'id property defined multiple times ' +
  10285. '(<' + this.idProperty.ns.name + '>, <' + p.ns.name + '>)');
  10286. }
  10287. this.idProperty = p;
  10288. };
  10289. DescriptorBuilder.prototype.assertNotDefined = function(p, name) {
  10290. var propertyName = p.name,
  10291. definedProperty = this.propertiesByName[propertyName];
  10292. if (definedProperty) {
  10293. throw new Error(
  10294. 'property <' + propertyName + '> already defined; ' +
  10295. 'override of <' + definedProperty.definedBy.ns.name + '#' + definedProperty.ns.name + '> by ' +
  10296. '<' + p.definedBy.ns.name + '#' + p.ns.name + '> not allowed without redefines');
  10297. }
  10298. };
  10299. DescriptorBuilder.prototype.hasProperty = function(name) {
  10300. return this.propertiesByName[name];
  10301. };
  10302. DescriptorBuilder.prototype.addTrait = function(t, inherited) {
  10303. var typesByName = this.allTypesByName,
  10304. types = this.allTypes;
  10305. var typeName = t.name;
  10306. if (typeName in typesByName) {
  10307. return;
  10308. }
  10309. forEach$1(t.properties, bind(function(p) {
  10310. // clone property to allow extensions
  10311. p = assign({}, p, {
  10312. name: p.ns.localName,
  10313. inherited: inherited
  10314. });
  10315. Object.defineProperty(p, 'definedBy', {
  10316. value: t
  10317. });
  10318. var replaces = p.replaces,
  10319. redefines = p.redefines;
  10320. // add replace/redefine support
  10321. if (replaces || redefines) {
  10322. this.redefineProperty(p, replaces || redefines, replaces);
  10323. } else {
  10324. if (p.isBody) {
  10325. this.setBodyProperty(p);
  10326. }
  10327. if (p.isId) {
  10328. this.setIdProperty(p);
  10329. }
  10330. this.addProperty(p);
  10331. }
  10332. }, this));
  10333. types.push(t);
  10334. typesByName[typeName] = t;
  10335. };
  10336. /**
  10337. * A registry of Moddle packages.
  10338. *
  10339. * @param {Array<Package>} packages
  10340. * @param {Properties} properties
  10341. */
  10342. function Registry(packages, properties) {
  10343. this.packageMap = {};
  10344. this.typeMap = {};
  10345. this.packages = [];
  10346. this.properties = properties;
  10347. forEach$1(packages, bind(this.registerPackage, this));
  10348. }
  10349. Registry.prototype.getPackage = function(uriOrPrefix) {
  10350. return this.packageMap[uriOrPrefix];
  10351. };
  10352. Registry.prototype.getPackages = function() {
  10353. return this.packages;
  10354. };
  10355. Registry.prototype.registerPackage = function(pkg) {
  10356. // copy package
  10357. pkg = assign({}, pkg);
  10358. var pkgMap = this.packageMap;
  10359. ensureAvailable(pkgMap, pkg, 'prefix');
  10360. ensureAvailable(pkgMap, pkg, 'uri');
  10361. // register types
  10362. forEach$1(pkg.types, bind(function(descriptor) {
  10363. this.registerType(descriptor, pkg);
  10364. }, this));
  10365. pkgMap[pkg.uri] = pkgMap[pkg.prefix] = pkg;
  10366. this.packages.push(pkg);
  10367. };
  10368. /**
  10369. * Register a type from a specific package with us
  10370. */
  10371. Registry.prototype.registerType = function(type, pkg) {
  10372. type = assign({}, type, {
  10373. superClass: (type.superClass || []).slice(),
  10374. extends: (type.extends || []).slice(),
  10375. properties: (type.properties || []).slice(),
  10376. meta: assign((type.meta || {}))
  10377. });
  10378. var ns = parseName(type.name, pkg.prefix),
  10379. name = ns.name,
  10380. propertiesByName = {};
  10381. // parse properties
  10382. forEach$1(type.properties, bind(function(p) {
  10383. // namespace property names
  10384. var propertyNs = parseName(p.name, ns.prefix),
  10385. propertyName = propertyNs.name;
  10386. // namespace property types
  10387. if (!isBuiltIn(p.type)) {
  10388. p.type = parseName(p.type, propertyNs.prefix).name;
  10389. }
  10390. assign(p, {
  10391. ns: propertyNs,
  10392. name: propertyName
  10393. });
  10394. propertiesByName[propertyName] = p;
  10395. }, this));
  10396. // update ns + name
  10397. assign(type, {
  10398. ns: ns,
  10399. name: name,
  10400. propertiesByName: propertiesByName
  10401. });
  10402. forEach$1(type.extends, bind(function(extendsName) {
  10403. var extended = this.typeMap[extendsName];
  10404. extended.traits = extended.traits || [];
  10405. extended.traits.push(name);
  10406. }, this));
  10407. // link to package
  10408. this.definePackage(type, pkg);
  10409. // register
  10410. this.typeMap[name] = type;
  10411. };
  10412. /**
  10413. * Traverse the type hierarchy from bottom to top,
  10414. * calling iterator with (type, inherited) for all elements in
  10415. * the inheritance chain.
  10416. *
  10417. * @param {Object} nsName
  10418. * @param {Function} iterator
  10419. * @param {Boolean} [trait=false]
  10420. */
  10421. Registry.prototype.mapTypes = function(nsName, iterator, trait) {
  10422. var type = isBuiltIn(nsName.name) ? { name: nsName.name } : this.typeMap[nsName.name];
  10423. var self = this;
  10424. /**
  10425. * Traverse the selected trait.
  10426. *
  10427. * @param {String} cls
  10428. */
  10429. function traverseTrait(cls) {
  10430. return traverseSuper(cls, true);
  10431. }
  10432. /**
  10433. * Traverse the selected super type or trait
  10434. *
  10435. * @param {String} cls
  10436. * @param {Boolean} [trait=false]
  10437. */
  10438. function traverseSuper(cls, trait) {
  10439. var parentNs = parseName(cls, isBuiltIn(cls) ? '' : nsName.prefix);
  10440. self.mapTypes(parentNs, iterator, trait);
  10441. }
  10442. if (!type) {
  10443. throw new Error('unknown type <' + nsName.name + '>');
  10444. }
  10445. forEach$1(type.superClass, trait ? traverseTrait : traverseSuper);
  10446. // call iterator with (type, inherited=!trait)
  10447. iterator(type, !trait);
  10448. forEach$1(type.traits, traverseTrait);
  10449. };
  10450. /**
  10451. * Returns the effective descriptor for a type.
  10452. *
  10453. * @param {String} type the namespaced name (ns:localName) of the type
  10454. *
  10455. * @return {Descriptor} the resulting effective descriptor
  10456. */
  10457. Registry.prototype.getEffectiveDescriptor = function(name) {
  10458. var nsName = parseName(name);
  10459. var builder = new DescriptorBuilder(nsName);
  10460. this.mapTypes(nsName, function(type, inherited) {
  10461. builder.addTrait(type, inherited);
  10462. });
  10463. var descriptor = builder.build();
  10464. // define package link
  10465. this.definePackage(descriptor, descriptor.allTypes[descriptor.allTypes.length - 1].$pkg);
  10466. return descriptor;
  10467. };
  10468. Registry.prototype.definePackage = function(target, pkg) {
  10469. this.properties.define(target, '$pkg', { value: pkg });
  10470. };
  10471. ///////// helpers ////////////////////////////
  10472. function ensureAvailable(packageMap, pkg, identifierKey) {
  10473. var value = pkg[identifierKey];
  10474. if (value in packageMap) {
  10475. throw new Error('package with ' + identifierKey + ' <' + value + '> already defined');
  10476. }
  10477. }
  10478. /**
  10479. * A utility that gets and sets properties of model elements.
  10480. *
  10481. * @param {Model} model
  10482. */
  10483. function Properties(model) {
  10484. this.model = model;
  10485. }
  10486. /**
  10487. * Sets a named property on the target element.
  10488. * If the value is undefined, the property gets deleted.
  10489. *
  10490. * @param {Object} target
  10491. * @param {String} name
  10492. * @param {Object} value
  10493. */
  10494. Properties.prototype.set = function(target, name, value) {
  10495. var property = this.model.getPropertyDescriptor(target, name);
  10496. var propertyName = property && property.name;
  10497. if (isUndefined(value)) {
  10498. // unset the property, if the specified value is undefined;
  10499. // delete from $attrs (for extensions) or the target itself
  10500. if (property) {
  10501. delete target[propertyName];
  10502. } else {
  10503. delete target.$attrs[name];
  10504. }
  10505. } else {
  10506. // set the property, defining well defined properties on the fly
  10507. // or simply updating them in target.$attrs (for extensions)
  10508. if (property) {
  10509. if (propertyName in target) {
  10510. target[propertyName] = value;
  10511. } else {
  10512. defineProperty(target, property, value);
  10513. }
  10514. } else {
  10515. target.$attrs[name] = value;
  10516. }
  10517. }
  10518. };
  10519. /**
  10520. * Returns the named property of the given element
  10521. *
  10522. * @param {Object} target
  10523. * @param {String} name
  10524. *
  10525. * @return {Object}
  10526. */
  10527. Properties.prototype.get = function(target, name) {
  10528. var property = this.model.getPropertyDescriptor(target, name);
  10529. if (!property) {
  10530. return target.$attrs[name];
  10531. }
  10532. var propertyName = property.name;
  10533. // check if access to collection property and lazily initialize it
  10534. if (!target[propertyName] && property.isMany) {
  10535. defineProperty(target, property, []);
  10536. }
  10537. return target[propertyName];
  10538. };
  10539. /**
  10540. * Define a property on the target element
  10541. *
  10542. * @param {Object} target
  10543. * @param {String} name
  10544. * @param {Object} options
  10545. */
  10546. Properties.prototype.define = function(target, name, options) {
  10547. Object.defineProperty(target, name, options);
  10548. };
  10549. /**
  10550. * Define the descriptor for an element
  10551. */
  10552. Properties.prototype.defineDescriptor = function(target, descriptor) {
  10553. this.define(target, '$descriptor', { value: descriptor });
  10554. };
  10555. /**
  10556. * Define the model for an element
  10557. */
  10558. Properties.prototype.defineModel = function(target, model) {
  10559. this.define(target, '$model', { value: model });
  10560. };
  10561. function isUndefined(val) {
  10562. return typeof val === 'undefined';
  10563. }
  10564. function defineProperty(target, property, value) {
  10565. Object.defineProperty(target, property.name, {
  10566. enumerable: !property.isReference,
  10567. writable: true,
  10568. value: value,
  10569. configurable: true
  10570. });
  10571. }
  10572. //// Moddle implementation /////////////////////////////////////////////////
  10573. /**
  10574. * @class Moddle
  10575. *
  10576. * A model that can be used to create elements of a specific type.
  10577. *
  10578. * @example
  10579. *
  10580. * var Moddle = require('moddle');
  10581. *
  10582. * var pkg = {
  10583. * name: 'mypackage',
  10584. * prefix: 'my',
  10585. * types: [
  10586. * { name: 'Root' }
  10587. * ]
  10588. * };
  10589. *
  10590. * var moddle = new Moddle([pkg]);
  10591. *
  10592. * @param {Array<Package>} packages the packages to contain
  10593. */
  10594. function Moddle(packages) {
  10595. this.properties = new Properties(this);
  10596. this.factory = new Factory(this, this.properties);
  10597. this.registry = new Registry(packages, this.properties);
  10598. this.typeCache = {};
  10599. }
  10600. /**
  10601. * Create an instance of the specified type.
  10602. *
  10603. * @method Moddle#create
  10604. *
  10605. * @example
  10606. *
  10607. * var foo = moddle.create('my:Foo');
  10608. * var bar = moddle.create('my:Bar', { id: 'BAR_1' });
  10609. *
  10610. * @param {String|Object} descriptor the type descriptor or name know to the model
  10611. * @param {Object} attrs a number of attributes to initialize the model instance with
  10612. * @return {Object} model instance
  10613. */
  10614. Moddle.prototype.create = function(descriptor, attrs) {
  10615. var Type = this.getType(descriptor);
  10616. if (!Type) {
  10617. throw new Error('unknown type <' + descriptor + '>');
  10618. }
  10619. return new Type(attrs);
  10620. };
  10621. /**
  10622. * Returns the type representing a given descriptor
  10623. *
  10624. * @method Moddle#getType
  10625. *
  10626. * @example
  10627. *
  10628. * var Foo = moddle.getType('my:Foo');
  10629. * var foo = new Foo({ 'id' : 'FOO_1' });
  10630. *
  10631. * @param {String|Object} descriptor the type descriptor or name know to the model
  10632. * @return {Object} the type representing the descriptor
  10633. */
  10634. Moddle.prototype.getType = function(descriptor) {
  10635. var cache = this.typeCache;
  10636. var name = isString(descriptor) ? descriptor : descriptor.ns.name;
  10637. var type = cache[name];
  10638. if (!type) {
  10639. descriptor = this.registry.getEffectiveDescriptor(name);
  10640. type = cache[name] = this.factory.createType(descriptor);
  10641. }
  10642. return type;
  10643. };
  10644. /**
  10645. * Creates an any-element type to be used within model instances.
  10646. *
  10647. * This can be used to create custom elements that lie outside the meta-model.
  10648. * The created element contains all the meta-data required to serialize it
  10649. * as part of meta-model elements.
  10650. *
  10651. * @method Moddle#createAny
  10652. *
  10653. * @example
  10654. *
  10655. * var foo = moddle.createAny('vendor:Foo', 'http://vendor', {
  10656. * value: 'bar'
  10657. * });
  10658. *
  10659. * var container = moddle.create('my:Container', 'http://my', {
  10660. * any: [ foo ]
  10661. * });
  10662. *
  10663. * // go ahead and serialize the stuff
  10664. *
  10665. *
  10666. * @param {String} name the name of the element
  10667. * @param {String} nsUri the namespace uri of the element
  10668. * @param {Object} [properties] a map of properties to initialize the instance with
  10669. * @return {Object} the any type instance
  10670. */
  10671. Moddle.prototype.createAny = function(name, nsUri, properties) {
  10672. var nameNs = parseName(name);
  10673. var element = {
  10674. $type: name,
  10675. $instanceOf: function(type) {
  10676. return type === this.$type;
  10677. }
  10678. };
  10679. var descriptor = {
  10680. name: name,
  10681. isGeneric: true,
  10682. ns: {
  10683. prefix: nameNs.prefix,
  10684. localName: nameNs.localName,
  10685. uri: nsUri
  10686. }
  10687. };
  10688. this.properties.defineDescriptor(element, descriptor);
  10689. this.properties.defineModel(element, this);
  10690. this.properties.define(element, '$parent', { enumerable: false, writable: true });
  10691. this.properties.define(element, '$instanceOf', { enumerable: false, writable: true });
  10692. forEach$1(properties, function(a, key) {
  10693. if (isObject(a) && a.value !== undefined) {
  10694. element[a.name] = a.value;
  10695. } else {
  10696. element[key] = a;
  10697. }
  10698. });
  10699. return element;
  10700. };
  10701. /**
  10702. * Returns a registered package by uri or prefix
  10703. *
  10704. * @return {Object} the package
  10705. */
  10706. Moddle.prototype.getPackage = function(uriOrPrefix) {
  10707. return this.registry.getPackage(uriOrPrefix);
  10708. };
  10709. /**
  10710. * Returns a snapshot of all known packages
  10711. *
  10712. * @return {Object} the package
  10713. */
  10714. Moddle.prototype.getPackages = function() {
  10715. return this.registry.getPackages();
  10716. };
  10717. /**
  10718. * Returns the descriptor for an element
  10719. */
  10720. Moddle.prototype.getElementDescriptor = function(element) {
  10721. return element.$descriptor;
  10722. };
  10723. /**
  10724. * Returns true if the given descriptor or instance
  10725. * represents the given type.
  10726. *
  10727. * May be applied to this, if element is omitted.
  10728. */
  10729. Moddle.prototype.hasType = function(element, type) {
  10730. if (type === undefined) {
  10731. type = element;
  10732. element = this;
  10733. }
  10734. var descriptor = element.$model.getElementDescriptor(element);
  10735. return (type in descriptor.allTypesByName);
  10736. };
  10737. /**
  10738. * Returns the descriptor of an elements named property
  10739. */
  10740. Moddle.prototype.getPropertyDescriptor = function(element, property) {
  10741. return this.getElementDescriptor(element).propertiesByName[property];
  10742. };
  10743. /**
  10744. * Returns a mapped type's descriptor
  10745. */
  10746. Moddle.prototype.getTypeDescriptor = function(type) {
  10747. return this.registry.typeMap[type];
  10748. };
  10749. var fromCharCode = String.fromCharCode;
  10750. var hasOwnProperty = Object.prototype.hasOwnProperty;
  10751. var ENTITY_PATTERN = /&#(\d+);|&#x([0-9a-f]+);|&(\w+);/ig;
  10752. var ENTITY_MAPPING = {
  10753. 'amp': '&',
  10754. 'apos': '\'',
  10755. 'gt': '>',
  10756. 'lt': '<',
  10757. 'quot': '"'
  10758. };
  10759. // map UPPERCASE variants of supported special chars
  10760. Object.keys(ENTITY_MAPPING).forEach(function(k) {
  10761. ENTITY_MAPPING[k.toUpperCase()] = ENTITY_MAPPING[k];
  10762. });
  10763. function replaceEntities(_, d, x, z) {
  10764. // reserved names, i.e. &nbsp;
  10765. if (z) {
  10766. if (hasOwnProperty.call(ENTITY_MAPPING, z)) {
  10767. return ENTITY_MAPPING[z];
  10768. } else {
  10769. // fall back to original value
  10770. return '&' + z + ';';
  10771. }
  10772. }
  10773. // decimal encoded char
  10774. if (d) {
  10775. return fromCharCode(d);
  10776. }
  10777. // hex encoded char
  10778. return fromCharCode(parseInt(x, 16));
  10779. }
  10780. /**
  10781. * A basic entity decoder that can decode a minimal
  10782. * sub-set of reserved names (&amp;) as well as
  10783. * hex (&#xaaf;) and decimal (&#1231;) encoded characters.
  10784. *
  10785. * @param {string} str
  10786. *
  10787. * @return {string} decoded string
  10788. */
  10789. function decodeEntities(s) {
  10790. if (s.length > 3 && s.indexOf('&') !== -1) {
  10791. return s.replace(ENTITY_PATTERN, replaceEntities);
  10792. }
  10793. return s;
  10794. }
  10795. var XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance';
  10796. var XSI_PREFIX = 'xsi';
  10797. var XSI_TYPE$1 = 'xsi:type';
  10798. var NON_WHITESPACE_OUTSIDE_ROOT_NODE = 'non-whitespace outside of root node';
  10799. function error$1(msg) {
  10800. return new Error(msg);
  10801. }
  10802. function missingNamespaceForPrefix(prefix) {
  10803. return 'missing namespace for prefix <' + prefix + '>';
  10804. }
  10805. function getter(getFn) {
  10806. return {
  10807. 'get': getFn,
  10808. 'enumerable': true
  10809. };
  10810. }
  10811. function cloneNsMatrix(nsMatrix) {
  10812. var clone = {}, key;
  10813. for (key in nsMatrix) {
  10814. clone[key] = nsMatrix[key];
  10815. }
  10816. return clone;
  10817. }
  10818. function uriPrefix(prefix) {
  10819. return prefix + '$uri';
  10820. }
  10821. function buildNsMatrix(nsUriToPrefix) {
  10822. var nsMatrix = {},
  10823. uri,
  10824. prefix;
  10825. for (uri in nsUriToPrefix) {
  10826. prefix = nsUriToPrefix[uri];
  10827. nsMatrix[prefix] = prefix;
  10828. nsMatrix[uriPrefix(prefix)] = uri;
  10829. }
  10830. return nsMatrix;
  10831. }
  10832. function noopGetContext() {
  10833. return { 'line': 0, 'column': 0 };
  10834. }
  10835. function throwFunc(err) {
  10836. throw err;
  10837. }
  10838. /**
  10839. * Creates a new parser with the given options.
  10840. *
  10841. * @constructor
  10842. *
  10843. * @param {!Object<string, ?>=} options
  10844. */
  10845. function Parser(options) {
  10846. if (!this) {
  10847. return new Parser(options);
  10848. }
  10849. var proxy = options && options['proxy'];
  10850. var onText,
  10851. onOpenTag,
  10852. onCloseTag,
  10853. onCDATA,
  10854. onError = throwFunc,
  10855. onWarning,
  10856. onComment,
  10857. onQuestion,
  10858. onAttention;
  10859. var getContext = noopGetContext;
  10860. /**
  10861. * Do we need to parse the current elements attributes for namespaces?
  10862. *
  10863. * @type {boolean}
  10864. */
  10865. var maybeNS = false;
  10866. /**
  10867. * Do we process namespaces at all?
  10868. *
  10869. * @type {boolean}
  10870. */
  10871. var isNamespace = false;
  10872. /**
  10873. * The caught error returned on parse end
  10874. *
  10875. * @type {Error}
  10876. */
  10877. var returnError = null;
  10878. /**
  10879. * Should we stop parsing?
  10880. *
  10881. * @type {boolean}
  10882. */
  10883. var parseStop = false;
  10884. /**
  10885. * A map of { uri: prefix } used by the parser.
  10886. *
  10887. * This map will ensure we can normalize prefixes during processing;
  10888. * for each uri, only one prefix will be exposed to the handlers.
  10889. *
  10890. * @type {!Object<string, string>}}
  10891. */
  10892. var nsUriToPrefix;
  10893. /**
  10894. * Handle parse error.
  10895. *
  10896. * @param {string|Error} err
  10897. */
  10898. function handleError(err) {
  10899. if (!(err instanceof Error)) {
  10900. err = error$1(err);
  10901. }
  10902. returnError = err;
  10903. onError(err, getContext);
  10904. }
  10905. /**
  10906. * Handle parse error.
  10907. *
  10908. * @param {string|Error} err
  10909. */
  10910. function handleWarning(err) {
  10911. if (!onWarning) {
  10912. return;
  10913. }
  10914. if (!(err instanceof Error)) {
  10915. err = error$1(err);
  10916. }
  10917. onWarning(err, getContext);
  10918. }
  10919. /**
  10920. * Register parse listener.
  10921. *
  10922. * @param {string} name
  10923. * @param {Function} cb
  10924. *
  10925. * @return {Parser}
  10926. */
  10927. this['on'] = function(name, cb) {
  10928. if (typeof cb !== 'function') {
  10929. throw error$1('required args <name, cb>');
  10930. }
  10931. switch (name) {
  10932. case 'openTag': onOpenTag = cb; break;
  10933. case 'text': onText = cb; break;
  10934. case 'closeTag': onCloseTag = cb; break;
  10935. case 'error': onError = cb; break;
  10936. case 'warn': onWarning = cb; break;
  10937. case 'cdata': onCDATA = cb; break;
  10938. case 'attention': onAttention = cb; break; // <!XXXXX zzzz="eeee">
  10939. case 'question': onQuestion = cb; break; // <? .... ?>
  10940. case 'comment': onComment = cb; break;
  10941. default:
  10942. throw error$1('unsupported event: ' + name);
  10943. }
  10944. return this;
  10945. };
  10946. /**
  10947. * Set the namespace to prefix mapping.
  10948. *
  10949. * @example
  10950. *
  10951. * parser.ns({
  10952. * 'http://foo': 'foo',
  10953. * 'http://bar': 'bar'
  10954. * });
  10955. *
  10956. * @param {!Object<string, string>} nsMap
  10957. *
  10958. * @return {Parser}
  10959. */
  10960. this['ns'] = function(nsMap) {
  10961. if (typeof nsMap === 'undefined') {
  10962. nsMap = {};
  10963. }
  10964. if (typeof nsMap !== 'object') {
  10965. throw error$1('required args <nsMap={}>');
  10966. }
  10967. var _nsUriToPrefix = {}, k;
  10968. for (k in nsMap) {
  10969. _nsUriToPrefix[k] = nsMap[k];
  10970. }
  10971. // FORCE default mapping for schema instance
  10972. _nsUriToPrefix[XSI_URI] = XSI_PREFIX;
  10973. isNamespace = true;
  10974. nsUriToPrefix = _nsUriToPrefix;
  10975. return this;
  10976. };
  10977. /**
  10978. * Parse xml string.
  10979. *
  10980. * @param {string} xml
  10981. *
  10982. * @return {Error} returnError, if not thrown
  10983. */
  10984. this['parse'] = function(xml) {
  10985. if (typeof xml !== 'string') {
  10986. throw error$1('required args <xml=string>');
  10987. }
  10988. returnError = null;
  10989. parse(xml);
  10990. getContext = noopGetContext;
  10991. parseStop = false;
  10992. return returnError;
  10993. };
  10994. /**
  10995. * Stop parsing.
  10996. */
  10997. this['stop'] = function() {
  10998. parseStop = true;
  10999. };
  11000. /**
  11001. * Parse string, invoking configured listeners on element.
  11002. *
  11003. * @param {string} xml
  11004. */
  11005. function parse(xml) {
  11006. var nsMatrixStack = isNamespace ? [] : null,
  11007. nsMatrix = isNamespace ? buildNsMatrix(nsUriToPrefix) : null,
  11008. _nsMatrix,
  11009. nodeStack = [],
  11010. anonymousNsCount = 0,
  11011. tagStart = false,
  11012. tagEnd = false,
  11013. i = 0, j = 0,
  11014. x, y, q, w, v,
  11015. xmlns,
  11016. elementName,
  11017. _elementName,
  11018. elementProxy
  11019. ;
  11020. var attrsString = '',
  11021. attrsStart = 0,
  11022. cachedAttrs // false = parsed with errors, null = needs parsing
  11023. ;
  11024. /**
  11025. * Parse attributes on demand and returns the parsed attributes.
  11026. *
  11027. * Return semantics: (1) `false` on attribute parse error,
  11028. * (2) object hash on extracted attrs.
  11029. *
  11030. * @return {boolean|Object}
  11031. */
  11032. function getAttrs() {
  11033. if (cachedAttrs !== null) {
  11034. return cachedAttrs;
  11035. }
  11036. var nsUri,
  11037. nsUriPrefix,
  11038. nsName,
  11039. defaultAlias = isNamespace && nsMatrix['xmlns'],
  11040. attrList = isNamespace && maybeNS ? [] : null,
  11041. i = attrsStart,
  11042. s = attrsString,
  11043. l = s.length,
  11044. hasNewMatrix,
  11045. newalias,
  11046. value,
  11047. alias,
  11048. name,
  11049. attrs = {},
  11050. seenAttrs = {},
  11051. skipAttr,
  11052. w,
  11053. j;
  11054. parseAttr:
  11055. for (; i < l; i++) {
  11056. skipAttr = false;
  11057. w = s.charCodeAt(i);
  11058. if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE={ \f\n\r\t\v}
  11059. continue;
  11060. }
  11061. // wait for non whitespace character
  11062. if (w < 65 || w > 122 || (w > 90 && w < 97)) {
  11063. if (w !== 95 && w !== 58) { // char 95"_" 58":"
  11064. handleWarning('illegal first char attribute name');
  11065. skipAttr = true;
  11066. }
  11067. }
  11068. // parse attribute name
  11069. for (j = i + 1; j < l; j++) {
  11070. w = s.charCodeAt(j);
  11071. if (
  11072. w > 96 && w < 123 ||
  11073. w > 64 && w < 91 ||
  11074. w > 47 && w < 59 ||
  11075. w === 46 || // '.'
  11076. w === 45 || // '-'
  11077. w === 95 // '_'
  11078. ) {
  11079. continue;
  11080. }
  11081. // unexpected whitespace
  11082. if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
  11083. handleWarning('missing attribute value');
  11084. i = j;
  11085. continue parseAttr;
  11086. }
  11087. // expected "="
  11088. if (w === 61) { // "=" == 61
  11089. break;
  11090. }
  11091. handleWarning('illegal attribute name char');
  11092. skipAttr = true;
  11093. }
  11094. name = s.substring(i, j);
  11095. if (name === 'xmlns:xmlns') {
  11096. handleWarning('illegal declaration of xmlns');
  11097. skipAttr = true;
  11098. }
  11099. w = s.charCodeAt(j + 1);
  11100. if (w === 34) { // '"'
  11101. j = s.indexOf('"', i = j + 2);
  11102. if (j === -1) {
  11103. j = s.indexOf('\'', i);
  11104. if (j !== -1) {
  11105. handleWarning('attribute value quote missmatch');
  11106. skipAttr = true;
  11107. }
  11108. }
  11109. } else if (w === 39) { // "'"
  11110. j = s.indexOf('\'', i = j + 2);
  11111. if (j === -1) {
  11112. j = s.indexOf('"', i);
  11113. if (j !== -1) {
  11114. handleWarning('attribute value quote missmatch');
  11115. skipAttr = true;
  11116. }
  11117. }
  11118. } else {
  11119. handleWarning('missing attribute value quotes');
  11120. skipAttr = true;
  11121. // skip to next space
  11122. for (j = j + 1; j < l; j++) {
  11123. w = s.charCodeAt(j + 1);
  11124. if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
  11125. break;
  11126. }
  11127. }
  11128. }
  11129. if (j === -1) {
  11130. handleWarning('missing closing quotes');
  11131. j = l;
  11132. skipAttr = true;
  11133. }
  11134. if (!skipAttr) {
  11135. value = s.substring(i, j);
  11136. }
  11137. i = j;
  11138. // ensure SPACE follows attribute
  11139. // skip illegal content otherwise
  11140. // example a="b"c
  11141. for (; j + 1 < l; j++) {
  11142. w = s.charCodeAt(j + 1);
  11143. if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
  11144. break;
  11145. }
  11146. // FIRST ILLEGAL CHAR
  11147. if (i === j) {
  11148. handleWarning('illegal character after attribute end');
  11149. skipAttr = true;
  11150. }
  11151. }
  11152. // advance cursor to next attribute
  11153. i = j + 1;
  11154. if (skipAttr) {
  11155. continue parseAttr;
  11156. }
  11157. // check attribute re-declaration
  11158. if (name in seenAttrs) {
  11159. handleWarning('attribute <' + name + '> already defined');
  11160. continue;
  11161. }
  11162. seenAttrs[name] = true;
  11163. if (!isNamespace) {
  11164. attrs[name] = value;
  11165. continue;
  11166. }
  11167. // try to extract namespace information
  11168. if (maybeNS) {
  11169. newalias = (
  11170. name === 'xmlns'
  11171. ? 'xmlns'
  11172. : (name.charCodeAt(0) === 120 && name.substr(0, 6) === 'xmlns:')
  11173. ? name.substr(6)
  11174. : null
  11175. );
  11176. // handle xmlns(:alias) assignment
  11177. if (newalias !== null) {
  11178. nsUri = decodeEntities(value);
  11179. nsUriPrefix = uriPrefix(newalias);
  11180. alias = nsUriToPrefix[nsUri];
  11181. if (!alias) {
  11182. // no prefix defined or prefix collision
  11183. if (
  11184. (newalias === 'xmlns') ||
  11185. (nsUriPrefix in nsMatrix && nsMatrix[nsUriPrefix] !== nsUri)
  11186. ) {
  11187. // alocate free ns prefix
  11188. do {
  11189. alias = 'ns' + (anonymousNsCount++);
  11190. } while (typeof nsMatrix[alias] !== 'undefined');
  11191. } else {
  11192. alias = newalias;
  11193. }
  11194. nsUriToPrefix[nsUri] = alias;
  11195. }
  11196. if (nsMatrix[newalias] !== alias) {
  11197. if (!hasNewMatrix) {
  11198. nsMatrix = cloneNsMatrix(nsMatrix);
  11199. hasNewMatrix = true;
  11200. }
  11201. nsMatrix[newalias] = alias;
  11202. if (newalias === 'xmlns') {
  11203. nsMatrix[uriPrefix(alias)] = nsUri;
  11204. defaultAlias = alias;
  11205. }
  11206. nsMatrix[nsUriPrefix] = nsUri;
  11207. }
  11208. // expose xmlns(:asd)="..." in attributes
  11209. attrs[name] = value;
  11210. continue;
  11211. }
  11212. // collect attributes until all namespace
  11213. // declarations are processed
  11214. attrList.push(name, value);
  11215. continue;
  11216. } /** end if (maybeNs) */
  11217. // handle attributes on element without
  11218. // namespace declarations
  11219. w = name.indexOf(':');
  11220. if (w === -1) {
  11221. attrs[name] = value;
  11222. continue;
  11223. }
  11224. // normalize ns attribute name
  11225. if (!(nsName = nsMatrix[name.substring(0, w)])) {
  11226. handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
  11227. continue;
  11228. }
  11229. name = defaultAlias === nsName
  11230. ? name.substr(w + 1)
  11231. : nsName + name.substr(w);
  11232. // end: normalize ns attribute name
  11233. // normalize xsi:type ns attribute value
  11234. if (name === XSI_TYPE$1) {
  11235. w = value.indexOf(':');
  11236. if (w !== -1) {
  11237. nsName = value.substring(0, w);
  11238. // handle default prefixes, i.e. xs:String gracefully
  11239. nsName = nsMatrix[nsName] || nsName;
  11240. value = nsName + value.substring(w);
  11241. } else {
  11242. value = defaultAlias + ':' + value;
  11243. }
  11244. }
  11245. // end: normalize xsi:type ns attribute value
  11246. attrs[name] = value;
  11247. }
  11248. // handle deferred, possibly namespaced attributes
  11249. if (maybeNS) {
  11250. // normalize captured attributes
  11251. for (i = 0, l = attrList.length; i < l; i++) {
  11252. name = attrList[i++];
  11253. value = attrList[i];
  11254. w = name.indexOf(':');
  11255. if (w !== -1) {
  11256. // normalize ns attribute name
  11257. if (!(nsName = nsMatrix[name.substring(0, w)])) {
  11258. handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
  11259. continue;
  11260. }
  11261. name = defaultAlias === nsName
  11262. ? name.substr(w + 1)
  11263. : nsName + name.substr(w);
  11264. // end: normalize ns attribute name
  11265. // normalize xsi:type ns attribute value
  11266. if (name === XSI_TYPE$1) {
  11267. w = value.indexOf(':');
  11268. if (w !== -1) {
  11269. nsName = value.substring(0, w);
  11270. // handle default prefixes, i.e. xs:String gracefully
  11271. nsName = nsMatrix[nsName] || nsName;
  11272. value = nsName + value.substring(w);
  11273. } else {
  11274. value = defaultAlias + ':' + value;
  11275. }
  11276. }
  11277. // end: normalize xsi:type ns attribute value
  11278. }
  11279. attrs[name] = value;
  11280. }
  11281. // end: normalize captured attributes
  11282. }
  11283. return cachedAttrs = attrs;
  11284. }
  11285. /**
  11286. * Extract the parse context { line, column, part }
  11287. * from the current parser position.
  11288. *
  11289. * @return {Object} parse context
  11290. */
  11291. function getParseContext() {
  11292. var splitsRe = /(\r\n|\r|\n)/g;
  11293. var line = 0;
  11294. var column = 0;
  11295. var startOfLine = 0;
  11296. var endOfLine = j;
  11297. var match;
  11298. var data;
  11299. while (i >= startOfLine) {
  11300. match = splitsRe.exec(xml);
  11301. if (!match) {
  11302. break;
  11303. }
  11304. // end of line = (break idx + break chars)
  11305. endOfLine = match[0].length + match.index;
  11306. if (endOfLine > i) {
  11307. break;
  11308. }
  11309. // advance to next line
  11310. line += 1;
  11311. startOfLine = endOfLine;
  11312. }
  11313. // EOF errors
  11314. if (i == -1) {
  11315. column = endOfLine;
  11316. data = xml.substring(j);
  11317. } else
  11318. // start errors
  11319. if (j === 0) {
  11320. data = xml.substring(j, i);
  11321. }
  11322. // other errors
  11323. else {
  11324. column = i - startOfLine;
  11325. data = (j == -1 ? xml.substring(i) : xml.substring(i, j + 1));
  11326. }
  11327. return {
  11328. 'data': data,
  11329. 'line': line,
  11330. 'column': column
  11331. };
  11332. }
  11333. getContext = getParseContext;
  11334. if (proxy) {
  11335. elementProxy = Object.create({}, {
  11336. 'name': getter(function() {
  11337. return elementName;
  11338. }),
  11339. 'originalName': getter(function() {
  11340. return _elementName;
  11341. }),
  11342. 'attrs': getter(getAttrs),
  11343. 'ns': getter(function() {
  11344. return nsMatrix;
  11345. })
  11346. });
  11347. }
  11348. // actual parse logic
  11349. while (j !== -1) {
  11350. if (xml.charCodeAt(j) === 60) { // "<"
  11351. i = j;
  11352. } else {
  11353. i = xml.indexOf('<', j);
  11354. }
  11355. // parse end
  11356. if (i === -1) {
  11357. if (nodeStack.length) {
  11358. return handleError('unexpected end of file');
  11359. }
  11360. if (j === 0) {
  11361. return handleError('missing start tag');
  11362. }
  11363. if (j < xml.length) {
  11364. if (xml.substring(j).trim()) {
  11365. handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
  11366. }
  11367. }
  11368. return;
  11369. }
  11370. // parse text
  11371. if (j !== i) {
  11372. if (nodeStack.length) {
  11373. if (onText) {
  11374. onText(xml.substring(j, i), decodeEntities, getContext);
  11375. if (parseStop) {
  11376. return;
  11377. }
  11378. }
  11379. } else {
  11380. if (xml.substring(j, i).trim()) {
  11381. handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
  11382. if (parseStop) {
  11383. return;
  11384. }
  11385. }
  11386. }
  11387. }
  11388. w = xml.charCodeAt(i+1);
  11389. // parse comments + CDATA
  11390. if (w === 33) { // "!"
  11391. q = xml.charCodeAt(i+2);
  11392. // CDATA section
  11393. if (q === 91 && xml.substr(i + 3, 6) === 'CDATA[') { // 91 == "["
  11394. j = xml.indexOf(']]>', i);
  11395. if (j === -1) {
  11396. return handleError('unclosed cdata');
  11397. }
  11398. if (onCDATA) {
  11399. onCDATA(xml.substring(i + 9, j), getContext);
  11400. if (parseStop) {
  11401. return;
  11402. }
  11403. }
  11404. j += 3;
  11405. continue;
  11406. }
  11407. // comment
  11408. if (q === 45 && xml.charCodeAt(i + 3) === 45) { // 45 == "-"
  11409. j = xml.indexOf('-->', i);
  11410. if (j === -1) {
  11411. return handleError('unclosed comment');
  11412. }
  11413. if (onComment) {
  11414. onComment(xml.substring(i + 4, j), decodeEntities, getContext);
  11415. if (parseStop) {
  11416. return;
  11417. }
  11418. }
  11419. j += 3;
  11420. continue;
  11421. }
  11422. }
  11423. // parse question <? ... ?>
  11424. if (w === 63) { // "?"
  11425. j = xml.indexOf('?>', i);
  11426. if (j === -1) {
  11427. return handleError('unclosed question');
  11428. }
  11429. if (onQuestion) {
  11430. onQuestion(xml.substring(i, j + 2), getContext);
  11431. if (parseStop) {
  11432. return;
  11433. }
  11434. }
  11435. j += 2;
  11436. continue;
  11437. }
  11438. // find matching closing tag for attention or standard tags
  11439. // for that we must skip through attribute values
  11440. // (enclosed in single or double quotes)
  11441. for (x = i + 1; ; x++) {
  11442. v = xml.charCodeAt(x);
  11443. if (isNaN(v)) {
  11444. j = -1;
  11445. return handleError('unclosed tag');
  11446. }
  11447. // [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
  11448. // skips the quoted string
  11449. // (double quotes) does not appear in a literal enclosed by (double quotes)
  11450. // (single quote) does not appear in a literal enclosed by (single quote)
  11451. if (v === 34) { // '"'
  11452. q = xml.indexOf('"', x + 1);
  11453. x = q !== -1 ? q : x;
  11454. } else if (v === 39) { // "'"
  11455. q = xml.indexOf("'", x + 1);
  11456. x = q !== -1 ? q : x;
  11457. } else if (v === 62) { // '>'
  11458. j = x;
  11459. break;
  11460. }
  11461. }
  11462. // parse attention <! ...>
  11463. // previously comment and CDATA have already been parsed
  11464. if (w === 33) { // "!"
  11465. if (onAttention) {
  11466. onAttention(xml.substring(i, j + 1), decodeEntities, getContext);
  11467. if (parseStop) {
  11468. return;
  11469. }
  11470. }
  11471. j += 1;
  11472. continue;
  11473. }
  11474. // don't process attributes;
  11475. // there are none
  11476. cachedAttrs = {};
  11477. // if (xml.charCodeAt(i+1) === 47) { // </...
  11478. if (w === 47) { // </...
  11479. tagStart = false;
  11480. tagEnd = true;
  11481. if (!nodeStack.length) {
  11482. return handleError('missing open tag');
  11483. }
  11484. // verify open <-> close tag match
  11485. x = elementName = nodeStack.pop();
  11486. q = i + 2 + x.length;
  11487. if (xml.substring(i + 2, q) !== x) {
  11488. return handleError('closing tag mismatch');
  11489. }
  11490. // verify chars in close tag
  11491. for (; q < j; q++) {
  11492. w = xml.charCodeAt(q);
  11493. if (w === 32 || (w > 8 && w < 14)) { // \f\n\r\t\v space
  11494. continue;
  11495. }
  11496. return handleError('close tag');
  11497. }
  11498. } else {
  11499. if (xml.charCodeAt(j - 1) === 47) { // .../>
  11500. x = elementName = xml.substring(i + 1, j - 1);
  11501. tagStart = true;
  11502. tagEnd = true;
  11503. } else {
  11504. x = elementName = xml.substring(i + 1, j);
  11505. tagStart = true;
  11506. tagEnd = false;
  11507. }
  11508. if (!(w > 96 && w < 123 || w > 64 && w < 91 || w === 95 || w === 58)) { // char 95"_" 58":"
  11509. return handleError('illegal first char nodeName');
  11510. }
  11511. for (q = 1, y = x.length; q < y; q++) {
  11512. w = x.charCodeAt(q);
  11513. if (w > 96 && w < 123 || w > 64 && w < 91 || w > 47 && w < 59 || w === 45 || w === 95 || w == 46) {
  11514. continue;
  11515. }
  11516. if (w === 32 || (w < 14 && w > 8)) { // \f\n\r\t\v space
  11517. elementName = x.substring(0, q);
  11518. // maybe there are attributes
  11519. cachedAttrs = null;
  11520. break;
  11521. }
  11522. return handleError('invalid nodeName');
  11523. }
  11524. if (!tagEnd) {
  11525. nodeStack.push(elementName);
  11526. }
  11527. }
  11528. if (isNamespace) {
  11529. _nsMatrix = nsMatrix;
  11530. if (tagStart) {
  11531. // remember old namespace
  11532. // unless we're self-closing
  11533. if (!tagEnd) {
  11534. nsMatrixStack.push(_nsMatrix);
  11535. }
  11536. if (cachedAttrs === null) {
  11537. // quick check, whether there may be namespace
  11538. // declarations on the node; if that is the case
  11539. // we need to eagerly parse the node attributes
  11540. if ((maybeNS = x.indexOf('xmlns', q) !== -1)) {
  11541. attrsStart = q;
  11542. attrsString = x;
  11543. getAttrs();
  11544. maybeNS = false;
  11545. }
  11546. }
  11547. }
  11548. _elementName = elementName;
  11549. w = elementName.indexOf(':');
  11550. if (w !== -1) {
  11551. xmlns = nsMatrix[elementName.substring(0, w)];
  11552. // prefix given; namespace must exist
  11553. if (!xmlns) {
  11554. return handleError('missing namespace on <' + _elementName + '>');
  11555. }
  11556. elementName = elementName.substr(w + 1);
  11557. } else {
  11558. xmlns = nsMatrix['xmlns'];
  11559. // if no default namespace is defined,
  11560. // we'll import the element as anonymous.
  11561. //
  11562. // it is up to users to correct that to the document defined
  11563. // targetNamespace, or whatever their undersanding of the
  11564. // XML spec mandates.
  11565. }
  11566. // adjust namespace prefixs as configured
  11567. if (xmlns) {
  11568. elementName = xmlns + ':' + elementName;
  11569. }
  11570. }
  11571. if (tagStart) {
  11572. attrsStart = q;
  11573. attrsString = x;
  11574. if (onOpenTag) {
  11575. if (proxy) {
  11576. onOpenTag(elementProxy, decodeEntities, tagEnd, getContext);
  11577. } else {
  11578. onOpenTag(elementName, getAttrs, decodeEntities, tagEnd, getContext);
  11579. }
  11580. if (parseStop) {
  11581. return;
  11582. }
  11583. }
  11584. }
  11585. if (tagEnd) {
  11586. if (onCloseTag) {
  11587. onCloseTag(proxy ? elementProxy : elementName, decodeEntities, tagStart, getContext);
  11588. if (parseStop) {
  11589. return;
  11590. }
  11591. }
  11592. // restore old namespace
  11593. if (isNamespace) {
  11594. if (!tagStart) {
  11595. nsMatrix = nsMatrixStack.pop();
  11596. } else {
  11597. nsMatrix = _nsMatrix;
  11598. }
  11599. }
  11600. }
  11601. j += 1;
  11602. }
  11603. } /** end parse */
  11604. }
  11605. function hasLowerCaseAlias(pkg) {
  11606. return pkg.xml && pkg.xml.tagAlias === 'lowerCase';
  11607. }
  11608. var DEFAULT_NS_MAP = {
  11609. 'xsi': 'http://www.w3.org/2001/XMLSchema-instance',
  11610. 'xml': 'http://www.w3.org/XML/1998/namespace'
  11611. };
  11612. var XSI_TYPE = 'xsi:type';
  11613. function serializeFormat(element) {
  11614. return element.xml && element.xml.serialize;
  11615. }
  11616. function serializeAsType(element) {
  11617. return serializeFormat(element) === XSI_TYPE;
  11618. }
  11619. function serializeAsProperty(element) {
  11620. return serializeFormat(element) === 'property';
  11621. }
  11622. function capitalize(str) {
  11623. return str.charAt(0).toUpperCase() + str.slice(1);
  11624. }
  11625. function aliasToName(aliasNs, pkg) {
  11626. if (!hasLowerCaseAlias(pkg)) {
  11627. return aliasNs.name;
  11628. }
  11629. return aliasNs.prefix + ':' + capitalize(aliasNs.localName);
  11630. }
  11631. function prefixedToName(nameNs, pkg) {
  11632. var name = nameNs.name,
  11633. localName = nameNs.localName;
  11634. var typePrefix = pkg.xml && pkg.xml.typePrefix;
  11635. if (typePrefix && localName.indexOf(typePrefix) === 0) {
  11636. return nameNs.prefix + ':' + localName.slice(typePrefix.length);
  11637. } else {
  11638. return name;
  11639. }
  11640. }
  11641. function normalizeXsiTypeName(name, model) {
  11642. var nameNs = parseName(name);
  11643. var pkg = model.getPackage(nameNs.prefix);
  11644. return prefixedToName(nameNs, pkg);
  11645. }
  11646. function error(message) {
  11647. return new Error(message);
  11648. }
  11649. /**
  11650. * Get the moddle descriptor for a given instance or type.
  11651. *
  11652. * @param {ModdleElement|Function} element
  11653. *
  11654. * @return {Object} the moddle descriptor
  11655. */
  11656. function getModdleDescriptor(element) {
  11657. return element.$descriptor;
  11658. }
  11659. /**
  11660. * A parse context.
  11661. *
  11662. * @class
  11663. *
  11664. * @param {Object} options
  11665. * @param {ElementHandler} options.rootHandler the root handler for parsing a document
  11666. * @param {boolean} [options.lax=false] whether or not to ignore invalid elements
  11667. */
  11668. function Context(options) {
  11669. /**
  11670. * @property {ElementHandler} rootHandler
  11671. */
  11672. /**
  11673. * @property {Boolean} lax
  11674. */
  11675. assign(this, options);
  11676. this.elementsById = {};
  11677. this.references = [];
  11678. this.warnings = [];
  11679. /**
  11680. * Add an unresolved reference.
  11681. *
  11682. * @param {Object} reference
  11683. */
  11684. this.addReference = function(reference) {
  11685. this.references.push(reference);
  11686. };
  11687. /**
  11688. * Add a processed element.
  11689. *
  11690. * @param {ModdleElement} element
  11691. */
  11692. this.addElement = function(element) {
  11693. if (!element) {
  11694. throw error('expected element');
  11695. }
  11696. var elementsById = this.elementsById;
  11697. var descriptor = getModdleDescriptor(element);
  11698. var idProperty = descriptor.idProperty,
  11699. id;
  11700. if (idProperty) {
  11701. id = element.get(idProperty.name);
  11702. if (id) {
  11703. // for QName validation as per http://www.w3.org/TR/REC-xml/#NT-NameChar
  11704. if (!/^([a-z][\w-.]*:)?[a-z_][\w-.]*$/i.test(id)) {
  11705. throw new Error('illegal ID <' + id + '>');
  11706. }
  11707. if (elementsById[id]) {
  11708. throw error('duplicate ID <' + id + '>');
  11709. }
  11710. elementsById[id] = element;
  11711. }
  11712. }
  11713. };
  11714. /**
  11715. * Add an import warning.
  11716. *
  11717. * @param {Object} warning
  11718. * @param {String} warning.message
  11719. * @param {Error} [warning.error]
  11720. */
  11721. this.addWarning = function(warning) {
  11722. this.warnings.push(warning);
  11723. };
  11724. }
  11725. function BaseHandler() {}
  11726. BaseHandler.prototype.handleEnd = function() {};
  11727. BaseHandler.prototype.handleText = function() {};
  11728. BaseHandler.prototype.handleNode = function() {};
  11729. /**
  11730. * A simple pass through handler that does nothing except for
  11731. * ignoring all input it receives.
  11732. *
  11733. * This is used to ignore unknown elements and
  11734. * attributes.
  11735. */
  11736. function NoopHandler() { }
  11737. NoopHandler.prototype = Object.create(BaseHandler.prototype);
  11738. NoopHandler.prototype.handleNode = function() {
  11739. return this;
  11740. };
  11741. function BodyHandler() {}
  11742. BodyHandler.prototype = Object.create(BaseHandler.prototype);
  11743. BodyHandler.prototype.handleText = function(text) {
  11744. this.body = (this.body || '') + text;
  11745. };
  11746. function ReferenceHandler(property, context) {
  11747. this.property = property;
  11748. this.context = context;
  11749. }
  11750. ReferenceHandler.prototype = Object.create(BodyHandler.prototype);
  11751. ReferenceHandler.prototype.handleNode = function(node) {
  11752. if (this.element) {
  11753. throw error('expected no sub nodes');
  11754. } else {
  11755. this.element = this.createReference(node);
  11756. }
  11757. return this;
  11758. };
  11759. ReferenceHandler.prototype.handleEnd = function() {
  11760. this.element.id = this.body;
  11761. };
  11762. ReferenceHandler.prototype.createReference = function(node) {
  11763. return {
  11764. property: this.property.ns.name,
  11765. id: ''
  11766. };
  11767. };
  11768. function ValueHandler(propertyDesc, element) {
  11769. this.element = element;
  11770. this.propertyDesc = propertyDesc;
  11771. }
  11772. ValueHandler.prototype = Object.create(BodyHandler.prototype);
  11773. ValueHandler.prototype.handleEnd = function() {
  11774. var value = this.body || '',
  11775. element = this.element,
  11776. propertyDesc = this.propertyDesc;
  11777. value = coerceType(propertyDesc.type, value);
  11778. if (propertyDesc.isMany) {
  11779. element.get(propertyDesc.name).push(value);
  11780. } else {
  11781. element.set(propertyDesc.name, value);
  11782. }
  11783. };
  11784. function BaseElementHandler() {}
  11785. BaseElementHandler.prototype = Object.create(BodyHandler.prototype);
  11786. BaseElementHandler.prototype.handleNode = function(node) {
  11787. var parser = this,
  11788. element = this.element;
  11789. if (!element) {
  11790. element = this.element = this.createElement(node);
  11791. this.context.addElement(element);
  11792. } else {
  11793. parser = this.handleChild(node);
  11794. }
  11795. return parser;
  11796. };
  11797. /**
  11798. * @class Reader.ElementHandler
  11799. *
  11800. */
  11801. function ElementHandler(model, typeName, context) {
  11802. this.model = model;
  11803. this.type = model.getType(typeName);
  11804. this.context = context;
  11805. }
  11806. ElementHandler.prototype = Object.create(BaseElementHandler.prototype);
  11807. ElementHandler.prototype.addReference = function(reference) {
  11808. this.context.addReference(reference);
  11809. };
  11810. ElementHandler.prototype.handleText = function(text) {
  11811. var element = this.element,
  11812. descriptor = getModdleDescriptor(element),
  11813. bodyProperty = descriptor.bodyProperty;
  11814. if (!bodyProperty) {
  11815. throw error('unexpected body text <' + text + '>');
  11816. }
  11817. BodyHandler.prototype.handleText.call(this, text);
  11818. };
  11819. ElementHandler.prototype.handleEnd = function() {
  11820. var value = this.body,
  11821. element = this.element,
  11822. descriptor = getModdleDescriptor(element),
  11823. bodyProperty = descriptor.bodyProperty;
  11824. if (bodyProperty && value !== undefined) {
  11825. value = coerceType(bodyProperty.type, value);
  11826. element.set(bodyProperty.name, value);
  11827. }
  11828. };
  11829. /**
  11830. * Create an instance of the model from the given node.
  11831. *
  11832. * @param {Element} node the xml node
  11833. */
  11834. ElementHandler.prototype.createElement = function(node) {
  11835. var attributes = node.attributes,
  11836. Type = this.type,
  11837. descriptor = getModdleDescriptor(Type),
  11838. context = this.context,
  11839. instance = new Type({}),
  11840. model = this.model,
  11841. propNameNs;
  11842. forEach$1(attributes, function(value, name) {
  11843. var prop = descriptor.propertiesByName[name],
  11844. values;
  11845. if (prop && prop.isReference) {
  11846. if (!prop.isMany) {
  11847. context.addReference({
  11848. element: instance,
  11849. property: prop.ns.name,
  11850. id: value
  11851. });
  11852. } else {
  11853. // IDREFS: parse references as whitespace-separated list
  11854. values = value.split(' ');
  11855. forEach$1(values, function(v) {
  11856. context.addReference({
  11857. element: instance,
  11858. property: prop.ns.name,
  11859. id: v
  11860. });
  11861. });
  11862. }
  11863. } else {
  11864. if (prop) {
  11865. value = coerceType(prop.type, value);
  11866. } else
  11867. if (name !== 'xmlns') {
  11868. propNameNs = parseName(name, descriptor.ns.prefix);
  11869. // check whether attribute is defined in a well-known namespace
  11870. // if that is the case we emit a warning to indicate potential misuse
  11871. if (model.getPackage(propNameNs.prefix)) {
  11872. context.addWarning({
  11873. message: 'unknown attribute <' + name + '>',
  11874. element: instance,
  11875. property: name,
  11876. value: value
  11877. });
  11878. }
  11879. }
  11880. instance.set(name, value);
  11881. }
  11882. });
  11883. return instance;
  11884. };
  11885. ElementHandler.prototype.getPropertyForNode = function(node) {
  11886. var name = node.name;
  11887. var nameNs = parseName(name);
  11888. var type = this.type,
  11889. model = this.model,
  11890. descriptor = getModdleDescriptor(type);
  11891. var propertyName = nameNs.name,
  11892. property = descriptor.propertiesByName[propertyName],
  11893. elementTypeName,
  11894. elementType;
  11895. // search for properties by name first
  11896. if (property && !property.isAttr) {
  11897. if (serializeAsType(property)) {
  11898. elementTypeName = node.attributes[XSI_TYPE];
  11899. // xsi type is optional, if it does not exists the
  11900. // default type is assumed
  11901. if (elementTypeName) {
  11902. // take possible type prefixes from XML
  11903. // into account, i.e.: xsi:type="t{ActualType}"
  11904. elementTypeName = normalizeXsiTypeName(elementTypeName, model);
  11905. elementType = model.getType(elementTypeName);
  11906. return assign({}, property, {
  11907. effectiveType: getModdleDescriptor(elementType).name
  11908. });
  11909. }
  11910. }
  11911. // search for properties by name first
  11912. return property;
  11913. }
  11914. var pkg = model.getPackage(nameNs.prefix);
  11915. if (pkg) {
  11916. elementTypeName = aliasToName(nameNs, pkg);
  11917. elementType = model.getType(elementTypeName);
  11918. // search for collection members later
  11919. property = find(descriptor.properties, function(p) {
  11920. return !p.isVirtual && !p.isReference && !p.isAttribute && elementType.hasType(p.type);
  11921. });
  11922. if (property) {
  11923. return assign({}, property, {
  11924. effectiveType: getModdleDescriptor(elementType).name
  11925. });
  11926. }
  11927. } else {
  11928. // parse unknown element (maybe extension)
  11929. property = find(descriptor.properties, function(p) {
  11930. return !p.isReference && !p.isAttribute && p.type === 'Element';
  11931. });
  11932. if (property) {
  11933. return property;
  11934. }
  11935. }
  11936. throw error('unrecognized element <' + nameNs.name + '>');
  11937. };
  11938. ElementHandler.prototype.toString = function() {
  11939. return 'ElementDescriptor[' + getModdleDescriptor(this.type).name + ']';
  11940. };
  11941. ElementHandler.prototype.valueHandler = function(propertyDesc, element) {
  11942. return new ValueHandler(propertyDesc, element);
  11943. };
  11944. ElementHandler.prototype.referenceHandler = function(propertyDesc) {
  11945. return new ReferenceHandler(propertyDesc, this.context);
  11946. };
  11947. ElementHandler.prototype.handler = function(type) {
  11948. if (type === 'Element') {
  11949. return new GenericElementHandler(this.model, type, this.context);
  11950. } else {
  11951. return new ElementHandler(this.model, type, this.context);
  11952. }
  11953. };
  11954. /**
  11955. * Handle the child element parsing
  11956. *
  11957. * @param {Element} node the xml node
  11958. */
  11959. ElementHandler.prototype.handleChild = function(node) {
  11960. var propertyDesc, type, element, childHandler;
  11961. propertyDesc = this.getPropertyForNode(node);
  11962. element = this.element;
  11963. type = propertyDesc.effectiveType || propertyDesc.type;
  11964. if (isSimple(type)) {
  11965. return this.valueHandler(propertyDesc, element);
  11966. }
  11967. if (propertyDesc.isReference) {
  11968. childHandler = this.referenceHandler(propertyDesc).handleNode(node);
  11969. } else {
  11970. childHandler = this.handler(type).handleNode(node);
  11971. }
  11972. var newElement = childHandler.element;
  11973. // child handles may decide to skip elements
  11974. // by not returning anything
  11975. if (newElement !== undefined) {
  11976. if (propertyDesc.isMany) {
  11977. element.get(propertyDesc.name).push(newElement);
  11978. } else {
  11979. element.set(propertyDesc.name, newElement);
  11980. }
  11981. if (propertyDesc.isReference) {
  11982. assign(newElement, {
  11983. element: element
  11984. });
  11985. this.context.addReference(newElement);
  11986. } else {
  11987. // establish child -> parent relationship
  11988. newElement.$parent = element;
  11989. }
  11990. }
  11991. return childHandler;
  11992. };
  11993. /**
  11994. * An element handler that performs special validation
  11995. * to ensure the node it gets initialized with matches
  11996. * the handlers type (namespace wise).
  11997. *
  11998. * @param {Moddle} model
  11999. * @param {String} typeName
  12000. * @param {Context} context
  12001. */
  12002. function RootElementHandler(model, typeName, context) {
  12003. ElementHandler.call(this, model, typeName, context);
  12004. }
  12005. RootElementHandler.prototype = Object.create(ElementHandler.prototype);
  12006. RootElementHandler.prototype.createElement = function(node) {
  12007. var name = node.name,
  12008. nameNs = parseName(name),
  12009. model = this.model,
  12010. type = this.type,
  12011. pkg = model.getPackage(nameNs.prefix),
  12012. typeName = pkg && aliasToName(nameNs, pkg) || name;
  12013. // verify the correct namespace if we parse
  12014. // the first element in the handler tree
  12015. //
  12016. // this ensures we don't mistakenly import wrong namespace elements
  12017. if (!type.hasType(typeName)) {
  12018. throw error('unexpected element <' + node.originalName + '>');
  12019. }
  12020. return ElementHandler.prototype.createElement.call(this, node);
  12021. };
  12022. function GenericElementHandler(model, typeName, context) {
  12023. this.model = model;
  12024. this.context = context;
  12025. }
  12026. GenericElementHandler.prototype = Object.create(BaseElementHandler.prototype);
  12027. GenericElementHandler.prototype.createElement = function(node) {
  12028. var name = node.name,
  12029. ns = parseName(name),
  12030. prefix = ns.prefix,
  12031. uri = node.ns[prefix + '$uri'],
  12032. attributes = node.attributes;
  12033. return this.model.createAny(name, uri, attributes);
  12034. };
  12035. GenericElementHandler.prototype.handleChild = function(node) {
  12036. var handler = new GenericElementHandler(this.model, 'Element', this.context).handleNode(node),
  12037. element = this.element;
  12038. var newElement = handler.element,
  12039. children;
  12040. if (newElement !== undefined) {
  12041. children = element.$children = element.$children || [];
  12042. children.push(newElement);
  12043. // establish child -> parent relationship
  12044. newElement.$parent = element;
  12045. }
  12046. return handler;
  12047. };
  12048. GenericElementHandler.prototype.handleEnd = function() {
  12049. if (this.body) {
  12050. this.element.$body = this.body;
  12051. }
  12052. };
  12053. /**
  12054. * A reader for a meta-model
  12055. *
  12056. * @param {Object} options
  12057. * @param {Model} options.model used to read xml files
  12058. * @param {Boolean} options.lax whether to make parse errors warnings
  12059. */
  12060. function Reader(options) {
  12061. if (options instanceof Moddle) {
  12062. options = {
  12063. model: options
  12064. };
  12065. }
  12066. assign(this, { lax: false }, options);
  12067. }
  12068. /**
  12069. * The fromXML result.
  12070. *
  12071. * @typedef {Object} ParseResult
  12072. *
  12073. * @property {ModdleElement} rootElement
  12074. * @property {Array<Object>} references
  12075. * @property {Array<Error>} warnings
  12076. * @property {Object} elementsById - a mapping containing each ID -> ModdleElement
  12077. */
  12078. /**
  12079. * The fromXML result.
  12080. *
  12081. * @typedef {Error} ParseError
  12082. *
  12083. * @property {Array<Error>} warnings
  12084. */
  12085. /**
  12086. * Parse the given XML into a moddle document tree.
  12087. *
  12088. * @param {String} xml
  12089. * @param {ElementHandler|Object} options or rootHandler
  12090. *
  12091. * @returns {Promise<ParseResult, ParseError>}
  12092. */
  12093. Reader.prototype.fromXML = function(xml, options, done) {
  12094. var rootHandler = options.rootHandler;
  12095. if (options instanceof ElementHandler) {
  12096. // root handler passed via (xml, { rootHandler: ElementHandler }, ...)
  12097. rootHandler = options;
  12098. options = {};
  12099. } else {
  12100. if (typeof options === 'string') {
  12101. // rootHandler passed via (xml, 'someString', ...)
  12102. rootHandler = this.handler(options);
  12103. options = {};
  12104. } else if (typeof rootHandler === 'string') {
  12105. // rootHandler passed via (xml, { rootHandler: 'someString' }, ...)
  12106. rootHandler = this.handler(rootHandler);
  12107. }
  12108. }
  12109. var model = this.model,
  12110. lax = this.lax;
  12111. var context = new Context(assign({}, options, { rootHandler: rootHandler })),
  12112. parser = new Parser({ proxy: true }),
  12113. stack = createStack();
  12114. rootHandler.context = context;
  12115. // push root handler
  12116. stack.push(rootHandler);
  12117. /**
  12118. * Handle error.
  12119. *
  12120. * @param {Error} err
  12121. * @param {Function} getContext
  12122. * @param {boolean} lax
  12123. *
  12124. * @return {boolean} true if handled
  12125. */
  12126. function handleError(err, getContext, lax) {
  12127. var ctx = getContext();
  12128. var line = ctx.line,
  12129. column = ctx.column,
  12130. data = ctx.data;
  12131. // we receive the full context data here,
  12132. // for elements trim down the information
  12133. // to the tag name, only
  12134. if (data.charAt(0) === '<' && data.indexOf(' ') !== -1) {
  12135. data = data.slice(0, data.indexOf(' ')) + '>';
  12136. }
  12137. var message =
  12138. 'unparsable content ' + (data ? data + ' ' : '') + 'detected\n\t' +
  12139. 'line: ' + line + '\n\t' +
  12140. 'column: ' + column + '\n\t' +
  12141. 'nested error: ' + err.message;
  12142. if (lax) {
  12143. context.addWarning({
  12144. message: message,
  12145. error: err
  12146. });
  12147. return true;
  12148. } else {
  12149. throw error(message);
  12150. }
  12151. }
  12152. function handleWarning(err, getContext) {
  12153. // just like handling errors in <lax=true> mode
  12154. return handleError(err, getContext, true);
  12155. }
  12156. /**
  12157. * Resolve collected references on parse end.
  12158. */
  12159. function resolveReferences() {
  12160. var elementsById = context.elementsById;
  12161. var references = context.references;
  12162. var i, r;
  12163. for (i = 0; (r = references[i]); i++) {
  12164. var element = r.element;
  12165. var reference = elementsById[r.id];
  12166. var property = getModdleDescriptor(element).propertiesByName[r.property];
  12167. if (!reference) {
  12168. context.addWarning({
  12169. message: 'unresolved reference <' + r.id + '>',
  12170. element: r.element,
  12171. property: r.property,
  12172. value: r.id
  12173. });
  12174. }
  12175. if (property.isMany) {
  12176. var collection = element.get(property.name),
  12177. idx = collection.indexOf(r);
  12178. // we replace an existing place holder (idx != -1) or
  12179. // append to the collection instead
  12180. if (idx === -1) {
  12181. idx = collection.length;
  12182. }
  12183. if (!reference) {
  12184. // remove unresolvable reference
  12185. collection.splice(idx, 1);
  12186. } else {
  12187. // add or update reference in collection
  12188. collection[idx] = reference;
  12189. }
  12190. } else {
  12191. element.set(property.name, reference);
  12192. }
  12193. }
  12194. }
  12195. function handleClose() {
  12196. stack.pop().handleEnd();
  12197. }
  12198. var PREAMBLE_START_PATTERN = /^<\?xml /i;
  12199. var ENCODING_PATTERN = / encoding="([^"]+)"/i;
  12200. var UTF_8_PATTERN = /^utf-8$/i;
  12201. function handleQuestion(question) {
  12202. if (!PREAMBLE_START_PATTERN.test(question)) {
  12203. return;
  12204. }
  12205. var match = ENCODING_PATTERN.exec(question);
  12206. var encoding = match && match[1];
  12207. if (!encoding || UTF_8_PATTERN.test(encoding)) {
  12208. return;
  12209. }
  12210. context.addWarning({
  12211. message:
  12212. 'unsupported document encoding <' + encoding + '>, ' +
  12213. 'falling back to UTF-8'
  12214. });
  12215. }
  12216. function handleOpen(node, getContext) {
  12217. var handler = stack.peek();
  12218. try {
  12219. stack.push(handler.handleNode(node));
  12220. } catch (err) {
  12221. if (handleError(err, getContext, lax)) {
  12222. stack.push(new NoopHandler());
  12223. }
  12224. }
  12225. }
  12226. function handleCData(text, getContext) {
  12227. try {
  12228. stack.peek().handleText(text);
  12229. } catch (err) {
  12230. handleWarning(err, getContext);
  12231. }
  12232. }
  12233. function handleText(text, getContext) {
  12234. // strip whitespace only nodes, i.e. before
  12235. // <!CDATA[ ... ]> sections and in between tags
  12236. if (!text.trim()) {
  12237. return;
  12238. }
  12239. handleCData(text, getContext);
  12240. }
  12241. var uriMap = model.getPackages().reduce(function(uriMap, p) {
  12242. uriMap[p.uri] = p.prefix;
  12243. return uriMap;
  12244. }, {
  12245. 'http://www.w3.org/XML/1998/namespace': 'xml' // add default xml ns
  12246. });
  12247. parser
  12248. .ns(uriMap)
  12249. .on('openTag', function(obj, decodeStr, selfClosing, getContext) {
  12250. // gracefully handle unparsable attributes (attrs=false)
  12251. var attrs = obj.attrs || {};
  12252. var decodedAttrs = Object.keys(attrs).reduce(function(d, key) {
  12253. var value = decodeStr(attrs[key]);
  12254. d[key] = value;
  12255. return d;
  12256. }, {});
  12257. var node = {
  12258. name: obj.name,
  12259. originalName: obj.originalName,
  12260. attributes: decodedAttrs,
  12261. ns: obj.ns
  12262. };
  12263. handleOpen(node, getContext);
  12264. })
  12265. .on('question', handleQuestion)
  12266. .on('closeTag', handleClose)
  12267. .on('cdata', handleCData)
  12268. .on('text', function(text, decodeEntities, getContext) {
  12269. handleText(decodeEntities(text), getContext);
  12270. })
  12271. .on('error', handleError)
  12272. .on('warn', handleWarning);
  12273. // async XML parsing to make sure the execution environment
  12274. // (node or brower) is kept responsive and that certain optimization
  12275. // strategies can kick in.
  12276. return new Promise(function(resolve, reject) {
  12277. var err;
  12278. try {
  12279. parser.parse(xml);
  12280. resolveReferences();
  12281. } catch (e) {
  12282. err = e;
  12283. }
  12284. var rootElement = rootHandler.element;
  12285. if (!err && !rootElement) {
  12286. err = error('failed to parse document as <' + rootHandler.type.$descriptor.name + '>');
  12287. }
  12288. var warnings = context.warnings;
  12289. var references = context.references;
  12290. var elementsById = context.elementsById;
  12291. if (err) {
  12292. err.warnings = warnings;
  12293. return reject(err);
  12294. } else {
  12295. return resolve({
  12296. rootElement: rootElement,
  12297. elementsById: elementsById,
  12298. references: references,
  12299. warnings: warnings
  12300. });
  12301. }
  12302. });
  12303. };
  12304. Reader.prototype.handler = function(name) {
  12305. return new RootElementHandler(this.model, name);
  12306. };
  12307. // helpers //////////////////////////
  12308. function createStack() {
  12309. var stack = [];
  12310. Object.defineProperty(stack, 'peek', {
  12311. value: function() {
  12312. return this[this.length - 1];
  12313. }
  12314. });
  12315. return stack;
  12316. }
  12317. var XML_PREAMBLE = '<?xml version="1.0" encoding="UTF-8"?>\n';
  12318. var ESCAPE_ATTR_CHARS = /<|>|'|"|&|\n\r|\n/g;
  12319. var ESCAPE_CHARS = /<|>|&/g;
  12320. function Namespaces(parent) {
  12321. var prefixMap = {};
  12322. var uriMap = {};
  12323. var used = {};
  12324. var wellknown = [];
  12325. var custom = [];
  12326. // API
  12327. this.byUri = function(uri) {
  12328. return uriMap[uri] || (
  12329. parent && parent.byUri(uri)
  12330. );
  12331. };
  12332. this.add = function(ns, isWellknown) {
  12333. uriMap[ns.uri] = ns;
  12334. if (isWellknown) {
  12335. wellknown.push(ns);
  12336. } else {
  12337. custom.push(ns);
  12338. }
  12339. this.mapPrefix(ns.prefix, ns.uri);
  12340. };
  12341. this.uriByPrefix = function(prefix) {
  12342. return prefixMap[prefix || 'xmlns'];
  12343. };
  12344. this.mapPrefix = function(prefix, uri) {
  12345. prefixMap[prefix || 'xmlns'] = uri;
  12346. };
  12347. this.getNSKey = function(ns) {
  12348. return (ns.prefix !== undefined) ? (ns.uri + '|' + ns.prefix) : ns.uri;
  12349. };
  12350. this.logUsed = function(ns) {
  12351. var uri = ns.uri;
  12352. var nsKey = this.getNSKey(ns);
  12353. used[nsKey] = this.byUri(uri);
  12354. // Inform parent recursively about the usage of this NS
  12355. if (parent) {
  12356. parent.logUsed(ns);
  12357. }
  12358. };
  12359. this.getUsed = function(ns) {
  12360. function isUsed(ns) {
  12361. var nsKey = self.getNSKey(ns);
  12362. return used[nsKey];
  12363. }
  12364. var self = this;
  12365. var allNs = [].concat(wellknown, custom);
  12366. return allNs.filter(isUsed);
  12367. };
  12368. }
  12369. function lower(string) {
  12370. return string.charAt(0).toLowerCase() + string.slice(1);
  12371. }
  12372. function nameToAlias(name, pkg) {
  12373. if (hasLowerCaseAlias(pkg)) {
  12374. return lower(name);
  12375. } else {
  12376. return name;
  12377. }
  12378. }
  12379. function inherits(ctor, superCtor) {
  12380. ctor.super_ = superCtor;
  12381. ctor.prototype = Object.create(superCtor.prototype, {
  12382. constructor: {
  12383. value: ctor,
  12384. enumerable: false,
  12385. writable: true,
  12386. configurable: true
  12387. }
  12388. });
  12389. }
  12390. function nsName(ns) {
  12391. if (isString(ns)) {
  12392. return ns;
  12393. } else {
  12394. return (ns.prefix ? ns.prefix + ':' : '') + ns.localName;
  12395. }
  12396. }
  12397. function getNsAttrs(namespaces) {
  12398. return namespaces.getUsed().filter(function(ns) {
  12399. // do not serialize built in <xml> namespace
  12400. return ns.prefix !== 'xml';
  12401. }).map(function(ns) {
  12402. var name = 'xmlns' + (ns.prefix ? ':' + ns.prefix : '');
  12403. return { name: name, value: ns.uri };
  12404. });
  12405. }
  12406. function getElementNs(ns, descriptor) {
  12407. if (descriptor.isGeneric) {
  12408. return assign({ localName: descriptor.ns.localName }, ns);
  12409. } else {
  12410. return assign({ localName: nameToAlias(descriptor.ns.localName, descriptor.$pkg) }, ns);
  12411. }
  12412. }
  12413. function getPropertyNs(ns, descriptor) {
  12414. return assign({ localName: descriptor.ns.localName }, ns);
  12415. }
  12416. function getSerializableProperties(element) {
  12417. var descriptor = element.$descriptor;
  12418. return filter(descriptor.properties, function(p) {
  12419. var name = p.name;
  12420. if (p.isVirtual) {
  12421. return false;
  12422. }
  12423. // do not serialize defaults
  12424. if (!has$1(element, name)) {
  12425. return false;
  12426. }
  12427. var value = element[name];
  12428. // do not serialize default equals
  12429. if (value === p.default) {
  12430. return false;
  12431. }
  12432. // do not serialize null properties
  12433. if (value === null) {
  12434. return false;
  12435. }
  12436. return p.isMany ? value.length : true;
  12437. });
  12438. }
  12439. var ESCAPE_ATTR_MAP = {
  12440. '\n': '#10',
  12441. '\n\r': '#10',
  12442. '"': '#34',
  12443. '\'': '#39',
  12444. '<': '#60',
  12445. '>': '#62',
  12446. '&': '#38'
  12447. };
  12448. var ESCAPE_MAP = {
  12449. '<': 'lt',
  12450. '>': 'gt',
  12451. '&': 'amp'
  12452. };
  12453. function escape(str, charPattern, replaceMap) {
  12454. // ensure we are handling strings here
  12455. str = isString(str) ? str : '' + str;
  12456. return str.replace(charPattern, function(s) {
  12457. return '&' + replaceMap[s] + ';';
  12458. });
  12459. }
  12460. /**
  12461. * Escape a string attribute to not contain any bad values (line breaks, '"', ...)
  12462. *
  12463. * @param {String} str the string to escape
  12464. * @return {String} the escaped string
  12465. */
  12466. function escapeAttr(str) {
  12467. return escape(str, ESCAPE_ATTR_CHARS, ESCAPE_ATTR_MAP);
  12468. }
  12469. function escapeBody(str) {
  12470. return escape(str, ESCAPE_CHARS, ESCAPE_MAP);
  12471. }
  12472. function filterAttributes(props) {
  12473. return filter(props, function(p) { return p.isAttr; });
  12474. }
  12475. function filterContained(props) {
  12476. return filter(props, function(p) { return !p.isAttr; });
  12477. }
  12478. function ReferenceSerializer(tagName) {
  12479. this.tagName = tagName;
  12480. }
  12481. ReferenceSerializer.prototype.build = function(element) {
  12482. this.element = element;
  12483. return this;
  12484. };
  12485. ReferenceSerializer.prototype.serializeTo = function(writer) {
  12486. writer
  12487. .appendIndent()
  12488. .append('<' + this.tagName + '>' + this.element.id + '</' + this.tagName + '>')
  12489. .appendNewLine();
  12490. };
  12491. function BodySerializer() {}
  12492. BodySerializer.prototype.serializeValue =
  12493. BodySerializer.prototype.serializeTo = function(writer) {
  12494. writer.append(
  12495. this.escape
  12496. ? escapeBody(this.value)
  12497. : this.value
  12498. );
  12499. };
  12500. BodySerializer.prototype.build = function(prop, value) {
  12501. this.value = value;
  12502. if (prop.type === 'String' && value.search(ESCAPE_CHARS) !== -1) {
  12503. this.escape = true;
  12504. }
  12505. return this;
  12506. };
  12507. function ValueSerializer(tagName) {
  12508. this.tagName = tagName;
  12509. }
  12510. inherits(ValueSerializer, BodySerializer);
  12511. ValueSerializer.prototype.serializeTo = function(writer) {
  12512. writer
  12513. .appendIndent()
  12514. .append('<' + this.tagName + '>');
  12515. this.serializeValue(writer);
  12516. writer
  12517. .append('</' + this.tagName + '>')
  12518. .appendNewLine();
  12519. };
  12520. function ElementSerializer(parent, propertyDescriptor) {
  12521. this.body = [];
  12522. this.attrs = [];
  12523. this.parent = parent;
  12524. this.propertyDescriptor = propertyDescriptor;
  12525. }
  12526. ElementSerializer.prototype.build = function(element) {
  12527. this.element = element;
  12528. var elementDescriptor = element.$descriptor,
  12529. propertyDescriptor = this.propertyDescriptor;
  12530. var otherAttrs,
  12531. properties;
  12532. var isGeneric = elementDescriptor.isGeneric;
  12533. if (isGeneric) {
  12534. otherAttrs = this.parseGeneric(element);
  12535. } else {
  12536. otherAttrs = this.parseNsAttributes(element);
  12537. }
  12538. if (propertyDescriptor) {
  12539. this.ns = this.nsPropertyTagName(propertyDescriptor);
  12540. } else {
  12541. this.ns = this.nsTagName(elementDescriptor);
  12542. }
  12543. // compute tag name
  12544. this.tagName = this.addTagName(this.ns);
  12545. if (!isGeneric) {
  12546. properties = getSerializableProperties(element);
  12547. this.parseAttributes(filterAttributes(properties));
  12548. this.parseContainments(filterContained(properties));
  12549. }
  12550. this.parseGenericAttributes(element, otherAttrs);
  12551. return this;
  12552. };
  12553. ElementSerializer.prototype.nsTagName = function(descriptor) {
  12554. var effectiveNs = this.logNamespaceUsed(descriptor.ns);
  12555. return getElementNs(effectiveNs, descriptor);
  12556. };
  12557. ElementSerializer.prototype.nsPropertyTagName = function(descriptor) {
  12558. var effectiveNs = this.logNamespaceUsed(descriptor.ns);
  12559. return getPropertyNs(effectiveNs, descriptor);
  12560. };
  12561. ElementSerializer.prototype.isLocalNs = function(ns) {
  12562. return ns.uri === this.ns.uri;
  12563. };
  12564. /**
  12565. * Get the actual ns attribute name for the given element.
  12566. *
  12567. * @param {Object} element
  12568. * @param {Boolean} [element.inherited=false]
  12569. *
  12570. * @return {Object} nsName
  12571. */
  12572. ElementSerializer.prototype.nsAttributeName = function(element) {
  12573. var ns;
  12574. if (isString(element)) {
  12575. ns = parseName(element);
  12576. } else {
  12577. ns = element.ns;
  12578. }
  12579. // return just local name for inherited attributes
  12580. if (element.inherited) {
  12581. return { localName: ns.localName };
  12582. }
  12583. // parse + log effective ns
  12584. var effectiveNs = this.logNamespaceUsed(ns);
  12585. // LOG ACTUAL namespace use
  12586. this.getNamespaces().logUsed(effectiveNs);
  12587. // strip prefix if same namespace like parent
  12588. if (this.isLocalNs(effectiveNs)) {
  12589. return { localName: ns.localName };
  12590. } else {
  12591. return assign({ localName: ns.localName }, effectiveNs);
  12592. }
  12593. };
  12594. ElementSerializer.prototype.parseGeneric = function(element) {
  12595. var self = this,
  12596. body = this.body;
  12597. var attributes = [];
  12598. forEach$1(element, function(val, key) {
  12599. var nonNsAttr;
  12600. if (key === '$body') {
  12601. body.push(new BodySerializer().build({ type: 'String' }, val));
  12602. } else
  12603. if (key === '$children') {
  12604. forEach$1(val, function(child) {
  12605. body.push(new ElementSerializer(self).build(child));
  12606. });
  12607. } else
  12608. if (key.indexOf('$') !== 0) {
  12609. nonNsAttr = self.parseNsAttribute(element, key, val);
  12610. if (nonNsAttr) {
  12611. attributes.push({ name: key, value: val });
  12612. }
  12613. }
  12614. });
  12615. return attributes;
  12616. };
  12617. ElementSerializer.prototype.parseNsAttribute = function(element, name, value) {
  12618. var model = element.$model;
  12619. var nameNs = parseName(name);
  12620. var ns;
  12621. // parse xmlns:foo="http://foo.bar"
  12622. if (nameNs.prefix === 'xmlns') {
  12623. ns = { prefix: nameNs.localName, uri: value };
  12624. }
  12625. // parse xmlns="http://foo.bar"
  12626. if (!nameNs.prefix && nameNs.localName === 'xmlns') {
  12627. ns = { uri: value };
  12628. }
  12629. if (!ns) {
  12630. return {
  12631. name: name,
  12632. value: value
  12633. };
  12634. }
  12635. if (model && model.getPackage(value)) {
  12636. // register well known namespace
  12637. this.logNamespace(ns, true, true);
  12638. } else {
  12639. // log custom namespace directly as used
  12640. var actualNs = this.logNamespaceUsed(ns, true);
  12641. this.getNamespaces().logUsed(actualNs);
  12642. }
  12643. };
  12644. /**
  12645. * Parse namespaces and return a list of left over generic attributes
  12646. *
  12647. * @param {Object} element
  12648. * @return {Array<Object>}
  12649. */
  12650. ElementSerializer.prototype.parseNsAttributes = function(element, attrs) {
  12651. var self = this;
  12652. var genericAttrs = element.$attrs;
  12653. var attributes = [];
  12654. // parse namespace attributes first
  12655. // and log them. push non namespace attributes to a list
  12656. // and process them later
  12657. forEach$1(genericAttrs, function(value, name) {
  12658. var nonNsAttr = self.parseNsAttribute(element, name, value);
  12659. if (nonNsAttr) {
  12660. attributes.push(nonNsAttr);
  12661. }
  12662. });
  12663. return attributes;
  12664. };
  12665. ElementSerializer.prototype.parseGenericAttributes = function(element, attributes) {
  12666. var self = this;
  12667. forEach$1(attributes, function(attr) {
  12668. // do not serialize xsi:type attribute
  12669. // it is set manually based on the actual implementation type
  12670. if (attr.name === XSI_TYPE) {
  12671. return;
  12672. }
  12673. try {
  12674. self.addAttribute(self.nsAttributeName(attr.name), attr.value);
  12675. } catch (e) {
  12676. console.warn(
  12677. 'missing namespace information for ',
  12678. attr.name, '=', attr.value, 'on', element,
  12679. e);
  12680. }
  12681. });
  12682. };
  12683. ElementSerializer.prototype.parseContainments = function(properties) {
  12684. var self = this,
  12685. body = this.body,
  12686. element = this.element;
  12687. forEach$1(properties, function(p) {
  12688. var value = element.get(p.name),
  12689. isReference = p.isReference,
  12690. isMany = p.isMany;
  12691. if (!isMany) {
  12692. value = [ value ];
  12693. }
  12694. if (p.isBody) {
  12695. body.push(new BodySerializer().build(p, value[0]));
  12696. } else
  12697. if (isSimple(p.type)) {
  12698. forEach$1(value, function(v) {
  12699. body.push(new ValueSerializer(self.addTagName(self.nsPropertyTagName(p))).build(p, v));
  12700. });
  12701. } else
  12702. if (isReference) {
  12703. forEach$1(value, function(v) {
  12704. body.push(new ReferenceSerializer(self.addTagName(self.nsPropertyTagName(p))).build(v));
  12705. });
  12706. } else {
  12707. // allow serialization via type
  12708. // rather than element name
  12709. var asType = serializeAsType(p),
  12710. asProperty = serializeAsProperty(p);
  12711. forEach$1(value, function(v) {
  12712. var serializer;
  12713. if (asType) {
  12714. serializer = new TypeSerializer(self, p);
  12715. } else
  12716. if (asProperty) {
  12717. serializer = new ElementSerializer(self, p);
  12718. } else {
  12719. serializer = new ElementSerializer(self);
  12720. }
  12721. body.push(serializer.build(v));
  12722. });
  12723. }
  12724. });
  12725. };
  12726. ElementSerializer.prototype.getNamespaces = function(local) {
  12727. var namespaces = this.namespaces,
  12728. parent = this.parent,
  12729. parentNamespaces;
  12730. if (!namespaces) {
  12731. parentNamespaces = parent && parent.getNamespaces();
  12732. if (local || !parentNamespaces) {
  12733. this.namespaces = namespaces = new Namespaces(parentNamespaces);
  12734. } else {
  12735. namespaces = parentNamespaces;
  12736. }
  12737. }
  12738. return namespaces;
  12739. };
  12740. ElementSerializer.prototype.logNamespace = function(ns, wellknown, local) {
  12741. var namespaces = this.getNamespaces(local);
  12742. var nsUri = ns.uri,
  12743. nsPrefix = ns.prefix;
  12744. var existing = namespaces.byUri(nsUri);
  12745. if (!existing || local) {
  12746. namespaces.add(ns, wellknown);
  12747. }
  12748. namespaces.mapPrefix(nsPrefix, nsUri);
  12749. return ns;
  12750. };
  12751. ElementSerializer.prototype.logNamespaceUsed = function(ns, local) {
  12752. var element = this.element,
  12753. model = element.$model,
  12754. namespaces = this.getNamespaces(local);
  12755. // ns may be
  12756. //
  12757. // * prefix only
  12758. // * prefix:uri
  12759. // * localName only
  12760. var prefix = ns.prefix,
  12761. uri = ns.uri,
  12762. newPrefix, idx,
  12763. wellknownUri;
  12764. // handle anonymous namespaces (elementForm=unqualified), cf. #23
  12765. if (!prefix && !uri) {
  12766. return { localName: ns.localName };
  12767. }
  12768. wellknownUri = DEFAULT_NS_MAP[prefix] || model && (model.getPackage(prefix) || {}).uri;
  12769. uri = uri || wellknownUri || namespaces.uriByPrefix(prefix);
  12770. if (!uri) {
  12771. throw new Error('no namespace uri given for prefix <' + prefix + '>');
  12772. }
  12773. ns = namespaces.byUri(uri);
  12774. if (!ns) {
  12775. newPrefix = prefix;
  12776. idx = 1;
  12777. // find a prefix that is not mapped yet
  12778. while (namespaces.uriByPrefix(newPrefix)) {
  12779. newPrefix = prefix + '_' + idx++;
  12780. }
  12781. ns = this.logNamespace({ prefix: newPrefix, uri: uri }, wellknownUri === uri);
  12782. }
  12783. if (prefix) {
  12784. namespaces.mapPrefix(prefix, uri);
  12785. }
  12786. return ns;
  12787. };
  12788. ElementSerializer.prototype.parseAttributes = function(properties) {
  12789. var self = this,
  12790. element = this.element;
  12791. forEach$1(properties, function(p) {
  12792. var value = element.get(p.name);
  12793. if (p.isReference) {
  12794. if (!p.isMany) {
  12795. value = value.id;
  12796. }
  12797. else {
  12798. var values = [];
  12799. forEach$1(value, function(v) {
  12800. values.push(v.id);
  12801. });
  12802. // IDREFS is a whitespace-separated list of references.
  12803. value = values.join(' ');
  12804. }
  12805. }
  12806. self.addAttribute(self.nsAttributeName(p), value);
  12807. });
  12808. };
  12809. ElementSerializer.prototype.addTagName = function(nsTagName) {
  12810. var actualNs = this.logNamespaceUsed(nsTagName);
  12811. this.getNamespaces().logUsed(actualNs);
  12812. return nsName(nsTagName);
  12813. };
  12814. ElementSerializer.prototype.addAttribute = function(name, value) {
  12815. var attrs = this.attrs;
  12816. if (isString(value)) {
  12817. value = escapeAttr(value);
  12818. }
  12819. attrs.push({ name: name, value: value });
  12820. };
  12821. ElementSerializer.prototype.serializeAttributes = function(writer) {
  12822. var attrs = this.attrs,
  12823. namespaces = this.namespaces;
  12824. if (namespaces) {
  12825. attrs = getNsAttrs(namespaces).concat(attrs);
  12826. }
  12827. forEach$1(attrs, function(a) {
  12828. writer
  12829. .append(' ')
  12830. .append(nsName(a.name)).append('="').append(a.value).append('"');
  12831. });
  12832. };
  12833. ElementSerializer.prototype.serializeTo = function(writer) {
  12834. var firstBody = this.body[0],
  12835. indent = firstBody && firstBody.constructor !== BodySerializer;
  12836. writer
  12837. .appendIndent()
  12838. .append('<' + this.tagName);
  12839. this.serializeAttributes(writer);
  12840. writer.append(firstBody ? '>' : ' />');
  12841. if (firstBody) {
  12842. if (indent) {
  12843. writer
  12844. .appendNewLine()
  12845. .indent();
  12846. }
  12847. forEach$1(this.body, function(b) {
  12848. b.serializeTo(writer);
  12849. });
  12850. if (indent) {
  12851. writer
  12852. .unindent()
  12853. .appendIndent();
  12854. }
  12855. writer.append('</' + this.tagName + '>');
  12856. }
  12857. writer.appendNewLine();
  12858. };
  12859. /**
  12860. * A serializer for types that handles serialization of data types
  12861. */
  12862. function TypeSerializer(parent, propertyDescriptor) {
  12863. ElementSerializer.call(this, parent, propertyDescriptor);
  12864. }
  12865. inherits(TypeSerializer, ElementSerializer);
  12866. TypeSerializer.prototype.parseNsAttributes = function(element) {
  12867. // extracted attributes
  12868. var attributes = ElementSerializer.prototype.parseNsAttributes.call(this, element);
  12869. var descriptor = element.$descriptor;
  12870. // only serialize xsi:type if necessary
  12871. if (descriptor.name === this.propertyDescriptor.type) {
  12872. return attributes;
  12873. }
  12874. var typeNs = this.typeNs = this.nsTagName(descriptor);
  12875. this.getNamespaces().logUsed(this.typeNs);
  12876. // add xsi:type attribute to represent the elements
  12877. // actual type
  12878. var pkg = element.$model.getPackage(typeNs.uri),
  12879. typePrefix = (pkg.xml && pkg.xml.typePrefix) || '';
  12880. this.addAttribute(
  12881. this.nsAttributeName(XSI_TYPE),
  12882. (typeNs.prefix ? typeNs.prefix + ':' : '') + typePrefix + descriptor.ns.localName
  12883. );
  12884. return attributes;
  12885. };
  12886. TypeSerializer.prototype.isLocalNs = function(ns) {
  12887. return ns.uri === (this.typeNs || this.ns).uri;
  12888. };
  12889. function SavingWriter() {
  12890. this.value = '';
  12891. this.write = function(str) {
  12892. this.value += str;
  12893. };
  12894. }
  12895. function FormatingWriter(out, format) {
  12896. var indent = [''];
  12897. this.append = function(str) {
  12898. out.write(str);
  12899. return this;
  12900. };
  12901. this.appendNewLine = function() {
  12902. if (format) {
  12903. out.write('\n');
  12904. }
  12905. return this;
  12906. };
  12907. this.appendIndent = function() {
  12908. if (format) {
  12909. out.write(indent.join(' '));
  12910. }
  12911. return this;
  12912. };
  12913. this.indent = function() {
  12914. indent.push('');
  12915. return this;
  12916. };
  12917. this.unindent = function() {
  12918. indent.pop();
  12919. return this;
  12920. };
  12921. }
  12922. /**
  12923. * A writer for meta-model backed document trees
  12924. *
  12925. * @param {Object} options output options to pass into the writer
  12926. */
  12927. function Writer(options) {
  12928. options = assign({ format: false, preamble: true }, options || {});
  12929. function toXML(tree, writer) {
  12930. var internalWriter = writer || new SavingWriter();
  12931. var formatingWriter = new FormatingWriter(internalWriter, options.format);
  12932. if (options.preamble) {
  12933. formatingWriter.append(XML_PREAMBLE);
  12934. }
  12935. new ElementSerializer().build(tree).serializeTo(formatingWriter);
  12936. if (!writer) {
  12937. return internalWriter.value;
  12938. }
  12939. }
  12940. return {
  12941. toXML: toXML
  12942. };
  12943. }
  12944. /**
  12945. * A sub class of {@link Moddle} with support for import and export of BPMN 2.0 xml files.
  12946. *
  12947. * @class BpmnModdle
  12948. * @extends Moddle
  12949. *
  12950. * @param {Object|Array} packages to use for instantiating the model
  12951. * @param {Object} [options] additional options to pass over
  12952. */
  12953. function BpmnModdle(packages, options) {
  12954. Moddle.call(this, packages, options);
  12955. }
  12956. BpmnModdle.prototype = Object.create(Moddle.prototype);
  12957. /**
  12958. * The fromXML result.
  12959. *
  12960. * @typedef {Object} ParseResult
  12961. *
  12962. * @property {ModdleElement} rootElement
  12963. * @property {Array<Object>} references
  12964. * @property {Array<Error>} warnings
  12965. * @property {Object} elementsById - a mapping containing each ID -> ModdleElement
  12966. */
  12967. /**
  12968. * The fromXML error.
  12969. *
  12970. * @typedef {Error} ParseError
  12971. *
  12972. * @property {Array<Error>} warnings
  12973. */
  12974. /**
  12975. * Instantiates a BPMN model tree from a given xml string.
  12976. *
  12977. * @param {String} xmlStr
  12978. * @param {String} [typeName='bpmn:Definitions'] name of the root element
  12979. * @param {Object} [options] options to pass to the underlying reader
  12980. *
  12981. * @returns {Promise<ParseResult, ParseError>}
  12982. */
  12983. BpmnModdle.prototype.fromXML = function(xmlStr, typeName, options) {
  12984. if (!isString(typeName)) {
  12985. options = typeName;
  12986. typeName = 'bpmn:Definitions';
  12987. }
  12988. var reader = new Reader(assign({ model: this, lax: true }, options));
  12989. var rootHandler = reader.handler(typeName);
  12990. return reader.fromXML(xmlStr, rootHandler);
  12991. };
  12992. /**
  12993. * The toXML result.
  12994. *
  12995. * @typedef {Object} SerializationResult
  12996. *
  12997. * @property {String} xml
  12998. */
  12999. /**
  13000. * Serializes a BPMN 2.0 object tree to XML.
  13001. *
  13002. * @param {String} element the root element, typically an instance of `bpmn:Definitions`
  13003. * @param {Object} [options] to pass to the underlying writer
  13004. *
  13005. * @returns {Promise<SerializationResult, Error>}
  13006. */
  13007. BpmnModdle.prototype.toXML = function(element, options) {
  13008. var writer = new Writer(options);
  13009. return new Promise(function(resolve, reject) {
  13010. try {
  13011. var result = writer.toXML(element);
  13012. return resolve({
  13013. xml: result
  13014. });
  13015. } catch (err) {
  13016. return reject(err);
  13017. }
  13018. });
  13019. };
  13020. var name = "BPMN20";
  13021. var uri = "http://www.omg.org/spec/BPMN/20100524/MODEL";
  13022. var prefix = "bpmn";
  13023. var associations = [
  13024. ];
  13025. var types = [
  13026. {
  13027. name: "Interface",
  13028. superClass: [
  13029. "RootElement"
  13030. ],
  13031. properties: [
  13032. {
  13033. name: "name",
  13034. isAttr: true,
  13035. type: "String"
  13036. },
  13037. {
  13038. name: "operations",
  13039. type: "Operation",
  13040. isMany: true
  13041. },
  13042. {
  13043. name: "implementationRef",
  13044. isAttr: true,
  13045. type: "String"
  13046. }
  13047. ]
  13048. },
  13049. {
  13050. name: "Operation",
  13051. superClass: [
  13052. "BaseElement"
  13053. ],
  13054. properties: [
  13055. {
  13056. name: "name",
  13057. isAttr: true,
  13058. type: "String"
  13059. },
  13060. {
  13061. name: "inMessageRef",
  13062. type: "Message",
  13063. isReference: true
  13064. },
  13065. {
  13066. name: "outMessageRef",
  13067. type: "Message",
  13068. isReference: true
  13069. },
  13070. {
  13071. name: "errorRef",
  13072. type: "Error",
  13073. isMany: true,
  13074. isReference: true
  13075. },
  13076. {
  13077. name: "implementationRef",
  13078. isAttr: true,
  13079. type: "String"
  13080. }
  13081. ]
  13082. },
  13083. {
  13084. name: "EndPoint",
  13085. superClass: [
  13086. "RootElement"
  13087. ]
  13088. },
  13089. {
  13090. name: "Auditing",
  13091. superClass: [
  13092. "BaseElement"
  13093. ]
  13094. },
  13095. {
  13096. name: "GlobalTask",
  13097. superClass: [
  13098. "CallableElement"
  13099. ],
  13100. properties: [
  13101. {
  13102. name: "resources",
  13103. type: "ResourceRole",
  13104. isMany: true
  13105. }
  13106. ]
  13107. },
  13108. {
  13109. name: "Monitoring",
  13110. superClass: [
  13111. "BaseElement"
  13112. ]
  13113. },
  13114. {
  13115. name: "Performer",
  13116. superClass: [
  13117. "ResourceRole"
  13118. ]
  13119. },
  13120. {
  13121. name: "Process",
  13122. superClass: [
  13123. "FlowElementsContainer",
  13124. "CallableElement"
  13125. ],
  13126. properties: [
  13127. {
  13128. name: "processType",
  13129. type: "ProcessType",
  13130. isAttr: true
  13131. },
  13132. {
  13133. name: "isClosed",
  13134. isAttr: true,
  13135. type: "Boolean"
  13136. },
  13137. {
  13138. name: "auditing",
  13139. type: "Auditing"
  13140. },
  13141. {
  13142. name: "monitoring",
  13143. type: "Monitoring"
  13144. },
  13145. {
  13146. name: "properties",
  13147. type: "Property",
  13148. isMany: true
  13149. },
  13150. {
  13151. name: "laneSets",
  13152. isMany: true,
  13153. replaces: "FlowElementsContainer#laneSets",
  13154. type: "LaneSet"
  13155. },
  13156. {
  13157. name: "flowElements",
  13158. isMany: true,
  13159. replaces: "FlowElementsContainer#flowElements",
  13160. type: "FlowElement"
  13161. },
  13162. {
  13163. name: "artifacts",
  13164. type: "Artifact",
  13165. isMany: true
  13166. },
  13167. {
  13168. name: "resources",
  13169. type: "ResourceRole",
  13170. isMany: true
  13171. },
  13172. {
  13173. name: "correlationSubscriptions",
  13174. type: "CorrelationSubscription",
  13175. isMany: true
  13176. },
  13177. {
  13178. name: "supports",
  13179. type: "Process",
  13180. isMany: true,
  13181. isReference: true
  13182. },
  13183. {
  13184. name: "definitionalCollaborationRef",
  13185. type: "Collaboration",
  13186. isAttr: true,
  13187. isReference: true
  13188. },
  13189. {
  13190. name: "isExecutable",
  13191. isAttr: true,
  13192. type: "Boolean"
  13193. }
  13194. ]
  13195. },
  13196. {
  13197. name: "LaneSet",
  13198. superClass: [
  13199. "BaseElement"
  13200. ],
  13201. properties: [
  13202. {
  13203. name: "lanes",
  13204. type: "Lane",
  13205. isMany: true
  13206. },
  13207. {
  13208. name: "name",
  13209. isAttr: true,
  13210. type: "String"
  13211. }
  13212. ]
  13213. },
  13214. {
  13215. name: "Lane",
  13216. superClass: [
  13217. "BaseElement"
  13218. ],
  13219. properties: [
  13220. {
  13221. name: "name",
  13222. isAttr: true,
  13223. type: "String"
  13224. },
  13225. {
  13226. name: "partitionElementRef",
  13227. type: "BaseElement",
  13228. isAttr: true,
  13229. isReference: true
  13230. },
  13231. {
  13232. name: "partitionElement",
  13233. type: "BaseElement"
  13234. },
  13235. {
  13236. name: "flowNodeRef",
  13237. type: "FlowNode",
  13238. isMany: true,
  13239. isReference: true
  13240. },
  13241. {
  13242. name: "childLaneSet",
  13243. type: "LaneSet",
  13244. xml: {
  13245. serialize: "xsi:type"
  13246. }
  13247. }
  13248. ]
  13249. },
  13250. {
  13251. name: "GlobalManualTask",
  13252. superClass: [
  13253. "GlobalTask"
  13254. ]
  13255. },
  13256. {
  13257. name: "ManualTask",
  13258. superClass: [
  13259. "Task"
  13260. ]
  13261. },
  13262. {
  13263. name: "UserTask",
  13264. superClass: [
  13265. "Task"
  13266. ],
  13267. properties: [
  13268. {
  13269. name: "renderings",
  13270. type: "Rendering",
  13271. isMany: true
  13272. },
  13273. {
  13274. name: "implementation",
  13275. isAttr: true,
  13276. type: "String"
  13277. }
  13278. ]
  13279. },
  13280. {
  13281. name: "Rendering",
  13282. superClass: [
  13283. "BaseElement"
  13284. ]
  13285. },
  13286. {
  13287. name: "HumanPerformer",
  13288. superClass: [
  13289. "Performer"
  13290. ]
  13291. },
  13292. {
  13293. name: "PotentialOwner",
  13294. superClass: [
  13295. "HumanPerformer"
  13296. ]
  13297. },
  13298. {
  13299. name: "GlobalUserTask",
  13300. superClass: [
  13301. "GlobalTask"
  13302. ],
  13303. properties: [
  13304. {
  13305. name: "implementation",
  13306. isAttr: true,
  13307. type: "String"
  13308. },
  13309. {
  13310. name: "renderings",
  13311. type: "Rendering",
  13312. isMany: true
  13313. }
  13314. ]
  13315. },
  13316. {
  13317. name: "Gateway",
  13318. isAbstract: true,
  13319. superClass: [
  13320. "FlowNode"
  13321. ],
  13322. properties: [
  13323. {
  13324. name: "gatewayDirection",
  13325. type: "GatewayDirection",
  13326. "default": "Unspecified",
  13327. isAttr: true
  13328. }
  13329. ]
  13330. },
  13331. {
  13332. name: "EventBasedGateway",
  13333. superClass: [
  13334. "Gateway"
  13335. ],
  13336. properties: [
  13337. {
  13338. name: "instantiate",
  13339. "default": false,
  13340. isAttr: true,
  13341. type: "Boolean"
  13342. },
  13343. {
  13344. name: "eventGatewayType",
  13345. type: "EventBasedGatewayType",
  13346. isAttr: true,
  13347. "default": "Exclusive"
  13348. }
  13349. ]
  13350. },
  13351. {
  13352. name: "ComplexGateway",
  13353. superClass: [
  13354. "Gateway"
  13355. ],
  13356. properties: [
  13357. {
  13358. name: "activationCondition",
  13359. type: "Expression",
  13360. xml: {
  13361. serialize: "xsi:type"
  13362. }
  13363. },
  13364. {
  13365. name: "default",
  13366. type: "SequenceFlow",
  13367. isAttr: true,
  13368. isReference: true
  13369. }
  13370. ]
  13371. },
  13372. {
  13373. name: "ExclusiveGateway",
  13374. superClass: [
  13375. "Gateway"
  13376. ],
  13377. properties: [
  13378. {
  13379. name: "default",
  13380. type: "SequenceFlow",
  13381. isAttr: true,
  13382. isReference: true
  13383. }
  13384. ]
  13385. },
  13386. {
  13387. name: "InclusiveGateway",
  13388. superClass: [
  13389. "Gateway"
  13390. ],
  13391. properties: [
  13392. {
  13393. name: "default",
  13394. type: "SequenceFlow",
  13395. isAttr: true,
  13396. isReference: true
  13397. }
  13398. ]
  13399. },
  13400. {
  13401. name: "ParallelGateway",
  13402. superClass: [
  13403. "Gateway"
  13404. ]
  13405. },
  13406. {
  13407. name: "RootElement",
  13408. isAbstract: true,
  13409. superClass: [
  13410. "BaseElement"
  13411. ]
  13412. },
  13413. {
  13414. name: "Relationship",
  13415. superClass: [
  13416. "BaseElement"
  13417. ],
  13418. properties: [
  13419. {
  13420. name: "type",
  13421. isAttr: true,
  13422. type: "String"
  13423. },
  13424. {
  13425. name: "direction",
  13426. type: "RelationshipDirection",
  13427. isAttr: true
  13428. },
  13429. {
  13430. name: "source",
  13431. isMany: true,
  13432. isReference: true,
  13433. type: "Element"
  13434. },
  13435. {
  13436. name: "target",
  13437. isMany: true,
  13438. isReference: true,
  13439. type: "Element"
  13440. }
  13441. ]
  13442. },
  13443. {
  13444. name: "BaseElement",
  13445. isAbstract: true,
  13446. properties: [
  13447. {
  13448. name: "id",
  13449. isAttr: true,
  13450. type: "String",
  13451. isId: true
  13452. },
  13453. {
  13454. name: "documentation",
  13455. type: "Documentation",
  13456. isMany: true
  13457. },
  13458. {
  13459. name: "extensionDefinitions",
  13460. type: "ExtensionDefinition",
  13461. isMany: true,
  13462. isReference: true
  13463. },
  13464. {
  13465. name: "extensionElements",
  13466. type: "ExtensionElements"
  13467. }
  13468. ]
  13469. },
  13470. {
  13471. name: "Extension",
  13472. properties: [
  13473. {
  13474. name: "mustUnderstand",
  13475. "default": false,
  13476. isAttr: true,
  13477. type: "Boolean"
  13478. },
  13479. {
  13480. name: "definition",
  13481. type: "ExtensionDefinition",
  13482. isAttr: true,
  13483. isReference: true
  13484. }
  13485. ]
  13486. },
  13487. {
  13488. name: "ExtensionDefinition",
  13489. properties: [
  13490. {
  13491. name: "name",
  13492. isAttr: true,
  13493. type: "String"
  13494. },
  13495. {
  13496. name: "extensionAttributeDefinitions",
  13497. type: "ExtensionAttributeDefinition",
  13498. isMany: true
  13499. }
  13500. ]
  13501. },
  13502. {
  13503. name: "ExtensionAttributeDefinition",
  13504. properties: [
  13505. {
  13506. name: "name",
  13507. isAttr: true,
  13508. type: "String"
  13509. },
  13510. {
  13511. name: "type",
  13512. isAttr: true,
  13513. type: "String"
  13514. },
  13515. {
  13516. name: "isReference",
  13517. "default": false,
  13518. isAttr: true,
  13519. type: "Boolean"
  13520. },
  13521. {
  13522. name: "extensionDefinition",
  13523. type: "ExtensionDefinition",
  13524. isAttr: true,
  13525. isReference: true
  13526. }
  13527. ]
  13528. },
  13529. {
  13530. name: "ExtensionElements",
  13531. properties: [
  13532. {
  13533. name: "valueRef",
  13534. isAttr: true,
  13535. isReference: true,
  13536. type: "Element"
  13537. },
  13538. {
  13539. name: "values",
  13540. type: "Element",
  13541. isMany: true
  13542. },
  13543. {
  13544. name: "extensionAttributeDefinition",
  13545. type: "ExtensionAttributeDefinition",
  13546. isAttr: true,
  13547. isReference: true
  13548. }
  13549. ]
  13550. },
  13551. {
  13552. name: "Documentation",
  13553. superClass: [
  13554. "BaseElement"
  13555. ],
  13556. properties: [
  13557. {
  13558. name: "text",
  13559. type: "String",
  13560. isBody: true
  13561. },
  13562. {
  13563. name: "textFormat",
  13564. "default": "text/plain",
  13565. isAttr: true,
  13566. type: "String"
  13567. }
  13568. ]
  13569. },
  13570. {
  13571. name: "Event",
  13572. isAbstract: true,
  13573. superClass: [
  13574. "FlowNode",
  13575. "InteractionNode"
  13576. ],
  13577. properties: [
  13578. {
  13579. name: "properties",
  13580. type: "Property",
  13581. isMany: true
  13582. }
  13583. ]
  13584. },
  13585. {
  13586. name: "IntermediateCatchEvent",
  13587. superClass: [
  13588. "CatchEvent"
  13589. ]
  13590. },
  13591. {
  13592. name: "IntermediateThrowEvent",
  13593. superClass: [
  13594. "ThrowEvent"
  13595. ]
  13596. },
  13597. {
  13598. name: "EndEvent",
  13599. superClass: [
  13600. "ThrowEvent"
  13601. ]
  13602. },
  13603. {
  13604. name: "StartEvent",
  13605. superClass: [
  13606. "CatchEvent"
  13607. ],
  13608. properties: [
  13609. {
  13610. name: "isInterrupting",
  13611. "default": true,
  13612. isAttr: true,
  13613. type: "Boolean"
  13614. }
  13615. ]
  13616. },
  13617. {
  13618. name: "ThrowEvent",
  13619. isAbstract: true,
  13620. superClass: [
  13621. "Event"
  13622. ],
  13623. properties: [
  13624. {
  13625. name: "dataInputs",
  13626. type: "DataInput",
  13627. isMany: true
  13628. },
  13629. {
  13630. name: "dataInputAssociations",
  13631. type: "DataInputAssociation",
  13632. isMany: true
  13633. },
  13634. {
  13635. name: "inputSet",
  13636. type: "InputSet"
  13637. },
  13638. {
  13639. name: "eventDefinitions",
  13640. type: "EventDefinition",
  13641. isMany: true
  13642. },
  13643. {
  13644. name: "eventDefinitionRef",
  13645. type: "EventDefinition",
  13646. isMany: true,
  13647. isReference: true
  13648. }
  13649. ]
  13650. },
  13651. {
  13652. name: "CatchEvent",
  13653. isAbstract: true,
  13654. superClass: [
  13655. "Event"
  13656. ],
  13657. properties: [
  13658. {
  13659. name: "parallelMultiple",
  13660. isAttr: true,
  13661. type: "Boolean",
  13662. "default": false
  13663. },
  13664. {
  13665. name: "dataOutputs",
  13666. type: "DataOutput",
  13667. isMany: true
  13668. },
  13669. {
  13670. name: "dataOutputAssociations",
  13671. type: "DataOutputAssociation",
  13672. isMany: true
  13673. },
  13674. {
  13675. name: "outputSet",
  13676. type: "OutputSet"
  13677. },
  13678. {
  13679. name: "eventDefinitions",
  13680. type: "EventDefinition",
  13681. isMany: true
  13682. },
  13683. {
  13684. name: "eventDefinitionRef",
  13685. type: "EventDefinition",
  13686. isMany: true,
  13687. isReference: true
  13688. }
  13689. ]
  13690. },
  13691. {
  13692. name: "BoundaryEvent",
  13693. superClass: [
  13694. "CatchEvent"
  13695. ],
  13696. properties: [
  13697. {
  13698. name: "cancelActivity",
  13699. "default": true,
  13700. isAttr: true,
  13701. type: "Boolean"
  13702. },
  13703. {
  13704. name: "attachedToRef",
  13705. type: "Activity",
  13706. isAttr: true,
  13707. isReference: true
  13708. }
  13709. ]
  13710. },
  13711. {
  13712. name: "EventDefinition",
  13713. isAbstract: true,
  13714. superClass: [
  13715. "RootElement"
  13716. ]
  13717. },
  13718. {
  13719. name: "CancelEventDefinition",
  13720. superClass: [
  13721. "EventDefinition"
  13722. ]
  13723. },
  13724. {
  13725. name: "ErrorEventDefinition",
  13726. superClass: [
  13727. "EventDefinition"
  13728. ],
  13729. properties: [
  13730. {
  13731. name: "errorRef",
  13732. type: "Error",
  13733. isAttr: true,
  13734. isReference: true
  13735. }
  13736. ]
  13737. },
  13738. {
  13739. name: "TerminateEventDefinition",
  13740. superClass: [
  13741. "EventDefinition"
  13742. ]
  13743. },
  13744. {
  13745. name: "EscalationEventDefinition",
  13746. superClass: [
  13747. "EventDefinition"
  13748. ],
  13749. properties: [
  13750. {
  13751. name: "escalationRef",
  13752. type: "Escalation",
  13753. isAttr: true,
  13754. isReference: true
  13755. }
  13756. ]
  13757. },
  13758. {
  13759. name: "Escalation",
  13760. properties: [
  13761. {
  13762. name: "structureRef",
  13763. type: "ItemDefinition",
  13764. isAttr: true,
  13765. isReference: true
  13766. },
  13767. {
  13768. name: "name",
  13769. isAttr: true,
  13770. type: "String"
  13771. },
  13772. {
  13773. name: "escalationCode",
  13774. isAttr: true,
  13775. type: "String"
  13776. }
  13777. ],
  13778. superClass: [
  13779. "RootElement"
  13780. ]
  13781. },
  13782. {
  13783. name: "CompensateEventDefinition",
  13784. superClass: [
  13785. "EventDefinition"
  13786. ],
  13787. properties: [
  13788. {
  13789. name: "waitForCompletion",
  13790. isAttr: true,
  13791. type: "Boolean",
  13792. "default": true
  13793. },
  13794. {
  13795. name: "activityRef",
  13796. type: "Activity",
  13797. isAttr: true,
  13798. isReference: true
  13799. }
  13800. ]
  13801. },
  13802. {
  13803. name: "TimerEventDefinition",
  13804. superClass: [
  13805. "EventDefinition"
  13806. ],
  13807. properties: [
  13808. {
  13809. name: "timeDate",
  13810. type: "Expression",
  13811. xml: {
  13812. serialize: "xsi:type"
  13813. }
  13814. },
  13815. {
  13816. name: "timeCycle",
  13817. type: "Expression",
  13818. xml: {
  13819. serialize: "xsi:type"
  13820. }
  13821. },
  13822. {
  13823. name: "timeDuration",
  13824. type: "Expression",
  13825. xml: {
  13826. serialize: "xsi:type"
  13827. }
  13828. }
  13829. ]
  13830. },
  13831. {
  13832. name: "LinkEventDefinition",
  13833. superClass: [
  13834. "EventDefinition"
  13835. ],
  13836. properties: [
  13837. {
  13838. name: "name",
  13839. isAttr: true,
  13840. type: "String"
  13841. },
  13842. {
  13843. name: "target",
  13844. type: "LinkEventDefinition",
  13845. isAttr: true,
  13846. isReference: true
  13847. },
  13848. {
  13849. name: "source",
  13850. type: "LinkEventDefinition",
  13851. isMany: true,
  13852. isReference: true
  13853. }
  13854. ]
  13855. },
  13856. {
  13857. name: "MessageEventDefinition",
  13858. superClass: [
  13859. "EventDefinition"
  13860. ],
  13861. properties: [
  13862. {
  13863. name: "messageRef",
  13864. type: "Message",
  13865. isAttr: true,
  13866. isReference: true
  13867. },
  13868. {
  13869. name: "operationRef",
  13870. type: "Operation",
  13871. isAttr: true,
  13872. isReference: true
  13873. }
  13874. ]
  13875. },
  13876. {
  13877. name: "ConditionalEventDefinition",
  13878. superClass: [
  13879. "EventDefinition"
  13880. ],
  13881. properties: [
  13882. {
  13883. name: "condition",
  13884. type: "Expression",
  13885. xml: {
  13886. serialize: "xsi:type"
  13887. }
  13888. }
  13889. ]
  13890. },
  13891. {
  13892. name: "SignalEventDefinition",
  13893. superClass: [
  13894. "EventDefinition"
  13895. ],
  13896. properties: [
  13897. {
  13898. name: "signalRef",
  13899. type: "Signal",
  13900. isAttr: true,
  13901. isReference: true
  13902. }
  13903. ]
  13904. },
  13905. {
  13906. name: "Signal",
  13907. superClass: [
  13908. "RootElement"
  13909. ],
  13910. properties: [
  13911. {
  13912. name: "structureRef",
  13913. type: "ItemDefinition",
  13914. isAttr: true,
  13915. isReference: true
  13916. },
  13917. {
  13918. name: "name",
  13919. isAttr: true,
  13920. type: "String"
  13921. }
  13922. ]
  13923. },
  13924. {
  13925. name: "ImplicitThrowEvent",
  13926. superClass: [
  13927. "ThrowEvent"
  13928. ]
  13929. },
  13930. {
  13931. name: "DataState",
  13932. superClass: [
  13933. "BaseElement"
  13934. ],
  13935. properties: [
  13936. {
  13937. name: "name",
  13938. isAttr: true,
  13939. type: "String"
  13940. }
  13941. ]
  13942. },
  13943. {
  13944. name: "ItemAwareElement",
  13945. superClass: [
  13946. "BaseElement"
  13947. ],
  13948. properties: [
  13949. {
  13950. name: "itemSubjectRef",
  13951. type: "ItemDefinition",
  13952. isAttr: true,
  13953. isReference: true
  13954. },
  13955. {
  13956. name: "dataState",
  13957. type: "DataState"
  13958. }
  13959. ]
  13960. },
  13961. {
  13962. name: "DataAssociation",
  13963. superClass: [
  13964. "BaseElement"
  13965. ],
  13966. properties: [
  13967. {
  13968. name: "sourceRef",
  13969. type: "ItemAwareElement",
  13970. isMany: true,
  13971. isReference: true
  13972. },
  13973. {
  13974. name: "targetRef",
  13975. type: "ItemAwareElement",
  13976. isReference: true
  13977. },
  13978. {
  13979. name: "transformation",
  13980. type: "FormalExpression",
  13981. xml: {
  13982. serialize: "property"
  13983. }
  13984. },
  13985. {
  13986. name: "assignment",
  13987. type: "Assignment",
  13988. isMany: true
  13989. }
  13990. ]
  13991. },
  13992. {
  13993. name: "DataInput",
  13994. superClass: [
  13995. "ItemAwareElement"
  13996. ],
  13997. properties: [
  13998. {
  13999. name: "name",
  14000. isAttr: true,
  14001. type: "String"
  14002. },
  14003. {
  14004. name: "isCollection",
  14005. "default": false,
  14006. isAttr: true,
  14007. type: "Boolean"
  14008. },
  14009. {
  14010. name: "inputSetRef",
  14011. type: "InputSet",
  14012. isMany: true,
  14013. isVirtual: true,
  14014. isReference: true
  14015. },
  14016. {
  14017. name: "inputSetWithOptional",
  14018. type: "InputSet",
  14019. isMany: true,
  14020. isVirtual: true,
  14021. isReference: true
  14022. },
  14023. {
  14024. name: "inputSetWithWhileExecuting",
  14025. type: "InputSet",
  14026. isMany: true,
  14027. isVirtual: true,
  14028. isReference: true
  14029. }
  14030. ]
  14031. },
  14032. {
  14033. name: "DataOutput",
  14034. superClass: [
  14035. "ItemAwareElement"
  14036. ],
  14037. properties: [
  14038. {
  14039. name: "name",
  14040. isAttr: true,
  14041. type: "String"
  14042. },
  14043. {
  14044. name: "isCollection",
  14045. "default": false,
  14046. isAttr: true,
  14047. type: "Boolean"
  14048. },
  14049. {
  14050. name: "outputSetRef",
  14051. type: "OutputSet",
  14052. isMany: true,
  14053. isVirtual: true,
  14054. isReference: true
  14055. },
  14056. {
  14057. name: "outputSetWithOptional",
  14058. type: "OutputSet",
  14059. isMany: true,
  14060. isVirtual: true,
  14061. isReference: true
  14062. },
  14063. {
  14064. name: "outputSetWithWhileExecuting",
  14065. type: "OutputSet",
  14066. isMany: true,
  14067. isVirtual: true,
  14068. isReference: true
  14069. }
  14070. ]
  14071. },
  14072. {
  14073. name: "InputSet",
  14074. superClass: [
  14075. "BaseElement"
  14076. ],
  14077. properties: [
  14078. {
  14079. name: "name",
  14080. isAttr: true,
  14081. type: "String"
  14082. },
  14083. {
  14084. name: "dataInputRefs",
  14085. type: "DataInput",
  14086. isMany: true,
  14087. isReference: true
  14088. },
  14089. {
  14090. name: "optionalInputRefs",
  14091. type: "DataInput",
  14092. isMany: true,
  14093. isReference: true
  14094. },
  14095. {
  14096. name: "whileExecutingInputRefs",
  14097. type: "DataInput",
  14098. isMany: true,
  14099. isReference: true
  14100. },
  14101. {
  14102. name: "outputSetRefs",
  14103. type: "OutputSet",
  14104. isMany: true,
  14105. isReference: true
  14106. }
  14107. ]
  14108. },
  14109. {
  14110. name: "OutputSet",
  14111. superClass: [
  14112. "BaseElement"
  14113. ],
  14114. properties: [
  14115. {
  14116. name: "dataOutputRefs",
  14117. type: "DataOutput",
  14118. isMany: true,
  14119. isReference: true
  14120. },
  14121. {
  14122. name: "name",
  14123. isAttr: true,
  14124. type: "String"
  14125. },
  14126. {
  14127. name: "inputSetRefs",
  14128. type: "InputSet",
  14129. isMany: true,
  14130. isReference: true
  14131. },
  14132. {
  14133. name: "optionalOutputRefs",
  14134. type: "DataOutput",
  14135. isMany: true,
  14136. isReference: true
  14137. },
  14138. {
  14139. name: "whileExecutingOutputRefs",
  14140. type: "DataOutput",
  14141. isMany: true,
  14142. isReference: true
  14143. }
  14144. ]
  14145. },
  14146. {
  14147. name: "Property",
  14148. superClass: [
  14149. "ItemAwareElement"
  14150. ],
  14151. properties: [
  14152. {
  14153. name: "name",
  14154. isAttr: true,
  14155. type: "String"
  14156. }
  14157. ]
  14158. },
  14159. {
  14160. name: "DataInputAssociation",
  14161. superClass: [
  14162. "DataAssociation"
  14163. ]
  14164. },
  14165. {
  14166. name: "DataOutputAssociation",
  14167. superClass: [
  14168. "DataAssociation"
  14169. ]
  14170. },
  14171. {
  14172. name: "InputOutputSpecification",
  14173. superClass: [
  14174. "BaseElement"
  14175. ],
  14176. properties: [
  14177. {
  14178. name: "dataInputs",
  14179. type: "DataInput",
  14180. isMany: true
  14181. },
  14182. {
  14183. name: "dataOutputs",
  14184. type: "DataOutput",
  14185. isMany: true
  14186. },
  14187. {
  14188. name: "inputSets",
  14189. type: "InputSet",
  14190. isMany: true
  14191. },
  14192. {
  14193. name: "outputSets",
  14194. type: "OutputSet",
  14195. isMany: true
  14196. }
  14197. ]
  14198. },
  14199. {
  14200. name: "DataObject",
  14201. superClass: [
  14202. "FlowElement",
  14203. "ItemAwareElement"
  14204. ],
  14205. properties: [
  14206. {
  14207. name: "isCollection",
  14208. "default": false,
  14209. isAttr: true,
  14210. type: "Boolean"
  14211. }
  14212. ]
  14213. },
  14214. {
  14215. name: "InputOutputBinding",
  14216. properties: [
  14217. {
  14218. name: "inputDataRef",
  14219. type: "InputSet",
  14220. isAttr: true,
  14221. isReference: true
  14222. },
  14223. {
  14224. name: "outputDataRef",
  14225. type: "OutputSet",
  14226. isAttr: true,
  14227. isReference: true
  14228. },
  14229. {
  14230. name: "operationRef",
  14231. type: "Operation",
  14232. isAttr: true,
  14233. isReference: true
  14234. }
  14235. ]
  14236. },
  14237. {
  14238. name: "Assignment",
  14239. superClass: [
  14240. "BaseElement"
  14241. ],
  14242. properties: [
  14243. {
  14244. name: "from",
  14245. type: "Expression",
  14246. xml: {
  14247. serialize: "xsi:type"
  14248. }
  14249. },
  14250. {
  14251. name: "to",
  14252. type: "Expression",
  14253. xml: {
  14254. serialize: "xsi:type"
  14255. }
  14256. }
  14257. ]
  14258. },
  14259. {
  14260. name: "DataStore",
  14261. superClass: [
  14262. "RootElement",
  14263. "ItemAwareElement"
  14264. ],
  14265. properties: [
  14266. {
  14267. name: "name",
  14268. isAttr: true,
  14269. type: "String"
  14270. },
  14271. {
  14272. name: "capacity",
  14273. isAttr: true,
  14274. type: "Integer"
  14275. },
  14276. {
  14277. name: "isUnlimited",
  14278. "default": true,
  14279. isAttr: true,
  14280. type: "Boolean"
  14281. }
  14282. ]
  14283. },
  14284. {
  14285. name: "DataStoreReference",
  14286. superClass: [
  14287. "ItemAwareElement",
  14288. "FlowElement"
  14289. ],
  14290. properties: [
  14291. {
  14292. name: "dataStoreRef",
  14293. type: "DataStore",
  14294. isAttr: true,
  14295. isReference: true
  14296. }
  14297. ]
  14298. },
  14299. {
  14300. name: "DataObjectReference",
  14301. superClass: [
  14302. "ItemAwareElement",
  14303. "FlowElement"
  14304. ],
  14305. properties: [
  14306. {
  14307. name: "dataObjectRef",
  14308. type: "DataObject",
  14309. isAttr: true,
  14310. isReference: true
  14311. }
  14312. ]
  14313. },
  14314. {
  14315. name: "ConversationLink",
  14316. superClass: [
  14317. "BaseElement"
  14318. ],
  14319. properties: [
  14320. {
  14321. name: "sourceRef",
  14322. type: "InteractionNode",
  14323. isAttr: true,
  14324. isReference: true
  14325. },
  14326. {
  14327. name: "targetRef",
  14328. type: "InteractionNode",
  14329. isAttr: true,
  14330. isReference: true
  14331. },
  14332. {
  14333. name: "name",
  14334. isAttr: true,
  14335. type: "String"
  14336. }
  14337. ]
  14338. },
  14339. {
  14340. name: "ConversationAssociation",
  14341. superClass: [
  14342. "BaseElement"
  14343. ],
  14344. properties: [
  14345. {
  14346. name: "innerConversationNodeRef",
  14347. type: "ConversationNode",
  14348. isAttr: true,
  14349. isReference: true
  14350. },
  14351. {
  14352. name: "outerConversationNodeRef",
  14353. type: "ConversationNode",
  14354. isAttr: true,
  14355. isReference: true
  14356. }
  14357. ]
  14358. },
  14359. {
  14360. name: "CallConversation",
  14361. superClass: [
  14362. "ConversationNode"
  14363. ],
  14364. properties: [
  14365. {
  14366. name: "calledCollaborationRef",
  14367. type: "Collaboration",
  14368. isAttr: true,
  14369. isReference: true
  14370. },
  14371. {
  14372. name: "participantAssociations",
  14373. type: "ParticipantAssociation",
  14374. isMany: true
  14375. }
  14376. ]
  14377. },
  14378. {
  14379. name: "Conversation",
  14380. superClass: [
  14381. "ConversationNode"
  14382. ]
  14383. },
  14384. {
  14385. name: "SubConversation",
  14386. superClass: [
  14387. "ConversationNode"
  14388. ],
  14389. properties: [
  14390. {
  14391. name: "conversationNodes",
  14392. type: "ConversationNode",
  14393. isMany: true
  14394. }
  14395. ]
  14396. },
  14397. {
  14398. name: "ConversationNode",
  14399. isAbstract: true,
  14400. superClass: [
  14401. "InteractionNode",
  14402. "BaseElement"
  14403. ],
  14404. properties: [
  14405. {
  14406. name: "name",
  14407. isAttr: true,
  14408. type: "String"
  14409. },
  14410. {
  14411. name: "participantRef",
  14412. type: "Participant",
  14413. isMany: true,
  14414. isReference: true
  14415. },
  14416. {
  14417. name: "messageFlowRefs",
  14418. type: "MessageFlow",
  14419. isMany: true,
  14420. isReference: true
  14421. },
  14422. {
  14423. name: "correlationKeys",
  14424. type: "CorrelationKey",
  14425. isMany: true
  14426. }
  14427. ]
  14428. },
  14429. {
  14430. name: "GlobalConversation",
  14431. superClass: [
  14432. "Collaboration"
  14433. ]
  14434. },
  14435. {
  14436. name: "PartnerEntity",
  14437. superClass: [
  14438. "RootElement"
  14439. ],
  14440. properties: [
  14441. {
  14442. name: "name",
  14443. isAttr: true,
  14444. type: "String"
  14445. },
  14446. {
  14447. name: "participantRef",
  14448. type: "Participant",
  14449. isMany: true,
  14450. isReference: true
  14451. }
  14452. ]
  14453. },
  14454. {
  14455. name: "PartnerRole",
  14456. superClass: [
  14457. "RootElement"
  14458. ],
  14459. properties: [
  14460. {
  14461. name: "name",
  14462. isAttr: true,
  14463. type: "String"
  14464. },
  14465. {
  14466. name: "participantRef",
  14467. type: "Participant",
  14468. isMany: true,
  14469. isReference: true
  14470. }
  14471. ]
  14472. },
  14473. {
  14474. name: "CorrelationProperty",
  14475. superClass: [
  14476. "RootElement"
  14477. ],
  14478. properties: [
  14479. {
  14480. name: "correlationPropertyRetrievalExpression",
  14481. type: "CorrelationPropertyRetrievalExpression",
  14482. isMany: true
  14483. },
  14484. {
  14485. name: "name",
  14486. isAttr: true,
  14487. type: "String"
  14488. },
  14489. {
  14490. name: "type",
  14491. type: "ItemDefinition",
  14492. isAttr: true,
  14493. isReference: true
  14494. }
  14495. ]
  14496. },
  14497. {
  14498. name: "Error",
  14499. superClass: [
  14500. "RootElement"
  14501. ],
  14502. properties: [
  14503. {
  14504. name: "structureRef",
  14505. type: "ItemDefinition",
  14506. isAttr: true,
  14507. isReference: true
  14508. },
  14509. {
  14510. name: "name",
  14511. isAttr: true,
  14512. type: "String"
  14513. },
  14514. {
  14515. name: "errorCode",
  14516. isAttr: true,
  14517. type: "String"
  14518. }
  14519. ]
  14520. },
  14521. {
  14522. name: "CorrelationKey",
  14523. superClass: [
  14524. "BaseElement"
  14525. ],
  14526. properties: [
  14527. {
  14528. name: "correlationPropertyRef",
  14529. type: "CorrelationProperty",
  14530. isMany: true,
  14531. isReference: true
  14532. },
  14533. {
  14534. name: "name",
  14535. isAttr: true,
  14536. type: "String"
  14537. }
  14538. ]
  14539. },
  14540. {
  14541. name: "Expression",
  14542. superClass: [
  14543. "BaseElement"
  14544. ],
  14545. isAbstract: false,
  14546. properties: [
  14547. {
  14548. name: "body",
  14549. isBody: true,
  14550. type: "String"
  14551. }
  14552. ]
  14553. },
  14554. {
  14555. name: "FormalExpression",
  14556. superClass: [
  14557. "Expression"
  14558. ],
  14559. properties: [
  14560. {
  14561. name: "language",
  14562. isAttr: true,
  14563. type: "String"
  14564. },
  14565. {
  14566. name: "evaluatesToTypeRef",
  14567. type: "ItemDefinition",
  14568. isAttr: true,
  14569. isReference: true
  14570. }
  14571. ]
  14572. },
  14573. {
  14574. name: "Message",
  14575. superClass: [
  14576. "RootElement"
  14577. ],
  14578. properties: [
  14579. {
  14580. name: "name",
  14581. isAttr: true,
  14582. type: "String"
  14583. },
  14584. {
  14585. name: "itemRef",
  14586. type: "ItemDefinition",
  14587. isAttr: true,
  14588. isReference: true
  14589. }
  14590. ]
  14591. },
  14592. {
  14593. name: "ItemDefinition",
  14594. superClass: [
  14595. "RootElement"
  14596. ],
  14597. properties: [
  14598. {
  14599. name: "itemKind",
  14600. type: "ItemKind",
  14601. isAttr: true
  14602. },
  14603. {
  14604. name: "structureRef",
  14605. isAttr: true,
  14606. type: "String"
  14607. },
  14608. {
  14609. name: "isCollection",
  14610. "default": false,
  14611. isAttr: true,
  14612. type: "Boolean"
  14613. },
  14614. {
  14615. name: "import",
  14616. type: "Import",
  14617. isAttr: true,
  14618. isReference: true
  14619. }
  14620. ]
  14621. },
  14622. {
  14623. name: "FlowElement",
  14624. isAbstract: true,
  14625. superClass: [
  14626. "BaseElement"
  14627. ],
  14628. properties: [
  14629. {
  14630. name: "name",
  14631. isAttr: true,
  14632. type: "String"
  14633. },
  14634. {
  14635. name: "auditing",
  14636. type: "Auditing"
  14637. },
  14638. {
  14639. name: "monitoring",
  14640. type: "Monitoring"
  14641. },
  14642. {
  14643. name: "categoryValueRef",
  14644. type: "CategoryValue",
  14645. isMany: true,
  14646. isReference: true
  14647. }
  14648. ]
  14649. },
  14650. {
  14651. name: "SequenceFlow",
  14652. superClass: [
  14653. "FlowElement"
  14654. ],
  14655. properties: [
  14656. {
  14657. name: "isImmediate",
  14658. isAttr: true,
  14659. type: "Boolean"
  14660. },
  14661. {
  14662. name: "conditionExpression",
  14663. type: "Expression",
  14664. xml: {
  14665. serialize: "xsi:type"
  14666. }
  14667. },
  14668. {
  14669. name: "sourceRef",
  14670. type: "FlowNode",
  14671. isAttr: true,
  14672. isReference: true
  14673. },
  14674. {
  14675. name: "targetRef",
  14676. type: "FlowNode",
  14677. isAttr: true,
  14678. isReference: true
  14679. }
  14680. ]
  14681. },
  14682. {
  14683. name: "FlowElementsContainer",
  14684. isAbstract: true,
  14685. superClass: [
  14686. "BaseElement"
  14687. ],
  14688. properties: [
  14689. {
  14690. name: "laneSets",
  14691. type: "LaneSet",
  14692. isMany: true
  14693. },
  14694. {
  14695. name: "flowElements",
  14696. type: "FlowElement",
  14697. isMany: true
  14698. }
  14699. ]
  14700. },
  14701. {
  14702. name: "CallableElement",
  14703. isAbstract: true,
  14704. superClass: [
  14705. "RootElement"
  14706. ],
  14707. properties: [
  14708. {
  14709. name: "name",
  14710. isAttr: true,
  14711. type: "String"
  14712. },
  14713. {
  14714. name: "ioSpecification",
  14715. type: "InputOutputSpecification",
  14716. xml: {
  14717. serialize: "property"
  14718. }
  14719. },
  14720. {
  14721. name: "supportedInterfaceRef",
  14722. type: "Interface",
  14723. isMany: true,
  14724. isReference: true
  14725. },
  14726. {
  14727. name: "ioBinding",
  14728. type: "InputOutputBinding",
  14729. isMany: true,
  14730. xml: {
  14731. serialize: "property"
  14732. }
  14733. }
  14734. ]
  14735. },
  14736. {
  14737. name: "FlowNode",
  14738. isAbstract: true,
  14739. superClass: [
  14740. "FlowElement"
  14741. ],
  14742. properties: [
  14743. {
  14744. name: "incoming",
  14745. type: "SequenceFlow",
  14746. isMany: true,
  14747. isReference: true
  14748. },
  14749. {
  14750. name: "outgoing",
  14751. type: "SequenceFlow",
  14752. isMany: true,
  14753. isReference: true
  14754. },
  14755. {
  14756. name: "lanes",
  14757. type: "Lane",
  14758. isMany: true,
  14759. isVirtual: true,
  14760. isReference: true
  14761. }
  14762. ]
  14763. },
  14764. {
  14765. name: "CorrelationPropertyRetrievalExpression",
  14766. superClass: [
  14767. "BaseElement"
  14768. ],
  14769. properties: [
  14770. {
  14771. name: "messagePath",
  14772. type: "FormalExpression"
  14773. },
  14774. {
  14775. name: "messageRef",
  14776. type: "Message",
  14777. isAttr: true,
  14778. isReference: true
  14779. }
  14780. ]
  14781. },
  14782. {
  14783. name: "CorrelationPropertyBinding",
  14784. superClass: [
  14785. "BaseElement"
  14786. ],
  14787. properties: [
  14788. {
  14789. name: "dataPath",
  14790. type: "FormalExpression"
  14791. },
  14792. {
  14793. name: "correlationPropertyRef",
  14794. type: "CorrelationProperty",
  14795. isAttr: true,
  14796. isReference: true
  14797. }
  14798. ]
  14799. },
  14800. {
  14801. name: "Resource",
  14802. superClass: [
  14803. "RootElement"
  14804. ],
  14805. properties: [
  14806. {
  14807. name: "name",
  14808. isAttr: true,
  14809. type: "String"
  14810. },
  14811. {
  14812. name: "resourceParameters",
  14813. type: "ResourceParameter",
  14814. isMany: true
  14815. }
  14816. ]
  14817. },
  14818. {
  14819. name: "ResourceParameter",
  14820. superClass: [
  14821. "BaseElement"
  14822. ],
  14823. properties: [
  14824. {
  14825. name: "name",
  14826. isAttr: true,
  14827. type: "String"
  14828. },
  14829. {
  14830. name: "isRequired",
  14831. isAttr: true,
  14832. type: "Boolean"
  14833. },
  14834. {
  14835. name: "type",
  14836. type: "ItemDefinition",
  14837. isAttr: true,
  14838. isReference: true
  14839. }
  14840. ]
  14841. },
  14842. {
  14843. name: "CorrelationSubscription",
  14844. superClass: [
  14845. "BaseElement"
  14846. ],
  14847. properties: [
  14848. {
  14849. name: "correlationKeyRef",
  14850. type: "CorrelationKey",
  14851. isAttr: true,
  14852. isReference: true
  14853. },
  14854. {
  14855. name: "correlationPropertyBinding",
  14856. type: "CorrelationPropertyBinding",
  14857. isMany: true
  14858. }
  14859. ]
  14860. },
  14861. {
  14862. name: "MessageFlow",
  14863. superClass: [
  14864. "BaseElement"
  14865. ],
  14866. properties: [
  14867. {
  14868. name: "name",
  14869. isAttr: true,
  14870. type: "String"
  14871. },
  14872. {
  14873. name: "sourceRef",
  14874. type: "InteractionNode",
  14875. isAttr: true,
  14876. isReference: true
  14877. },
  14878. {
  14879. name: "targetRef",
  14880. type: "InteractionNode",
  14881. isAttr: true,
  14882. isReference: true
  14883. },
  14884. {
  14885. name: "messageRef",
  14886. type: "Message",
  14887. isAttr: true,
  14888. isReference: true
  14889. }
  14890. ]
  14891. },
  14892. {
  14893. name: "MessageFlowAssociation",
  14894. superClass: [
  14895. "BaseElement"
  14896. ],
  14897. properties: [
  14898. {
  14899. name: "innerMessageFlowRef",
  14900. type: "MessageFlow",
  14901. isAttr: true,
  14902. isReference: true
  14903. },
  14904. {
  14905. name: "outerMessageFlowRef",
  14906. type: "MessageFlow",
  14907. isAttr: true,
  14908. isReference: true
  14909. }
  14910. ]
  14911. },
  14912. {
  14913. name: "InteractionNode",
  14914. isAbstract: true,
  14915. properties: [
  14916. {
  14917. name: "incomingConversationLinks",
  14918. type: "ConversationLink",
  14919. isMany: true,
  14920. isVirtual: true,
  14921. isReference: true
  14922. },
  14923. {
  14924. name: "outgoingConversationLinks",
  14925. type: "ConversationLink",
  14926. isMany: true,
  14927. isVirtual: true,
  14928. isReference: true
  14929. }
  14930. ]
  14931. },
  14932. {
  14933. name: "Participant",
  14934. superClass: [
  14935. "InteractionNode",
  14936. "BaseElement"
  14937. ],
  14938. properties: [
  14939. {
  14940. name: "name",
  14941. isAttr: true,
  14942. type: "String"
  14943. },
  14944. {
  14945. name: "interfaceRef",
  14946. type: "Interface",
  14947. isMany: true,
  14948. isReference: true
  14949. },
  14950. {
  14951. name: "participantMultiplicity",
  14952. type: "ParticipantMultiplicity"
  14953. },
  14954. {
  14955. name: "endPointRefs",
  14956. type: "EndPoint",
  14957. isMany: true,
  14958. isReference: true
  14959. },
  14960. {
  14961. name: "processRef",
  14962. type: "Process",
  14963. isAttr: true,
  14964. isReference: true
  14965. }
  14966. ]
  14967. },
  14968. {
  14969. name: "ParticipantAssociation",
  14970. superClass: [
  14971. "BaseElement"
  14972. ],
  14973. properties: [
  14974. {
  14975. name: "innerParticipantRef",
  14976. type: "Participant",
  14977. isAttr: true,
  14978. isReference: true
  14979. },
  14980. {
  14981. name: "outerParticipantRef",
  14982. type: "Participant",
  14983. isAttr: true,
  14984. isReference: true
  14985. }
  14986. ]
  14987. },
  14988. {
  14989. name: "ParticipantMultiplicity",
  14990. properties: [
  14991. {
  14992. name: "minimum",
  14993. "default": 0,
  14994. isAttr: true,
  14995. type: "Integer"
  14996. },
  14997. {
  14998. name: "maximum",
  14999. "default": 1,
  15000. isAttr: true,
  15001. type: "Integer"
  15002. }
  15003. ],
  15004. superClass: [
  15005. "BaseElement"
  15006. ]
  15007. },
  15008. {
  15009. name: "Collaboration",
  15010. superClass: [
  15011. "RootElement"
  15012. ],
  15013. properties: [
  15014. {
  15015. name: "name",
  15016. isAttr: true,
  15017. type: "String"
  15018. },
  15019. {
  15020. name: "isClosed",
  15021. isAttr: true,
  15022. type: "Boolean"
  15023. },
  15024. {
  15025. name: "participants",
  15026. type: "Participant",
  15027. isMany: true
  15028. },
  15029. {
  15030. name: "messageFlows",
  15031. type: "MessageFlow",
  15032. isMany: true
  15033. },
  15034. {
  15035. name: "artifacts",
  15036. type: "Artifact",
  15037. isMany: true
  15038. },
  15039. {
  15040. name: "conversations",
  15041. type: "ConversationNode",
  15042. isMany: true
  15043. },
  15044. {
  15045. name: "conversationAssociations",
  15046. type: "ConversationAssociation"
  15047. },
  15048. {
  15049. name: "participantAssociations",
  15050. type: "ParticipantAssociation",
  15051. isMany: true
  15052. },
  15053. {
  15054. name: "messageFlowAssociations",
  15055. type: "MessageFlowAssociation",
  15056. isMany: true
  15057. },
  15058. {
  15059. name: "correlationKeys",
  15060. type: "CorrelationKey",
  15061. isMany: true
  15062. },
  15063. {
  15064. name: "choreographyRef",
  15065. type: "Choreography",
  15066. isMany: true,
  15067. isReference: true
  15068. },
  15069. {
  15070. name: "conversationLinks",
  15071. type: "ConversationLink",
  15072. isMany: true
  15073. }
  15074. ]
  15075. },
  15076. {
  15077. name: "ChoreographyActivity",
  15078. isAbstract: true,
  15079. superClass: [
  15080. "FlowNode"
  15081. ],
  15082. properties: [
  15083. {
  15084. name: "participantRef",
  15085. type: "Participant",
  15086. isMany: true,
  15087. isReference: true
  15088. },
  15089. {
  15090. name: "initiatingParticipantRef",
  15091. type: "Participant",
  15092. isAttr: true,
  15093. isReference: true
  15094. },
  15095. {
  15096. name: "correlationKeys",
  15097. type: "CorrelationKey",
  15098. isMany: true
  15099. },
  15100. {
  15101. name: "loopType",
  15102. type: "ChoreographyLoopType",
  15103. "default": "None",
  15104. isAttr: true
  15105. }
  15106. ]
  15107. },
  15108. {
  15109. name: "CallChoreography",
  15110. superClass: [
  15111. "ChoreographyActivity"
  15112. ],
  15113. properties: [
  15114. {
  15115. name: "calledChoreographyRef",
  15116. type: "Choreography",
  15117. isAttr: true,
  15118. isReference: true
  15119. },
  15120. {
  15121. name: "participantAssociations",
  15122. type: "ParticipantAssociation",
  15123. isMany: true
  15124. }
  15125. ]
  15126. },
  15127. {
  15128. name: "SubChoreography",
  15129. superClass: [
  15130. "ChoreographyActivity",
  15131. "FlowElementsContainer"
  15132. ],
  15133. properties: [
  15134. {
  15135. name: "artifacts",
  15136. type: "Artifact",
  15137. isMany: true
  15138. }
  15139. ]
  15140. },
  15141. {
  15142. name: "ChoreographyTask",
  15143. superClass: [
  15144. "ChoreographyActivity"
  15145. ],
  15146. properties: [
  15147. {
  15148. name: "messageFlowRef",
  15149. type: "MessageFlow",
  15150. isMany: true,
  15151. isReference: true
  15152. }
  15153. ]
  15154. },
  15155. {
  15156. name: "Choreography",
  15157. superClass: [
  15158. "Collaboration",
  15159. "FlowElementsContainer"
  15160. ]
  15161. },
  15162. {
  15163. name: "GlobalChoreographyTask",
  15164. superClass: [
  15165. "Choreography"
  15166. ],
  15167. properties: [
  15168. {
  15169. name: "initiatingParticipantRef",
  15170. type: "Participant",
  15171. isAttr: true,
  15172. isReference: true
  15173. }
  15174. ]
  15175. },
  15176. {
  15177. name: "TextAnnotation",
  15178. superClass: [
  15179. "Artifact"
  15180. ],
  15181. properties: [
  15182. {
  15183. name: "text",
  15184. type: "String"
  15185. },
  15186. {
  15187. name: "textFormat",
  15188. "default": "text/plain",
  15189. isAttr: true,
  15190. type: "String"
  15191. }
  15192. ]
  15193. },
  15194. {
  15195. name: "Group",
  15196. superClass: [
  15197. "Artifact"
  15198. ],
  15199. properties: [
  15200. {
  15201. name: "categoryValueRef",
  15202. type: "CategoryValue",
  15203. isAttr: true,
  15204. isReference: true
  15205. }
  15206. ]
  15207. },
  15208. {
  15209. name: "Association",
  15210. superClass: [
  15211. "Artifact"
  15212. ],
  15213. properties: [
  15214. {
  15215. name: "associationDirection",
  15216. type: "AssociationDirection",
  15217. isAttr: true
  15218. },
  15219. {
  15220. name: "sourceRef",
  15221. type: "BaseElement",
  15222. isAttr: true,
  15223. isReference: true
  15224. },
  15225. {
  15226. name: "targetRef",
  15227. type: "BaseElement",
  15228. isAttr: true,
  15229. isReference: true
  15230. }
  15231. ]
  15232. },
  15233. {
  15234. name: "Category",
  15235. superClass: [
  15236. "RootElement"
  15237. ],
  15238. properties: [
  15239. {
  15240. name: "categoryValue",
  15241. type: "CategoryValue",
  15242. isMany: true
  15243. },
  15244. {
  15245. name: "name",
  15246. isAttr: true,
  15247. type: "String"
  15248. }
  15249. ]
  15250. },
  15251. {
  15252. name: "Artifact",
  15253. isAbstract: true,
  15254. superClass: [
  15255. "BaseElement"
  15256. ]
  15257. },
  15258. {
  15259. name: "CategoryValue",
  15260. superClass: [
  15261. "BaseElement"
  15262. ],
  15263. properties: [
  15264. {
  15265. name: "categorizedFlowElements",
  15266. type: "FlowElement",
  15267. isMany: true,
  15268. isVirtual: true,
  15269. isReference: true
  15270. },
  15271. {
  15272. name: "value",
  15273. isAttr: true,
  15274. type: "String"
  15275. }
  15276. ]
  15277. },
  15278. {
  15279. name: "Activity",
  15280. isAbstract: true,
  15281. superClass: [
  15282. "FlowNode"
  15283. ],
  15284. properties: [
  15285. {
  15286. name: "isForCompensation",
  15287. "default": false,
  15288. isAttr: true,
  15289. type: "Boolean"
  15290. },
  15291. {
  15292. name: "default",
  15293. type: "SequenceFlow",
  15294. isAttr: true,
  15295. isReference: true
  15296. },
  15297. {
  15298. name: "ioSpecification",
  15299. type: "InputOutputSpecification",
  15300. xml: {
  15301. serialize: "property"
  15302. }
  15303. },
  15304. {
  15305. name: "boundaryEventRefs",
  15306. type: "BoundaryEvent",
  15307. isMany: true,
  15308. isReference: true
  15309. },
  15310. {
  15311. name: "properties",
  15312. type: "Property",
  15313. isMany: true
  15314. },
  15315. {
  15316. name: "dataInputAssociations",
  15317. type: "DataInputAssociation",
  15318. isMany: true
  15319. },
  15320. {
  15321. name: "dataOutputAssociations",
  15322. type: "DataOutputAssociation",
  15323. isMany: true
  15324. },
  15325. {
  15326. name: "startQuantity",
  15327. "default": 1,
  15328. isAttr: true,
  15329. type: "Integer"
  15330. },
  15331. {
  15332. name: "resources",
  15333. type: "ResourceRole",
  15334. isMany: true
  15335. },
  15336. {
  15337. name: "completionQuantity",
  15338. "default": 1,
  15339. isAttr: true,
  15340. type: "Integer"
  15341. },
  15342. {
  15343. name: "loopCharacteristics",
  15344. type: "LoopCharacteristics"
  15345. }
  15346. ]
  15347. },
  15348. {
  15349. name: "ServiceTask",
  15350. superClass: [
  15351. "Task"
  15352. ],
  15353. properties: [
  15354. {
  15355. name: "implementation",
  15356. isAttr: true,
  15357. type: "String"
  15358. },
  15359. {
  15360. name: "operationRef",
  15361. type: "Operation",
  15362. isAttr: true,
  15363. isReference: true
  15364. }
  15365. ]
  15366. },
  15367. {
  15368. name: "SubProcess",
  15369. superClass: [
  15370. "Activity",
  15371. "FlowElementsContainer",
  15372. "InteractionNode"
  15373. ],
  15374. properties: [
  15375. {
  15376. name: "triggeredByEvent",
  15377. "default": false,
  15378. isAttr: true,
  15379. type: "Boolean"
  15380. },
  15381. {
  15382. name: "artifacts",
  15383. type: "Artifact",
  15384. isMany: true
  15385. }
  15386. ]
  15387. },
  15388. {
  15389. name: "LoopCharacteristics",
  15390. isAbstract: true,
  15391. superClass: [
  15392. "BaseElement"
  15393. ]
  15394. },
  15395. {
  15396. name: "MultiInstanceLoopCharacteristics",
  15397. superClass: [
  15398. "LoopCharacteristics"
  15399. ],
  15400. properties: [
  15401. {
  15402. name: "isSequential",
  15403. "default": false,
  15404. isAttr: true,
  15405. type: "Boolean"
  15406. },
  15407. {
  15408. name: "behavior",
  15409. type: "MultiInstanceBehavior",
  15410. "default": "All",
  15411. isAttr: true
  15412. },
  15413. {
  15414. name: "loopCardinality",
  15415. type: "Expression",
  15416. xml: {
  15417. serialize: "xsi:type"
  15418. }
  15419. },
  15420. {
  15421. name: "loopDataInputRef",
  15422. type: "ItemAwareElement",
  15423. isReference: true
  15424. },
  15425. {
  15426. name: "loopDataOutputRef",
  15427. type: "ItemAwareElement",
  15428. isReference: true
  15429. },
  15430. {
  15431. name: "inputDataItem",
  15432. type: "DataInput",
  15433. xml: {
  15434. serialize: "property"
  15435. }
  15436. },
  15437. {
  15438. name: "outputDataItem",
  15439. type: "DataOutput",
  15440. xml: {
  15441. serialize: "property"
  15442. }
  15443. },
  15444. {
  15445. name: "complexBehaviorDefinition",
  15446. type: "ComplexBehaviorDefinition",
  15447. isMany: true
  15448. },
  15449. {
  15450. name: "completionCondition",
  15451. type: "Expression",
  15452. xml: {
  15453. serialize: "xsi:type"
  15454. }
  15455. },
  15456. {
  15457. name: "oneBehaviorEventRef",
  15458. type: "EventDefinition",
  15459. isAttr: true,
  15460. isReference: true
  15461. },
  15462. {
  15463. name: "noneBehaviorEventRef",
  15464. type: "EventDefinition",
  15465. isAttr: true,
  15466. isReference: true
  15467. }
  15468. ]
  15469. },
  15470. {
  15471. name: "StandardLoopCharacteristics",
  15472. superClass: [
  15473. "LoopCharacteristics"
  15474. ],
  15475. properties: [
  15476. {
  15477. name: "testBefore",
  15478. "default": false,
  15479. isAttr: true,
  15480. type: "Boolean"
  15481. },
  15482. {
  15483. name: "loopCondition",
  15484. type: "Expression",
  15485. xml: {
  15486. serialize: "xsi:type"
  15487. }
  15488. },
  15489. {
  15490. name: "loopMaximum",
  15491. type: "Integer",
  15492. isAttr: true
  15493. }
  15494. ]
  15495. },
  15496. {
  15497. name: "CallActivity",
  15498. superClass: [
  15499. "Activity",
  15500. "InteractionNode"
  15501. ],
  15502. properties: [
  15503. {
  15504. name: "calledElement",
  15505. type: "String",
  15506. isAttr: true
  15507. }
  15508. ]
  15509. },
  15510. {
  15511. name: "Task",
  15512. superClass: [
  15513. "Activity",
  15514. "InteractionNode"
  15515. ]
  15516. },
  15517. {
  15518. name: "SendTask",
  15519. superClass: [
  15520. "Task"
  15521. ],
  15522. properties: [
  15523. {
  15524. name: "implementation",
  15525. isAttr: true,
  15526. type: "String"
  15527. },
  15528. {
  15529. name: "operationRef",
  15530. type: "Operation",
  15531. isAttr: true,
  15532. isReference: true
  15533. },
  15534. {
  15535. name: "messageRef",
  15536. type: "Message",
  15537. isAttr: true,
  15538. isReference: true
  15539. }
  15540. ]
  15541. },
  15542. {
  15543. name: "ReceiveTask",
  15544. superClass: [
  15545. "Task"
  15546. ],
  15547. properties: [
  15548. {
  15549. name: "implementation",
  15550. isAttr: true,
  15551. type: "String"
  15552. },
  15553. {
  15554. name: "instantiate",
  15555. "default": false,
  15556. isAttr: true,
  15557. type: "Boolean"
  15558. },
  15559. {
  15560. name: "operationRef",
  15561. type: "Operation",
  15562. isAttr: true,
  15563. isReference: true
  15564. },
  15565. {
  15566. name: "messageRef",
  15567. type: "Message",
  15568. isAttr: true,
  15569. isReference: true
  15570. }
  15571. ]
  15572. },
  15573. {
  15574. name: "ScriptTask",
  15575. superClass: [
  15576. "Task"
  15577. ],
  15578. properties: [
  15579. {
  15580. name: "scriptFormat",
  15581. isAttr: true,
  15582. type: "String"
  15583. },
  15584. {
  15585. name: "script",
  15586. type: "String"
  15587. }
  15588. ]
  15589. },
  15590. {
  15591. name: "BusinessRuleTask",
  15592. superClass: [
  15593. "Task"
  15594. ],
  15595. properties: [
  15596. {
  15597. name: "implementation",
  15598. isAttr: true,
  15599. type: "String"
  15600. }
  15601. ]
  15602. },
  15603. {
  15604. name: "AdHocSubProcess",
  15605. superClass: [
  15606. "SubProcess"
  15607. ],
  15608. properties: [
  15609. {
  15610. name: "completionCondition",
  15611. type: "Expression",
  15612. xml: {
  15613. serialize: "xsi:type"
  15614. }
  15615. },
  15616. {
  15617. name: "ordering",
  15618. type: "AdHocOrdering",
  15619. isAttr: true
  15620. },
  15621. {
  15622. name: "cancelRemainingInstances",
  15623. "default": true,
  15624. isAttr: true,
  15625. type: "Boolean"
  15626. }
  15627. ]
  15628. },
  15629. {
  15630. name: "Transaction",
  15631. superClass: [
  15632. "SubProcess"
  15633. ],
  15634. properties: [
  15635. {
  15636. name: "protocol",
  15637. isAttr: true,
  15638. type: "String"
  15639. },
  15640. {
  15641. name: "method",
  15642. isAttr: true,
  15643. type: "String"
  15644. }
  15645. ]
  15646. },
  15647. {
  15648. name: "GlobalScriptTask",
  15649. superClass: [
  15650. "GlobalTask"
  15651. ],
  15652. properties: [
  15653. {
  15654. name: "scriptLanguage",
  15655. isAttr: true,
  15656. type: "String"
  15657. },
  15658. {
  15659. name: "script",
  15660. isAttr: true,
  15661. type: "String"
  15662. }
  15663. ]
  15664. },
  15665. {
  15666. name: "GlobalBusinessRuleTask",
  15667. superClass: [
  15668. "GlobalTask"
  15669. ],
  15670. properties: [
  15671. {
  15672. name: "implementation",
  15673. isAttr: true,
  15674. type: "String"
  15675. }
  15676. ]
  15677. },
  15678. {
  15679. name: "ComplexBehaviorDefinition",
  15680. superClass: [
  15681. "BaseElement"
  15682. ],
  15683. properties: [
  15684. {
  15685. name: "condition",
  15686. type: "FormalExpression"
  15687. },
  15688. {
  15689. name: "event",
  15690. type: "ImplicitThrowEvent"
  15691. }
  15692. ]
  15693. },
  15694. {
  15695. name: "ResourceRole",
  15696. superClass: [
  15697. "BaseElement"
  15698. ],
  15699. properties: [
  15700. {
  15701. name: "resourceRef",
  15702. type: "Resource",
  15703. isReference: true
  15704. },
  15705. {
  15706. name: "resourceParameterBindings",
  15707. type: "ResourceParameterBinding",
  15708. isMany: true
  15709. },
  15710. {
  15711. name: "resourceAssignmentExpression",
  15712. type: "ResourceAssignmentExpression"
  15713. },
  15714. {
  15715. name: "name",
  15716. isAttr: true,
  15717. type: "String"
  15718. }
  15719. ]
  15720. },
  15721. {
  15722. name: "ResourceParameterBinding",
  15723. properties: [
  15724. {
  15725. name: "expression",
  15726. type: "Expression",
  15727. xml: {
  15728. serialize: "xsi:type"
  15729. }
  15730. },
  15731. {
  15732. name: "parameterRef",
  15733. type: "ResourceParameter",
  15734. isAttr: true,
  15735. isReference: true
  15736. }
  15737. ],
  15738. superClass: [
  15739. "BaseElement"
  15740. ]
  15741. },
  15742. {
  15743. name: "ResourceAssignmentExpression",
  15744. properties: [
  15745. {
  15746. name: "expression",
  15747. type: "Expression",
  15748. xml: {
  15749. serialize: "xsi:type"
  15750. }
  15751. }
  15752. ],
  15753. superClass: [
  15754. "BaseElement"
  15755. ]
  15756. },
  15757. {
  15758. name: "Import",
  15759. properties: [
  15760. {
  15761. name: "importType",
  15762. isAttr: true,
  15763. type: "String"
  15764. },
  15765. {
  15766. name: "location",
  15767. isAttr: true,
  15768. type: "String"
  15769. },
  15770. {
  15771. name: "namespace",
  15772. isAttr: true,
  15773. type: "String"
  15774. }
  15775. ]
  15776. },
  15777. {
  15778. name: "Definitions",
  15779. superClass: [
  15780. "BaseElement"
  15781. ],
  15782. properties: [
  15783. {
  15784. name: "name",
  15785. isAttr: true,
  15786. type: "String"
  15787. },
  15788. {
  15789. name: "targetNamespace",
  15790. isAttr: true,
  15791. type: "String"
  15792. },
  15793. {
  15794. name: "expressionLanguage",
  15795. "default": "http://www.w3.org/1999/XPath",
  15796. isAttr: true,
  15797. type: "String"
  15798. },
  15799. {
  15800. name: "typeLanguage",
  15801. "default": "http://www.w3.org/2001/XMLSchema",
  15802. isAttr: true,
  15803. type: "String"
  15804. },
  15805. {
  15806. name: "imports",
  15807. type: "Import",
  15808. isMany: true
  15809. },
  15810. {
  15811. name: "extensions",
  15812. type: "Extension",
  15813. isMany: true
  15814. },
  15815. {
  15816. name: "rootElements",
  15817. type: "RootElement",
  15818. isMany: true
  15819. },
  15820. {
  15821. name: "diagrams",
  15822. isMany: true,
  15823. type: "bpmndi:BPMNDiagram"
  15824. },
  15825. {
  15826. name: "exporter",
  15827. isAttr: true,
  15828. type: "String"
  15829. },
  15830. {
  15831. name: "relationships",
  15832. type: "Relationship",
  15833. isMany: true
  15834. },
  15835. {
  15836. name: "exporterVersion",
  15837. isAttr: true,
  15838. type: "String"
  15839. }
  15840. ]
  15841. }
  15842. ];
  15843. var enumerations = [
  15844. {
  15845. name: "ProcessType",
  15846. literalValues: [
  15847. {
  15848. name: "None"
  15849. },
  15850. {
  15851. name: "Public"
  15852. },
  15853. {
  15854. name: "Private"
  15855. }
  15856. ]
  15857. },
  15858. {
  15859. name: "GatewayDirection",
  15860. literalValues: [
  15861. {
  15862. name: "Unspecified"
  15863. },
  15864. {
  15865. name: "Converging"
  15866. },
  15867. {
  15868. name: "Diverging"
  15869. },
  15870. {
  15871. name: "Mixed"
  15872. }
  15873. ]
  15874. },
  15875. {
  15876. name: "EventBasedGatewayType",
  15877. literalValues: [
  15878. {
  15879. name: "Parallel"
  15880. },
  15881. {
  15882. name: "Exclusive"
  15883. }
  15884. ]
  15885. },
  15886. {
  15887. name: "RelationshipDirection",
  15888. literalValues: [
  15889. {
  15890. name: "None"
  15891. },
  15892. {
  15893. name: "Forward"
  15894. },
  15895. {
  15896. name: "Backward"
  15897. },
  15898. {
  15899. name: "Both"
  15900. }
  15901. ]
  15902. },
  15903. {
  15904. name: "ItemKind",
  15905. literalValues: [
  15906. {
  15907. name: "Physical"
  15908. },
  15909. {
  15910. name: "Information"
  15911. }
  15912. ]
  15913. },
  15914. {
  15915. name: "ChoreographyLoopType",
  15916. literalValues: [
  15917. {
  15918. name: "None"
  15919. },
  15920. {
  15921. name: "Standard"
  15922. },
  15923. {
  15924. name: "MultiInstanceSequential"
  15925. },
  15926. {
  15927. name: "MultiInstanceParallel"
  15928. }
  15929. ]
  15930. },
  15931. {
  15932. name: "AssociationDirection",
  15933. literalValues: [
  15934. {
  15935. name: "None"
  15936. },
  15937. {
  15938. name: "One"
  15939. },
  15940. {
  15941. name: "Both"
  15942. }
  15943. ]
  15944. },
  15945. {
  15946. name: "MultiInstanceBehavior",
  15947. literalValues: [
  15948. {
  15949. name: "None"
  15950. },
  15951. {
  15952. name: "One"
  15953. },
  15954. {
  15955. name: "All"
  15956. },
  15957. {
  15958. name: "Complex"
  15959. }
  15960. ]
  15961. },
  15962. {
  15963. name: "AdHocOrdering",
  15964. literalValues: [
  15965. {
  15966. name: "Parallel"
  15967. },
  15968. {
  15969. name: "Sequential"
  15970. }
  15971. ]
  15972. }
  15973. ];
  15974. var xml = {
  15975. tagAlias: "lowerCase",
  15976. typePrefix: "t"
  15977. };
  15978. var BpmnPackage = {
  15979. name: name,
  15980. uri: uri,
  15981. prefix: prefix,
  15982. associations: associations,
  15983. types: types,
  15984. enumerations: enumerations,
  15985. xml: xml
  15986. };
  15987. var name$1 = "BPMNDI";
  15988. var uri$1 = "http://www.omg.org/spec/BPMN/20100524/DI";
  15989. var prefix$1 = "bpmndi";
  15990. var types$1 = [
  15991. {
  15992. name: "BPMNDiagram",
  15993. properties: [
  15994. {
  15995. name: "plane",
  15996. type: "BPMNPlane",
  15997. redefines: "di:Diagram#rootElement"
  15998. },
  15999. {
  16000. name: "labelStyle",
  16001. type: "BPMNLabelStyle",
  16002. isMany: true
  16003. }
  16004. ],
  16005. superClass: [
  16006. "di:Diagram"
  16007. ]
  16008. },
  16009. {
  16010. name: "BPMNPlane",
  16011. properties: [
  16012. {
  16013. name: "bpmnElement",
  16014. isAttr: true,
  16015. isReference: true,
  16016. type: "bpmn:BaseElement",
  16017. redefines: "di:DiagramElement#modelElement"
  16018. }
  16019. ],
  16020. superClass: [
  16021. "di:Plane"
  16022. ]
  16023. },
  16024. {
  16025. name: "BPMNShape",
  16026. properties: [
  16027. {
  16028. name: "bpmnElement",
  16029. isAttr: true,
  16030. isReference: true,
  16031. type: "bpmn:BaseElement",
  16032. redefines: "di:DiagramElement#modelElement"
  16033. },
  16034. {
  16035. name: "isHorizontal",
  16036. isAttr: true,
  16037. type: "Boolean"
  16038. },
  16039. {
  16040. name: "isExpanded",
  16041. isAttr: true,
  16042. type: "Boolean"
  16043. },
  16044. {
  16045. name: "isMarkerVisible",
  16046. isAttr: true,
  16047. type: "Boolean"
  16048. },
  16049. {
  16050. name: "label",
  16051. type: "BPMNLabel"
  16052. },
  16053. {
  16054. name: "isMessageVisible",
  16055. isAttr: true,
  16056. type: "Boolean"
  16057. },
  16058. {
  16059. name: "participantBandKind",
  16060. type: "ParticipantBandKind",
  16061. isAttr: true
  16062. },
  16063. {
  16064. name: "choreographyActivityShape",
  16065. type: "BPMNShape",
  16066. isAttr: true,
  16067. isReference: true
  16068. }
  16069. ],
  16070. superClass: [
  16071. "di:LabeledShape"
  16072. ]
  16073. },
  16074. {
  16075. name: "BPMNEdge",
  16076. properties: [
  16077. {
  16078. name: "label",
  16079. type: "BPMNLabel"
  16080. },
  16081. {
  16082. name: "bpmnElement",
  16083. isAttr: true,
  16084. isReference: true,
  16085. type: "bpmn:BaseElement",
  16086. redefines: "di:DiagramElement#modelElement"
  16087. },
  16088. {
  16089. name: "sourceElement",
  16090. isAttr: true,
  16091. isReference: true,
  16092. type: "di:DiagramElement",
  16093. redefines: "di:Edge#source"
  16094. },
  16095. {
  16096. name: "targetElement",
  16097. isAttr: true,
  16098. isReference: true,
  16099. type: "di:DiagramElement",
  16100. redefines: "di:Edge#target"
  16101. },
  16102. {
  16103. name: "messageVisibleKind",
  16104. type: "MessageVisibleKind",
  16105. isAttr: true,
  16106. "default": "initiating"
  16107. }
  16108. ],
  16109. superClass: [
  16110. "di:LabeledEdge"
  16111. ]
  16112. },
  16113. {
  16114. name: "BPMNLabel",
  16115. properties: [
  16116. {
  16117. name: "labelStyle",
  16118. type: "BPMNLabelStyle",
  16119. isAttr: true,
  16120. isReference: true,
  16121. redefines: "di:DiagramElement#style"
  16122. }
  16123. ],
  16124. superClass: [
  16125. "di:Label"
  16126. ]
  16127. },
  16128. {
  16129. name: "BPMNLabelStyle",
  16130. properties: [
  16131. {
  16132. name: "font",
  16133. type: "dc:Font"
  16134. }
  16135. ],
  16136. superClass: [
  16137. "di:Style"
  16138. ]
  16139. }
  16140. ];
  16141. var enumerations$1 = [
  16142. {
  16143. name: "ParticipantBandKind",
  16144. literalValues: [
  16145. {
  16146. name: "top_initiating"
  16147. },
  16148. {
  16149. name: "middle_initiating"
  16150. },
  16151. {
  16152. name: "bottom_initiating"
  16153. },
  16154. {
  16155. name: "top_non_initiating"
  16156. },
  16157. {
  16158. name: "middle_non_initiating"
  16159. },
  16160. {
  16161. name: "bottom_non_initiating"
  16162. }
  16163. ]
  16164. },
  16165. {
  16166. name: "MessageVisibleKind",
  16167. literalValues: [
  16168. {
  16169. name: "initiating"
  16170. },
  16171. {
  16172. name: "non_initiating"
  16173. }
  16174. ]
  16175. }
  16176. ];
  16177. var associations$1 = [
  16178. ];
  16179. var BpmnDiPackage = {
  16180. name: name$1,
  16181. uri: uri$1,
  16182. prefix: prefix$1,
  16183. types: types$1,
  16184. enumerations: enumerations$1,
  16185. associations: associations$1
  16186. };
  16187. var name$2 = "DC";
  16188. var uri$2 = "http://www.omg.org/spec/DD/20100524/DC";
  16189. var prefix$2 = "dc";
  16190. var types$2 = [
  16191. {
  16192. name: "Boolean"
  16193. },
  16194. {
  16195. name: "Integer"
  16196. },
  16197. {
  16198. name: "Real"
  16199. },
  16200. {
  16201. name: "String"
  16202. },
  16203. {
  16204. name: "Font",
  16205. properties: [
  16206. {
  16207. name: "name",
  16208. type: "String",
  16209. isAttr: true
  16210. },
  16211. {
  16212. name: "size",
  16213. type: "Real",
  16214. isAttr: true
  16215. },
  16216. {
  16217. name: "isBold",
  16218. type: "Boolean",
  16219. isAttr: true
  16220. },
  16221. {
  16222. name: "isItalic",
  16223. type: "Boolean",
  16224. isAttr: true
  16225. },
  16226. {
  16227. name: "isUnderline",
  16228. type: "Boolean",
  16229. isAttr: true
  16230. },
  16231. {
  16232. name: "isStrikeThrough",
  16233. type: "Boolean",
  16234. isAttr: true
  16235. }
  16236. ]
  16237. },
  16238. {
  16239. name: "Point",
  16240. properties: [
  16241. {
  16242. name: "x",
  16243. type: "Real",
  16244. "default": "0",
  16245. isAttr: true
  16246. },
  16247. {
  16248. name: "y",
  16249. type: "Real",
  16250. "default": "0",
  16251. isAttr: true
  16252. }
  16253. ]
  16254. },
  16255. {
  16256. name: "Bounds",
  16257. properties: [
  16258. {
  16259. name: "x",
  16260. type: "Real",
  16261. "default": "0",
  16262. isAttr: true
  16263. },
  16264. {
  16265. name: "y",
  16266. type: "Real",
  16267. "default": "0",
  16268. isAttr: true
  16269. },
  16270. {
  16271. name: "width",
  16272. type: "Real",
  16273. isAttr: true
  16274. },
  16275. {
  16276. name: "height",
  16277. type: "Real",
  16278. isAttr: true
  16279. }
  16280. ]
  16281. }
  16282. ];
  16283. var associations$2 = [
  16284. ];
  16285. var DcPackage = {
  16286. name: name$2,
  16287. uri: uri$2,
  16288. prefix: prefix$2,
  16289. types: types$2,
  16290. associations: associations$2
  16291. };
  16292. var name$3 = "DI";
  16293. var uri$3 = "http://www.omg.org/spec/DD/20100524/DI";
  16294. var prefix$3 = "di";
  16295. var types$3 = [
  16296. {
  16297. name: "DiagramElement",
  16298. isAbstract: true,
  16299. properties: [
  16300. {
  16301. name: "id",
  16302. isAttr: true,
  16303. isId: true,
  16304. type: "String"
  16305. },
  16306. {
  16307. name: "extension",
  16308. type: "Extension"
  16309. },
  16310. {
  16311. name: "owningDiagram",
  16312. type: "Diagram",
  16313. isReadOnly: true,
  16314. isVirtual: true,
  16315. isReference: true
  16316. },
  16317. {
  16318. name: "owningElement",
  16319. type: "DiagramElement",
  16320. isReadOnly: true,
  16321. isVirtual: true,
  16322. isReference: true
  16323. },
  16324. {
  16325. name: "modelElement",
  16326. isReadOnly: true,
  16327. isVirtual: true,
  16328. isReference: true,
  16329. type: "Element"
  16330. },
  16331. {
  16332. name: "style",
  16333. type: "Style",
  16334. isReadOnly: true,
  16335. isVirtual: true,
  16336. isReference: true
  16337. },
  16338. {
  16339. name: "ownedElement",
  16340. type: "DiagramElement",
  16341. isReadOnly: true,
  16342. isMany: true,
  16343. isVirtual: true
  16344. }
  16345. ]
  16346. },
  16347. {
  16348. name: "Node",
  16349. isAbstract: true,
  16350. superClass: [
  16351. "DiagramElement"
  16352. ]
  16353. },
  16354. {
  16355. name: "Edge",
  16356. isAbstract: true,
  16357. superClass: [
  16358. "DiagramElement"
  16359. ],
  16360. properties: [
  16361. {
  16362. name: "source",
  16363. type: "DiagramElement",
  16364. isReadOnly: true,
  16365. isVirtual: true,
  16366. isReference: true
  16367. },
  16368. {
  16369. name: "target",
  16370. type: "DiagramElement",
  16371. isReadOnly: true,
  16372. isVirtual: true,
  16373. isReference: true
  16374. },
  16375. {
  16376. name: "waypoint",
  16377. isUnique: false,
  16378. isMany: true,
  16379. type: "dc:Point",
  16380. xml: {
  16381. serialize: "xsi:type"
  16382. }
  16383. }
  16384. ]
  16385. },
  16386. {
  16387. name: "Diagram",
  16388. isAbstract: true,
  16389. properties: [
  16390. {
  16391. name: "id",
  16392. isAttr: true,
  16393. isId: true,
  16394. type: "String"
  16395. },
  16396. {
  16397. name: "rootElement",
  16398. type: "DiagramElement",
  16399. isReadOnly: true,
  16400. isVirtual: true
  16401. },
  16402. {
  16403. name: "name",
  16404. isAttr: true,
  16405. type: "String"
  16406. },
  16407. {
  16408. name: "documentation",
  16409. isAttr: true,
  16410. type: "String"
  16411. },
  16412. {
  16413. name: "resolution",
  16414. isAttr: true,
  16415. type: "Real"
  16416. },
  16417. {
  16418. name: "ownedStyle",
  16419. type: "Style",
  16420. isReadOnly: true,
  16421. isMany: true,
  16422. isVirtual: true
  16423. }
  16424. ]
  16425. },
  16426. {
  16427. name: "Shape",
  16428. isAbstract: true,
  16429. superClass: [
  16430. "Node"
  16431. ],
  16432. properties: [
  16433. {
  16434. name: "bounds",
  16435. type: "dc:Bounds"
  16436. }
  16437. ]
  16438. },
  16439. {
  16440. name: "Plane",
  16441. isAbstract: true,
  16442. superClass: [
  16443. "Node"
  16444. ],
  16445. properties: [
  16446. {
  16447. name: "planeElement",
  16448. type: "DiagramElement",
  16449. subsettedProperty: "DiagramElement-ownedElement",
  16450. isMany: true
  16451. }
  16452. ]
  16453. },
  16454. {
  16455. name: "LabeledEdge",
  16456. isAbstract: true,
  16457. superClass: [
  16458. "Edge"
  16459. ],
  16460. properties: [
  16461. {
  16462. name: "ownedLabel",
  16463. type: "Label",
  16464. isReadOnly: true,
  16465. subsettedProperty: "DiagramElement-ownedElement",
  16466. isMany: true,
  16467. isVirtual: true
  16468. }
  16469. ]
  16470. },
  16471. {
  16472. name: "LabeledShape",
  16473. isAbstract: true,
  16474. superClass: [
  16475. "Shape"
  16476. ],
  16477. properties: [
  16478. {
  16479. name: "ownedLabel",
  16480. type: "Label",
  16481. isReadOnly: true,
  16482. subsettedProperty: "DiagramElement-ownedElement",
  16483. isMany: true,
  16484. isVirtual: true
  16485. }
  16486. ]
  16487. },
  16488. {
  16489. name: "Label",
  16490. isAbstract: true,
  16491. superClass: [
  16492. "Node"
  16493. ],
  16494. properties: [
  16495. {
  16496. name: "bounds",
  16497. type: "dc:Bounds"
  16498. }
  16499. ]
  16500. },
  16501. {
  16502. name: "Style",
  16503. isAbstract: true,
  16504. properties: [
  16505. {
  16506. name: "id",
  16507. isAttr: true,
  16508. isId: true,
  16509. type: "String"
  16510. }
  16511. ]
  16512. },
  16513. {
  16514. name: "Extension",
  16515. properties: [
  16516. {
  16517. name: "values",
  16518. isMany: true,
  16519. type: "Element"
  16520. }
  16521. ]
  16522. }
  16523. ];
  16524. var associations$3 = [
  16525. ];
  16526. var xml$1 = {
  16527. tagAlias: "lowerCase"
  16528. };
  16529. var DiPackage = {
  16530. name: name$3,
  16531. uri: uri$3,
  16532. prefix: prefix$3,
  16533. types: types$3,
  16534. associations: associations$3,
  16535. xml: xml$1
  16536. };
  16537. var name$4 = "bpmn.io colors for BPMN";
  16538. var uri$4 = "http://bpmn.io/schema/bpmn/biocolor/1.0";
  16539. var prefix$4 = "bioc";
  16540. var types$4 = [
  16541. {
  16542. name: "ColoredShape",
  16543. "extends": [
  16544. "bpmndi:BPMNShape"
  16545. ],
  16546. properties: [
  16547. {
  16548. name: "stroke",
  16549. isAttr: true,
  16550. type: "String"
  16551. },
  16552. {
  16553. name: "fill",
  16554. isAttr: true,
  16555. type: "String"
  16556. }
  16557. ]
  16558. },
  16559. {
  16560. name: "ColoredEdge",
  16561. "extends": [
  16562. "bpmndi:BPMNEdge"
  16563. ],
  16564. properties: [
  16565. {
  16566. name: "stroke",
  16567. isAttr: true,
  16568. type: "String"
  16569. },
  16570. {
  16571. name: "fill",
  16572. isAttr: true,
  16573. type: "String"
  16574. }
  16575. ]
  16576. }
  16577. ];
  16578. var enumerations$2 = [
  16579. ];
  16580. var associations$4 = [
  16581. ];
  16582. var BiocPackage = {
  16583. name: name$4,
  16584. uri: uri$4,
  16585. prefix: prefix$4,
  16586. types: types$4,
  16587. enumerations: enumerations$2,
  16588. associations: associations$4
  16589. };
  16590. var name$5 = "BPMN in Color";
  16591. var uri$5 = "http://www.omg.org/spec/BPMN/non-normative/color/1.0";
  16592. var prefix$5 = "color";
  16593. var types$5 = [
  16594. {
  16595. name: "ColoredLabel",
  16596. "extends": [
  16597. "bpmndi:BPMNLabel"
  16598. ],
  16599. properties: [
  16600. {
  16601. name: "color",
  16602. isAttr: true,
  16603. type: "String"
  16604. }
  16605. ]
  16606. },
  16607. {
  16608. name: "ColoredShape",
  16609. "extends": [
  16610. "bpmndi:BPMNShape"
  16611. ],
  16612. properties: [
  16613. {
  16614. name: "background-color",
  16615. isAttr: true,
  16616. type: "String"
  16617. },
  16618. {
  16619. name: "border-color",
  16620. isAttr: true,
  16621. type: "String"
  16622. }
  16623. ]
  16624. },
  16625. {
  16626. name: "ColoredEdge",
  16627. "extends": [
  16628. "bpmndi:BPMNEdge"
  16629. ],
  16630. properties: [
  16631. {
  16632. name: "border-color",
  16633. isAttr: true,
  16634. type: "String"
  16635. }
  16636. ]
  16637. }
  16638. ];
  16639. var enumerations$3 = [
  16640. ];
  16641. var associations$5 = [
  16642. ];
  16643. var BpmnInColorPackage = {
  16644. name: name$5,
  16645. uri: uri$5,
  16646. prefix: prefix$5,
  16647. types: types$5,
  16648. enumerations: enumerations$3,
  16649. associations: associations$5
  16650. };
  16651. var packages = {
  16652. bpmn: BpmnPackage,
  16653. bpmndi: BpmnDiPackage,
  16654. dc: DcPackage,
  16655. di: DiPackage,
  16656. bioc: BiocPackage,
  16657. color: BpmnInColorPackage
  16658. };
  16659. function simple(additionalPackages, options) {
  16660. var pks = assign({}, packages, additionalPackages);
  16661. return new BpmnModdle(pks, options);
  16662. }
  16663. // TODO(nikku): remove with future bpmn-js version
  16664. /**
  16665. * Wraps APIs to check:
  16666. *
  16667. * 1) If a callback is passed -> Warn users about callback deprecation.
  16668. * 2) If Promise class is implemented in current environment.
  16669. *
  16670. * @private
  16671. */
  16672. function wrapForCompatibility(api) {
  16673. return function() {
  16674. if (!window.Promise) {
  16675. throw new Error('Promises is not supported in this environment. Please polyfill Promise.');
  16676. }
  16677. var argLen = arguments.length;
  16678. if (argLen >= 1 && isFunction(arguments[argLen - 1])) {
  16679. var callback = arguments[argLen - 1];
  16680. console.warn(new Error(
  16681. 'Passing callbacks to ' + api.name + ' is deprecated and will be removed in a future major release. ' +
  16682. 'Please switch to promises: https://bpmn.io/l/moving-to-promises.html'
  16683. ));
  16684. var argsWithoutCallback = Array.prototype.slice.call(arguments, 0, -1);
  16685. api.apply(this, argsWithoutCallback).then(function(result) {
  16686. var firstKey = Object.keys(result)[0];
  16687. // The APIs we are wrapping all resolve a single item depending on the API.
  16688. // For instance, importXML resolves { warnings } and saveXML returns { xml }.
  16689. // That's why we can call the callback with the first item of result.
  16690. return callback(null, result[firstKey]);
  16691. // Passing a second paramter instead of catch because we don't want to
  16692. // catch errors thrown by callback().
  16693. }, function(err) {
  16694. return callback(err, err.warnings);
  16695. });
  16696. } else {
  16697. return api.apply(this, arguments);
  16698. }
  16699. };
  16700. }
  16701. // TODO(nikku): remove with future bpmn-js version
  16702. 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';
  16703. function ensureCompatDiRef(businessObject) {
  16704. // bpmnElement can have multiple independent DIs
  16705. if (!has$1(businessObject, 'di')) {
  16706. Object.defineProperty(businessObject, 'di', {
  16707. get: function() {
  16708. throw new Error(DI_ERROR_MESSAGE);
  16709. }
  16710. });
  16711. }
  16712. }
  16713. /**
  16714. * Returns true if an element has the given meta-model type
  16715. *
  16716. * @param {ModdleElement} element
  16717. * @param {string} type
  16718. *
  16719. * @return {boolean}
  16720. */
  16721. function is(element, type) {
  16722. return element.$instanceOf(type);
  16723. }
  16724. /**
  16725. * Find a suitable display candidate for definitions where the DI does not
  16726. * correctly specify one.
  16727. */
  16728. function findDisplayCandidate(definitions) {
  16729. return find(definitions.rootElements, function(e) {
  16730. return is(e, 'bpmn:Process') || is(e, 'bpmn:Collaboration');
  16731. });
  16732. }
  16733. function BpmnTreeWalker(handler, translate) {
  16734. // list of containers already walked
  16735. var handledElements = {};
  16736. // list of elements to handle deferred to ensure
  16737. // prerequisites are drawn
  16738. var deferred = [];
  16739. var diMap = {};
  16740. // Helpers //////////////////////
  16741. function contextual(fn, ctx) {
  16742. return function(e) {
  16743. fn(e, ctx);
  16744. };
  16745. }
  16746. function handled(element) {
  16747. handledElements[element.id] = element;
  16748. }
  16749. function isHandled(element) {
  16750. return handledElements[element.id];
  16751. }
  16752. function visit(element, ctx) {
  16753. var gfx = element.gfx;
  16754. // avoid multiple rendering of elements
  16755. if (gfx) {
  16756. throw new Error(
  16757. translate('already rendered {element}', { element: elementToString(element) })
  16758. );
  16759. }
  16760. // call handler
  16761. return handler.element(element, diMap[element.id], ctx);
  16762. }
  16763. function visitRoot(element, diagram) {
  16764. return handler.root(element, diMap[element.id], diagram);
  16765. }
  16766. function visitIfDi(element, ctx) {
  16767. try {
  16768. var gfx = diMap[element.id] && visit(element, ctx);
  16769. handled(element);
  16770. return gfx;
  16771. } catch (e) {
  16772. logError(e.message, { element: element, error: e });
  16773. console.error(translate('failed to import {element}', { element: elementToString(element) }));
  16774. console.error(e);
  16775. }
  16776. }
  16777. function logError(message, context) {
  16778. handler.error(message, context);
  16779. }
  16780. // DI handling //////////////////////
  16781. function registerDi(di) {
  16782. var bpmnElement = di.bpmnElement;
  16783. if (bpmnElement) {
  16784. if (diMap[bpmnElement.id]) {
  16785. logError(
  16786. translate('multiple DI elements defined for {element}', {
  16787. element: elementToString(bpmnElement)
  16788. }),
  16789. { element: bpmnElement }
  16790. );
  16791. } else {
  16792. diMap[bpmnElement.id] = di;
  16793. ensureCompatDiRef(bpmnElement);
  16794. }
  16795. } else {
  16796. logError(
  16797. translate('no bpmnElement referenced in {element}', {
  16798. element: elementToString(di)
  16799. }),
  16800. { element: di }
  16801. );
  16802. }
  16803. }
  16804. function handleDiagram(diagram) {
  16805. handlePlane(diagram.plane);
  16806. }
  16807. function handlePlane(plane) {
  16808. registerDi(plane);
  16809. forEach$1(plane.planeElement, handlePlaneElement);
  16810. }
  16811. function handlePlaneElement(planeElement) {
  16812. registerDi(planeElement);
  16813. }
  16814. // Semantic handling //////////////////////
  16815. /**
  16816. * Handle definitions and return the rendered diagram (if any)
  16817. *
  16818. * @param {ModdleElement} definitions to walk and import
  16819. * @param {ModdleElement} [diagram] specific diagram to import and display
  16820. *
  16821. * @throws {Error} if no diagram to display could be found
  16822. */
  16823. function handleDefinitions(definitions, diagram) {
  16824. // make sure we walk the correct bpmnElement
  16825. var diagrams = definitions.diagrams;
  16826. if (diagram && diagrams.indexOf(diagram) === -1) {
  16827. throw new Error(translate('diagram not part of bpmn:Definitions'));
  16828. }
  16829. if (!diagram && diagrams && diagrams.length) {
  16830. diagram = diagrams[0];
  16831. }
  16832. // no diagram -> nothing to import
  16833. if (!diagram) {
  16834. throw new Error(translate('no diagram to display'));
  16835. }
  16836. // load DI from selected diagram only
  16837. diMap = {};
  16838. handleDiagram(diagram);
  16839. var plane = diagram.plane;
  16840. if (!plane) {
  16841. throw new Error(translate(
  16842. 'no plane for {element}',
  16843. { element: elementToString(diagram) }
  16844. ));
  16845. }
  16846. var rootElement = plane.bpmnElement;
  16847. // ensure we default to a suitable display candidate (process or collaboration),
  16848. // even if non is specified in DI
  16849. if (!rootElement) {
  16850. rootElement = findDisplayCandidate(definitions);
  16851. if (!rootElement) {
  16852. throw new Error(translate('no process or collaboration to display'));
  16853. } else {
  16854. logError(
  16855. translate('correcting missing bpmnElement on {plane} to {rootElement}', {
  16856. plane: elementToString(plane),
  16857. rootElement: elementToString(rootElement)
  16858. })
  16859. );
  16860. // correct DI on the fly
  16861. plane.bpmnElement = rootElement;
  16862. registerDi(plane);
  16863. }
  16864. }
  16865. var ctx = visitRoot(rootElement, plane);
  16866. if (is(rootElement, 'bpmn:Process') || is(rootElement, 'bpmn:SubProcess')) {
  16867. handleProcess(rootElement, ctx);
  16868. } else if (is(rootElement, 'bpmn:Collaboration')) {
  16869. handleCollaboration(rootElement, ctx);
  16870. // force drawing of everything not yet drawn that is part of the target DI
  16871. handleUnhandledProcesses(definitions.rootElements, ctx);
  16872. } else {
  16873. throw new Error(
  16874. translate('unsupported bpmnElement for {plane}: {rootElement}', {
  16875. plane: elementToString(plane),
  16876. rootElement: elementToString(rootElement)
  16877. })
  16878. );
  16879. }
  16880. // handle all deferred elements
  16881. handleDeferred();
  16882. }
  16883. function handleDeferred() {
  16884. var fn;
  16885. // drain deferred until empty
  16886. while (deferred.length) {
  16887. fn = deferred.shift();
  16888. fn();
  16889. }
  16890. }
  16891. function handleProcess(process, context) {
  16892. handleFlowElementsContainer(process, context);
  16893. handleIoSpecification(process.ioSpecification, context);
  16894. handleArtifacts(process.artifacts, context);
  16895. // log process handled
  16896. handled(process);
  16897. }
  16898. function handleUnhandledProcesses(rootElements, ctx) {
  16899. // walk through all processes that have not yet been drawn and draw them
  16900. // if they contain lanes with DI information.
  16901. // we do this to pass the free-floating lane test cases in the MIWG test suite
  16902. var processes = filter(rootElements, function(e) {
  16903. return !isHandled(e) && is(e, 'bpmn:Process') && e.laneSets;
  16904. });
  16905. processes.forEach(contextual(handleProcess, ctx));
  16906. }
  16907. function handleMessageFlow(messageFlow, context) {
  16908. visitIfDi(messageFlow, context);
  16909. }
  16910. function handleMessageFlows(messageFlows, context) {
  16911. forEach$1(messageFlows, contextual(handleMessageFlow, context));
  16912. }
  16913. function handleDataAssociation(association, context) {
  16914. visitIfDi(association, context);
  16915. }
  16916. function handleDataInput(dataInput, context) {
  16917. visitIfDi(dataInput, context);
  16918. }
  16919. function handleDataOutput(dataOutput, context) {
  16920. visitIfDi(dataOutput, context);
  16921. }
  16922. function handleArtifact(artifact, context) {
  16923. // bpmn:TextAnnotation
  16924. // bpmn:Group
  16925. // bpmn:Association
  16926. visitIfDi(artifact, context);
  16927. }
  16928. function handleArtifacts(artifacts, context) {
  16929. forEach$1(artifacts, function(e) {
  16930. if (is(e, 'bpmn:Association')) {
  16931. deferred.push(function() {
  16932. handleArtifact(e, context);
  16933. });
  16934. } else {
  16935. handleArtifact(e, context);
  16936. }
  16937. });
  16938. }
  16939. function handleIoSpecification(ioSpecification, context) {
  16940. if (!ioSpecification) {
  16941. return;
  16942. }
  16943. forEach$1(ioSpecification.dataInputs, contextual(handleDataInput, context));
  16944. forEach$1(ioSpecification.dataOutputs, contextual(handleDataOutput, context));
  16945. }
  16946. function handleSubProcess(subProcess, context) {
  16947. handleFlowElementsContainer(subProcess, context);
  16948. handleArtifacts(subProcess.artifacts, context);
  16949. }
  16950. function handleFlowNode(flowNode, context) {
  16951. var childCtx = visitIfDi(flowNode, context);
  16952. if (is(flowNode, 'bpmn:SubProcess')) {
  16953. handleSubProcess(flowNode, childCtx || context);
  16954. }
  16955. if (is(flowNode, 'bpmn:Activity')) {
  16956. handleIoSpecification(flowNode.ioSpecification, context);
  16957. }
  16958. // defer handling of associations
  16959. // affected types:
  16960. //
  16961. // * bpmn:Activity
  16962. // * bpmn:ThrowEvent
  16963. // * bpmn:CatchEvent
  16964. //
  16965. deferred.push(function() {
  16966. forEach$1(flowNode.dataInputAssociations, contextual(handleDataAssociation, context));
  16967. forEach$1(flowNode.dataOutputAssociations, contextual(handleDataAssociation, context));
  16968. });
  16969. }
  16970. function handleSequenceFlow(sequenceFlow, context) {
  16971. visitIfDi(sequenceFlow, context);
  16972. }
  16973. function handleDataElement(dataObject, context) {
  16974. visitIfDi(dataObject, context);
  16975. }
  16976. function handleLane(lane, context) {
  16977. deferred.push(function() {
  16978. var newContext = visitIfDi(lane, context);
  16979. if (lane.childLaneSet) {
  16980. handleLaneSet(lane.childLaneSet, newContext || context);
  16981. }
  16982. wireFlowNodeRefs(lane);
  16983. });
  16984. }
  16985. function handleLaneSet(laneSet, context) {
  16986. forEach$1(laneSet.lanes, contextual(handleLane, context));
  16987. }
  16988. function handleLaneSets(laneSets, context) {
  16989. forEach$1(laneSets, contextual(handleLaneSet, context));
  16990. }
  16991. function handleFlowElementsContainer(container, context) {
  16992. handleFlowElements(container.flowElements, context);
  16993. if (container.laneSets) {
  16994. handleLaneSets(container.laneSets, context);
  16995. }
  16996. }
  16997. function handleFlowElements(flowElements, context) {
  16998. forEach$1(flowElements, function(e) {
  16999. if (is(e, 'bpmn:SequenceFlow')) {
  17000. deferred.push(function() {
  17001. handleSequenceFlow(e, context);
  17002. });
  17003. } else if (is(e, 'bpmn:BoundaryEvent')) {
  17004. deferred.unshift(function() {
  17005. handleFlowNode(e, context);
  17006. });
  17007. } else if (is(e, 'bpmn:FlowNode')) {
  17008. handleFlowNode(e, context);
  17009. } else if (is(e, 'bpmn:DataObject')) ; else if (is(e, 'bpmn:DataStoreReference')) {
  17010. handleDataElement(e, context);
  17011. } else if (is(e, 'bpmn:DataObjectReference')) {
  17012. handleDataElement(e, context);
  17013. } else {
  17014. logError(
  17015. translate('unrecognized flowElement {element} in context {context}', {
  17016. element: elementToString(e),
  17017. context: (context ? elementToString(context.businessObject) : 'null')
  17018. }),
  17019. { element: e, context: context }
  17020. );
  17021. }
  17022. });
  17023. }
  17024. function handleParticipant(participant, context) {
  17025. var newCtx = visitIfDi(participant, context);
  17026. var process = participant.processRef;
  17027. if (process) {
  17028. handleProcess(process, newCtx || context);
  17029. }
  17030. }
  17031. function handleCollaboration(collaboration, context) {
  17032. forEach$1(collaboration.participants, contextual(handleParticipant, context));
  17033. handleArtifacts(collaboration.artifacts, context);
  17034. // handle message flows latest in the process
  17035. deferred.push(function() {
  17036. handleMessageFlows(collaboration.messageFlows, context);
  17037. });
  17038. }
  17039. function wireFlowNodeRefs(lane) {
  17040. // wire the virtual flowNodeRefs <-> relationship
  17041. forEach$1(lane.flowNodeRef, function(flowNode) {
  17042. var lanes = flowNode.get('lanes');
  17043. if (lanes) {
  17044. lanes.push(lane);
  17045. }
  17046. });
  17047. }
  17048. // API //////////////////////
  17049. return {
  17050. handleDeferred: handleDeferred,
  17051. handleDefinitions: handleDefinitions,
  17052. handleSubProcess: handleSubProcess,
  17053. registerDi: registerDi
  17054. };
  17055. }
  17056. /**
  17057. * The importBpmnDiagram result.
  17058. *
  17059. * @typedef {Object} ImportBPMNDiagramResult
  17060. *
  17061. * @property {Array<string>} warnings
  17062. */
  17063. /**
  17064. * The importBpmnDiagram error.
  17065. *
  17066. * @typedef {Error} ImportBPMNDiagramError
  17067. *
  17068. * @property {Array<string>} warnings
  17069. */
  17070. /**
  17071. * Import the definitions into a diagram.
  17072. *
  17073. * Errors and warnings are reported through the specified callback.
  17074. *
  17075. * @param {djs.Diagram} diagram
  17076. * @param {ModdleElement<Definitions>} definitions
  17077. * @param {ModdleElement<BPMNDiagram>} [bpmnDiagram] the diagram to be rendered
  17078. * (if not provided, the first one will be rendered)
  17079. *
  17080. * Returns {Promise<ImportBPMNDiagramResult, ImportBPMNDiagramError>}
  17081. */
  17082. function importBpmnDiagram(diagram, definitions, bpmnDiagram) {
  17083. var importer,
  17084. eventBus,
  17085. translate,
  17086. canvas;
  17087. var error,
  17088. warnings = [];
  17089. /**
  17090. * Walk the diagram semantically, importing (=drawing)
  17091. * all elements you encounter.
  17092. *
  17093. * @param {ModdleElement<Definitions>} definitions
  17094. * @param {ModdleElement<BPMNDiagram>} bpmnDiagram
  17095. */
  17096. function render(definitions, bpmnDiagram) {
  17097. var visitor = {
  17098. root: function(element, di) {
  17099. return importer.add(element, di);
  17100. },
  17101. element: function(element, di, parentShape) {
  17102. return importer.add(element, di, parentShape);
  17103. },
  17104. error: function(message, context) {
  17105. warnings.push({ message: message, context: context });
  17106. }
  17107. };
  17108. var walker = new BpmnTreeWalker(visitor, translate);
  17109. bpmnDiagram = bpmnDiagram || (definitions.diagrams && definitions.diagrams[0]);
  17110. var diagramsToImport = getDiagramsToImport(definitions, bpmnDiagram);
  17111. if (!diagramsToImport) {
  17112. throw new Error(translate('no diagram to display'));
  17113. }
  17114. // traverse BPMN 2.0 document model,
  17115. // starting at definitions
  17116. forEach$1(diagramsToImport, function(diagram) {
  17117. walker.handleDefinitions(definitions, diagram);
  17118. });
  17119. var rootId = bpmnDiagram.plane.bpmnElement.id;
  17120. // we do need to account for different ways we create root elements
  17121. // each nested imported <root> do have the `_plane` suffix, while
  17122. // the root <root> is found under the business object ID
  17123. canvas.setRootElement(
  17124. canvas.findRoot(rootId + '_plane') || canvas.findRoot(rootId)
  17125. );
  17126. }
  17127. return new Promise(function(resolve, reject) {
  17128. try {
  17129. importer = diagram.get('bpmnImporter');
  17130. eventBus = diagram.get('eventBus');
  17131. translate = diagram.get('translate');
  17132. canvas = diagram.get('canvas');
  17133. eventBus.fire('import.render.start', { definitions: definitions });
  17134. render(definitions, bpmnDiagram);
  17135. eventBus.fire('import.render.complete', {
  17136. error: error,
  17137. warnings: warnings
  17138. });
  17139. return resolve({ warnings: warnings });
  17140. } catch (e) {
  17141. e.warnings = warnings;
  17142. return reject(e);
  17143. }
  17144. });
  17145. }
  17146. /**
  17147. * Returns all diagrams in the same hierarchy as the requested diagram.
  17148. * Includes all parent and sub process diagrams.
  17149. *
  17150. * @param {Array} definitions
  17151. * @param {Object} bpmnDiagram
  17152. *
  17153. * @returns {Array<Object>}
  17154. */
  17155. function getDiagramsToImport(definitions, bpmnDiagram) {
  17156. if (!bpmnDiagram) {
  17157. return;
  17158. }
  17159. var bpmnElement = bpmnDiagram.plane.bpmnElement,
  17160. rootElement = bpmnElement;
  17161. if (!is$1(bpmnElement, 'bpmn:Process') && !is$1(bpmnElement, 'bpmn:Collaboration')) {
  17162. rootElement = findRootProcess(bpmnElement);
  17163. }
  17164. // in case the process is part of a collaboration, the plane references the
  17165. // collaboration, not the process
  17166. var collaboration;
  17167. if (is$1(rootElement, 'bpmn:Collaboration')) {
  17168. collaboration = rootElement;
  17169. } else {
  17170. collaboration = find(definitions.rootElements, function(element) {
  17171. if (!is$1(element, 'bpmn:Collaboration')) {
  17172. return;
  17173. }
  17174. return find(element.participants, function(participant) {
  17175. return participant.processRef === rootElement;
  17176. });
  17177. });
  17178. }
  17179. var rootElements = [ rootElement ];
  17180. // all collaboration processes can contain sub-diagrams
  17181. if (collaboration) {
  17182. rootElements = map(collaboration.participants, function(participant) {
  17183. return participant.processRef;
  17184. });
  17185. rootElements.push(collaboration);
  17186. }
  17187. var allChildren = selfAndAllFlowElements(rootElements);
  17188. // if we have multiple diagrams referencing the same element, we
  17189. // use the first in the file
  17190. var diagramsToImport = [ bpmnDiagram ];
  17191. var handledElements = [ bpmnElement ];
  17192. forEach$1(definitions.diagrams, function(diagram) {
  17193. var businessObject = diagram.plane.bpmnElement;
  17194. if (
  17195. allChildren.indexOf(businessObject) !== -1 &&
  17196. handledElements.indexOf(businessObject) === -1
  17197. ) {
  17198. diagramsToImport.push(diagram);
  17199. handledElements.push(businessObject);
  17200. }
  17201. });
  17202. return diagramsToImport;
  17203. }
  17204. function selfAndAllFlowElements(elements) {
  17205. var result = [];
  17206. forEach$1(elements, function(element) {
  17207. if (!element) {
  17208. return;
  17209. }
  17210. result.push(element);
  17211. result = result.concat(selfAndAllFlowElements(element.flowElements));
  17212. });
  17213. return result;
  17214. }
  17215. function findRootProcess(element) {
  17216. var parent = element;
  17217. while (parent) {
  17218. if (is$1(parent, 'bpmn:Process')) {
  17219. return parent;
  17220. }
  17221. parent = parent.$parent;
  17222. }
  17223. }
  17224. /**
  17225. * This file must not be changed or exchanged.
  17226. *
  17227. * @see http://bpmn.io/license for more information.
  17228. */
  17229. // inlined ../../resources/logo.svg
  17230. 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>';
  17231. var BPMNIO_IMG = BPMNIO_LOGO_SVG;
  17232. var LOGO_STYLES = {
  17233. verticalAlign: 'middle'
  17234. };
  17235. var LINK_STYLES = {
  17236. 'color': '#404040'
  17237. };
  17238. var LIGHTBOX_STYLES = {
  17239. 'zIndex': '1001',
  17240. 'position': 'fixed',
  17241. 'top': '0',
  17242. 'left': '0',
  17243. 'right': '0',
  17244. 'bottom': '0'
  17245. };
  17246. var BACKDROP_STYLES = {
  17247. 'width': '100%',
  17248. 'height': '100%',
  17249. 'background': 'rgba(40,40,40,0.2)'
  17250. };
  17251. var NOTICE_STYLES = {
  17252. 'position': 'absolute',
  17253. 'left': '50%',
  17254. 'top': '40%',
  17255. 'transform': 'translate(-50%)',
  17256. 'width': '260px',
  17257. 'padding': '10px',
  17258. 'background': 'white',
  17259. 'boxShadow': '0 1px 4px rgba(0,0,0,0.3)',
  17260. 'fontFamily': 'Helvetica, Arial, sans-serif',
  17261. 'fontSize': '14px',
  17262. 'display': 'flex',
  17263. 'lineHeight': '1.3'
  17264. };
  17265. var LIGHTBOX_MARKUP =
  17266. '<div class="bjs-powered-by-lightbox">' +
  17267. '<div class="backdrop"></div>' +
  17268. '<div class="notice">' +
  17269. '<a href="https://bpmn.io" target="_blank" rel="noopener" class="link">' +
  17270. BPMNIO_IMG +
  17271. '</a>' +
  17272. '<span>' +
  17273. 'Web-based tooling for BPMN, DMN and CMMN diagrams ' +
  17274. 'powered by <a href="https://bpmn.io" target="_blank" rel="noopener">bpmn.io</a>.' +
  17275. '</span>' +
  17276. '</div>' +
  17277. '</div>';
  17278. var lightbox;
  17279. function createLightbox() {
  17280. lightbox = domify(LIGHTBOX_MARKUP);
  17281. assign$1(lightbox, LIGHTBOX_STYLES);
  17282. assign$1(query('svg', lightbox), LOGO_STYLES);
  17283. assign$1(query('.backdrop', lightbox), BACKDROP_STYLES);
  17284. assign$1(query('.notice', lightbox), NOTICE_STYLES);
  17285. assign$1(query('.link', lightbox), LINK_STYLES, {
  17286. 'margin': '15px 20px 15px 10px',
  17287. 'alignSelf': 'center'
  17288. });
  17289. }
  17290. function open() {
  17291. if (!lightbox) {
  17292. createLightbox();
  17293. delegate.bind(lightbox, '.backdrop', 'click', function(event) {
  17294. document.body.removeChild(lightbox);
  17295. });
  17296. }
  17297. document.body.appendChild(lightbox);
  17298. }
  17299. /**
  17300. * The code in the <project-logo></project-logo> area
  17301. * must not be changed.
  17302. *
  17303. * @see http://bpmn.io/license for more information.
  17304. */
  17305. /**
  17306. * A base viewer for BPMN 2.0 diagrams.
  17307. *
  17308. * Have a look at {@link Viewer}, {@link NavigatedViewer} or {@link Modeler} for
  17309. * bundles that include actual features.
  17310. *
  17311. * @param {Object} [options] configuration options to pass to the viewer
  17312. * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
  17313. * @param {string|number} [options.width] the width of the viewer
  17314. * @param {string|number} [options.height] the height of the viewer
  17315. * @param {Object} [options.moddleExtensions] extension packages to provide
  17316. * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
  17317. * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
  17318. */
  17319. function BaseViewer(options) {
  17320. options = assign({}, DEFAULT_OPTIONS, options);
  17321. this._moddle = this._createModdle(options);
  17322. this._container = this._createContainer(options);
  17323. /* <project-logo> */
  17324. addProjectLogo(this._container);
  17325. /* </project-logo> */
  17326. this._init(this._container, this._moddle, options);
  17327. }
  17328. e(BaseViewer, Diagram);
  17329. /**
  17330. * The importXML result.
  17331. *
  17332. * @typedef {Object} ImportXMLResult
  17333. *
  17334. * @property {Array<string>} warnings
  17335. */
  17336. /**
  17337. * The importXML error.
  17338. *
  17339. * @typedef {Error} ImportXMLError
  17340. *
  17341. * @property {Array<string>} warnings
  17342. */
  17343. /**
  17344. * Parse and render a BPMN 2.0 diagram.
  17345. *
  17346. * Once finished the viewer reports back the result to the
  17347. * provided callback function with (err, warnings).
  17348. *
  17349. * ## Life-Cycle Events
  17350. *
  17351. * During import the viewer will fire life-cycle events:
  17352. *
  17353. * * import.parse.start (about to read model from xml)
  17354. * * import.parse.complete (model read; may have worked or not)
  17355. * * import.render.start (graphical import start)
  17356. * * import.render.complete (graphical import finished)
  17357. * * import.done (everything done)
  17358. *
  17359. * You can use these events to hook into the life-cycle.
  17360. *
  17361. * @param {string} xml the BPMN 2.0 xml
  17362. * @param {ModdleElement<BPMNDiagram>|string} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
  17363. *
  17364. * Returns {Promise<ImportXMLResult, ImportXMLError>}
  17365. */
  17366. BaseViewer.prototype.importXML = wrapForCompatibility(function importXML(xml, bpmnDiagram) {
  17367. var self = this;
  17368. function ParseCompleteEvent(data) {
  17369. var event = self.get('eventBus').createEvent(data);
  17370. // TODO(nikku): remove with future bpmn-js version
  17371. Object.defineProperty(event, 'context', {
  17372. enumerable: true,
  17373. get: function() {
  17374. console.warn(new Error(
  17375. 'import.parse.complete <context> is deprecated ' +
  17376. 'and will be removed in future library versions'
  17377. ));
  17378. return {
  17379. warnings: data.warnings,
  17380. references: data.references,
  17381. elementsById: data.elementsById
  17382. };
  17383. }
  17384. });
  17385. return event;
  17386. }
  17387. return new Promise(function(resolve, reject) {
  17388. // hook in pre-parse listeners +
  17389. // allow xml manipulation
  17390. xml = self._emit('import.parse.start', { xml: xml }) || xml;
  17391. self._moddle.fromXML(xml, 'bpmn:Definitions').then(function(result) {
  17392. var definitions = result.rootElement;
  17393. var references = result.references;
  17394. var parseWarnings = result.warnings;
  17395. var elementsById = result.elementsById;
  17396. // hook in post parse listeners +
  17397. // allow definitions manipulation
  17398. definitions = self._emit('import.parse.complete', ParseCompleteEvent({
  17399. error: null,
  17400. definitions: definitions,
  17401. elementsById: elementsById,
  17402. references: references,
  17403. warnings: parseWarnings
  17404. })) || definitions;
  17405. self.importDefinitions(definitions, bpmnDiagram).then(function(result) {
  17406. var allWarnings = [].concat(parseWarnings, result.warnings || []);
  17407. self._emit('import.done', { error: null, warnings: allWarnings });
  17408. return resolve({ warnings: allWarnings });
  17409. }).catch(function(err) {
  17410. var allWarnings = [].concat(parseWarnings, err.warnings || []);
  17411. self._emit('import.done', { error: err, warnings: allWarnings });
  17412. return reject(addWarningsToError(err, allWarnings));
  17413. });
  17414. }).catch(function(err) {
  17415. self._emit('import.parse.complete', {
  17416. error: err
  17417. });
  17418. err = checkValidationError(err);
  17419. self._emit('import.done', { error: err, warnings: err.warnings });
  17420. return reject(err);
  17421. });
  17422. });
  17423. });
  17424. /**
  17425. * The importDefinitions result.
  17426. *
  17427. * @typedef {Object} ImportDefinitionsResult
  17428. *
  17429. * @property {Array<string>} warnings
  17430. */
  17431. /**
  17432. * The importDefinitions error.
  17433. *
  17434. * @typedef {Error} ImportDefinitionsError
  17435. *
  17436. * @property {Array<string>} warnings
  17437. */
  17438. /**
  17439. * Import parsed definitions and render a BPMN 2.0 diagram.
  17440. *
  17441. * Once finished the viewer reports back the result to the
  17442. * provided callback function with (err, warnings).
  17443. *
  17444. * ## Life-Cycle Events
  17445. *
  17446. * During import the viewer will fire life-cycle events:
  17447. *
  17448. * * import.render.start (graphical import start)
  17449. * * import.render.complete (graphical import finished)
  17450. *
  17451. * You can use these events to hook into the life-cycle.
  17452. *
  17453. * @param {ModdleElement<Definitions>} definitions parsed BPMN 2.0 definitions
  17454. * @param {ModdleElement<BPMNDiagram>|string} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
  17455. *
  17456. * Returns {Promise<ImportDefinitionsResult, ImportDefinitionsError>}
  17457. */
  17458. BaseViewer.prototype.importDefinitions = wrapForCompatibility(function importDefinitions(definitions, bpmnDiagram) {
  17459. var self = this;
  17460. return new Promise(function(resolve, reject) {
  17461. self._setDefinitions(definitions);
  17462. self.open(bpmnDiagram).then(function(result) {
  17463. var warnings = result.warnings;
  17464. return resolve({ warnings: warnings });
  17465. }).catch(function(err) {
  17466. return reject(err);
  17467. });
  17468. });
  17469. });
  17470. /**
  17471. * The open result.
  17472. *
  17473. * @typedef {Object} OpenResult
  17474. *
  17475. * @property {Array<string>} warnings
  17476. */
  17477. /**
  17478. * The open error.
  17479. *
  17480. * @typedef {Error} OpenError
  17481. *
  17482. * @property {Array<string>} warnings
  17483. */
  17484. /**
  17485. * Open diagram of previously imported XML.
  17486. *
  17487. * Once finished the viewer reports back the result to the
  17488. * provided callback function with (err, warnings).
  17489. *
  17490. * ## Life-Cycle Events
  17491. *
  17492. * During switch the viewer will fire life-cycle events:
  17493. *
  17494. * * import.render.start (graphical import start)
  17495. * * import.render.complete (graphical import finished)
  17496. *
  17497. * You can use these events to hook into the life-cycle.
  17498. *
  17499. * @param {string|ModdleElement<BPMNDiagram>} [bpmnDiagramOrId] id or the diagram to open
  17500. *
  17501. * Returns {Promise<OpenResult, OpenError>}
  17502. */
  17503. BaseViewer.prototype.open = wrapForCompatibility(function open(bpmnDiagramOrId) {
  17504. var definitions = this._definitions;
  17505. var bpmnDiagram = bpmnDiagramOrId;
  17506. var self = this;
  17507. return new Promise(function(resolve, reject) {
  17508. if (!definitions) {
  17509. var err1 = new Error('no XML imported');
  17510. return reject(addWarningsToError(err1, []));
  17511. }
  17512. if (typeof bpmnDiagramOrId === 'string') {
  17513. bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId);
  17514. if (!bpmnDiagram) {
  17515. var err2 = new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found');
  17516. return reject(addWarningsToError(err2, []));
  17517. }
  17518. }
  17519. // clear existing rendered diagram
  17520. // catch synchronous exceptions during #clear()
  17521. try {
  17522. self.clear();
  17523. } catch (error) {
  17524. return reject(addWarningsToError(error, []));
  17525. }
  17526. // perform graphical import
  17527. importBpmnDiagram(self, definitions, bpmnDiagram).then(function(result) {
  17528. var warnings = result.warnings;
  17529. return resolve({ warnings: warnings });
  17530. }).catch(function(err) {
  17531. return reject(err);
  17532. });
  17533. });
  17534. });
  17535. /**
  17536. * The saveXML result.
  17537. *
  17538. * @typedef {Object} SaveXMLResult
  17539. *
  17540. * @property {string} xml
  17541. */
  17542. /**
  17543. * Export the currently displayed BPMN 2.0 diagram as
  17544. * a BPMN 2.0 XML document.
  17545. *
  17546. * ## Life-Cycle Events
  17547. *
  17548. * During XML saving the viewer will fire life-cycle events:
  17549. *
  17550. * * saveXML.start (before serialization)
  17551. * * saveXML.serialized (after xml generation)
  17552. * * saveXML.done (everything done)
  17553. *
  17554. * You can use these events to hook into the life-cycle.
  17555. *
  17556. * @param {Object} [options] export options
  17557. * @param {boolean} [options.format=false] output formatted XML
  17558. * @param {boolean} [options.preamble=true] output preamble
  17559. *
  17560. * Returns {Promise<SaveXMLResult, Error>}
  17561. */
  17562. BaseViewer.prototype.saveXML = wrapForCompatibility(function saveXML(options) {
  17563. options = options || {};
  17564. var self = this;
  17565. var definitions = this._definitions;
  17566. return new Promise(function(resolve) {
  17567. if (!definitions) {
  17568. return resolve({
  17569. error: new Error('no definitions loaded')
  17570. });
  17571. }
  17572. // allow to fiddle around with definitions
  17573. definitions = self._emit('saveXML.start', {
  17574. definitions: definitions
  17575. }) || definitions;
  17576. self._moddle.toXML(definitions, options).then(function(result) {
  17577. var xml = result.xml;
  17578. xml = self._emit('saveXML.serialized', {
  17579. xml: xml
  17580. }) || xml;
  17581. return resolve({
  17582. xml: xml
  17583. });
  17584. });
  17585. }).catch(function(error) {
  17586. return { error: error };
  17587. }).then(function(result) {
  17588. self._emit('saveXML.done', result);
  17589. var error = result.error;
  17590. if (error) {
  17591. return Promise.reject(error);
  17592. }
  17593. return result;
  17594. });
  17595. });
  17596. /**
  17597. * The saveSVG result.
  17598. *
  17599. * @typedef {Object} SaveSVGResult
  17600. *
  17601. * @property {string} svg
  17602. */
  17603. /**
  17604. * Export the currently displayed BPMN 2.0 diagram as
  17605. * an SVG image.
  17606. *
  17607. * ## Life-Cycle Events
  17608. *
  17609. * During SVG saving the viewer will fire life-cycle events:
  17610. *
  17611. * * saveSVG.start (before serialization)
  17612. * * saveSVG.done (everything done)
  17613. *
  17614. * You can use these events to hook into the life-cycle.
  17615. *
  17616. * @param {Object} [options]
  17617. *
  17618. * Returns {Promise<SaveSVGResult, Error>}
  17619. */
  17620. BaseViewer.prototype.saveSVG = wrapForCompatibility(function saveSVG(options) {
  17621. var self = this;
  17622. return new Promise(function(resolve, reject) {
  17623. self._emit('saveSVG.start');
  17624. var svg, err;
  17625. try {
  17626. var canvas = self.get('canvas');
  17627. var contentNode = canvas.getActiveLayer(),
  17628. defsNode = query('defs', canvas._svg);
  17629. var contents = innerSVG(contentNode),
  17630. defs = defsNode ? '<defs>' + innerSVG(defsNode) + '</defs>' : '';
  17631. var bbox = contentNode.getBBox();
  17632. svg =
  17633. '<?xml version="1.0" encoding="utf-8"?>\n' +
  17634. '<!-- created with bpmn-js / http://bpmn.io -->\n' +
  17635. '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
  17636. '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
  17637. 'width="' + bbox.width + '" height="' + bbox.height + '" ' +
  17638. 'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
  17639. defs + contents +
  17640. '</svg>';
  17641. } catch (e) {
  17642. err = e;
  17643. }
  17644. self._emit('saveSVG.done', {
  17645. error: err,
  17646. svg: svg
  17647. });
  17648. if (!err) {
  17649. return resolve({ svg: svg });
  17650. }
  17651. return reject(err);
  17652. });
  17653. });
  17654. /**
  17655. * Get a named diagram service.
  17656. *
  17657. * @example
  17658. *
  17659. * var elementRegistry = viewer.get('elementRegistry');
  17660. * var startEventShape = elementRegistry.get('StartEvent_1');
  17661. *
  17662. * @param {string} name
  17663. *
  17664. * @return {Object} diagram service instance
  17665. *
  17666. * @method BaseViewer#get
  17667. */
  17668. /**
  17669. * Invoke a function in the context of this viewer.
  17670. *
  17671. * @example
  17672. *
  17673. * viewer.invoke(function(elementRegistry) {
  17674. * var startEventShape = elementRegistry.get('StartEvent_1');
  17675. * });
  17676. *
  17677. * @param {Function} fn to be invoked
  17678. *
  17679. * @return {Object} the functions return value
  17680. *
  17681. * @method BaseViewer#invoke
  17682. */
  17683. BaseViewer.prototype._setDefinitions = function(definitions) {
  17684. this._definitions = definitions;
  17685. };
  17686. BaseViewer.prototype.getModules = function() {
  17687. return this._modules;
  17688. };
  17689. /**
  17690. * Remove all drawn elements from the viewer.
  17691. *
  17692. * After calling this method the viewer can still
  17693. * be reused for opening another diagram.
  17694. *
  17695. * @method BaseViewer#clear
  17696. */
  17697. BaseViewer.prototype.clear = function() {
  17698. if (!this.getDefinitions()) {
  17699. // no diagram to clear
  17700. return;
  17701. }
  17702. // remove drawn elements
  17703. Diagram.prototype.clear.call(this);
  17704. };
  17705. /**
  17706. * Destroy the viewer instance and remove all its
  17707. * remainders from the document tree.
  17708. */
  17709. BaseViewer.prototype.destroy = function() {
  17710. // diagram destroy
  17711. Diagram.prototype.destroy.call(this);
  17712. // dom detach
  17713. remove$1(this._container);
  17714. };
  17715. /**
  17716. * Register an event listener
  17717. *
  17718. * Remove a previously added listener via {@link #off(event, callback)}.
  17719. *
  17720. * @param {string} event
  17721. * @param {number} [priority]
  17722. * @param {Function} callback
  17723. * @param {Object} [that]
  17724. */
  17725. BaseViewer.prototype.on = function(event, priority, callback, target) {
  17726. return this.get('eventBus').on(event, priority, callback, target);
  17727. };
  17728. /**
  17729. * De-register an event listener
  17730. *
  17731. * @param {string} event
  17732. * @param {Function} callback
  17733. */
  17734. BaseViewer.prototype.off = function(event, callback) {
  17735. this.get('eventBus').off(event, callback);
  17736. };
  17737. BaseViewer.prototype.attachTo = function(parentNode) {
  17738. if (!parentNode) {
  17739. throw new Error('parentNode required');
  17740. }
  17741. // ensure we detach from the
  17742. // previous, old parent
  17743. this.detach();
  17744. // unwrap jQuery if provided
  17745. if (parentNode.get && parentNode.constructor.prototype.jquery) {
  17746. parentNode = parentNode.get(0);
  17747. }
  17748. if (typeof parentNode === 'string') {
  17749. parentNode = query(parentNode);
  17750. }
  17751. parentNode.appendChild(this._container);
  17752. this._emit('attach', {});
  17753. this.get('canvas').resized();
  17754. };
  17755. BaseViewer.prototype.getDefinitions = function() {
  17756. return this._definitions;
  17757. };
  17758. BaseViewer.prototype.detach = function() {
  17759. var container = this._container,
  17760. parentNode = container.parentNode;
  17761. if (!parentNode) {
  17762. return;
  17763. }
  17764. this._emit('detach', {});
  17765. parentNode.removeChild(container);
  17766. };
  17767. BaseViewer.prototype._init = function(container, moddle, options) {
  17768. var baseModules = options.modules || this.getModules(),
  17769. additionalModules = options.additionalModules || [],
  17770. staticModules = [
  17771. {
  17772. bpmnjs: [ 'value', this ],
  17773. moddle: [ 'value', moddle ]
  17774. }
  17775. ];
  17776. var diagramModules = [].concat(staticModules, baseModules, additionalModules);
  17777. var diagramOptions = assign(omit(options, [ 'additionalModules' ]), {
  17778. canvas: assign({}, options.canvas, { container: container }),
  17779. modules: diagramModules
  17780. });
  17781. // invoke diagram constructor
  17782. Diagram.call(this, diagramOptions);
  17783. if (options && options.container) {
  17784. this.attachTo(options.container);
  17785. }
  17786. };
  17787. /**
  17788. * Emit an event on the underlying {@link EventBus}
  17789. *
  17790. * @param {string} type
  17791. * @param {Object} event
  17792. *
  17793. * @return {Object} event processing result (if any)
  17794. */
  17795. BaseViewer.prototype._emit = function(type, event) {
  17796. return this.get('eventBus').fire(type, event);
  17797. };
  17798. BaseViewer.prototype._createContainer = function(options) {
  17799. var container = domify('<div class="bjs-container"></div>');
  17800. assign$1(container, {
  17801. width: ensureUnit(options.width),
  17802. height: ensureUnit(options.height),
  17803. position: options.position
  17804. });
  17805. return container;
  17806. };
  17807. BaseViewer.prototype._createModdle = function(options) {
  17808. var moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
  17809. return new simple(moddleOptions);
  17810. };
  17811. BaseViewer.prototype._modules = [];
  17812. // helpers ///////////////
  17813. function addWarningsToError(err, warningsAry) {
  17814. err.warnings = warningsAry;
  17815. return err;
  17816. }
  17817. function checkValidationError(err) {
  17818. // check if we can help the user by indicating wrong BPMN 2.0 xml
  17819. // (in case he or the exporting tool did not get that right)
  17820. var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
  17821. var match = pattern.exec(err.message);
  17822. if (match) {
  17823. err.message =
  17824. 'unparsable content <' + match[1] + '> detected; ' +
  17825. 'this may indicate an invalid BPMN 2.0 diagram file' + match[2];
  17826. }
  17827. return err;
  17828. }
  17829. var DEFAULT_OPTIONS = {
  17830. width: '100%',
  17831. height: '100%',
  17832. position: 'relative'
  17833. };
  17834. /**
  17835. * Ensure the passed argument is a proper unit (defaulting to px)
  17836. */
  17837. function ensureUnit(val) {
  17838. return val + (isNumber(val) ? 'px' : '');
  17839. }
  17840. /**
  17841. * Find BPMNDiagram in definitions by ID
  17842. *
  17843. * @param {ModdleElement<Definitions>} definitions
  17844. * @param {string} diagramId
  17845. *
  17846. * @return {ModdleElement<BPMNDiagram>|null}
  17847. */
  17848. function findBPMNDiagram(definitions, diagramId) {
  17849. if (!diagramId) {
  17850. return null;
  17851. }
  17852. return find(definitions.diagrams, function(element) {
  17853. return element.id === diagramId;
  17854. }) || null;
  17855. }
  17856. /**
  17857. * Adds the project logo to the diagram container as
  17858. * required by the bpmn.io license.
  17859. *
  17860. * @see http://bpmn.io/license
  17861. *
  17862. * @param {Element} container
  17863. */
  17864. function addProjectLogo(container) {
  17865. var img = BPMNIO_IMG;
  17866. var linkMarkup =
  17867. '<a href="http://bpmn.io" ' +
  17868. 'target="_blank" ' +
  17869. 'class="bjs-powered-by" ' +
  17870. 'title="Powered by bpmn.io" ' +
  17871. '>' +
  17872. img +
  17873. '</a>';
  17874. var linkElement = domify(linkMarkup);
  17875. assign$1(query('svg', linkElement), LOGO_STYLES);
  17876. assign$1(linkElement, LINK_STYLES, {
  17877. position: 'absolute',
  17878. bottom: '15px',
  17879. right: '15px',
  17880. zIndex: '100'
  17881. });
  17882. container.appendChild(linkElement);
  17883. componentEvent.bind(linkElement, 'click', function(event) {
  17884. open();
  17885. event.preventDefault();
  17886. });
  17887. }
  17888. /* </project-logo> */
  17889. /**
  17890. * A viewer for BPMN 2.0 diagrams.
  17891. *
  17892. * Have a look at {@link NavigatedViewer} or {@link Modeler} for bundles that include
  17893. * additional features.
  17894. *
  17895. *
  17896. * ## Extending the Viewer
  17897. *
  17898. * In order to extend the viewer pass extension modules to bootstrap via the
  17899. * `additionalModules` option. An extension module is an object that exposes
  17900. * named services.
  17901. *
  17902. * The following example depicts the integration of a simple
  17903. * logging component that integrates with interaction events:
  17904. *
  17905. *
  17906. * ```javascript
  17907. *
  17908. * // logging component
  17909. * function InteractionLogger(eventBus) {
  17910. * eventBus.on('element.hover', function(event) {
  17911. * console.log()
  17912. * })
  17913. * }
  17914. *
  17915. * InteractionLogger.$inject = [ 'eventBus' ]; // minification save
  17916. *
  17917. * // extension module
  17918. * var extensionModule = {
  17919. * __init__: [ 'interactionLogger' ],
  17920. * interactionLogger: [ 'type', InteractionLogger ]
  17921. * };
  17922. *
  17923. * // extend the viewer
  17924. * var bpmnViewer = new Viewer({ additionalModules: [ extensionModule ] });
  17925. * bpmnViewer.importXML(...);
  17926. * ```
  17927. *
  17928. * @param {Object} [options] configuration options to pass to the viewer
  17929. * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
  17930. * @param {string|number} [options.width] the width of the viewer
  17931. * @param {string|number} [options.height] the height of the viewer
  17932. * @param {Object} [options.moddleExtensions] extension packages to provide
  17933. * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
  17934. * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
  17935. */
  17936. function Viewer(options) {
  17937. BaseViewer.call(this, options);
  17938. }
  17939. e(Viewer, BaseViewer);
  17940. // modules the viewer is composed of
  17941. Viewer.prototype._modules = [
  17942. CoreModule$1,
  17943. TranslateModule,
  17944. SelectionModule,
  17945. OverlaysModule,
  17946. DrilldownModdule
  17947. ];
  17948. // default moddle extensions the viewer is composed of
  17949. Viewer.prototype._moddleExtensions = {};
  17950. /**
  17951. * Returns true if event was triggered with any modifier
  17952. * @param {KeyboardEvent} event
  17953. */
  17954. function hasModifier(event) {
  17955. return (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey);
  17956. }
  17957. /**
  17958. * @param {KeyboardEvent} event
  17959. */
  17960. function isCmd(event) {
  17961. // ensure we don't react to AltGr
  17962. // (mapped to CTRL + ALT)
  17963. if (event.altKey) {
  17964. return false;
  17965. }
  17966. return event.ctrlKey || event.metaKey;
  17967. }
  17968. /**
  17969. * Checks if key pressed is one of provided keys.
  17970. *
  17971. * @param {string|Array<string>} keys
  17972. * @param {KeyboardEvent} event
  17973. */
  17974. function isKey(keys, event) {
  17975. keys = isArray$2(keys) ? keys : [ keys ];
  17976. return keys.indexOf(event.key) !== -1 || keys.indexOf(event.keyCode) !== -1;
  17977. }
  17978. /**
  17979. * @param {KeyboardEvent} event
  17980. */
  17981. function isShift(event) {
  17982. return event.shiftKey;
  17983. }
  17984. var KEYDOWN_EVENT = 'keyboard.keydown',
  17985. KEYUP_EVENT = 'keyboard.keyup';
  17986. var HANDLE_MODIFIER_ATTRIBUTE = 'input-handle-modified-keys';
  17987. var DEFAULT_PRIORITY = 1000;
  17988. /**
  17989. * A keyboard abstraction that may be activated and
  17990. * deactivated by users at will, consuming key events
  17991. * and triggering diagram actions.
  17992. *
  17993. * For keys pressed down, keyboard fires `keyboard.keydown` event.
  17994. * The event context contains one field which is `KeyboardEvent` event.
  17995. *
  17996. * The implementation fires the following key events that allow
  17997. * other components to hook into key handling:
  17998. *
  17999. * - keyboard.bind
  18000. * - keyboard.unbind
  18001. * - keyboard.init
  18002. * - keyboard.destroy
  18003. *
  18004. * All events contain one field which is node.
  18005. *
  18006. * A default binding for the keyboard may be specified via the
  18007. * `keyboard.bindTo` configuration option.
  18008. *
  18009. * @param {Config} config
  18010. * @param {EventBus} eventBus
  18011. */
  18012. function Keyboard(config, eventBus) {
  18013. var self = this;
  18014. this._config = config || {};
  18015. this._eventBus = eventBus;
  18016. this._keydownHandler = this._keydownHandler.bind(this);
  18017. this._keyupHandler = this._keyupHandler.bind(this);
  18018. // properly clean dom registrations
  18019. eventBus.on('diagram.destroy', function() {
  18020. self._fire('destroy');
  18021. self.unbind();
  18022. });
  18023. eventBus.on('diagram.init', function() {
  18024. self._fire('init');
  18025. });
  18026. eventBus.on('attach', function() {
  18027. if (config && config.bindTo) {
  18028. self.bind(config.bindTo);
  18029. }
  18030. });
  18031. eventBus.on('detach', function() {
  18032. self.unbind();
  18033. });
  18034. }
  18035. Keyboard.$inject = [
  18036. 'config.keyboard',
  18037. 'eventBus'
  18038. ];
  18039. Keyboard.prototype._keydownHandler = function(event) {
  18040. this._keyHandler(event, KEYDOWN_EVENT);
  18041. };
  18042. Keyboard.prototype._keyupHandler = function(event) {
  18043. this._keyHandler(event, KEYUP_EVENT);
  18044. };
  18045. Keyboard.prototype._keyHandler = function(event, type) {
  18046. var eventBusResult;
  18047. if (this._isEventIgnored(event)) {
  18048. return;
  18049. }
  18050. var context = {
  18051. keyEvent: event
  18052. };
  18053. eventBusResult = this._eventBus.fire(type || KEYDOWN_EVENT, context);
  18054. if (eventBusResult) {
  18055. event.preventDefault();
  18056. }
  18057. };
  18058. Keyboard.prototype._isEventIgnored = function(event) {
  18059. return isInput(event.target) && this._isModifiedKeyIgnored(event);
  18060. };
  18061. Keyboard.prototype._isModifiedKeyIgnored = function(event) {
  18062. if (!isCmd(event)) {
  18063. return true;
  18064. }
  18065. var allowedModifiers = this._getAllowedModifiers(event.target);
  18066. return allowedModifiers.indexOf(event.key) === -1;
  18067. };
  18068. Keyboard.prototype._getAllowedModifiers = function(element) {
  18069. var modifierContainer = closest(element, '[' + HANDLE_MODIFIER_ATTRIBUTE + ']', true);
  18070. if (!modifierContainer || (this._node && !this._node.contains(modifierContainer))) {
  18071. return [];
  18072. }
  18073. return modifierContainer.getAttribute(HANDLE_MODIFIER_ATTRIBUTE).split(',');
  18074. };
  18075. Keyboard.prototype.bind = function(node) {
  18076. // make sure that the keyboard is only bound once to the DOM
  18077. this.unbind();
  18078. this._node = node;
  18079. // bind key events
  18080. componentEvent.bind(node, 'keydown', this._keydownHandler, true);
  18081. componentEvent.bind(node, 'keyup', this._keyupHandler, true);
  18082. this._fire('bind');
  18083. };
  18084. Keyboard.prototype.getBinding = function() {
  18085. return this._node;
  18086. };
  18087. Keyboard.prototype.unbind = function() {
  18088. var node = this._node;
  18089. if (node) {
  18090. this._fire('unbind');
  18091. // unbind key events
  18092. componentEvent.unbind(node, 'keydown', this._keydownHandler, true);
  18093. componentEvent.unbind(node, 'keyup', this._keyupHandler, true);
  18094. }
  18095. this._node = null;
  18096. };
  18097. Keyboard.prototype._fire = function(event) {
  18098. this._eventBus.fire('keyboard.' + event, { node: this._node });
  18099. };
  18100. /**
  18101. * Add a listener function that is notified with `KeyboardEvent` whenever
  18102. * the keyboard is bound and the user presses a key. If no priority is
  18103. * provided, the default value of 1000 is used.
  18104. *
  18105. * @param {number} [priority]
  18106. * @param {Function} listener
  18107. * @param {string} type
  18108. */
  18109. Keyboard.prototype.addListener = function(priority, listener, type) {
  18110. if (isFunction(priority)) {
  18111. type = listener;
  18112. listener = priority;
  18113. priority = DEFAULT_PRIORITY;
  18114. }
  18115. this._eventBus.on(type || KEYDOWN_EVENT, priority, listener);
  18116. };
  18117. Keyboard.prototype.removeListener = function(listener, type) {
  18118. this._eventBus.off(type || KEYDOWN_EVENT, listener);
  18119. };
  18120. Keyboard.prototype.hasModifier = hasModifier;
  18121. Keyboard.prototype.isCmd = isCmd;
  18122. Keyboard.prototype.isShift = isShift;
  18123. Keyboard.prototype.isKey = isKey;
  18124. // helpers ///////
  18125. function isInput(target) {
  18126. return target && (matchesSelector(target, 'input, textarea') || target.contentEditable === 'true');
  18127. }
  18128. var LOW_PRIORITY = 500;
  18129. var KEYCODE_C = 67;
  18130. var KEYCODE_V = 86;
  18131. var KEYCODE_Y = 89;
  18132. var KEYCODE_Z = 90;
  18133. var KEYS_COPY = [ 'c', 'C', KEYCODE_C ];
  18134. var KEYS_PASTE = [ 'v', 'V', KEYCODE_V ];
  18135. var KEYS_REDO = [ 'y', 'Y', KEYCODE_Y ];
  18136. var KEYS_UNDO = [ 'z', 'Z', KEYCODE_Z ];
  18137. /**
  18138. * Adds default keyboard bindings.
  18139. *
  18140. * This does not pull in any features will bind only actions that
  18141. * have previously been registered against the editorActions component.
  18142. *
  18143. * @param {EventBus} eventBus
  18144. * @param {Keyboard} keyboard
  18145. */
  18146. function KeyboardBindings(eventBus, keyboard) {
  18147. var self = this;
  18148. eventBus.on('editorActions.init', LOW_PRIORITY, function(event) {
  18149. var editorActions = event.editorActions;
  18150. self.registerBindings(keyboard, editorActions);
  18151. });
  18152. }
  18153. KeyboardBindings.$inject = [
  18154. 'eventBus',
  18155. 'keyboard'
  18156. ];
  18157. /**
  18158. * Register available keyboard bindings.
  18159. *
  18160. * @param {Keyboard} keyboard
  18161. * @param {EditorActions} editorActions
  18162. */
  18163. KeyboardBindings.prototype.registerBindings = function(keyboard, editorActions) {
  18164. /**
  18165. * Add keyboard binding if respective editor action
  18166. * is registered.
  18167. *
  18168. * @param {string} action name
  18169. * @param {Function} fn that implements the key binding
  18170. */
  18171. function addListener(action, fn) {
  18172. if (editorActions.isRegistered(action)) {
  18173. keyboard.addListener(fn);
  18174. }
  18175. }
  18176. // undo
  18177. // (CTRL|CMD) + Z
  18178. addListener('undo', function(context) {
  18179. var event = context.keyEvent;
  18180. if (isCmd(event) && !isShift(event) && isKey(KEYS_UNDO, event)) {
  18181. editorActions.trigger('undo');
  18182. return true;
  18183. }
  18184. });
  18185. // redo
  18186. // CTRL + Y
  18187. // CMD + SHIFT + Z
  18188. addListener('redo', function(context) {
  18189. var event = context.keyEvent;
  18190. if (isCmd(event) && (isKey(KEYS_REDO, event) || (isKey(KEYS_UNDO, event) && isShift(event)))) {
  18191. editorActions.trigger('redo');
  18192. return true;
  18193. }
  18194. });
  18195. // copy
  18196. // CTRL/CMD + C
  18197. addListener('copy', function(context) {
  18198. var event = context.keyEvent;
  18199. if (isCmd(event) && isKey(KEYS_COPY, event)) {
  18200. editorActions.trigger('copy');
  18201. return true;
  18202. }
  18203. });
  18204. // paste
  18205. // CTRL/CMD + V
  18206. addListener('paste', function(context) {
  18207. var event = context.keyEvent;
  18208. if (isCmd(event) && isKey(KEYS_PASTE, event)) {
  18209. editorActions.trigger('paste');
  18210. return true;
  18211. }
  18212. });
  18213. // zoom in one step
  18214. // CTRL/CMD + +
  18215. addListener('stepZoom', function(context) {
  18216. var event = context.keyEvent;
  18217. // quirk: it has to be triggered by `=` as well to work on international keyboard layout
  18218. // cf: https://github.com/bpmn-io/bpmn-js/issues/1362#issuecomment-722989754
  18219. if (isKey([ '+', 'Add', '=' ], event) && isCmd(event)) {
  18220. editorActions.trigger('stepZoom', { value: 1 });
  18221. return true;
  18222. }
  18223. });
  18224. // zoom out one step
  18225. // CTRL + -
  18226. addListener('stepZoom', function(context) {
  18227. var event = context.keyEvent;
  18228. if (isKey([ '-', 'Subtract' ], event) && isCmd(event)) {
  18229. editorActions.trigger('stepZoom', { value: -1 });
  18230. return true;
  18231. }
  18232. });
  18233. // zoom to the default level
  18234. // CTRL + 0
  18235. addListener('zoom', function(context) {
  18236. var event = context.keyEvent;
  18237. if (isKey('0', event) && isCmd(event)) {
  18238. editorActions.trigger('zoom', { value: 1 });
  18239. return true;
  18240. }
  18241. });
  18242. // delete selected element
  18243. // DEL
  18244. addListener('removeSelection', function(context) {
  18245. var event = context.keyEvent;
  18246. if (isKey([ 'Backspace', 'Delete', 'Del' ], event)) {
  18247. editorActions.trigger('removeSelection');
  18248. return true;
  18249. }
  18250. });
  18251. };
  18252. var KeyboardModule = {
  18253. __init__: [ 'keyboard', 'keyboardBindings' ],
  18254. keyboard: [ 'type', Keyboard ],
  18255. keyboardBindings: [ 'type', KeyboardBindings ]
  18256. };
  18257. var DEFAULT_CONFIG = {
  18258. moveSpeed: 50,
  18259. moveSpeedAccelerated: 200
  18260. };
  18261. /**
  18262. * A feature that allows users to move the canvas using the keyboard.
  18263. *
  18264. * @param {Object} config
  18265. * @param {number} [config.moveSpeed=50]
  18266. * @param {number} [config.moveSpeedAccelerated=200]
  18267. * @param {Keyboard} keyboard
  18268. * @param {Canvas} canvas
  18269. */
  18270. function KeyboardMove(
  18271. config,
  18272. keyboard,
  18273. canvas
  18274. ) {
  18275. var self = this;
  18276. this._config = assign({}, DEFAULT_CONFIG, config || {});
  18277. keyboard.addListener(arrowsListener);
  18278. function arrowsListener(context) {
  18279. var event = context.keyEvent,
  18280. config = self._config;
  18281. if (!keyboard.isCmd(event)) {
  18282. return;
  18283. }
  18284. if (keyboard.isKey([
  18285. 'ArrowLeft', 'Left',
  18286. 'ArrowUp', 'Up',
  18287. 'ArrowDown', 'Down',
  18288. 'ArrowRight', 'Right'
  18289. ], event)) {
  18290. var speed = (
  18291. keyboard.isShift(event) ?
  18292. config.moveSpeedAccelerated :
  18293. config.moveSpeed
  18294. );
  18295. var direction;
  18296. switch (event.key) {
  18297. case 'ArrowLeft':
  18298. case 'Left':
  18299. direction = 'left';
  18300. break;
  18301. case 'ArrowUp':
  18302. case 'Up':
  18303. direction = 'up';
  18304. break;
  18305. case 'ArrowRight':
  18306. case 'Right':
  18307. direction = 'right';
  18308. break;
  18309. case 'ArrowDown':
  18310. case 'Down':
  18311. direction = 'down';
  18312. break;
  18313. }
  18314. self.moveCanvas({
  18315. speed: speed,
  18316. direction: direction
  18317. });
  18318. return true;
  18319. }
  18320. }
  18321. this.moveCanvas = function(opts) {
  18322. var dx = 0,
  18323. dy = 0,
  18324. speed = opts.speed;
  18325. var actualSpeed = speed / Math.min(Math.sqrt(canvas.viewbox().scale), 1);
  18326. switch (opts.direction) {
  18327. case 'left': // Left
  18328. dx = actualSpeed;
  18329. break;
  18330. case 'up': // Up
  18331. dy = actualSpeed;
  18332. break;
  18333. case 'right': // Right
  18334. dx = -actualSpeed;
  18335. break;
  18336. case 'down': // Down
  18337. dy = -actualSpeed;
  18338. break;
  18339. }
  18340. canvas.scroll({
  18341. dx: dx,
  18342. dy: dy
  18343. });
  18344. };
  18345. }
  18346. KeyboardMove.$inject = [
  18347. 'config.keyboardMove',
  18348. 'keyboard',
  18349. 'canvas'
  18350. ];
  18351. var KeyboardMoveModule = {
  18352. __depends__: [
  18353. KeyboardModule
  18354. ],
  18355. __init__: [ 'keyboardMove' ],
  18356. keyboardMove: [ 'type', KeyboardMove ]
  18357. };
  18358. var CURSOR_CLS_PATTERN = /^djs-cursor-.*$/;
  18359. function set(mode) {
  18360. var classes$1 = classes(document.body);
  18361. classes$1.removeMatching(CURSOR_CLS_PATTERN);
  18362. if (mode) {
  18363. classes$1.add('djs-cursor-' + mode);
  18364. }
  18365. }
  18366. function unset() {
  18367. set(null);
  18368. }
  18369. var TRAP_PRIORITY = 5000;
  18370. /**
  18371. * Installs a click trap that prevents a ghost click following a dragging operation.
  18372. *
  18373. * @return {Function} a function to immediately remove the installed trap.
  18374. */
  18375. function install(eventBus, eventName) {
  18376. eventName = eventName || 'element.click';
  18377. function trap() {
  18378. return false;
  18379. }
  18380. eventBus.once(eventName, TRAP_PRIORITY, trap);
  18381. return function() {
  18382. eventBus.off(eventName, trap);
  18383. };
  18384. }
  18385. function delta(a, b) {
  18386. return {
  18387. x: a.x - b.x,
  18388. y: a.y - b.y
  18389. };
  18390. }
  18391. var THRESHOLD = 15;
  18392. /**
  18393. * Move the canvas via mouse.
  18394. *
  18395. * @param {EventBus} eventBus
  18396. * @param {Canvas} canvas
  18397. */
  18398. function MoveCanvas(eventBus, canvas) {
  18399. var context;
  18400. // listen for move on element mouse down;
  18401. // allow others to hook into the event before us though
  18402. // (dragging / element moving will do this)
  18403. eventBus.on('element.mousedown', 500, function(e) {
  18404. return handleStart(e.originalEvent);
  18405. });
  18406. function handleMove(event) {
  18407. var start = context.start,
  18408. button = context.button,
  18409. position = toPoint(event),
  18410. delta$1 = delta(position, start);
  18411. if (!context.dragging && length(delta$1) > THRESHOLD) {
  18412. context.dragging = true;
  18413. if (button === 0) {
  18414. install(eventBus);
  18415. }
  18416. set('grab');
  18417. }
  18418. if (context.dragging) {
  18419. var lastPosition = context.last || context.start;
  18420. delta$1 = delta(position, lastPosition);
  18421. canvas.scroll({
  18422. dx: delta$1.x,
  18423. dy: delta$1.y
  18424. });
  18425. context.last = position;
  18426. }
  18427. // prevent select
  18428. event.preventDefault();
  18429. }
  18430. function handleEnd(event) {
  18431. componentEvent.unbind(document, 'mousemove', handleMove);
  18432. componentEvent.unbind(document, 'mouseup', handleEnd);
  18433. context = null;
  18434. unset();
  18435. }
  18436. function handleStart(event) {
  18437. // event is already handled by '.djs-draggable'
  18438. if (closest(event.target, '.djs-draggable')) {
  18439. return;
  18440. }
  18441. var button = event.button;
  18442. // reject right mouse button or modifier key
  18443. if (button >= 2 || event.ctrlKey || event.shiftKey || event.altKey) {
  18444. return;
  18445. }
  18446. context = {
  18447. button: button,
  18448. start: toPoint(event)
  18449. };
  18450. componentEvent.bind(document, 'mousemove', handleMove);
  18451. componentEvent.bind(document, 'mouseup', handleEnd);
  18452. // we've handled the event
  18453. return true;
  18454. }
  18455. this.isActive = function() {
  18456. return !!context;
  18457. };
  18458. }
  18459. MoveCanvas.$inject = [
  18460. 'eventBus',
  18461. 'canvas'
  18462. ];
  18463. // helpers ///////
  18464. function length(point) {
  18465. return Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2));
  18466. }
  18467. var MoveCanvasModule = {
  18468. __init__: [ 'moveCanvas' ],
  18469. moveCanvas: [ 'type', MoveCanvas ]
  18470. };
  18471. /**
  18472. * Get the logarithm of x with base 10
  18473. * @param {Integer} value
  18474. */
  18475. function log10(x) {
  18476. return Math.log(x) / Math.log(10);
  18477. }
  18478. /**
  18479. * Get step size for given range and number of steps.
  18480. *
  18481. * @param {Object} range
  18482. * @param {number} range.min
  18483. * @param {number} range.max
  18484. */
  18485. function getStepSize(range, steps) {
  18486. var minLinearRange = log10(range.min),
  18487. maxLinearRange = log10(range.max);
  18488. var absoluteLinearRange = Math.abs(minLinearRange) + Math.abs(maxLinearRange);
  18489. return absoluteLinearRange / steps;
  18490. }
  18491. function cap(range, scale) {
  18492. return Math.max(range.min, Math.min(range.max, scale));
  18493. }
  18494. var sign = Math.sign || function(n) {
  18495. return n >= 0 ? 1 : -1;
  18496. };
  18497. var RANGE = { min: 0.2, max: 4 },
  18498. NUM_STEPS = 10;
  18499. var DELTA_THRESHOLD = 0.1;
  18500. var DEFAULT_SCALE = 0.75;
  18501. /**
  18502. * An implementation of zooming and scrolling within the
  18503. * {@link Canvas} via the mouse wheel.
  18504. *
  18505. * Mouse wheel zooming / scrolling may be disabled using
  18506. * the {@link toggle(enabled)} method.
  18507. *
  18508. * @param {Object} [config]
  18509. * @param {boolean} [config.enabled=true] default enabled state
  18510. * @param {number} [config.scale=.75] scroll sensivity
  18511. * @param {EventBus} eventBus
  18512. * @param {Canvas} canvas
  18513. */
  18514. function ZoomScroll(config, eventBus, canvas) {
  18515. config = config || {};
  18516. this._enabled = false;
  18517. this._canvas = canvas;
  18518. this._container = canvas._container;
  18519. this._handleWheel = bind(this._handleWheel, this);
  18520. this._totalDelta = 0;
  18521. this._scale = config.scale || DEFAULT_SCALE;
  18522. var self = this;
  18523. eventBus.on('canvas.init', function(e) {
  18524. self._init(config.enabled !== false);
  18525. });
  18526. }
  18527. ZoomScroll.$inject = [
  18528. 'config.zoomScroll',
  18529. 'eventBus',
  18530. 'canvas'
  18531. ];
  18532. ZoomScroll.prototype.scroll = function scroll(delta) {
  18533. this._canvas.scroll(delta);
  18534. };
  18535. ZoomScroll.prototype.reset = function reset() {
  18536. this._canvas.zoom('fit-viewport');
  18537. };
  18538. /**
  18539. * Zoom depending on delta.
  18540. *
  18541. * @param {number} delta
  18542. * @param {Object} position
  18543. */
  18544. ZoomScroll.prototype.zoom = function zoom(delta, position) {
  18545. // zoom with half the step size of stepZoom
  18546. var stepSize = getStepSize(RANGE, NUM_STEPS * 2);
  18547. // add until threshold reached
  18548. this._totalDelta += delta;
  18549. if (Math.abs(this._totalDelta) > DELTA_THRESHOLD) {
  18550. this._zoom(delta, position, stepSize);
  18551. // reset
  18552. this._totalDelta = 0;
  18553. }
  18554. };
  18555. ZoomScroll.prototype._handleWheel = function handleWheel(event) {
  18556. // event is already handled by '.djs-scrollable'
  18557. if (closest(event.target, '.djs-scrollable', true)) {
  18558. return;
  18559. }
  18560. var element = this._container;
  18561. event.preventDefault();
  18562. // pinch to zoom is mapped to wheel + ctrlKey = true
  18563. // in modern browsers (!)
  18564. var isZoom = event.ctrlKey;
  18565. var isHorizontalScroll = event.shiftKey;
  18566. var factor = -1 * this._scale,
  18567. delta;
  18568. if (isZoom) {
  18569. factor *= event.deltaMode === 0 ? 0.020 : 0.32;
  18570. } else {
  18571. factor *= event.deltaMode === 0 ? 1.0 : 16.0;
  18572. }
  18573. if (isZoom) {
  18574. var elementRect = element.getBoundingClientRect();
  18575. var offset = {
  18576. x: event.clientX - elementRect.left,
  18577. y: event.clientY - elementRect.top
  18578. };
  18579. delta = (
  18580. Math.sqrt(
  18581. Math.pow(event.deltaY, 2) +
  18582. Math.pow(event.deltaX, 2)
  18583. ) * sign(event.deltaY) * factor
  18584. );
  18585. // zoom in relative to diagram {x,y} coordinates
  18586. this.zoom(delta, offset);
  18587. } else {
  18588. if (isHorizontalScroll) {
  18589. delta = {
  18590. dx: factor * event.deltaY,
  18591. dy: 0
  18592. };
  18593. } else {
  18594. delta = {
  18595. dx: factor * event.deltaX,
  18596. dy: factor * event.deltaY
  18597. };
  18598. }
  18599. this.scroll(delta);
  18600. }
  18601. };
  18602. /**
  18603. * Zoom with fixed step size.
  18604. *
  18605. * @param {number} delta - Zoom delta (1 for zooming in, -1 for out).
  18606. * @param {Object} position
  18607. */
  18608. ZoomScroll.prototype.stepZoom = function stepZoom(delta, position) {
  18609. var stepSize = getStepSize(RANGE, NUM_STEPS);
  18610. this._zoom(delta, position, stepSize);
  18611. };
  18612. /**
  18613. * Zoom in/out given a step size.
  18614. *
  18615. * @param {number} delta
  18616. * @param {Object} position
  18617. * @param {number} stepSize
  18618. */
  18619. ZoomScroll.prototype._zoom = function(delta, position, stepSize) {
  18620. var canvas = this._canvas;
  18621. var direction = delta > 0 ? 1 : -1;
  18622. var currentLinearZoomLevel = log10(canvas.zoom());
  18623. // snap to a proximate zoom step
  18624. var newLinearZoomLevel = Math.round(currentLinearZoomLevel / stepSize) * stepSize;
  18625. // increase or decrease one zoom step in the given direction
  18626. newLinearZoomLevel += stepSize * direction;
  18627. // calculate the absolute logarithmic zoom level based on the linear zoom level
  18628. // (e.g. 2 for an absolute x2 zoom)
  18629. var newLogZoomLevel = Math.pow(10, newLinearZoomLevel);
  18630. canvas.zoom(cap(RANGE, newLogZoomLevel), position);
  18631. };
  18632. /**
  18633. * Toggle the zoom scroll ability via mouse wheel.
  18634. *
  18635. * @param {boolean} [newEnabled] new enabled state
  18636. */
  18637. ZoomScroll.prototype.toggle = function toggle(newEnabled) {
  18638. var element = this._container;
  18639. var handleWheel = this._handleWheel;
  18640. var oldEnabled = this._enabled;
  18641. if (typeof newEnabled === 'undefined') {
  18642. newEnabled = !oldEnabled;
  18643. }
  18644. // only react on actual changes
  18645. if (oldEnabled !== newEnabled) {
  18646. // add or remove wheel listener based on
  18647. // changed enabled state
  18648. componentEvent[newEnabled ? 'bind' : 'unbind'](element, 'wheel', handleWheel, false);
  18649. }
  18650. this._enabled = newEnabled;
  18651. return newEnabled;
  18652. };
  18653. ZoomScroll.prototype._init = function(newEnabled) {
  18654. this.toggle(newEnabled);
  18655. };
  18656. var ZoomScrollModule = {
  18657. __init__: [ 'zoomScroll' ],
  18658. zoomScroll: [ 'type', ZoomScroll ]
  18659. };
  18660. /**
  18661. * A viewer that includes mouse navigation facilities
  18662. *
  18663. * @param {Object} options
  18664. */
  18665. function NavigatedViewer(options) {
  18666. Viewer.call(this, options);
  18667. }
  18668. e(NavigatedViewer, Viewer);
  18669. NavigatedViewer.prototype._navigationModules = [
  18670. KeyboardMoveModule,
  18671. MoveCanvasModule,
  18672. ZoomScrollModule
  18673. ];
  18674. NavigatedViewer.prototype._modules = [].concat(
  18675. Viewer.prototype._modules,
  18676. NavigatedViewer.prototype._navigationModules
  18677. );
  18678. return NavigatedViewer;
  18679. })));