1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154 |
- /*!
- * bpmn-js - bpmn-viewer v6.5.1
- *
- * Copyright (c) 2014-present, camunda Services GmbH
- *
- * Released under the bpmn.io license
- * http://bpmn.io/license
- *
- * Source Code: https://github.com/bpmn-io/bpmn-js
- *
- * Date: 2020-04-28
- */
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
- typeof define === 'function' && define.amd ? define(factory) :
- (global = global || self, global.BpmnJS = factory());
- }(this, function () { 'use strict';
- function createCommonjsModule(fn, module) {
- return module = { exports: {} }, fn(module, module.exports), module.exports;
- }
- var inherits_browser = createCommonjsModule(function (module) {
- if (typeof Object.create === 'function') {
- // implementation from standard node.js 'util' module
- module.exports = function inherits(ctor, superCtor) {
- ctor.super_ = superCtor;
- ctor.prototype = Object.create(superCtor.prototype, {
- constructor: {
- value: ctor,
- enumerable: false,
- writable: true,
- configurable: true
- }
- });
- };
- } else {
- // old school shim for old browsers
- module.exports = function inherits(ctor, superCtor) {
- ctor.super_ = superCtor;
- var TempCtor = function () {};
- TempCtor.prototype = superCtor.prototype;
- ctor.prototype = new TempCtor();
- ctor.prototype.constructor = ctor;
- };
- }
- });
- /**
- * Flatten array, one level deep.
- *
- * @param {Array<?>} arr
- *
- * @return {Array<?>}
- */
- var nativeToString = Object.prototype.toString;
- var nativeHasOwnProperty = Object.prototype.hasOwnProperty;
- function isUndefined(obj) {
- return obj === undefined;
- }
- function isDefined(obj) {
- return obj !== undefined;
- }
- function isArray(obj) {
- return nativeToString.call(obj) === '[object Array]';
- }
- function isObject(obj) {
- return nativeToString.call(obj) === '[object Object]';
- }
- function isNumber(obj) {
- return nativeToString.call(obj) === '[object Number]';
- }
- function isFunction(obj) {
- var tag = nativeToString.call(obj);
- return tag === '[object Function]' || tag === '[object AsyncFunction]' || tag === '[object GeneratorFunction]' || tag === '[object AsyncGeneratorFunction]' || tag === '[object Proxy]';
- }
- function isString(obj) {
- return nativeToString.call(obj) === '[object String]';
- }
- /**
- * Return true, if target owns a property with the given key.
- *
- * @param {Object} target
- * @param {String} key
- *
- * @return {Boolean}
- */
- function has(target, key) {
- return nativeHasOwnProperty.call(target, key);
- }
- /**
- * Find element in collection.
- *
- * @param {Array|Object} collection
- * @param {Function|Object} matcher
- *
- * @return {Object}
- */
- function find(collection, matcher) {
- matcher = toMatcher(matcher);
- var match;
- forEach(collection, function (val, key) {
- if (matcher(val, key)) {
- match = val;
- return false;
- }
- });
- return match;
- }
- /**
- * Find element in collection.
- *
- * @param {Array|Object} collection
- * @param {Function} matcher
- *
- * @return {Array} result
- */
- function filter(collection, matcher) {
- var result = [];
- forEach(collection, function (val, key) {
- if (matcher(val, key)) {
- result.push(val);
- }
- });
- return result;
- }
- /**
- * Iterate over collection; returning something
- * (non-undefined) will stop iteration.
- *
- * @param {Array|Object} collection
- * @param {Function} iterator
- *
- * @return {Object} return result that stopped the iteration
- */
- function forEach(collection, iterator) {
- var val, result;
- if (isUndefined(collection)) {
- return;
- }
- var convertKey = isArray(collection) ? toNum : identity;
- for (var key in collection) {
- if (has(collection, key)) {
- val = collection[key];
- result = iterator(val, convertKey(key));
- if (result === false) {
- return val;
- }
- }
- }
- }
- /**
- * Reduce collection, returning a single result.
- *
- * @param {Object|Array} collection
- * @param {Function} iterator
- * @param {Any} result
- *
- * @return {Any} result returned from last iterator
- */
- function reduce(collection, iterator, result) {
- forEach(collection, function (value, idx) {
- result = iterator(result, value, idx);
- });
- return result;
- }
- /**
- * Return true if every element in the collection
- * matches the criteria.
- *
- * @param {Object|Array} collection
- * @param {Function} matcher
- *
- * @return {Boolean}
- */
- function every(collection, matcher) {
- return !!reduce(collection, function (matches, val, key) {
- return matches && matcher(val, key);
- }, true);
- }
- /**
- * Return true if some elements in the collection
- * match the criteria.
- *
- * @param {Object|Array} collection
- * @param {Function} matcher
- *
- * @return {Boolean}
- */
- function some(collection, matcher) {
- return !!find(collection, matcher);
- }
- /**
- * Transform a collection into another collection
- * by piping each member through the given fn.
- *
- * @param {Object|Array} collection
- * @param {Function} fn
- *
- * @return {Array} transformed collection
- */
- function map(collection, fn) {
- var result = [];
- forEach(collection, function (val, key) {
- result.push(fn(val, key));
- });
- return result;
- }
- /**
- * Create an object pattern matcher.
- *
- * @example
- *
- * const matcher = matchPattern({ id: 1 });
- *
- * var element = find(elements, matcher);
- *
- * @param {Object} pattern
- *
- * @return {Function} matcherFn
- */
- function matchPattern(pattern) {
- return function (el) {
- return every(pattern, function (val, key) {
- return el[key] === val;
- });
- };
- }
- function toMatcher(matcher) {
- return isFunction(matcher) ? matcher : function (e) {
- return e === matcher;
- };
- }
- function identity(arg) {
- return arg;
- }
- function toNum(arg) {
- return Number(arg);
- }
- /**
- * Debounce fn, calling it only once if
- * the given time elapsed between calls.
- *
- * @param {Function} fn
- * @param {Number} timeout
- *
- * @return {Function} debounced function
- */
- function debounce(fn, timeout) {
- var timer;
- var lastArgs;
- var lastThis;
- var lastNow;
- function fire() {
- var now = Date.now();
- var scheduledDiff = lastNow + timeout - now;
- if (scheduledDiff > 0) {
- return schedule(scheduledDiff);
- }
- fn.apply(lastThis, lastArgs);
- timer = lastNow = lastArgs = lastThis = undefined;
- }
- function schedule(timeout) {
- timer = setTimeout(fire, timeout);
- }
- return function () {
- lastNow = Date.now();
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
- args[_key] = arguments[_key];
- }
- lastArgs = args;
- lastThis = this; // ensure an execution is scheduled
- if (!timer) {
- schedule(timeout);
- }
- };
- }
- /**
- * Bind function against target <this>.
- *
- * @param {Function} fn
- * @param {Object} target
- *
- * @return {Function} bound function
- */
- function bind(fn, target) {
- return fn.bind(target);
- }
- function _extends() {
- _extends = Object.assign || function (target) {
- for (var i = 1; i < arguments.length; i++) {
- var source = arguments[i];
- for (var key in source) {
- if (Object.prototype.hasOwnProperty.call(source, key)) {
- target[key] = source[key];
- }
- }
- }
- return target;
- };
- return _extends.apply(this, arguments);
- }
- /**
- * Convenience wrapper for `Object.assign`.
- *
- * @param {Object} target
- * @param {...Object} others
- *
- * @return {Object} the target
- */
- function assign(target) {
- for (var _len = arguments.length, others = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
- others[_key - 1] = arguments[_key];
- }
- return _extends.apply(void 0, [target].concat(others));
- }
- /**
- * Pick given properties from the target object.
- *
- * @param {Object} target
- * @param {Array} properties
- *
- * @return {Object} target
- */
- function pick(target, properties) {
- var result = {};
- var obj = Object(target);
- forEach(properties, function (prop) {
- if (prop in obj) {
- result[prop] = target[prop];
- }
- });
- return result;
- }
- /**
- * Pick all target properties, excluding the given ones.
- *
- * @param {Object} target
- * @param {Array} properties
- *
- * @return {Object} target
- */
- function omit(target, properties) {
- var result = {};
- var obj = Object(target);
- forEach(obj, function (prop, key) {
- if (properties.indexOf(key) === -1) {
- result[key] = prop;
- }
- });
- return result;
- }
- var DEFAULT_RENDER_PRIORITY = 1000;
- /**
- * The base implementation of shape and connection renderers.
- *
- * @param {EventBus} eventBus
- * @param {number} [renderPriority=1000]
- */
- function BaseRenderer(eventBus, renderPriority) {
- var self = this;
- renderPriority = renderPriority || DEFAULT_RENDER_PRIORITY;
- eventBus.on([ 'render.shape', 'render.connection' ], renderPriority, function(evt, context) {
- var type = evt.type,
- element = context.element,
- visuals = context.gfx;
- if (self.canRender(element)) {
- if (type === 'render.shape') {
- return self.drawShape(visuals, element);
- } else {
- return self.drawConnection(visuals, element);
- }
- }
- });
- eventBus.on([ 'render.getShapePath', 'render.getConnectionPath'], renderPriority, function(evt, element) {
- if (self.canRender(element)) {
- if (evt.type === 'render.getShapePath') {
- return self.getShapePath(element);
- } else {
- return self.getConnectionPath(element);
- }
- }
- });
- }
- /**
- * Should check whether *this* renderer can render
- * the element/connection.
- *
- * @param {element} element
- *
- * @returns {boolean}
- */
- BaseRenderer.prototype.canRender = function() {};
- /**
- * Provides the shape's snap svg element to be drawn on the `canvas`.
- *
- * @param {djs.Graphics} visuals
- * @param {Shape} shape
- *
- * @returns {Snap.svg} [returns a Snap.svg paper element ]
- */
- BaseRenderer.prototype.drawShape = function() {};
- /**
- * Provides the shape's snap svg element to be drawn on the `canvas`.
- *
- * @param {djs.Graphics} visuals
- * @param {Connection} connection
- *
- * @returns {Snap.svg} [returns a Snap.svg paper element ]
- */
- BaseRenderer.prototype.drawConnection = function() {};
- /**
- * Gets the SVG path of a shape that represents it's visual bounds.
- *
- * @param {Shape} shape
- *
- * @return {string} svg path
- */
- BaseRenderer.prototype.getShapePath = function() {};
- /**
- * Gets the SVG path of a connection that represents it's visual bounds.
- *
- * @param {Connection} connection
- *
- * @return {string} svg path
- */
- BaseRenderer.prototype.getConnectionPath = function() {};
- /**
- * Is an element of the given BPMN type?
- *
- * @param {djs.model.Base|ModdleElement} element
- * @param {string} type
- *
- * @return {boolean}
- */
- function is(element, type) {
- var bo = getBusinessObject(element);
- return bo && (typeof bo.$instanceOf === 'function') && bo.$instanceOf(type);
- }
- /**
- * Return the business object for a given element.
- *
- * @param {djs.model.Base|ModdleElement} element
- *
- * @return {ModdleElement}
- */
- function getBusinessObject(element) {
- return (element && element.businessObject) || element;
- }
- function isExpanded(element) {
- if (is(element, 'bpmn:CallActivity')) {
- return false;
- }
- if (is(element, 'bpmn:SubProcess')) {
- return !!getBusinessObject(element).di.isExpanded;
- }
- if (is(element, 'bpmn:Participant')) {
- return !!getBusinessObject(element).processRef;
- }
- return true;
- }
- function isEventSubProcess(element) {
- return element && !!getBusinessObject(element).triggeredByEvent;
- }
- function getLabelAttr(semantic) {
- if (
- is(semantic, 'bpmn:FlowElement') ||
- is(semantic, 'bpmn:Participant') ||
- is(semantic, 'bpmn:Lane') ||
- is(semantic, 'bpmn:SequenceFlow') ||
- is(semantic, 'bpmn:MessageFlow') ||
- is(semantic, 'bpmn:DataInput') ||
- is(semantic, 'bpmn:DataOutput')
- ) {
- return 'name';
- }
- if (is(semantic, 'bpmn:TextAnnotation')) {
- return 'text';
- }
- if (is(semantic, 'bpmn:Group')) {
- return 'categoryValueRef';
- }
- }
- function getCategoryValue(semantic) {
- var categoryValueRef = semantic['categoryValueRef'];
- if (!categoryValueRef) {
- return '';
- }
- return categoryValueRef.value || '';
- }
- function getLabel(element) {
- var semantic = element.businessObject,
- attr = getLabelAttr(semantic);
- if (attr) {
- if (attr === 'categoryValueRef') {
- return getCategoryValue(semantic);
- }
- return semantic[attr] || '';
- }
- }
- function ensureImported(element, target) {
- if (element.ownerDocument !== target.ownerDocument) {
- try {
- // may fail on webkit
- return target.ownerDocument.importNode(element, true);
- } catch (e) {
- // ignore
- }
- }
- return element;
- }
- /**
- * appendTo utility
- */
- /**
- * Append a node to a target element and return the appended node.
- *
- * @param {SVGElement} element
- * @param {SVGElement} target
- *
- * @return {SVGElement} the appended node
- */
- function appendTo(element, target) {
- return target.appendChild(ensureImported(element, target));
- }
- /**
- * append utility
- */
- /**
- * Append a node to an element
- *
- * @param {SVGElement} element
- * @param {SVGElement} node
- *
- * @return {SVGElement} the element
- */
- function append(target, node) {
- appendTo(node, target);
- return target;
- }
- /**
- * attribute accessor utility
- */
- var LENGTH_ATTR = 2;
- var CSS_PROPERTIES = {
- 'alignment-baseline': 1,
- 'baseline-shift': 1,
- 'clip': 1,
- 'clip-path': 1,
- 'clip-rule': 1,
- 'color': 1,
- 'color-interpolation': 1,
- 'color-interpolation-filters': 1,
- 'color-profile': 1,
- 'color-rendering': 1,
- 'cursor': 1,
- 'direction': 1,
- 'display': 1,
- 'dominant-baseline': 1,
- 'enable-background': 1,
- 'fill': 1,
- 'fill-opacity': 1,
- 'fill-rule': 1,
- 'filter': 1,
- 'flood-color': 1,
- 'flood-opacity': 1,
- 'font': 1,
- 'font-family': 1,
- 'font-size': LENGTH_ATTR,
- 'font-size-adjust': 1,
- 'font-stretch': 1,
- 'font-style': 1,
- 'font-variant': 1,
- 'font-weight': 1,
- 'glyph-orientation-horizontal': 1,
- 'glyph-orientation-vertical': 1,
- 'image-rendering': 1,
- 'kerning': 1,
- 'letter-spacing': 1,
- 'lighting-color': 1,
- 'marker': 1,
- 'marker-end': 1,
- 'marker-mid': 1,
- 'marker-start': 1,
- 'mask': 1,
- 'opacity': 1,
- 'overflow': 1,
- 'pointer-events': 1,
- 'shape-rendering': 1,
- 'stop-color': 1,
- 'stop-opacity': 1,
- 'stroke': 1,
- 'stroke-dasharray': 1,
- 'stroke-dashoffset': 1,
- 'stroke-linecap': 1,
- 'stroke-linejoin': 1,
- 'stroke-miterlimit': 1,
- 'stroke-opacity': 1,
- 'stroke-width': LENGTH_ATTR,
- 'text-anchor': 1,
- 'text-decoration': 1,
- 'text-rendering': 1,
- 'unicode-bidi': 1,
- 'visibility': 1,
- 'word-spacing': 1,
- 'writing-mode': 1
- };
- function getAttribute(node, name) {
- if (CSS_PROPERTIES[name]) {
- return node.style[name];
- } else {
- return node.getAttributeNS(null, name);
- }
- }
- function setAttribute(node, name, value) {
- var hyphenated = name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
- var type = CSS_PROPERTIES[hyphenated];
- if (type) {
- // append pixel unit, unless present
- if (type === LENGTH_ATTR && typeof value === 'number') {
- value = String(value) + 'px';
- }
- node.style[hyphenated] = value;
- } else {
- node.setAttributeNS(null, name, value);
- }
- }
- function setAttributes(node, attrs) {
- var names = Object.keys(attrs), i, name;
- for (i = 0, name; (name = names[i]); i++) {
- setAttribute(node, name, attrs[name]);
- }
- }
- /**
- * Gets or sets raw attributes on a node.
- *
- * @param {SVGElement} node
- * @param {Object} [attrs]
- * @param {String} [name]
- * @param {String} [value]
- *
- * @return {String}
- */
- function attr(node, name, value) {
- if (typeof name === 'string') {
- if (value !== undefined) {
- setAttribute(node, name, value);
- } else {
- return getAttribute(node, name);
- }
- } else {
- setAttributes(node, name);
- }
- return node;
- }
- /**
- * Clear utility
- */
- function index(arr, obj) {
- if (arr.indexOf) {
- return arr.indexOf(obj);
- }
- for (var i = 0; i < arr.length; ++i) {
- if (arr[i] === obj) {
- return i;
- }
- }
- return -1;
- }
- var re = /\s+/;
- var toString = Object.prototype.toString;
- function defined(o) {
- return typeof o !== 'undefined';
- }
- /**
- * Wrap `el` in a `ClassList`.
- *
- * @param {Element} el
- * @return {ClassList}
- * @api public
- */
- function classes(el) {
- return new ClassList(el);
- }
- function ClassList(el) {
- if (!el || !el.nodeType) {
- throw new Error('A DOM element reference is required');
- }
- this.el = el;
- this.list = el.classList;
- }
- /**
- * Add class `name` if not already present.
- *
- * @param {String} name
- * @return {ClassList}
- * @api public
- */
- ClassList.prototype.add = function(name) {
- // classList
- if (this.list) {
- this.list.add(name);
- return this;
- }
- // fallback
- var arr = this.array();
- var i = index(arr, name);
- if (!~i) {
- arr.push(name);
- }
- if (defined(this.el.className.baseVal)) {
- this.el.className.baseVal = arr.join(' ');
- } else {
- this.el.className = arr.join(' ');
- }
- return this;
- };
- /**
- * Remove class `name` when present, or
- * pass a regular expression to remove
- * any which match.
- *
- * @param {String|RegExp} name
- * @return {ClassList}
- * @api public
- */
- ClassList.prototype.remove = function(name) {
- if ('[object RegExp]' === toString.call(name)) {
- return this.removeMatching(name);
- }
- // classList
- if (this.list) {
- this.list.remove(name);
- return this;
- }
- // fallback
- var arr = this.array();
- var i = index(arr, name);
- if (~i) {
- arr.splice(i, 1);
- }
- this.el.className.baseVal = arr.join(' ');
- return this;
- };
- /**
- * Remove all classes matching `re`.
- *
- * @param {RegExp} re
- * @return {ClassList}
- * @api private
- */
- ClassList.prototype.removeMatching = function(re) {
- var arr = this.array();
- for (var i = 0; i < arr.length; i++) {
- if (re.test(arr[i])) {
- this.remove(arr[i]);
- }
- }
- return this;
- };
- /**
- * Toggle class `name`, can force state via `force`.
- *
- * For browsers that support classList, but do not support `force` yet,
- * the mistake will be detected and corrected.
- *
- * @param {String} name
- * @param {Boolean} force
- * @return {ClassList}
- * @api public
- */
- ClassList.prototype.toggle = function(name, force) {
- // classList
- if (this.list) {
- if (defined(force)) {
- if (force !== this.list.toggle(name, force)) {
- this.list.toggle(name); // toggle again to correct
- }
- } else {
- this.list.toggle(name);
- }
- return this;
- }
- // fallback
- if (defined(force)) {
- if (!force) {
- this.remove(name);
- } else {
- this.add(name);
- }
- } else {
- if (this.has(name)) {
- this.remove(name);
- } else {
- this.add(name);
- }
- }
- return this;
- };
- /**
- * Return an array of classes.
- *
- * @return {Array}
- * @api public
- */
- ClassList.prototype.array = function() {
- var className = this.el.getAttribute('class') || '';
- var str = className.replace(/^\s+|\s+$/g, '');
- var arr = str.split(re);
- if ('' === arr[0]) {
- arr.shift();
- }
- return arr;
- };
- /**
- * Check if class `name` is present.
- *
- * @param {String} name
- * @return {ClassList}
- * @api public
- */
- ClassList.prototype.has =
- ClassList.prototype.contains = function(name) {
- return (
- this.list ?
- this.list.contains(name) :
- !! ~index(this.array(), name)
- );
- };
- function remove(element) {
- var parent = element.parentNode;
- if (parent) {
- parent.removeChild(element);
- }
- return element;
- }
- /**
- * Clear utility
- */
- /**
- * Removes all children from the given element
- *
- * @param {DOMElement} element
- * @return {DOMElement} the element (for chaining)
- */
- function clear(element) {
- var child;
- while ((child = element.firstChild)) {
- remove(child);
- }
- return element;
- }
- var ns = {
- svg: 'http://www.w3.org/2000/svg'
- };
- /**
- * DOM parsing utility
- */
- var SVG_START = '<svg xmlns="' + ns.svg + '"';
- function parse(svg) {
- var unwrap = false;
- // ensure we import a valid svg document
- if (svg.substring(0, 4) === '<svg') {
- if (svg.indexOf(ns.svg) === -1) {
- svg = SVG_START + svg.substring(4);
- }
- } else {
- // namespace svg
- svg = SVG_START + '>' + svg + '</svg>';
- unwrap = true;
- }
- var parsed = parseDocument(svg);
- if (!unwrap) {
- return parsed;
- }
- var fragment = document.createDocumentFragment();
- var parent = parsed.firstChild;
- while (parent.firstChild) {
- fragment.appendChild(parent.firstChild);
- }
- return fragment;
- }
- function parseDocument(svg) {
- var parser;
- // parse
- parser = new DOMParser();
- parser.async = false;
- return parser.parseFromString(svg, 'text/xml');
- }
- /**
- * Create utility for SVG elements
- */
- /**
- * Create a specific type from name or SVG markup.
- *
- * @param {String} name the name or markup of the element
- * @param {Object} [attrs] attributes to set on the element
- *
- * @returns {SVGElement}
- */
- function create(name, attrs) {
- var element;
- if (name.charAt(0) === '<') {
- element = parse(name).firstChild;
- element = document.importNode(element, true);
- } else {
- element = document.createElementNS(ns.svg, name);
- }
- if (attrs) {
- attr(element, attrs);
- }
- return element;
- }
- /**
- * Geometry helpers
- */
- // fake node used to instantiate svg geometry elements
- var node = create('svg');
- function extend(object, props) {
- var i, k, keys = Object.keys(props);
- for (i = 0; (k = keys[i]); i++) {
- object[k] = props[k];
- }
- return object;
- }
- /**
- * Create matrix via args.
- *
- * @example
- *
- * createMatrix({ a: 1, b: 1 });
- * createMatrix();
- * createMatrix(1, 2, 0, 0, 30, 20);
- *
- * @return {SVGMatrix}
- */
- function createMatrix(a, b, c, d, e, f) {
- var matrix = node.createSVGMatrix();
- switch (arguments.length) {
- case 0:
- return matrix;
- case 1:
- return extend(matrix, a);
- case 6:
- return extend(matrix, {
- a: a,
- b: b,
- c: c,
- d: d,
- e: e,
- f: f
- });
- }
- }
- function createTransform(matrix) {
- if (matrix) {
- return node.createSVGTransformFromMatrix(matrix);
- } else {
- return node.createSVGTransform();
- }
- }
- /**
- * Serialization util
- */
- var TEXT_ENTITIES = /([&<>]{1})/g;
- var ATTR_ENTITIES = /([\n\r"]{1})/g;
- var ENTITY_REPLACEMENT = {
- '&': '&',
- '<': '<',
- '>': '>',
- '"': '\''
- };
- function escape(str, pattern) {
- function replaceFn(match, entity) {
- return ENTITY_REPLACEMENT[entity] || entity;
- }
- return str.replace(pattern, replaceFn);
- }
- function serialize(node, output) {
- var i, len, attrMap, attrNode, childNodes;
- switch (node.nodeType) {
- // TEXT
- case 3:
- // replace special XML characters
- output.push(escape(node.textContent, TEXT_ENTITIES));
- break;
- // ELEMENT
- case 1:
- output.push('<', node.tagName);
- if (node.hasAttributes()) {
- attrMap = node.attributes;
- for (i = 0, len = attrMap.length; i < len; ++i) {
- attrNode = attrMap.item(i);
- output.push(' ', attrNode.name, '="', escape(attrNode.value, ATTR_ENTITIES), '"');
- }
- }
- if (node.hasChildNodes()) {
- output.push('>');
- childNodes = node.childNodes;
- for (i = 0, len = childNodes.length; i < len; ++i) {
- serialize(childNodes.item(i), output);
- }
- output.push('</', node.tagName, '>');
- } else {
- output.push('/>');
- }
- break;
- // COMMENT
- case 8:
- output.push('<!--', escape(node.nodeValue, TEXT_ENTITIES), '-->');
- break;
- // CDATA
- case 4:
- output.push('<![CDATA[', node.nodeValue, ']]>');
- break;
- default:
- throw new Error('unable to handle node ' + node.nodeType);
- }
- return output;
- }
- /**
- * innerHTML like functionality for SVG elements.
- * based on innerSVG (https://code.google.com/p/innersvg)
- */
- function set(element, svg) {
- var parsed = parse(svg);
- // clear element contents
- clear(element);
- if (!svg) {
- return;
- }
- if (!isFragment(parsed)) {
- // extract <svg> from parsed document
- parsed = parsed.documentElement;
- }
- var nodes = slice(parsed.childNodes);
- // import + append each node
- for (var i = 0; i < nodes.length; i++) {
- appendTo(nodes[i], element);
- }
- }
- function get(element) {
- var child = element.firstChild,
- output = [];
- while (child) {
- serialize(child, output);
- child = child.nextSibling;
- }
- return output.join('');
- }
- function isFragment(node) {
- return node.nodeName === '#document-fragment';
- }
- function innerSVG(element, svg) {
- if (svg !== undefined) {
- try {
- set(element, svg);
- } catch (e) {
- throw new Error('error parsing SVG: ' + e.message);
- }
- return element;
- } else {
- return get(element);
- }
- }
- function slice(arr) {
- return Array.prototype.slice.call(arr);
- }
- /**
- * transform accessor utility
- */
- function wrapMatrix(transformList, transform) {
- if (transform instanceof SVGMatrix) {
- return transformList.createSVGTransformFromMatrix(transform);
- }
- return transform;
- }
- function setTransforms(transformList, transforms) {
- var i, t;
- transformList.clear();
- for (i = 0; (t = transforms[i]); i++) {
- transformList.appendItem(wrapMatrix(transformList, t));
- }
- }
- /**
- * Get or set the transforms on the given node.
- *
- * @param {SVGElement} node
- * @param {SVGTransform|SVGMatrix|Array<SVGTransform|SVGMatrix>} [transforms]
- *
- * @return {SVGTransform} the consolidated transform
- */
- function transform(node, transforms) {
- var transformList = node.transform.baseVal;
- if (transforms) {
- if (!Array.isArray(transforms)) {
- transforms = [ transforms ];
- }
- setTransforms(transformList, transforms);
- }
- return transformList.consolidate();
- }
- function componentsToPath(elements) {
- return elements.join(',').replace(/,?([A-z]),?/g, '$1');
- }
- function toSVGPoints(points) {
- var result = '';
- for (var i = 0, p; (p = points[i]); i++) {
- result += p.x + ',' + p.y + ' ';
- }
- return result;
- }
- function createLine(points, attrs) {
- var line = create('polyline');
- attr(line, { points: toSVGPoints(points) });
- if (attrs) {
- attr(line, attrs);
- }
- return line;
- }
- function updateLine(gfx, points) {
- attr(gfx, { points: toSVGPoints(points) });
- return gfx;
- }
- // element utils //////////////////////
- /**
- * Checks if eventDefinition of the given element matches with semantic type.
- *
- * @return {boolean} true if element is of the given semantic type
- */
- function isTypedEvent(event, eventDefinitionType, filter) {
- function matches(definition, filter) {
- return every(filter, function(val, key) {
- // we want a == conversion here, to be able to catch
- // undefined == false and friends
- /* jshint -W116 */
- return definition[key] == val;
- });
- }
- return some(event.eventDefinitions, function(definition) {
- return definition.$type === eventDefinitionType && matches(event, filter);
- });
- }
- function isThrowEvent(event) {
- return (event.$type === 'bpmn:IntermediateThrowEvent') || (event.$type === 'bpmn:EndEvent');
- }
- function isCollection(element) {
- var dataObject = element.dataObjectRef;
- return element.isCollection || (dataObject && dataObject.isCollection);
- }
- function getDi(element) {
- return element.businessObject.di;
- }
- function getSemantic(element) {
- return element.businessObject;
- }
- // color access //////////////////////
- function getFillColor(element, defaultColor) {
- return getDi(element).get('bioc:fill') || defaultColor || 'white';
- }
- function getStrokeColor(element, defaultColor) {
- return getDi(element).get('bioc:stroke') || defaultColor || 'black';
- }
- // cropping path customizations //////////////////////
- function getCirclePath(shape) {
- var cx = shape.x + shape.width / 2,
- cy = shape.y + shape.height / 2,
- radius = shape.width / 2;
- var circlePath = [
- ['M', cx, cy],
- ['m', 0, -radius],
- ['a', radius, radius, 0, 1, 1, 0, 2 * radius],
- ['a', radius, radius, 0, 1, 1, 0, -2 * radius],
- ['z']
- ];
- return componentsToPath(circlePath);
- }
- function getRoundRectPath(shape, borderRadius) {
- var x = shape.x,
- y = shape.y,
- width = shape.width,
- height = shape.height;
- var roundRectPath = [
- ['M', x + borderRadius, y],
- ['l', width - borderRadius * 2, 0],
- ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, borderRadius],
- ['l', 0, height - borderRadius * 2],
- ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, borderRadius],
- ['l', borderRadius * 2 - width, 0],
- ['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, -borderRadius],
- ['l', 0, borderRadius * 2 - height],
- ['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, -borderRadius],
- ['z']
- ];
- return componentsToPath(roundRectPath);
- }
- function getDiamondPath(shape) {
- var width = shape.width,
- height = shape.height,
- x = shape.x,
- y = shape.y,
- halfWidth = width / 2,
- halfHeight = height / 2;
- var diamondPath = [
- ['M', x + halfWidth, y],
- ['l', halfWidth, halfHeight],
- ['l', -halfWidth, halfHeight],
- ['l', -halfWidth, -halfHeight],
- ['z']
- ];
- return componentsToPath(diamondPath);
- }
- function getRectPath(shape) {
- var x = shape.x,
- y = shape.y,
- width = shape.width,
- height = shape.height;
- var rectPath = [
- ['M', x, y],
- ['l', width, 0],
- ['l', 0, height],
- ['l', -width, 0],
- ['z']
- ];
- return componentsToPath(rectPath);
- }
- /**
- * Set attribute `name` to `val`, or get attr `name`.
- *
- * @param {Element} el
- * @param {String} name
- * @param {String} [val]
- * @api public
- */
- function attr$1(el, name, val) {
- // get
- if (arguments.length == 2) {
- return el.getAttribute(name);
- }
- // remove
- if (val === null) {
- return el.removeAttribute(name);
- }
- // set
- el.setAttribute(name, val);
- return el;
- }
- var indexOf = [].indexOf;
- var indexof = function(arr, obj){
- if (indexOf) return arr.indexOf(obj);
- for (var i = 0; i < arr.length; ++i) {
- if (arr[i] === obj) return i;
- }
- return -1;
- };
- /**
- * Taken from https://github.com/component/classes
- *
- * Without the component bits.
- */
- /**
- * Whitespace regexp.
- */
- var re$1 = /\s+/;
- /**
- * toString reference.
- */
- var toString$1 = Object.prototype.toString;
- /**
- * Wrap `el` in a `ClassList`.
- *
- * @param {Element} el
- * @return {ClassList}
- * @api public
- */
- function classes$1(el) {
- return new ClassList$1(el);
- }
- /**
- * Initialize a new ClassList for `el`.
- *
- * @param {Element} el
- * @api private
- */
- function ClassList$1(el) {
- if (!el || !el.nodeType) {
- throw new Error('A DOM element reference is required');
- }
- this.el = el;
- this.list = el.classList;
- }
- /**
- * Add class `name` if not already present.
- *
- * @param {String} name
- * @return {ClassList}
- * @api public
- */
- ClassList$1.prototype.add = function (name) {
- // classList
- if (this.list) {
- this.list.add(name);
- return this;
- }
- // fallback
- var arr = this.array();
- var i = indexof(arr, name);
- if (!~i) arr.push(name);
- this.el.className = arr.join(' ');
- return this;
- };
- /**
- * Remove class `name` when present, or
- * pass a regular expression to remove
- * any which match.
- *
- * @param {String|RegExp} name
- * @return {ClassList}
- * @api public
- */
- ClassList$1.prototype.remove = function (name) {
- if ('[object RegExp]' == toString$1.call(name)) {
- return this.removeMatching(name);
- }
- // classList
- if (this.list) {
- this.list.remove(name);
- return this;
- }
- // fallback
- var arr = this.array();
- var i = indexof(arr, name);
- if (~i) arr.splice(i, 1);
- this.el.className = arr.join(' ');
- return this;
- };
- /**
- * Remove all classes matching `re`.
- *
- * @param {RegExp} re
- * @return {ClassList}
- * @api private
- */
- ClassList$1.prototype.removeMatching = function (re) {
- var arr = this.array();
- for (var i = 0; i < arr.length; i++) {
- if (re.test(arr[i])) {
- this.remove(arr[i]);
- }
- }
- return this;
- };
- /**
- * Toggle class `name`, can force state via `force`.
- *
- * For browsers that support classList, but do not support `force` yet,
- * the mistake will be detected and corrected.
- *
- * @param {String} name
- * @param {Boolean} force
- * @return {ClassList}
- * @api public
- */
- ClassList$1.prototype.toggle = function (name, force) {
- // classList
- if (this.list) {
- if ('undefined' !== typeof force) {
- if (force !== this.list.toggle(name, force)) {
- this.list.toggle(name); // toggle again to correct
- }
- } else {
- this.list.toggle(name);
- }
- return this;
- }
- // fallback
- if ('undefined' !== typeof force) {
- if (!force) {
- this.remove(name);
- } else {
- this.add(name);
- }
- } else {
- if (this.has(name)) {
- this.remove(name);
- } else {
- this.add(name);
- }
- }
- return this;
- };
- /**
- * Return an array of classes.
- *
- * @return {Array}
- * @api public
- */
- ClassList$1.prototype.array = function () {
- var className = this.el.getAttribute('class') || '';
- var str = className.replace(/^\s+|\s+$/g, '');
- var arr = str.split(re$1);
- if ('' === arr[0]) arr.shift();
- return arr;
- };
- /**
- * Check if class `name` is present.
- *
- * @param {String} name
- * @return {ClassList}
- * @api public
- */
- ClassList$1.prototype.has = ClassList$1.prototype.contains = function (name) {
- return this.list ? this.list.contains(name) : !!~indexof(this.array(), name);
- };
- /**
- * Remove all children from the given element.
- */
- function clear$1(el) {
- var c;
- while (el.childNodes.length) {
- c = el.childNodes[0];
- el.removeChild(c);
- }
- return el;
- }
- var proto = typeof Element !== 'undefined' ? Element.prototype : {};
- var vendor = proto.matches
- || proto.matchesSelector
- || proto.webkitMatchesSelector
- || proto.mozMatchesSelector
- || proto.msMatchesSelector
- || proto.oMatchesSelector;
- /**
- * Element prototype.
- */
- var proto$1 = Element.prototype;
- /**
- * Vendor function.
- */
- var vendor$1 = proto$1.matchesSelector
- || proto$1.webkitMatchesSelector
- || proto$1.mozMatchesSelector
- || proto$1.msMatchesSelector
- || proto$1.oMatchesSelector;
- /**
- * Expose `match()`.
- */
- var matchesSelector$1 = match$1;
- /**
- * Match `el` to `selector`.
- *
- * @param {Element} el
- * @param {String} selector
- * @return {Boolean}
- * @api public
- */
- function match$1(el, selector) {
- if (vendor$1) return vendor$1.call(el, selector);
- var nodes = el.parentNode.querySelectorAll(selector);
- for (var i = 0; i < nodes.length; ++i) {
- if (nodes[i] == el) return true;
- }
- return false;
- }
- var closest$1 = function (element, selector, checkYoSelf) {
- var parent = checkYoSelf ? element : element.parentNode;
- while (parent && parent !== document) {
- if (matchesSelector$1(parent, selector)) return parent;
- parent = parent.parentNode;
- }
- };
- var bind$1 = window.addEventListener ? 'addEventListener' : 'attachEvent',
- unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent',
- prefix = bind$1 !== 'addEventListener' ? 'on' : '';
- /**
- * Bind `el` event `type` to `fn`.
- *
- * @param {Element} el
- * @param {String} type
- * @param {Function} fn
- * @param {Boolean} capture
- * @return {Function}
- * @api public
- */
- var bind_1 = function(el, type, fn, capture){
- el[bind$1](prefix + type, fn, capture || false);
- return fn;
- };
- /**
- * Unbind `el` event `type`'s callback `fn`.
- *
- * @param {Element} el
- * @param {String} type
- * @param {Function} fn
- * @param {Boolean} capture
- * @return {Function}
- * @api public
- */
- var unbind_1 = function(el, type, fn, capture){
- el[unbind](prefix + type, fn, capture || false);
- return fn;
- };
- var componentEvent = {
- bind: bind_1,
- unbind: unbind_1
- };
- /**
- * Module dependencies.
- */
- /**
- * Delegate event `type` to `selector`
- * and invoke `fn(e)`. A callback function
- * is returned which may be passed to `.unbind()`.
- *
- * @param {Element} el
- * @param {String} selector
- * @param {String} type
- * @param {Function} fn
- * @param {Boolean} capture
- * @return {Function}
- * @api public
- */
- // Some events don't bubble, so we want to bind to the capture phase instead
- // when delegating.
- var forceCaptureEvents = ['focus', 'blur'];
- var bind$1$1 = function(el, selector, type, fn, capture){
- if (forceCaptureEvents.indexOf(type) !== -1) capture = true;
- return componentEvent.bind(el, type, function(e){
- var target = e.target || e.srcElement;
- e.delegateTarget = closest$1(target, selector, true);
- if (e.delegateTarget) fn.call(el, e);
- }, capture);
- };
- /**
- * Unbind event `type`'s callback `fn`.
- *
- * @param {Element} el
- * @param {String} type
- * @param {Function} fn
- * @param {Boolean} capture
- * @api public
- */
- var unbind$1 = function(el, type, fn, capture){
- if (forceCaptureEvents.indexOf(type) !== -1) capture = true;
- componentEvent.unbind(el, type, fn, capture);
- };
- var delegateEvents = {
- bind: bind$1$1,
- unbind: unbind$1
- };
- /**
- * Expose `parse`.
- */
- var domify = parse$1;
- /**
- * Tests for browser support.
- */
- var innerHTMLBug = false;
- var bugTestDiv;
- if (typeof document !== 'undefined') {
- bugTestDiv = document.createElement('div');
- // Setup
- bugTestDiv.innerHTML = ' <link/><table></table><a href="/a">a</a><input type="checkbox"/>';
- // Make sure that link elements get serialized correctly by innerHTML
- // This requires a wrapper element in IE
- innerHTMLBug = !bugTestDiv.getElementsByTagName('link').length;
- bugTestDiv = undefined;
- }
- /**
- * Wrap map from jquery.
- */
- var map$1 = {
- legend: [1, '<fieldset>', '</fieldset>'],
- tr: [2, '<table><tbody>', '</tbody></table>'],
- col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
- // for script/link/style tags to work in IE6-8, you have to wrap
- // in a div with a non-whitespace character in front, ha!
- _default: innerHTMLBug ? [1, 'X<div>', '</div>'] : [0, '', '']
- };
- map$1.td =
- map$1.th = [3, '<table><tbody><tr>', '</tr></tbody></table>'];
- map$1.option =
- map$1.optgroup = [1, '<select multiple="multiple">', '</select>'];
- map$1.thead =
- map$1.tbody =
- map$1.colgroup =
- map$1.caption =
- map$1.tfoot = [1, '<table>', '</table>'];
- map$1.polyline =
- map$1.ellipse =
- map$1.polygon =
- map$1.circle =
- map$1.text =
- map$1.line =
- map$1.path =
- map$1.rect =
- map$1.g = [1, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">','</svg>'];
- /**
- * Parse `html` and return a DOM Node instance, which could be a TextNode,
- * HTML DOM Node of some kind (<div> for example), or a DocumentFragment
- * instance, depending on the contents of the `html` string.
- *
- * @param {String} html - HTML string to "domify"
- * @param {Document} doc - The `document` instance to create the Node for
- * @return {DOMNode} the TextNode, DOM Node, or DocumentFragment instance
- * @api private
- */
- function parse$1(html, doc) {
- if ('string' != typeof html) throw new TypeError('String expected');
- // default to the global `document` object
- if (!doc) doc = document;
- // tag name
- var m = /<([\w:]+)/.exec(html);
- if (!m) return doc.createTextNode(html);
- html = html.replace(/^\s+|\s+$/g, ''); // Remove leading/trailing whitespace
- var tag = m[1];
- // body support
- if (tag == 'body') {
- var el = doc.createElement('html');
- el.innerHTML = html;
- return el.removeChild(el.lastChild);
- }
- // wrap map
- var wrap = map$1[tag] || map$1._default;
- var depth = wrap[0];
- var prefix = wrap[1];
- var suffix = wrap[2];
- var el = doc.createElement('div');
- el.innerHTML = prefix + html + suffix;
- while (depth--) el = el.lastChild;
- // one element
- if (el.firstChild == el.lastChild) {
- return el.removeChild(el.firstChild);
- }
- // several elements
- var fragment = doc.createDocumentFragment();
- while (el.firstChild) {
- fragment.appendChild(el.removeChild(el.firstChild));
- }
- return fragment;
- }
- function query(selector, el) {
- el = el || document;
- return el.querySelector(selector);
- }
- function all(selector, el) {
- el = el || document;
- return el.querySelectorAll(selector);
- }
- function remove$1(el) {
- el.parentNode && el.parentNode.removeChild(el);
- }
- /**
- * @param {<SVGElement>} element
- * @param {number} x
- * @param {number} y
- * @param {number} angle
- * @param {number} amount
- */
- function transform$1(gfx, x, y, angle, amount) {
- var translate = createTransform();
- translate.setTranslate(x, y);
- var rotate = createTransform();
- rotate.setRotate(angle || 0, 0, 0);
- var scale = createTransform();
- scale.setScale(amount || 1, amount || 1);
- transform(gfx, [ translate, rotate, scale ]);
- }
- /**
- * @param {SVGElement} element
- * @param {number} x
- * @param {number} y
- */
- function translate(gfx, x, y) {
- var translate = createTransform();
- translate.setTranslate(x, y);
- transform(gfx, translate);
- }
- /**
- * @param {SVGElement} element
- * @param {number} angle
- */
- function rotate(gfx, angle) {
- var rotate = createTransform();
- rotate.setRotate(angle, 0, 0);
- transform(gfx, rotate);
- }
- function createCommonjsModule$1(fn, module) {
- return module = { exports: {} }, fn(module, module.exports), module.exports;
- }
- var hat_1 = createCommonjsModule$1(function (module) {
- var hat = module.exports = function (bits, base) {
- if (!base) base = 16;
- if (bits === undefined) bits = 128;
- if (bits <= 0) return '0';
-
- var digits = Math.log(Math.pow(2, bits)) / Math.log(base);
- for (var i = 2; digits === Infinity; i *= 2) {
- digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i;
- }
-
- var rem = digits - Math.floor(digits);
-
- var res = '';
-
- for (var i = 0; i < Math.floor(digits); i++) {
- var x = Math.floor(Math.random() * base).toString(base);
- res = x + res;
- }
-
- if (rem) {
- var b = Math.pow(base, rem);
- var x = Math.floor(Math.random() * b).toString(base);
- res = x + res;
- }
-
- var parsed = parseInt(res, base);
- if (parsed !== Infinity && parsed >= Math.pow(2, bits)) {
- return hat(bits, base)
- }
- else return res;
- };
- hat.rack = function (bits, base, expandBy) {
- var fn = function (data) {
- var iters = 0;
- do {
- if (iters ++ > 10) {
- if (expandBy) bits += expandBy;
- else throw new Error('too many ID collisions, use more bits')
- }
-
- var id = hat(bits, base);
- } while (Object.hasOwnProperty.call(hats, id));
-
- hats[id] = data;
- return id;
- };
- var hats = fn.hats = {};
-
- fn.get = function (id) {
- return fn.hats[id];
- };
-
- fn.set = function (id, value) {
- fn.hats[id] = value;
- return fn;
- };
-
- fn.bits = bits || 128;
- fn.base = base || 16;
- return fn;
- };
- });
- /**
- * Create a new id generator / cache instance.
- *
- * You may optionally provide a seed that is used internally.
- *
- * @param {Seed} seed
- */
- function Ids(seed) {
- if (!(this instanceof Ids)) {
- return new Ids(seed);
- }
- seed = seed || [128, 36, 1];
- this._seed = seed.length ? hat_1.rack(seed[0], seed[1], seed[2]) : seed;
- }
- /**
- * Generate a next id.
- *
- * @param {Object} [element] element to bind the id to
- *
- * @return {String} id
- */
- Ids.prototype.next = function (element) {
- return this._seed(element || true);
- };
- /**
- * Generate a next id with a given prefix.
- *
- * @param {Object} [element] element to bind the id to
- *
- * @return {String} id
- */
- Ids.prototype.nextPrefixed = function (prefix, element) {
- var id;
- do {
- id = prefix + this.next(true);
- } while (this.assigned(id)); // claim {prefix}{random}
- this.claim(id, element); // return
- return id;
- };
- /**
- * Manually claim an existing id.
- *
- * @param {String} id
- * @param {String} [element] element the id is claimed by
- */
- Ids.prototype.claim = function (id, element) {
- this._seed.set(id, element || true);
- };
- /**
- * Returns true if the given id has already been assigned.
- *
- * @param {String} id
- * @return {Boolean}
- */
- Ids.prototype.assigned = function (id) {
- return this._seed.get(id) || false;
- };
- /**
- * Unclaim an id.
- *
- * @param {String} id the id to unclaim
- */
- Ids.prototype.unclaim = function (id) {
- delete this._seed.hats[id];
- };
- /**
- * Clear all claimed ids.
- */
- Ids.prototype.clear = function () {
- var hats = this._seed.hats,
- id;
- for (id in hats) {
- this.unclaim(id);
- }
- };
- var RENDERER_IDS = new Ids();
- var TASK_BORDER_RADIUS = 10;
- var INNER_OUTER_DIST = 3;
- var DEFAULT_FILL_OPACITY = .95,
- HIGH_FILL_OPACITY = .35;
- function BpmnRenderer(
- config, eventBus, styles, pathMap,
- canvas, textRenderer, priority) {
- BaseRenderer.call(this, eventBus, priority);
- var defaultFillColor = config && config.defaultFillColor,
- defaultStrokeColor = config && config.defaultStrokeColor;
- var rendererId = RENDERER_IDS.next();
- var markers = {};
- var computeStyle = styles.computeStyle;
- function addMarker(id, options) {
- var attrs = assign({
- fill: 'black',
- strokeWidth: 1,
- strokeLinecap: 'round',
- strokeDasharray: 'none'
- }, options.attrs);
- var ref = options.ref || { x: 0, y: 0 };
- var scale = options.scale || 1;
- // fix for safari / chrome / firefox bug not correctly
- // resetting stroke dash array
- if (attrs.strokeDasharray === 'none') {
- attrs.strokeDasharray = [10000, 1];
- }
- var marker = create('marker');
- attr(options.element, attrs);
- append(marker, options.element);
- attr(marker, {
- id: id,
- viewBox: '0 0 20 20',
- refX: ref.x,
- refY: ref.y,
- markerWidth: 20 * scale,
- markerHeight: 20 * scale,
- orient: 'auto'
- });
- var defs = query('defs', canvas._svg);
- if (!defs) {
- defs = create('defs');
- append(canvas._svg, defs);
- }
- append(defs, marker);
- markers[id] = marker;
- }
- function colorEscape(str) {
- // only allow characters and numbers
- return str.replace(/[^0-9a-zA-z]+/g, '_');
- }
- function marker(type, fill, stroke) {
- var id = type + '-' + colorEscape(fill) + '-' + colorEscape(stroke) + '-' + rendererId;
- if (!markers[id]) {
- createMarker(id, type, fill, stroke);
- }
- return 'url(#' + id + ')';
- }
- function createMarker(id, type, fill, stroke) {
- if (type === 'sequenceflow-end') {
- var sequenceflowEnd = create('path');
- attr(sequenceflowEnd, { d: 'M 1 5 L 11 10 L 1 15 Z' });
- addMarker(id, {
- element: sequenceflowEnd,
- ref: { x: 11, y: 10 },
- scale: 0.5,
- attrs: {
- fill: stroke,
- stroke: stroke
- }
- });
- }
- if (type === 'messageflow-start') {
- var messageflowStart = create('circle');
- attr(messageflowStart, { cx: 6, cy: 6, r: 3.5 });
- addMarker(id, {
- element: messageflowStart,
- attrs: {
- fill: fill,
- stroke: stroke
- },
- ref: { x: 6, y: 6 }
- });
- }
- if (type === 'messageflow-end') {
- var messageflowEnd = create('path');
- attr(messageflowEnd, { d: 'm 1 5 l 0 -3 l 7 3 l -7 3 z' });
- addMarker(id, {
- element: messageflowEnd,
- attrs: {
- fill: fill,
- stroke: stroke,
- strokeLinecap: 'butt'
- },
- ref: { x: 8.5, y: 5 }
- });
- }
- if (type === 'association-start') {
- var associationStart = create('path');
- attr(associationStart, { d: 'M 11 5 L 1 10 L 11 15' });
- addMarker(id, {
- element: associationStart,
- attrs: {
- fill: 'none',
- stroke: stroke,
- strokeWidth: 1.5
- },
- ref: { x: 1, y: 10 },
- scale: 0.5
- });
- }
- if (type === 'association-end') {
- var associationEnd = create('path');
- attr(associationEnd, { d: 'M 1 5 L 11 10 L 1 15' });
- addMarker(id, {
- element: associationEnd,
- attrs: {
- fill: 'none',
- stroke: stroke,
- strokeWidth: 1.5
- },
- ref: { x: 12, y: 10 },
- scale: 0.5
- });
- }
- if (type === 'conditional-flow-marker') {
- var conditionalflowMarker = create('path');
- attr(conditionalflowMarker, { d: 'M 0 10 L 8 6 L 16 10 L 8 14 Z' });
- addMarker(id, {
- element: conditionalflowMarker,
- attrs: {
- fill: fill,
- stroke: stroke
- },
- ref: { x: -1, y: 10 },
- scale: 0.5
- });
- }
- if (type === 'conditional-default-flow-marker') {
- var conditionaldefaultflowMarker = create('path');
- attr(conditionaldefaultflowMarker, { d: 'M 6 4 L 10 16' });
- addMarker(id, {
- element: conditionaldefaultflowMarker,
- attrs: {
- stroke: stroke
- },
- ref: { x: 0, y: 10 },
- scale: 0.5
- });
- }
- }
- function drawCircle(parentGfx, width, height, offset, attrs) {
- if (isObject(offset)) {
- attrs = offset;
- offset = 0;
- }
- offset = offset || 0;
- attrs = computeStyle(attrs, {
- stroke: 'black',
- strokeWidth: 2,
- fill: 'white'
- });
- if (attrs.fill === 'none') {
- delete attrs.fillOpacity;
- }
- var cx = width / 2,
- cy = height / 2;
- var circle = create('circle');
- attr(circle, {
- cx: cx,
- cy: cy,
- r: Math.round((width + height) / 4 - offset)
- });
- attr(circle, attrs);
- append(parentGfx, circle);
- return circle;
- }
- function drawRect(parentGfx, width, height, r, offset, attrs) {
- if (isObject(offset)) {
- attrs = offset;
- offset = 0;
- }
- offset = offset || 0;
- attrs = computeStyle(attrs, {
- stroke: 'black',
- strokeWidth: 2,
- fill: 'white'
- });
- var rect = create('rect');
- attr(rect, {
- x: offset,
- y: offset,
- width: width - offset * 2,
- height: height - offset * 2,
- rx: r,
- ry: r
- });
- attr(rect, attrs);
- append(parentGfx, rect);
- return rect;
- }
- function drawDiamond(parentGfx, width, height, attrs) {
- var x_2 = width / 2;
- var y_2 = height / 2;
- var points = [{ x: x_2, y: 0 }, { x: width, y: y_2 }, { x: x_2, y: height }, { x: 0, y: y_2 }];
- var pointsString = points.map(function(point) {
- return point.x + ',' + point.y;
- }).join(' ');
- attrs = computeStyle(attrs, {
- stroke: 'black',
- strokeWidth: 2,
- fill: 'white'
- });
- var polygon = create('polygon');
- attr(polygon, {
- points: pointsString
- });
- attr(polygon, attrs);
- append(parentGfx, polygon);
- return polygon;
- }
- function drawLine(parentGfx, waypoints, attrs) {
- attrs = computeStyle(attrs, [ 'no-fill' ], {
- stroke: 'black',
- strokeWidth: 2,
- fill: 'none'
- });
- var line = createLine(waypoints, attrs);
- append(parentGfx, line);
- return line;
- }
- function drawPath(parentGfx, d, attrs) {
- attrs = computeStyle(attrs, [ 'no-fill' ], {
- strokeWidth: 2,
- stroke: 'black'
- });
- var path = create('path');
- attr(path, { d: d });
- attr(path, attrs);
- append(parentGfx, path);
- return path;
- }
- function drawMarker(type, parentGfx, path, attrs) {
- return drawPath(parentGfx, path, assign({ 'data-marker': type }, attrs));
- }
- function as(type) {
- return function(parentGfx, element) {
- return handlers[type](parentGfx, element);
- };
- }
- function renderer(type) {
- return handlers[type];
- }
- function renderEventContent(element, parentGfx) {
- var event = getSemantic(element);
- var isThrowing = isThrowEvent(event);
- if (event.eventDefinitions && event.eventDefinitions.length>1) {
- if (event.parallelMultiple) {
- return renderer('bpmn:ParallelMultipleEventDefinition')(parentGfx, element, isThrowing);
- }
- else {
- return renderer('bpmn:MultipleEventDefinition')(parentGfx, element, isThrowing);
- }
- }
- if (isTypedEvent(event, 'bpmn:MessageEventDefinition')) {
- return renderer('bpmn:MessageEventDefinition')(parentGfx, element, isThrowing);
- }
- if (isTypedEvent(event, 'bpmn:TimerEventDefinition')) {
- return renderer('bpmn:TimerEventDefinition')(parentGfx, element, isThrowing);
- }
- if (isTypedEvent(event, 'bpmn:ConditionalEventDefinition')) {
- return renderer('bpmn:ConditionalEventDefinition')(parentGfx, element);
- }
- if (isTypedEvent(event, 'bpmn:SignalEventDefinition')) {
- return renderer('bpmn:SignalEventDefinition')(parentGfx, element, isThrowing);
- }
- if (isTypedEvent(event, 'bpmn:EscalationEventDefinition')) {
- return renderer('bpmn:EscalationEventDefinition')(parentGfx, element, isThrowing);
- }
- if (isTypedEvent(event, 'bpmn:LinkEventDefinition')) {
- return renderer('bpmn:LinkEventDefinition')(parentGfx, element, isThrowing);
- }
- if (isTypedEvent(event, 'bpmn:ErrorEventDefinition')) {
- return renderer('bpmn:ErrorEventDefinition')(parentGfx, element, isThrowing);
- }
- if (isTypedEvent(event, 'bpmn:CancelEventDefinition')) {
- return renderer('bpmn:CancelEventDefinition')(parentGfx, element, isThrowing);
- }
- if (isTypedEvent(event, 'bpmn:CompensateEventDefinition')) {
- return renderer('bpmn:CompensateEventDefinition')(parentGfx, element, isThrowing);
- }
- if (isTypedEvent(event, 'bpmn:TerminateEventDefinition')) {
- return renderer('bpmn:TerminateEventDefinition')(parentGfx, element, isThrowing);
- }
- return null;
- }
- function renderLabel(parentGfx, label, options) {
- options = assign({
- size: {
- width: 100
- }
- }, options);
- var text = textRenderer.createText(label || '', options);
- classes(text).add('djs-label');
- append(parentGfx, text);
- return text;
- }
- function renderEmbeddedLabel(parentGfx, element, align) {
- var semantic = getSemantic(element);
- return renderLabel(parentGfx, semantic.name, {
- box: element,
- align: align,
- padding: 5,
- style: {
- fill: getStrokeColor(element, defaultStrokeColor)
- }
- });
- }
- function renderExternalLabel(parentGfx, element) {
- var box = {
- width: 90,
- height: 30,
- x: element.width / 2 + element.x,
- y: element.height / 2 + element.y
- };
- return renderLabel(parentGfx, getLabel(element), {
- box: box,
- fitBox: true,
- style: assign(
- {},
- textRenderer.getExternalStyle(),
- {
- fill: getStrokeColor(element, defaultStrokeColor)
- }
- )
- });
- }
- function renderLaneLabel(parentGfx, text, element) {
- var textBox = renderLabel(parentGfx, text, {
- box: {
- height: 30,
- width: element.height
- },
- align: 'center-middle',
- style: {
- fill: getStrokeColor(element, defaultStrokeColor)
- }
- });
- var top = -1 * element.height;
- transform$1(textBox, 0, -top, 270);
- }
- function createPathFromConnection(connection) {
- var waypoints = connection.waypoints;
- var pathData = 'm ' + waypoints[0].x + ',' + waypoints[0].y;
- for (var i = 1; i < waypoints.length; i++) {
- pathData += 'L' + waypoints[i].x + ',' + waypoints[i].y + ' ';
- }
- return pathData;
- }
- var handlers = this.handlers = {
- 'bpmn:Event': function(parentGfx, element, attrs) {
- if (!('fillOpacity' in attrs)) {
- attrs.fillOpacity = DEFAULT_FILL_OPACITY;
- }
- return drawCircle(parentGfx, element.width, element.height, attrs);
- },
- 'bpmn:StartEvent': function(parentGfx, element) {
- var attrs = {
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- };
- var semantic = getSemantic(element);
- if (!semantic.isInterrupting) {
- attrs = {
- strokeDasharray: '6',
- strokeLinecap: 'round',
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- };
- }
- var circle = renderer('bpmn:Event')(parentGfx, element, attrs);
- renderEventContent(element, parentGfx);
- return circle;
- },
- 'bpmn:MessageEventDefinition': function(parentGfx, element, isThrowing) {
- var pathData = pathMap.getScaledPath('EVENT_MESSAGE', {
- xScaleFactor: 0.9,
- yScaleFactor: 0.9,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: 0.235,
- my: 0.315
- }
- });
- var fill = isThrowing ? getStrokeColor(element, defaultStrokeColor) : getFillColor(element, defaultFillColor);
- var stroke = isThrowing ? getFillColor(element, defaultFillColor) : getStrokeColor(element, defaultStrokeColor);
- var messagePath = drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: fill,
- stroke: stroke
- });
- return messagePath;
- },
- 'bpmn:TimerEventDefinition': function(parentGfx, element) {
- var circle = drawCircle(parentGfx, element.width, element.height, 0.2 * element.height, {
- strokeWidth: 2,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- var pathData = pathMap.getScaledPath('EVENT_TIMER_WH', {
- xScaleFactor: 0.75,
- yScaleFactor: 0.75,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: 0.5,
- my: 0.5
- }
- });
- drawPath(parentGfx, pathData, {
- strokeWidth: 2,
- strokeLinecap: 'square',
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- for (var i = 0;i < 12; i++) {
- var linePathData = pathMap.getScaledPath('EVENT_TIMER_LINE', {
- xScaleFactor: 0.75,
- yScaleFactor: 0.75,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: 0.5,
- my: 0.5
- }
- });
- var width = element.width / 2;
- var height = element.height / 2;
- drawPath(parentGfx, linePathData, {
- strokeWidth: 1,
- strokeLinecap: 'square',
- transform: 'rotate(' + (i * 30) + ',' + height + ',' + width + ')',
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- }
- return circle;
- },
- 'bpmn:EscalationEventDefinition': function(parentGfx, event, isThrowing) {
- var pathData = pathMap.getScaledPath('EVENT_ESCALATION', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: event.width,
- containerHeight: event.height,
- position: {
- mx: 0.5,
- my: 0.2
- }
- });
- var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
- return drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: fill,
- stroke: getStrokeColor(event, defaultStrokeColor)
- });
- },
- 'bpmn:ConditionalEventDefinition': function(parentGfx, event) {
- var pathData = pathMap.getScaledPath('EVENT_CONDITIONAL', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: event.width,
- containerHeight: event.height,
- position: {
- mx: 0.5,
- my: 0.222
- }
- });
- return drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- stroke: getStrokeColor(event, defaultStrokeColor)
- });
- },
- 'bpmn:LinkEventDefinition': function(parentGfx, event, isThrowing) {
- var pathData = pathMap.getScaledPath('EVENT_LINK', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: event.width,
- containerHeight: event.height,
- position: {
- mx: 0.57,
- my: 0.263
- }
- });
- var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
- return drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: fill,
- stroke: getStrokeColor(event, defaultStrokeColor)
- });
- },
- 'bpmn:ErrorEventDefinition': function(parentGfx, event, isThrowing) {
- var pathData = pathMap.getScaledPath('EVENT_ERROR', {
- xScaleFactor: 1.1,
- yScaleFactor: 1.1,
- containerWidth: event.width,
- containerHeight: event.height,
- position: {
- mx: 0.2,
- my: 0.722
- }
- });
- var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
- return drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: fill,
- stroke: getStrokeColor(event, defaultStrokeColor)
- });
- },
- 'bpmn:CancelEventDefinition': function(parentGfx, event, isThrowing) {
- var pathData = pathMap.getScaledPath('EVENT_CANCEL_45', {
- xScaleFactor: 1.0,
- yScaleFactor: 1.0,
- containerWidth: event.width,
- containerHeight: event.height,
- position: {
- mx: 0.638,
- my: -0.055
- }
- });
- var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
- var path = drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: fill,
- stroke: getStrokeColor(event, defaultStrokeColor)
- });
- rotate(path, 45);
- return path;
- },
- 'bpmn:CompensateEventDefinition': function(parentGfx, event, isThrowing) {
- var pathData = pathMap.getScaledPath('EVENT_COMPENSATION', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: event.width,
- containerHeight: event.height,
- position: {
- mx: 0.22,
- my: 0.5
- }
- });
- var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
- return drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: fill,
- stroke: getStrokeColor(event, defaultStrokeColor)
- });
- },
- 'bpmn:SignalEventDefinition': function(parentGfx, event, isThrowing) {
- var pathData = pathMap.getScaledPath('EVENT_SIGNAL', {
- xScaleFactor: 0.9,
- yScaleFactor: 0.9,
- containerWidth: event.width,
- containerHeight: event.height,
- position: {
- mx: 0.5,
- my: 0.2
- }
- });
- var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
- return drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: fill,
- stroke: getStrokeColor(event, defaultStrokeColor)
- });
- },
- 'bpmn:MultipleEventDefinition': function(parentGfx, event, isThrowing) {
- var pathData = pathMap.getScaledPath('EVENT_MULTIPLE', {
- xScaleFactor: 1.1,
- yScaleFactor: 1.1,
- containerWidth: event.width,
- containerHeight: event.height,
- position: {
- mx: 0.222,
- my: 0.36
- }
- });
- var fill = isThrowing ? getStrokeColor(event, defaultStrokeColor) : 'none';
- return drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: fill
- });
- },
- 'bpmn:ParallelMultipleEventDefinition': function(parentGfx, event) {
- var pathData = pathMap.getScaledPath('EVENT_PARALLEL_MULTIPLE', {
- xScaleFactor: 1.2,
- yScaleFactor: 1.2,
- containerWidth: event.width,
- containerHeight: event.height,
- position: {
- mx: 0.458,
- my: 0.194
- }
- });
- return drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: getStrokeColor(event, defaultStrokeColor),
- stroke: getStrokeColor(event, defaultStrokeColor)
- });
- },
- 'bpmn:EndEvent': function(parentGfx, element) {
- var circle = renderer('bpmn:Event')(parentGfx, element, {
- strokeWidth: 4,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- renderEventContent(element, parentGfx);
- return circle;
- },
- 'bpmn:TerminateEventDefinition': function(parentGfx, element) {
- var circle = drawCircle(parentGfx, element.width, element.height, 8, {
- strokeWidth: 4,
- fill: getStrokeColor(element, defaultStrokeColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- return circle;
- },
- 'bpmn:IntermediateEvent': function(parentGfx, element) {
- var outer = renderer('bpmn:Event')(parentGfx, element, {
- strokeWidth: 1,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- /* inner */
- drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, {
- strokeWidth: 1,
- fill: getFillColor(element, 'none'),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- renderEventContent(element, parentGfx);
- return outer;
- },
- 'bpmn:IntermediateCatchEvent': as('bpmn:IntermediateEvent'),
- 'bpmn:IntermediateThrowEvent': as('bpmn:IntermediateEvent'),
- 'bpmn:Activity': function(parentGfx, element, attrs) {
- attrs = attrs || {};
- if (!('fillOpacity' in attrs)) {
- attrs.fillOpacity = DEFAULT_FILL_OPACITY;
- }
- return drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, attrs);
- },
- 'bpmn:Task': function(parentGfx, element) {
- var attrs = {
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- };
- var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
- renderEmbeddedLabel(parentGfx, element, 'center-middle');
- attachTaskMarkers(parentGfx, element);
- return rect;
- },
- 'bpmn:ServiceTask': function(parentGfx, element) {
- var task = renderer('bpmn:Task')(parentGfx, element);
- var pathDataBG = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
- abspos: {
- x: 12,
- y: 18
- }
- });
- /* service bg */ drawPath(parentGfx, pathDataBG, {
- strokeWidth: 1,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- var fillPathData = pathMap.getScaledPath('TASK_TYPE_SERVICE_FILL', {
- abspos: {
- x: 17.2,
- y: 18
- }
- });
- /* service fill */ drawPath(parentGfx, fillPathData, {
- strokeWidth: 0,
- fill: getFillColor(element, defaultFillColor)
- });
- var pathData = pathMap.getScaledPath('TASK_TYPE_SERVICE', {
- abspos: {
- x: 17,
- y: 22
- }
- });
- /* service */ drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- return task;
- },
- 'bpmn:UserTask': function(parentGfx, element) {
- var task = renderer('bpmn:Task')(parentGfx, element);
- var x = 15;
- var y = 12;
- var pathData = pathMap.getScaledPath('TASK_TYPE_USER_1', {
- abspos: {
- x: x,
- y: y
- }
- });
- /* user path */ drawPath(parentGfx, pathData, {
- strokeWidth: 0.5,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- var pathData2 = pathMap.getScaledPath('TASK_TYPE_USER_2', {
- abspos: {
- x: x,
- y: y
- }
- });
- /* user2 path */ drawPath(parentGfx, pathData2, {
- strokeWidth: 0.5,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- var pathData3 = pathMap.getScaledPath('TASK_TYPE_USER_3', {
- abspos: {
- x: x,
- y: y
- }
- });
- /* user3 path */ drawPath(parentGfx, pathData3, {
- strokeWidth: 0.5,
- fill: getStrokeColor(element, defaultStrokeColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- return task;
- },
- 'bpmn:ManualTask': function(parentGfx, element) {
- var task = renderer('bpmn:Task')(parentGfx, element);
- var pathData = pathMap.getScaledPath('TASK_TYPE_MANUAL', {
- abspos: {
- x: 17,
- y: 15
- }
- });
- /* manual path */ drawPath(parentGfx, pathData, {
- strokeWidth: 0.5, // 0.25,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- return task;
- },
- 'bpmn:SendTask': function(parentGfx, element) {
- var task = renderer('bpmn:Task')(parentGfx, element);
- var pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: 21,
- containerHeight: 14,
- position: {
- mx: 0.285,
- my: 0.357
- }
- });
- /* send path */ drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: getStrokeColor(element, defaultStrokeColor),
- stroke: getFillColor(element, defaultFillColor)
- });
- return task;
- },
- 'bpmn:ReceiveTask' : function(parentGfx, element) {
- var semantic = getSemantic(element);
- var task = renderer('bpmn:Task')(parentGfx, element);
- var pathData;
- if (semantic.instantiate) {
- drawCircle(parentGfx, 28, 28, 20 * 0.22, { strokeWidth: 1 });
- pathData = pathMap.getScaledPath('TASK_TYPE_INSTANTIATING_SEND', {
- abspos: {
- x: 7.77,
- y: 9.52
- }
- });
- } else {
- pathData = pathMap.getScaledPath('TASK_TYPE_SEND', {
- xScaleFactor: 0.9,
- yScaleFactor: 0.9,
- containerWidth: 21,
- containerHeight: 14,
- position: {
- mx: 0.3,
- my: 0.4
- }
- });
- }
- /* receive path */ drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- return task;
- },
- 'bpmn:ScriptTask': function(parentGfx, element) {
- var task = renderer('bpmn:Task')(parentGfx, element);
- var pathData = pathMap.getScaledPath('TASK_TYPE_SCRIPT', {
- abspos: {
- x: 15,
- y: 20
- }
- });
- /* script path */ drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- return task;
- },
- 'bpmn:BusinessRuleTask': function(parentGfx, element) {
- var task = renderer('bpmn:Task')(parentGfx, element);
- var headerPathData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_HEADER', {
- abspos: {
- x: 8,
- y: 8
- }
- });
- var businessHeaderPath = drawPath(parentGfx, headerPathData);
- attr(businessHeaderPath, {
- strokeWidth: 1,
- fill: getFillColor(element, '#aaaaaa'),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- var headerData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_MAIN', {
- abspos: {
- x: 8,
- y: 8
- }
- });
- var businessPath = drawPath(parentGfx, headerData);
- attr(businessPath, {
- strokeWidth: 1,
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- return task;
- },
- 'bpmn:SubProcess': function(parentGfx, element, attrs) {
- attrs = assign({
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- }, attrs);
- var rect = renderer('bpmn:Activity')(parentGfx, element, attrs);
- var expanded = isExpanded(element);
- if (isEventSubProcess(element)) {
- attr(rect, {
- strokeDasharray: '1,2'
- });
- }
- renderEmbeddedLabel(parentGfx, element, expanded ? 'center-top' : 'center-middle');
- if (expanded) {
- attachTaskMarkers(parentGfx, element);
- } else {
- attachTaskMarkers(parentGfx, element, ['SubProcessMarker']);
- }
- return rect;
- },
- 'bpmn:AdHocSubProcess': function(parentGfx, element) {
- return renderer('bpmn:SubProcess')(parentGfx, element);
- },
- 'bpmn:Transaction': function(parentGfx, element) {
- var outer = renderer('bpmn:SubProcess')(parentGfx, element);
- var innerAttrs = styles.style([ 'no-fill', 'no-events' ], {
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- /* inner path */ drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS - 2, INNER_OUTER_DIST, innerAttrs);
- return outer;
- },
- 'bpmn:CallActivity': function(parentGfx, element) {
- return renderer('bpmn:SubProcess')(parentGfx, element, {
- strokeWidth: 5
- });
- },
- 'bpmn:Participant': function(parentGfx, element) {
- var attrs = {
- fillOpacity: DEFAULT_FILL_OPACITY,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- };
- var lane = renderer('bpmn:Lane')(parentGfx, element, attrs);
- var expandedPool = isExpanded(element);
- if (expandedPool) {
- drawLine(parentGfx, [
- { x: 30, y: 0 },
- { x: 30, y: element.height }
- ], {
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- var text = getSemantic(element).name;
- renderLaneLabel(parentGfx, text, element);
- } else {
- // Collapsed pool draw text inline
- var text2 = getSemantic(element).name;
- renderLabel(parentGfx, text2, {
- box: element, align: 'center-middle',
- style: {
- fill: getStrokeColor(element, defaultStrokeColor)
- }
- });
- }
- var participantMultiplicity = !!(getSemantic(element).participantMultiplicity);
- if (participantMultiplicity) {
- renderer('ParticipantMultiplicityMarker')(parentGfx, element);
- }
- return lane;
- },
- 'bpmn:Lane': function(parentGfx, element, attrs) {
- var rect = drawRect(parentGfx, element.width, element.height, 0, assign({
- fill: getFillColor(element, defaultFillColor),
- fillOpacity: HIGH_FILL_OPACITY,
- stroke: getStrokeColor(element, defaultStrokeColor)
- }, attrs));
- var semantic = getSemantic(element);
- if (semantic.$type === 'bpmn:Lane') {
- var text = semantic.name;
- renderLaneLabel(parentGfx, text, element);
- }
- return rect;
- },
- 'bpmn:InclusiveGateway': function(parentGfx, element) {
- var diamond = renderer('bpmn:Gateway')(parentGfx, element);
- /* circle path */
- drawCircle(parentGfx, element.width, element.height, element.height * 0.24, {
- strokeWidth: 2.5,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- return diamond;
- },
- 'bpmn:ExclusiveGateway': function(parentGfx, element) {
- var diamond = renderer('bpmn:Gateway')(parentGfx, element);
- var pathData = pathMap.getScaledPath('GATEWAY_EXCLUSIVE', {
- xScaleFactor: 0.4,
- yScaleFactor: 0.4,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: 0.32,
- my: 0.3
- }
- });
- if ((getDi(element).isMarkerVisible)) {
- drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: getStrokeColor(element, defaultStrokeColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- }
- return diamond;
- },
- 'bpmn:ComplexGateway': function(parentGfx, element) {
- var diamond = renderer('bpmn:Gateway')(parentGfx, element);
- var pathData = pathMap.getScaledPath('GATEWAY_COMPLEX', {
- xScaleFactor: 0.5,
- yScaleFactor:0.5,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: 0.46,
- my: 0.26
- }
- });
- /* complex path */ drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: getStrokeColor(element, defaultStrokeColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- return diamond;
- },
- 'bpmn:ParallelGateway': function(parentGfx, element) {
- var diamond = renderer('bpmn:Gateway')(parentGfx, element);
- var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
- xScaleFactor: 0.6,
- yScaleFactor:0.6,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: 0.46,
- my: 0.2
- }
- });
- /* parallel path */ drawPath(parentGfx, pathData, {
- strokeWidth: 1,
- fill: getStrokeColor(element, defaultStrokeColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- return diamond;
- },
- 'bpmn:EventBasedGateway': function(parentGfx, element) {
- var semantic = getSemantic(element);
- var diamond = renderer('bpmn:Gateway')(parentGfx, element);
- /* outer circle path */ drawCircle(parentGfx, element.width, element.height, element.height * 0.20, {
- strokeWidth: 1,
- fill: 'none',
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- var type = semantic.eventGatewayType;
- var instantiate = !!semantic.instantiate;
- function drawEvent() {
- var pathData = pathMap.getScaledPath('GATEWAY_EVENT_BASED', {
- xScaleFactor: 0.18,
- yScaleFactor: 0.18,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: 0.36,
- my: 0.44
- }
- });
- var attrs = {
- strokeWidth: 2,
- fill: getFillColor(element, 'none'),
- stroke: getStrokeColor(element, defaultStrokeColor)
- };
- /* event path */ drawPath(parentGfx, pathData, attrs);
- }
- if (type === 'Parallel') {
- var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', {
- xScaleFactor: 0.4,
- yScaleFactor:0.4,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: 0.474,
- my: 0.296
- }
- });
- var parallelPath = drawPath(parentGfx, pathData);
- attr(parallelPath, {
- strokeWidth: 1,
- fill: 'none'
- });
- } else if (type === 'Exclusive') {
- if (!instantiate) {
- var innerCircle = drawCircle(parentGfx, element.width, element.height, element.height * 0.26);
- attr(innerCircle, {
- strokeWidth: 1,
- fill: 'none',
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- }
- drawEvent();
- }
- return diamond;
- },
- 'bpmn:Gateway': function(parentGfx, element) {
- var attrs = {
- fill: getFillColor(element, defaultFillColor),
- fillOpacity: DEFAULT_FILL_OPACITY,
- stroke: getStrokeColor(element, defaultStrokeColor)
- };
- return drawDiamond(parentGfx, element.width, element.height, attrs);
- },
- 'bpmn:SequenceFlow': function(parentGfx, element) {
- var pathData = createPathFromConnection(element);
- var fill = getFillColor(element, defaultFillColor),
- stroke = getStrokeColor(element, defaultStrokeColor);
- var attrs = {
- strokeLinejoin: 'round',
- markerEnd: marker('sequenceflow-end', fill, stroke),
- stroke: getStrokeColor(element, defaultStrokeColor)
- };
- var path = drawPath(parentGfx, pathData, attrs);
- var sequenceFlow = getSemantic(element);
- var source;
- if (element.source) {
- source = element.source.businessObject;
- // conditional flow marker
- if (sequenceFlow.conditionExpression && source.$instanceOf('bpmn:Activity')) {
- attr(path, {
- markerStart: marker('conditional-flow-marker', fill, stroke)
- });
- }
- // default marker
- if (source.default && (source.$instanceOf('bpmn:Gateway') || source.$instanceOf('bpmn:Activity')) &&
- source.default === sequenceFlow) {
- attr(path, {
- markerStart: marker('conditional-default-flow-marker', fill, stroke)
- });
- }
- }
- return path;
- },
- 'bpmn:Association': function(parentGfx, element, attrs) {
- var semantic = getSemantic(element);
- var fill = getFillColor(element, defaultFillColor),
- stroke = getStrokeColor(element, defaultStrokeColor);
- attrs = assign({
- strokeDasharray: '0.5, 5',
- strokeLinecap: 'round',
- strokeLinejoin: 'round',
- stroke: getStrokeColor(element, defaultStrokeColor)
- }, attrs || {});
- if (semantic.associationDirection === 'One' ||
- semantic.associationDirection === 'Both') {
- attrs.markerEnd = marker('association-end', fill, stroke);
- }
- if (semantic.associationDirection === 'Both') {
- attrs.markerStart = marker('association-start', fill, stroke);
- }
- return drawLine(parentGfx, element.waypoints, attrs);
- },
- 'bpmn:DataInputAssociation': function(parentGfx, element) {
- var fill = getFillColor(element, defaultFillColor),
- stroke = getStrokeColor(element, defaultStrokeColor);
- return renderer('bpmn:Association')(parentGfx, element, {
- markerEnd: marker('association-end', fill, stroke)
- });
- },
- 'bpmn:DataOutputAssociation': function(parentGfx, element) {
- var fill = getFillColor(element, defaultFillColor),
- stroke = getStrokeColor(element, defaultStrokeColor);
- return renderer('bpmn:Association')(parentGfx, element, {
- markerEnd: marker('association-end', fill, stroke)
- });
- },
- 'bpmn:MessageFlow': function(parentGfx, element) {
- var semantic = getSemantic(element),
- di = getDi(element);
- var fill = getFillColor(element, defaultFillColor),
- stroke = getStrokeColor(element, defaultStrokeColor);
- var pathData = createPathFromConnection(element);
- var attrs = {
- markerEnd: marker('messageflow-end', fill, stroke),
- markerStart: marker('messageflow-start', fill, stroke),
- strokeDasharray: '10, 12',
- strokeLinecap: 'round',
- strokeLinejoin: 'round',
- strokeWidth: '1.5px',
- stroke: getStrokeColor(element, defaultStrokeColor)
- };
- var path = drawPath(parentGfx, pathData, attrs);
- if (semantic.messageRef) {
- var midPoint = path.getPointAtLength(path.getTotalLength() / 2);
- var markerPathData = pathMap.getScaledPath('MESSAGE_FLOW_MARKER', {
- abspos: {
- x: midPoint.x,
- y: midPoint.y
- }
- });
- var messageAttrs = { strokeWidth: 1 };
- if (di.messageVisibleKind === 'initiating') {
- messageAttrs.fill = 'white';
- messageAttrs.stroke = 'black';
- } else {
- messageAttrs.fill = '#888';
- messageAttrs.stroke = 'white';
- }
- drawPath(parentGfx, markerPathData, messageAttrs);
- }
- return path;
- },
- 'bpmn:DataObject': function(parentGfx, element) {
- var pathData = pathMap.getScaledPath('DATA_OBJECT_PATH', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: 0.474,
- my: 0.296
- }
- });
- var elementObject = drawPath(parentGfx, pathData, {
- fill: getFillColor(element, defaultFillColor),
- fillOpacity: DEFAULT_FILL_OPACITY,
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- var semantic = getSemantic(element);
- if (isCollection(semantic)) {
- renderDataItemCollection(parentGfx, element);
- }
- return elementObject;
- },
- 'bpmn:DataObjectReference': as('bpmn:DataObject'),
- 'bpmn:DataInput': function(parentGfx, element) {
- var arrowPathData = pathMap.getRawPath('DATA_ARROW');
- // page
- var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
- /* input arrow path */ drawPath(parentGfx, arrowPathData, { strokeWidth: 1 });
- return elementObject;
- },
- 'bpmn:DataOutput': function(parentGfx, element) {
- var arrowPathData = pathMap.getRawPath('DATA_ARROW');
- // page
- var elementObject = renderer('bpmn:DataObject')(parentGfx, element);
- /* output arrow path */ drawPath(parentGfx, arrowPathData, {
- strokeWidth: 1,
- fill: 'black'
- });
- return elementObject;
- },
- 'bpmn:DataStoreReference': function(parentGfx, element) {
- var DATA_STORE_PATH = pathMap.getScaledPath('DATA_STORE', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: 0,
- my: 0.133
- }
- });
- var elementStore = drawPath(parentGfx, DATA_STORE_PATH, {
- strokeWidth: 2,
- fill: getFillColor(element, defaultFillColor),
- fillOpacity: DEFAULT_FILL_OPACITY,
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- return elementStore;
- },
- 'bpmn:BoundaryEvent': function(parentGfx, element) {
- var semantic = getSemantic(element),
- cancel = semantic.cancelActivity;
- var attrs = {
- strokeWidth: 1,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- };
- if (!cancel) {
- attrs.strokeDasharray = '6';
- attrs.strokeLinecap = 'round';
- }
- // apply fillOpacity
- var outerAttrs = assign({}, attrs, {
- fillOpacity: 1
- });
- // apply no-fill
- var innerAttrs = assign({}, attrs, {
- fill: 'none'
- });
- var outer = renderer('bpmn:Event')(parentGfx, element, outerAttrs);
- /* inner path */ drawCircle(parentGfx, element.width, element.height, INNER_OUTER_DIST, innerAttrs);
- renderEventContent(element, parentGfx);
- return outer;
- },
- 'bpmn:Group': function(parentGfx, element) {
- var group = drawRect(parentGfx, element.width, element.height, TASK_BORDER_RADIUS, {
- stroke: getStrokeColor(element, defaultStrokeColor),
- strokeWidth: 1,
- strokeDasharray: '8,3,1,3',
- fill: 'none',
- pointerEvents: 'none'
- });
- return group;
- },
- 'label': function(parentGfx, element) {
- return renderExternalLabel(parentGfx, element);
- },
- 'bpmn:TextAnnotation': function(parentGfx, element) {
- var style = {
- 'fill': 'none',
- 'stroke': 'none'
- };
- var textElement = drawRect(parentGfx, element.width, element.height, 0, 0, style);
- var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: 0.0,
- my: 0.0
- }
- });
- drawPath(parentGfx, textPathData, {
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- var text = getSemantic(element).text || '';
- renderLabel(parentGfx, text, {
- box: element,
- align: 'left-top',
- padding: 5,
- style: {
- fill: getStrokeColor(element, defaultStrokeColor)
- }
- });
- return textElement;
- },
- 'ParticipantMultiplicityMarker': function(parentGfx, element) {
- var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: ((element.width / 2) / element.width),
- my: (element.height - 15) / element.height
- }
- });
- drawMarker('participant-multiplicity', parentGfx, markerPath, {
- strokeWidth: 1,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- },
- 'SubProcessMarker': function(parentGfx, element) {
- var markerRect = drawRect(parentGfx, 14, 14, 0, {
- strokeWidth: 1,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- // Process marker is placed in the middle of the box
- // therefore fixed values can be used here
- translate(markerRect, element.width / 2 - 7.5, element.height - 20);
- var markerPath = pathMap.getScaledPath('MARKER_SUB_PROCESS', {
- xScaleFactor: 1.5,
- yScaleFactor: 1.5,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: (element.width / 2 - 7.5) / element.width,
- my: (element.height - 20) / element.height
- }
- });
- drawMarker('sub-process', parentGfx, markerPath, {
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- },
- 'ParallelMarker': function(parentGfx, element, position) {
- var markerPath = pathMap.getScaledPath('MARKER_PARALLEL', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: ((element.width / 2 + position.parallel) / element.width),
- my: (element.height - 20) / element.height
- }
- });
- drawMarker('parallel', parentGfx, markerPath, {
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- },
- 'SequentialMarker': function(parentGfx, element, position) {
- var markerPath = pathMap.getScaledPath('MARKER_SEQUENTIAL', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: ((element.width / 2 + position.seq) / element.width),
- my: (element.height - 19) / element.height
- }
- });
- drawMarker('sequential', parentGfx, markerPath, {
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- },
- 'CompensationMarker': function(parentGfx, element, position) {
- var markerMath = pathMap.getScaledPath('MARKER_COMPENSATION', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: ((element.width / 2 + position.compensation) / element.width),
- my: (element.height - 13) / element.height
- }
- });
- drawMarker('compensation', parentGfx, markerMath, {
- strokeWidth: 1,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- },
- 'LoopMarker': function(parentGfx, element, position) {
- var markerPath = pathMap.getScaledPath('MARKER_LOOP', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: ((element.width / 2 + position.loop) / element.width),
- my: (element.height - 7) / element.height
- }
- });
- drawMarker('loop', parentGfx, markerPath, {
- strokeWidth: 1,
- fill: getFillColor(element, defaultFillColor),
- stroke: getStrokeColor(element, defaultStrokeColor),
- strokeLinecap: 'round',
- strokeMiterlimit: 0.5
- });
- },
- 'AdhocMarker': function(parentGfx, element, position) {
- var markerPath = pathMap.getScaledPath('MARKER_ADHOC', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: ((element.width / 2 + position.adhoc) / element.width),
- my: (element.height - 15) / element.height
- }
- });
- drawMarker('adhoc', parentGfx, markerPath, {
- strokeWidth: 1,
- fill: getStrokeColor(element, defaultStrokeColor),
- stroke: getStrokeColor(element, defaultStrokeColor)
- });
- }
- };
- function attachTaskMarkers(parentGfx, element, taskMarkers) {
- var obj = getSemantic(element);
- var subprocess = taskMarkers && taskMarkers.indexOf('SubProcessMarker') !== -1;
- var position;
- if (subprocess) {
- position = {
- seq: -21,
- parallel: -22,
- compensation: -42,
- loop: -18,
- adhoc: 10
- };
- } else {
- position = {
- seq: -3,
- parallel: -6,
- compensation: -27,
- loop: 0,
- adhoc: 10
- };
- }
- forEach(taskMarkers, function(marker) {
- renderer(marker)(parentGfx, element, position);
- });
- if (obj.isForCompensation) {
- renderer('CompensationMarker')(parentGfx, element, position);
- }
- if (obj.$type === 'bpmn:AdHocSubProcess') {
- renderer('AdhocMarker')(parentGfx, element, position);
- }
- var loopCharacteristics = obj.loopCharacteristics,
- isSequential = loopCharacteristics && loopCharacteristics.isSequential;
- if (loopCharacteristics) {
- if (isSequential === undefined) {
- renderer('LoopMarker')(parentGfx, element, position);
- }
- if (isSequential === false) {
- renderer('ParallelMarker')(parentGfx, element, position);
- }
- if (isSequential === true) {
- renderer('SequentialMarker')(parentGfx, element, position);
- }
- }
- }
- function renderDataItemCollection(parentGfx, element) {
- var yPosition = (element.height - 16) / element.height;
- var pathData = pathMap.getScaledPath('DATA_OBJECT_COLLECTION_PATH', {
- xScaleFactor: 1,
- yScaleFactor: 1,
- containerWidth: element.width,
- containerHeight: element.height,
- position: {
- mx: 0.451,
- my: yPosition
- }
- });
- /* collection path */ drawPath(parentGfx, pathData, {
- strokeWidth: 2
- });
- }
- // extension API, use at your own risk
- this._drawPath = drawPath;
- }
- inherits_browser(BpmnRenderer, BaseRenderer);
- BpmnRenderer.$inject = [
- 'config.bpmnRenderer',
- 'eventBus',
- 'styles',
- 'pathMap',
- 'canvas',
- 'textRenderer'
- ];
- BpmnRenderer.prototype.canRender = function(element) {
- return is(element, 'bpmn:BaseElement');
- };
- BpmnRenderer.prototype.drawShape = function(parentGfx, element) {
- var type = element.type;
- var h = this.handlers[type];
- /* jshint -W040 */
- return h(parentGfx, element);
- };
- BpmnRenderer.prototype.drawConnection = function(parentGfx, element) {
- var type = element.type;
- var h = this.handlers[type];
- /* jshint -W040 */
- return h(parentGfx, element);
- };
- BpmnRenderer.prototype.getShapePath = function(element) {
- if (is(element, 'bpmn:Event')) {
- return getCirclePath(element);
- }
- if (is(element, 'bpmn:Activity')) {
- return getRoundRectPath(element, TASK_BORDER_RADIUS);
- }
- if (is(element, 'bpmn:Gateway')) {
- return getDiamondPath(element);
- }
- return getRectPath(element);
- };
- var DEFAULT_BOX_PADDING = 0;
- var DEFAULT_LABEL_SIZE = {
- width: 150,
- height: 50
- };
- function parseAlign(align) {
- var parts = align.split('-');
- return {
- horizontal: parts[0] || 'center',
- vertical: parts[1] || 'top'
- };
- }
- function parsePadding(padding) {
- if (isObject(padding)) {
- return assign({ top: 0, left: 0, right: 0, bottom: 0 }, padding);
- } else {
- return {
- top: padding,
- left: padding,
- right: padding,
- bottom: padding
- };
- }
- }
- function getTextBBox(text, fakeText) {
- fakeText.textContent = text;
- var textBBox;
- try {
- var bbox,
- emptyLine = text === '';
- // add dummy text, when line is empty to
- // determine correct height
- fakeText.textContent = emptyLine ? 'dummy' : text;
- textBBox = fakeText.getBBox();
- // take text rendering related horizontal
- // padding into account
- bbox = {
- width: textBBox.width + textBBox.x * 2,
- height: textBBox.height
- };
- if (emptyLine) {
- // correct width
- bbox.width = 0;
- }
- return bbox;
- } catch (e) {
- return { width: 0, height: 0 };
- }
- }
- /**
- * Layout the next line and return the layouted element.
- *
- * Alters the lines passed.
- *
- * @param {Array<string>} lines
- * @return {Object} the line descriptor, an object { width, height, text }
- */
- function layoutNext(lines, maxWidth, fakeText) {
- var originalLine = lines.shift(),
- fitLine = originalLine;
- var textBBox;
- for (;;) {
- textBBox = getTextBBox(fitLine, fakeText);
- textBBox.width = fitLine ? textBBox.width : 0;
- // try to fit
- if (fitLine === ' ' || fitLine === '' || textBBox.width < Math.round(maxWidth) || fitLine.length < 2) {
- return fit(lines, fitLine, originalLine, textBBox);
- }
- fitLine = shortenLine(fitLine, textBBox.width, maxWidth);
- }
- }
- function fit(lines, fitLine, originalLine, textBBox) {
- if (fitLine.length < originalLine.length) {
- var remainder = originalLine.slice(fitLine.length).trim();
- lines.unshift(remainder);
- }
- return {
- width: textBBox.width,
- height: textBBox.height,
- text: fitLine
- };
- }
- /**
- * Shortens a line based on spacing and hyphens.
- * Returns the shortened result on success.
- *
- * @param {string} line
- * @param {number} maxLength the maximum characters of the string
- * @return {string} the shortened string
- */
- function semanticShorten(line, maxLength) {
- var parts = line.split(/(\s|-)/g),
- part,
- shortenedParts = [],
- length = 0;
- // try to shorten via spaces + hyphens
- if (parts.length > 1) {
- while ((part = parts.shift())) {
- if (part.length + length < maxLength) {
- shortenedParts.push(part);
- length += part.length;
- } else {
- // remove previous part, too if hyphen does not fit anymore
- if (part === '-') {
- shortenedParts.pop();
- }
- break;
- }
- }
- }
- return shortenedParts.join('');
- }
- function shortenLine(line, width, maxWidth) {
- var length = Math.max(line.length * (maxWidth / width), 1);
- // try to shorten semantically (i.e. based on spaces and hyphens)
- var shortenedLine = semanticShorten(line, length);
- if (!shortenedLine) {
- // force shorten by cutting the long word
- shortenedLine = line.slice(0, Math.max(Math.round(length - 1), 1));
- }
- return shortenedLine;
- }
- function getHelperSvg() {
- var helperSvg = document.getElementById('helper-svg');
- if (!helperSvg) {
- helperSvg = create('svg');
- attr(helperSvg, {
- id: 'helper-svg',
- width: 0,
- height: 0,
- style: 'visibility: hidden; position: fixed'
- });
- document.body.appendChild(helperSvg);
- }
- return helperSvg;
- }
- /**
- * Creates a new label utility
- *
- * @param {Object} config
- * @param {Dimensions} config.size
- * @param {number} config.padding
- * @param {Object} config.style
- * @param {string} config.align
- */
- function Text(config) {
- this._config = assign({}, {
- size: DEFAULT_LABEL_SIZE,
- padding: DEFAULT_BOX_PADDING,
- style: {},
- align: 'center-top'
- }, config || {});
- }
- /**
- * Returns the layouted text as an SVG element.
- *
- * @param {string} text
- * @param {Object} options
- *
- * @return {SVGElement}
- */
- Text.prototype.createText = function(text, options) {
- return this.layoutText(text, options).element;
- };
- /**
- * Returns a labels layouted dimensions.
- *
- * @param {string} text to layout
- * @param {Object} options
- *
- * @return {Dimensions}
- */
- Text.prototype.getDimensions = function(text, options) {
- return this.layoutText(text, options).dimensions;
- };
- /**
- * Creates and returns a label and its bounding box.
- *
- * @method Text#createText
- *
- * @param {string} text the text to render on the label
- * @param {Object} options
- * @param {string} options.align how to align in the bounding box.
- * Any of { 'center-middle', 'center-top' },
- * defaults to 'center-top'.
- * @param {string} options.style style to be applied to the text
- * @param {boolean} options.fitBox indicates if box will be recalculated to
- * fit text
- *
- * @return {Object} { element, dimensions }
- */
- Text.prototype.layoutText = function(text, options) {
- var box = assign({}, this._config.size, options.box),
- style = assign({}, this._config.style, options.style),
- align = parseAlign(options.align || this._config.align),
- padding = parsePadding(options.padding !== undefined ? options.padding : this._config.padding),
- fitBox = options.fitBox || false;
- var lineHeight = getLineHeight(style);
- var lines = text.split(/\r?\n/g),
- layouted = [];
- var maxWidth = box.width - padding.left - padding.right;
- // ensure correct rendering by attaching helper text node to invisible SVG
- var helperText = create('text');
- attr(helperText, { x: 0, y: 0 });
- attr(helperText, style);
- var helperSvg = getHelperSvg();
- append(helperSvg, helperText);
- while (lines.length) {
- layouted.push(layoutNext(lines, maxWidth, helperText));
- }
- if (align.vertical === 'middle') {
- padding.top = padding.bottom = 0;
- }
- var totalHeight = reduce(layouted, function(sum, line, idx) {
- return sum + (lineHeight || line.height);
- }, 0) + padding.top + padding.bottom;
- var maxLineWidth = reduce(layouted, function(sum, line, idx) {
- return line.width > sum ? line.width : sum;
- }, 0);
- // the y position of the next line
- var y = padding.top;
- if (align.vertical === 'middle') {
- y += (box.height - totalHeight) / 2;
- }
- // magic number initial offset
- y -= (lineHeight || layouted[0].height) / 4;
- var textElement = create('text');
- attr(textElement, style);
- // layout each line taking into account that parent
- // shape might resize to fit text size
- forEach(layouted, function(line) {
- var x;
- y += (lineHeight || line.height);
- switch (align.horizontal) {
- case 'left':
- x = padding.left;
- break;
- case 'right':
- x = ((fitBox ? maxLineWidth : maxWidth)
- - padding.right - line.width);
- break;
- default:
- // aka center
- x = Math.max((((fitBox ? maxLineWidth : maxWidth)
- - line.width) / 2 + padding.left), 0);
- }
- var tspan = create('tspan');
- attr(tspan, { x: x, y: y });
- tspan.textContent = line.text;
- append(textElement, tspan);
- });
- remove(helperText);
- var dimensions = {
- width: maxLineWidth,
- height: totalHeight
- };
- return {
- dimensions: dimensions,
- element: textElement
- };
- };
- function getLineHeight(style) {
- if ('fontSize' in style && 'lineHeight' in style) {
- return style.lineHeight * parseInt(style.fontSize, 10);
- }
- }
- var DEFAULT_FONT_SIZE = 12;
- var LINE_HEIGHT_RATIO = 1.2;
- var MIN_TEXT_ANNOTATION_HEIGHT = 30;
- function TextRenderer(config) {
- var defaultStyle = assign({
- fontFamily: 'Arial, sans-serif',
- fontSize: DEFAULT_FONT_SIZE,
- fontWeight: 'normal',
- lineHeight: LINE_HEIGHT_RATIO
- }, config && config.defaultStyle || {});
- var fontSize = parseInt(defaultStyle.fontSize, 10) - 1;
- var externalStyle = assign({}, defaultStyle, {
- fontSize: fontSize
- }, config && config.externalStyle || {});
- var textUtil = new Text({
- style: defaultStyle
- });
- /**
- * Get the new bounds of an externally rendered,
- * layouted label.
- *
- * @param {Bounds} bounds
- * @param {string} text
- *
- * @return {Bounds}
- */
- this.getExternalLabelBounds = function(bounds, text) {
- var layoutedDimensions = textUtil.getDimensions(text, {
- box: {
- width: 90,
- height: 30,
- x: bounds.width / 2 + bounds.x,
- y: bounds.height / 2 + bounds.y
- },
- style: externalStyle
- });
- // resize label shape to fit label text
- return {
- x: Math.round(bounds.x + bounds.width / 2 - layoutedDimensions.width / 2),
- y: Math.round(bounds.y),
- width: Math.ceil(layoutedDimensions.width),
- height: Math.ceil(layoutedDimensions.height)
- };
- };
- /**
- * Get the new bounds of text annotation.
- *
- * @param {Bounds} bounds
- * @param {string} text
- *
- * @return {Bounds}
- */
- this.getTextAnnotationBounds = function(bounds, text) {
- var layoutedDimensions = textUtil.getDimensions(text, {
- box: bounds,
- style: defaultStyle,
- align: 'left-top',
- padding: 5
- });
- return {
- x: bounds.x,
- y: bounds.y,
- width: bounds.width,
- height: Math.max(MIN_TEXT_ANNOTATION_HEIGHT, Math.round(layoutedDimensions.height))
- };
- };
- /**
- * Create a layouted text element.
- *
- * @param {string} text
- * @param {Object} [options]
- *
- * @return {SVGElement} rendered text
- */
- this.createText = function(text, options) {
- return textUtil.createText(text, options || {});
- };
- /**
- * Get default text style.
- */
- this.getDefaultStyle = function() {
- return defaultStyle;
- };
- /**
- * Get the external text style.
- */
- this.getExternalStyle = function() {
- return externalStyle;
- };
- }
- TextRenderer.$inject = [
- 'config.textRenderer'
- ];
- /**
- * Map containing SVG paths needed by BpmnRenderer.
- */
- function PathMap() {
- /**
- * Contains a map of path elements
- *
- * <h1>Path definition</h1>
- * A parameterized path is defined like this:
- * <pre>
- * 'GATEWAY_PARALLEL': {
- * d: 'm {mx},{my} {e.x0},0 0,{e.x1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
- '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
- * height: 17.5,
- * width: 17.5,
- * heightElements: [2.5, 7.5],
- * widthElements: [2.5, 7.5]
- * }
- * </pre>
- * <p>It's important to specify a correct <b>height and width</b> for the path as the scaling
- * is based on the ratio between the specified height and width in this object and the
- * height and width that is set as scale target (Note x,y coordinates will be scaled with
- * individual ratios).</p>
- * <p>The '<b>heightElements</b>' and '<b>widthElements</b>' array must contain the values that will be scaled.
- * The scaling is based on the computed ratios.
- * Coordinates on the y axis should be in the <b>heightElement</b>'s array, they will be scaled using
- * the computed ratio coefficient.
- * In the parameterized path the scaled values can be accessed through the 'e' object in {} brackets.
- * <ul>
- * <li>The values for the y axis can be accessed in the path string using {e.y0}, {e.y1}, ....</li>
- * <li>The values for the x axis can be accessed in the path string using {e.x0}, {e.x1}, ....</li>
- * </ul>
- * The numbers x0, x1 respectively y0, y1, ... map to the corresponding array index.
- * </p>
- */
- this.pathMap = {
- 'EVENT_MESSAGE': {
- 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}',
- height: 36,
- width: 36,
- heightElements: [6, 14],
- widthElements: [10.5, 21]
- },
- 'EVENT_SIGNAL': {
- d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x1},0 Z',
- height: 36,
- width: 36,
- heightElements: [18],
- widthElements: [10, 20]
- },
- 'EVENT_ESCALATION': {
- d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x0},-{e.y1} l -{e.x0},{e.y1} Z',
- height: 36,
- width: 36,
- heightElements: [20, 7],
- widthElements: [8]
- },
- 'EVENT_CONDITIONAL': {
- d: 'M {e.x0},{e.y0} l {e.x1},0 l 0,{e.y2} l -{e.x1},0 Z ' +
- 'M {e.x2},{e.y3} l {e.x0},0 ' +
- 'M {e.x2},{e.y4} l {e.x0},0 ' +
- 'M {e.x2},{e.y5} l {e.x0},0 ' +
- 'M {e.x2},{e.y6} l {e.x0},0 ' +
- 'M {e.x2},{e.y7} l {e.x0},0 ' +
- 'M {e.x2},{e.y8} l {e.x0},0 ',
- height: 36,
- width: 36,
- heightElements: [8.5, 14.5, 18, 11.5, 14.5, 17.5, 20.5, 23.5, 26.5],
- widthElements: [10.5, 14.5, 12.5]
- },
- 'EVENT_LINK': {
- 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',
- height: 36,
- width: 36,
- heightElements: [4.4375, 6.75, 7.8125],
- widthElements: [9.84375, 13.5]
- },
- 'EVENT_ERROR': {
- 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',
- height: 36,
- width: 36,
- heightElements: [0.023, 8.737, 8.151, 16.564, 10.591, 8.714],
- widthElements: [0.085, 6.672, 6.97, 4.273, 5.337, 6.636]
- },
- 'EVENT_CANCEL_45': {
- d: 'm {mx},{my} -{e.x1},0 0,{e.x0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
- '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
- height: 36,
- width: 36,
- heightElements: [4.75, 8.5],
- widthElements: [4.75, 8.5]
- },
- 'EVENT_COMPENSATION': {
- 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',
- height: 36,
- width: 36,
- heightElements: [6.5, 13, 0.4, 6.1],
- widthElements: [9, 9.3, 8.7]
- },
- 'EVENT_TIMER_WH': {
- d: 'M {mx},{my} l {e.x0},-{e.y0} m -{e.x0},{e.y0} l {e.x1},{e.y1} ',
- height: 36,
- width: 36,
- heightElements: [10, 2],
- widthElements: [3, 7]
- },
- 'EVENT_TIMER_LINE': {
- d: 'M {mx},{my} ' +
- 'm {e.x0},{e.y0} l -{e.x1},{e.y1} ',
- height: 36,
- width: 36,
- heightElements: [10, 3],
- widthElements: [0, 0]
- },
- 'EVENT_MULTIPLE': {
- d:'m {mx},{my} {e.x1},-{e.y0} {e.x1},{e.y0} -{e.x0},{e.y1} -{e.x2},0 z',
- height: 36,
- width: 36,
- heightElements: [6.28099, 12.56199],
- widthElements: [3.1405, 9.42149, 12.56198]
- },
- 'EVENT_PARALLEL_MULTIPLE': {
- d:'m {mx},{my} {e.x0},0 0,{e.y1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' +
- '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z',
- height: 36,
- width: 36,
- heightElements: [2.56228, 7.68683],
- widthElements: [2.56228, 7.68683]
- },
- 'GATEWAY_EXCLUSIVE': {
- d:'m {mx},{my} {e.x0},{e.y0} {e.x1},{e.y0} {e.x2},0 {e.x4},{e.y2} ' +
- '{e.x4},{e.y1} {e.x2},0 {e.x1},{e.y3} {e.x0},{e.y3} ' +
- '{e.x3},0 {e.x5},{e.y1} {e.x5},{e.y2} {e.x3},0 z',
- height: 17.5,
- width: 17.5,
- heightElements: [8.5, 6.5312, -6.5312, -8.5],
- widthElements: [6.5, -6.5, 3, -3, 5, -5]
- },
- 'GATEWAY_PARALLEL': {
- d:'m {mx},{my} 0,{e.y1} -{e.x1},0 0,{e.y0} {e.x1},0 0,{e.y1} {e.x0},0 ' +
- '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z',
- height: 30,
- width: 30,
- heightElements: [5, 12.5],
- widthElements: [5, 12.5]
- },
- 'GATEWAY_EVENT_BASED': {
- d:'m {mx},{my} {e.x0},{e.y0} {e.x0},{e.y1} {e.x1},{e.y2} {e.x2},0 z',
- height: 11,
- width: 11,
- heightElements: [-6, 6, 12, -12],
- widthElements: [9, -3, -12]
- },
- 'GATEWAY_COMPLEX': {
- 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} ' +
- '{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} ' +
- '{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} ' +
- '-{e.x0},{e.y1} 0,-{e.y0} -{e.x3},0 z',
- height: 17.125,
- width: 17.125,
- heightElements: [4.875, 3.4375, 2.125, 3],
- widthElements: [3.4375, 2.125, 4.875, 3]
- },
- 'DATA_OBJECT_PATH': {
- 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',
- height: 61,
- width: 51,
- heightElements: [10, 50, 60],
- widthElements: [10, 40, 50, 60]
- },
- 'DATA_OBJECT_COLLECTION_PATH': {
- d:'m {mx}, {my} ' +
- 'm 0 15 l 0 -15 ' +
- 'm 4 15 l 0 -15 ' +
- 'm 4 15 l 0 -15 ',
- height: 61,
- width: 51,
- heightElements: [12],
- widthElements: [1, 6, 12, 15]
- },
- 'DATA_ARROW': {
- d:'m 5,9 9,0 0,-3 5,5 -5,5 0,-3 -9,0 z',
- height: 61,
- width: 51,
- heightElements: [],
- widthElements: []
- },
- 'DATA_STORE': {
- d:'m {mx},{my} ' +
- 'l 0,{e.y2} ' +
- 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
- 'l 0,-{e.y2} ' +
- 'c -{e.x0},-{e.y1} -{e.x1},-{e.y1} -{e.x2},0' +
- 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' +
- 'm -{e.x2},{e.y0}' +
- 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0' +
- 'm -{e.x2},{e.y0}' +
- 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0',
- height: 61,
- width: 61,
- heightElements: [7, 10, 45],
- widthElements: [2, 58, 60]
- },
- 'TEXT_ANNOTATION': {
- d: 'm {mx}, {my} m 10,0 l -10,0 l 0,{e.y0} l 10,0',
- height: 30,
- width: 10,
- heightElements: [30],
- widthElements: [10]
- },
- 'MARKER_SUB_PROCESS': {
- d: 'm{mx},{my} m 7,2 l 0,10 m -5,-5 l 10,0',
- height: 10,
- width: 10,
- heightElements: [],
- widthElements: []
- },
- 'MARKER_PARALLEL': {
- d: 'm{mx},{my} m 3,2 l 0,10 m 3,-10 l 0,10 m 3,-10 l 0,10',
- height: 10,
- width: 10,
- heightElements: [],
- widthElements: []
- },
- 'MARKER_SEQUENTIAL': {
- d: 'm{mx},{my} m 0,3 l 10,0 m -10,3 l 10,0 m -10,3 l 10,0',
- height: 10,
- width: 10,
- heightElements: [],
- widthElements: []
- },
- 'MARKER_COMPENSATION': {
- 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',
- height: 10,
- width: 21,
- heightElements: [],
- widthElements: []
- },
- 'MARKER_LOOP': {
- d: 'm {mx},{my} c 3.526979,0 6.386161,-2.829858 6.386161,-6.320661 0,-3.490806 -2.859182,-6.320661 ' +
- '-6.386161,-6.320661 -3.526978,0 -6.38616,2.829855 -6.38616,6.320661 0,1.745402 ' +
- '0.714797,3.325567 1.870463,4.469381 0.577834,0.571908 1.265885,1.034728 2.029916,1.35457 ' +
- 'l -0.718163,-3.909793 m 0.718163,3.909793 -3.885211,0.802902',
- height: 13.9,
- width: 13.7,
- heightElements: [],
- widthElements: []
- },
- 'MARKER_ADHOC': {
- 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 ' +
- '3.85579,1.15803 5.76082,1.79107 1.06385,0.34139996 2.24454,0.1438 3.18759,-0.43767 0.61743,-0.33642 ' +
- '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 ' +
- '-3.6918,1.66181996 -1.24459,0.0927 -2.46671,-0.2491 -3.59505,-0.74812 -1.35789,-0.55965 ' +
- '-2.75133,-1.33436996 -4.27027,-1.18121996 -1.37741,0.14601 -2.41842,1.13685996 -3.44288,1.96782996 z',
- height: 4,
- width: 15,
- heightElements: [],
- widthElements: []
- },
- 'TASK_TYPE_SEND': {
- 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}',
- height: 14,
- width: 21,
- heightElements: [6, 14],
- widthElements: [10.5, 21]
- },
- 'TASK_TYPE_SCRIPT': {
- d: 'm {mx},{my} c 9.966553,-6.27276 -8.000926,-7.91932 2.968968,-14.938 l -8.802728,0 ' +
- 'c -10.969894,7.01868 6.997585,8.66524 -2.968967,14.938 z ' +
- 'm -7,-12 l 5,0 ' +
- 'm -4.5,3 l 4.5,0 ' +
- 'm -3,3 l 5,0' +
- 'm -4,3 l 5,0',
- height: 15,
- width: 12.6,
- heightElements: [6, 14],
- widthElements: [10.5, 21]
- },
- 'TASK_TYPE_USER_1': {
- d: 'm {mx},{my} c 0.909,-0.845 1.594,-2.049 1.594,-3.385 0,-2.554 -1.805,-4.62199999 ' +
- '-4.357,-4.62199999 -2.55199998,0 -4.28799998,2.06799999 -4.28799998,4.62199999 0,1.348 ' +
- '0.974,2.562 1.89599998,3.405 -0.52899998,0.187 -5.669,2.097 -5.794,4.7560005 v 6.718 ' +
- 'h 17 v -6.718 c 0,-2.2980005 -5.5279996,-4.5950005 -6.0509996,-4.7760005 z' +
- 'm -8,6 l 0,5.5 m 11,0 l 0,-5'
- },
- 'TASK_TYPE_USER_2': {
- d: 'm {mx},{my} m 2.162,1.009 c 0,2.4470005 -2.158,4.4310005 -4.821,4.4310005 ' +
- '-2.66499998,0 -4.822,-1.981 -4.822,-4.4310005 '
- },
- 'TASK_TYPE_USER_3': {
- 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 ' +
- '4.124,0.965 -0.098,-0.57 -0.117,-3.79099999 -4.191,-4.13599999 -3.57499998,0.001 ' +
- '-4.20799998,3.36699999 -4.20699998,4.34799999 z'
- },
- 'TASK_TYPE_MANUAL': {
- 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 ' +
- '-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 ' +
- '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 ' +
- '-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 ' +
- '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 ' +
- '-10.86,-0.003 -11.0829995,-0.003 -0.022,-0.047 -0.045,-0.094 -0.069,-0.139 0.3939995,-0.319 ' +
- '2.0409995,-1.626 2.4149995,-2.017 0.469,-0.4870005 0.519,-1.1650005 0.162,-1.6040005 -0.414,-0.511 ' +
- '-0.973,-0.5 -1.48,-0.236 -1.4609995,0.764 -6.5999995,3.6430005 -7.7329995,4.2710005 -0.9,0.499 ' +
- '-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 ' +
- '-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 ' +
- '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 ' +
- '-5.824,-0.004 -6.04,-0.004 10e-4,-0.084 0.003,-0.586 10e-4,-0.67 z'
- },
- 'TASK_TYPE_INSTANTIATING_SEND': {
- 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'
- },
- 'TASK_TYPE_SERVICE': {
- d: 'm {mx},{my} v -1.71335 c 0.352326,-0.0705 0.703932,-0.17838 1.047628,-0.32133 ' +
- '0.344416,-0.14465 0.665822,-0.32133 0.966377,-0.52145 l 1.19431,1.18005 1.567487,-1.57688 ' +
- '-1.195028,-1.18014 c 0.403376,-0.61394 0.683079,-1.29908 0.825447,-2.01824 l 1.622133,-0.01 ' +
- 'v -2.2196 l -1.636514,0.01 c -0.07333,-0.35153 -0.178319,-0.70024 -0.323564,-1.04372 ' +
- '-0.145244,-0.34406 -0.321407,-0.6644 -0.522735,-0.96217 l 1.131035,-1.13631 -1.583305,-1.56293 ' +
- '-1.129598,1.13589 c -0.614052,-0.40108 -1.302883,-0.68093 -2.022633,-0.82247 l 0.0093,-1.61852 ' +
- '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 ' +
- '-0.665102,0.32092 -0.9635006,0.52046 l -1.1698628,-1.15823 -1.5667691,1.5792 1.1684265,1.15669 ' +
- 'c -0.4026573,0.61283 -0.68308,1.29797 -0.8247287,2.01713 l -1.6588041,0.003 v 2.22174 ' +
- 'l 1.6724648,-0.006 c 0.073327,0.35077 0.1797598,0.70243 0.3242851,1.04472 0.1452428,0.34448 ' +
- '0.3214064,0.6644 0.5227339,0.96066 l -1.1993431,1.19723 1.5840256,1.56011 1.1964668,-1.19348 ' +
- 'c 0.6140517,0.40346 1.3028827,0.68232 2.0233517,0.82331 l 7.19e-4,1.69892 h 2.226848 z ' +
- 'm 0.221462,-3.9957 c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
- '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
- '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
- },
- 'TASK_TYPE_SERVICE_FILL': {
- d: 'm {mx},{my} c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' +
- '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' +
- '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z'
- },
- 'TASK_TYPE_BUSINESS_RULE_HEADER': {
- d: 'm {mx},{my} 0,4 20,0 0,-4 z'
- },
- 'TASK_TYPE_BUSINESS_RULE_MAIN': {
- d: 'm {mx},{my} 0,12 20,0 0,-12 z' +
- 'm 0,8 l 20,0 ' +
- 'm -13,-4 l 0,8'
- },
- 'MESSAGE_FLOW_MARKER': {
- 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'
- }
- };
- this.getRawPath = function getRawPath(pathId) {
- return this.pathMap[pathId].d;
- };
- /**
- * Scales the path to the given height and width.
- * <h1>Use case</h1>
- * <p>Use case is to scale the content of elements (event, gateways) based
- * on the element bounding box's size.
- * </p>
- * <h1>Why not transform</h1>
- * <p>Scaling a path with transform() will also scale the stroke and IE does not support
- * the option 'non-scaling-stroke' to prevent this.
- * Also there are use cases where only some parts of a path should be
- * scaled.</p>
- *
- * @param {string} pathId The ID of the path.
- * @param {Object} param <p>
- * Example param object scales the path to 60% size of the container (data.width, data.height).
- * <pre>
- * {
- * xScaleFactor: 0.6,
- * yScaleFactor:0.6,
- * containerWidth: data.width,
- * containerHeight: data.height,
- * position: {
- * mx: 0.46,
- * my: 0.2,
- * }
- * }
- * </pre>
- * <ul>
- * <li>targetpathwidth = xScaleFactor * containerWidth</li>
- * <li>targetpathheight = yScaleFactor * containerHeight</li>
- * <li>Position is used to set the starting coordinate of the path. M is computed:
- * <ul>
- * <li>position.x * containerWidth</li>
- * <li>position.y * containerHeight</li>
- * </ul>
- * Center of the container <pre> position: {
- * mx: 0.5,
- * my: 0.5,
- * }</pre>
- * Upper left corner of the container
- * <pre> position: {
- * mx: 0.0,
- * my: 0.0,
- * }</pre>
- * </li>
- * </ul>
- * </p>
- *
- */
- this.getScaledPath = function getScaledPath(pathId, param) {
- var rawPath = this.pathMap[pathId];
- // positioning
- // compute the start point of the path
- var mx, my;
- if (param.abspos) {
- mx = param.abspos.x;
- my = param.abspos.y;
- } else {
- mx = param.containerWidth * param.position.mx;
- my = param.containerHeight * param.position.my;
- }
- var coordinates = {}; // map for the scaled coordinates
- if (param.position) {
- // path
- var heightRatio = (param.containerHeight / rawPath.height) * param.yScaleFactor;
- var widthRatio = (param.containerWidth / rawPath.width) * param.xScaleFactor;
- // Apply height ratio
- for (var heightIndex = 0; heightIndex < rawPath.heightElements.length; heightIndex++) {
- coordinates['y' + heightIndex] = rawPath.heightElements[heightIndex] * heightRatio;
- }
- // Apply width ratio
- for (var widthIndex = 0; widthIndex < rawPath.widthElements.length; widthIndex++) {
- coordinates['x' + widthIndex] = rawPath.widthElements[widthIndex] * widthRatio;
- }
- }
- // Apply value to raw path
- var path = format(
- rawPath.d, {
- mx: mx,
- my: my,
- e: coordinates
- }
- );
- return path;
- };
- }
- // helpers //////////////////////
- // copied from https://github.com/adobe-webplatform/Snap.svg/blob/master/src/svg.js
- var tokenRegex = /\{([^}]+)\}/g,
- objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g; // matches .xxxxx or ["xxxxx"] to run over object properties
- function replacer(all, key, obj) {
- var res = obj;
- key.replace(objNotationRegex, function(all, name, quote, quotedName, isFunc) {
- name = name || quotedName;
- if (res) {
- if (name in res) {
- res = res[name];
- }
- typeof res == 'function' && isFunc && (res = res());
- }
- });
- res = (res == null || res == obj ? all : res) + '';
- return res;
- }
- function format(str, obj) {
- return String(str).replace(tokenRegex, function(all, key) {
- return replacer(all, key, obj);
- });
- }
- var DrawModule = {
- __init__: [ 'bpmnRenderer' ],
- bpmnRenderer: [ 'type', BpmnRenderer ],
- textRenderer: [ 'type', TextRenderer ],
- pathMap: [ 'type', PathMap ]
- };
- /**
- * A simple translation stub to be used for multi-language support
- * in diagrams. Can be easily replaced with a more sophisticated
- * solution.
- *
- * @example
- *
- * // use it inside any diagram component by injecting `translate`.
- *
- * function MyService(translate) {
- * alert(translate('HELLO {you}', { you: 'You!' }));
- * }
- *
- * @param {string} template to interpolate
- * @param {Object} [replacements] a map with substitutes
- *
- * @return {string} the translated string
- */
- function translate$1(template, replacements) {
- replacements = replacements || {};
- return template.replace(/{([^}]+)}/g, function(_, key) {
- return replacements[key] || '{' + key + '}';
- });
- }
- var TranslateModule = {
- translate: [ 'value', translate$1 ]
- };
- var DEFAULT_LABEL_SIZE$1 = {
- width: 90,
- height: 20
- };
- var FLOW_LABEL_INDENT = 15;
- /**
- * Returns true if the given semantic has an external label
- *
- * @param {BpmnElement} semantic
- * @return {boolean} true if has label
- */
- function isLabelExternal(semantic) {
- return is(semantic, 'bpmn:Event') ||
- is(semantic, 'bpmn:Gateway') ||
- is(semantic, 'bpmn:DataStoreReference') ||
- is(semantic, 'bpmn:DataObjectReference') ||
- is(semantic, 'bpmn:DataInput') ||
- is(semantic, 'bpmn:DataOutput') ||
- is(semantic, 'bpmn:SequenceFlow') ||
- is(semantic, 'bpmn:MessageFlow') ||
- is(semantic, 'bpmn:Group');
- }
- /**
- * Get the position for sequence flow labels
- *
- * @param {Array<Point>} waypoints
- * @return {Point} the label position
- */
- function getFlowLabelPosition(waypoints) {
- // get the waypoints mid
- var mid = waypoints.length / 2 - 1;
- var first = waypoints[Math.floor(mid)];
- var second = waypoints[Math.ceil(mid + 0.01)];
- // get position
- var position = getWaypointsMid(waypoints);
- // calculate angle
- var angle = Math.atan((second.y - first.y) / (second.x - first.x));
- var x = position.x,
- y = position.y;
- if (Math.abs(angle) < Math.PI / 2) {
- y -= FLOW_LABEL_INDENT;
- } else {
- x += FLOW_LABEL_INDENT;
- }
- return { x: x, y: y };
- }
- /**
- * Get the middle of a number of waypoints
- *
- * @param {Array<Point>} waypoints
- * @return {Point} the mid point
- */
- function getWaypointsMid(waypoints) {
- var mid = waypoints.length / 2 - 1;
- var first = waypoints[Math.floor(mid)];
- var second = waypoints[Math.ceil(mid + 0.01)];
- return {
- x: first.x + (second.x - first.x) / 2,
- y: first.y + (second.y - first.y) / 2
- };
- }
- function getExternalLabelMid(element) {
- if (element.waypoints) {
- return getFlowLabelPosition(element.waypoints);
- } else if (is(element, 'bpmn:Group')) {
- return {
- x: element.x + element.width / 2,
- y: element.y + DEFAULT_LABEL_SIZE$1.height / 2
- };
- } else {
- return {
- x: element.x + element.width / 2,
- y: element.y + element.height + DEFAULT_LABEL_SIZE$1.height / 2
- };
- }
- }
- /**
- * Returns the bounds of an elements label, parsed from the elements DI or
- * generated from its bounds.
- *
- * @param {BpmnElement} semantic
- * @param {djs.model.Base} element
- */
- function getExternalLabelBounds(semantic, element) {
- var mid,
- size,
- bounds,
- di = semantic.di,
- label = di.label;
- if (label && label.bounds) {
- bounds = label.bounds;
- size = {
- width: Math.max(DEFAULT_LABEL_SIZE$1.width, bounds.width),
- height: bounds.height
- };
- mid = {
- x: bounds.x + bounds.width / 2,
- y: bounds.y + bounds.height / 2
- };
- } else {
- mid = getExternalLabelMid(element);
- size = DEFAULT_LABEL_SIZE$1;
- }
- return assign({
- x: mid.x - size.width / 2,
- y: mid.y - size.height / 2
- }, size);
- }
- /**
- * This file contains source code adapted from Snap.svg (licensed Apache-2.0).
- *
- * @see https://github.com/adobe-webplatform/Snap.svg/blob/master/src/path.js
- */
- /* eslint no-fallthrough: "off" */
- var math = Math,
- PI = math.PI;
- function roundPoint(point) {
- return {
- x: Math.round(point.x),
- y: Math.round(point.y)
- };
- }
- /**
- * Get the mid of the given bounds or point.
- *
- * @param {Bounds|Point} bounds
- *
- * @return {Point}
- */
- function getMid(bounds) {
- return roundPoint({
- x: bounds.x + (bounds.width || 0) / 2,
- y: bounds.y + (bounds.height || 0) / 2
- });
- }
- function elementToString(e) {
- if (!e) {
- return '<null>';
- }
- return '<' + e.$type + (e.id ? ' id="' + e.id : '') + '" />';
- }
- function elementData(semantic, attrs) {
- return assign({
- id: semantic.id,
- type: semantic.$type,
- businessObject: semantic
- }, attrs);
- }
- function getWaypoints(bo, source, target) {
- var waypoints = bo.di.waypoint;
- if (!waypoints || waypoints.length < 2) {
- return [ getMid(source), getMid(target) ];
- }
- return waypoints.map(function(p) {
- return { x: p.x, y: p.y };
- });
- }
- function notYetDrawn(translate, semantic, refSemantic, property) {
- return new Error(translate('element {element} referenced by {referenced}#{property} not yet drawn', {
- element: elementToString(refSemantic),
- referenced: elementToString(semantic),
- property: property
- }));
- }
- /**
- * An importer that adds bpmn elements to the canvas
- *
- * @param {EventBus} eventBus
- * @param {Canvas} canvas
- * @param {ElementFactory} elementFactory
- * @param {ElementRegistry} elementRegistry
- * @param {Function} translate
- * @param {TextRenderer} textRenderer
- */
- function BpmnImporter(
- eventBus, canvas, elementFactory,
- elementRegistry, translate, textRenderer) {
- this._eventBus = eventBus;
- this._canvas = canvas;
- this._elementFactory = elementFactory;
- this._elementRegistry = elementRegistry;
- this._translate = translate;
- this._textRenderer = textRenderer;
- }
- BpmnImporter.$inject = [
- 'eventBus',
- 'canvas',
- 'elementFactory',
- 'elementRegistry',
- 'translate',
- 'textRenderer'
- ];
- /**
- * Add bpmn element (semantic) to the canvas onto the
- * specified parent shape.
- */
- BpmnImporter.prototype.add = function(semantic, parentElement) {
- var di = semantic.di,
- element,
- translate = this._translate,
- hidden;
- var parentIndex;
- // ROOT ELEMENT
- // handle the special case that we deal with a
- // invisible root element (process or collaboration)
- if (is(di, 'bpmndi:BPMNPlane')) {
- // add a virtual element (not being drawn)
- element = this._elementFactory.createRoot(elementData(semantic));
- this._canvas.setRootElement(element);
- }
- // SHAPE
- else if (is(di, 'bpmndi:BPMNShape')) {
- var collapsed = !isExpanded(semantic),
- isFrame = isFrameElement(semantic);
- hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
- var bounds = semantic.di.bounds;
- element = this._elementFactory.createShape(elementData(semantic, {
- collapsed: collapsed,
- hidden: hidden,
- x: Math.round(bounds.x),
- y: Math.round(bounds.y),
- width: Math.round(bounds.width),
- height: Math.round(bounds.height),
- isFrame: isFrame
- }));
- if (is(semantic, 'bpmn:BoundaryEvent')) {
- this._attachBoundary(semantic, element);
- }
- // insert lanes behind other flow nodes (cf. #727)
- if (is(semantic, 'bpmn:Lane')) {
- parentIndex = 0;
- }
- if (is(semantic, 'bpmn:DataStoreReference')) {
- // check whether data store is inside our outside of its semantic parent
- if (!isPointInsideBBox(parentElement, getMid(bounds))) {
- parentElement = this._canvas.getRootElement();
- }
- }
- this._canvas.addShape(element, parentElement, parentIndex);
- }
- // CONNECTION
- else if (is(di, 'bpmndi:BPMNEdge')) {
- var source = this._getSource(semantic),
- target = this._getTarget(semantic);
- hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
- element = this._elementFactory.createConnection(elementData(semantic, {
- hidden: hidden,
- source: source,
- target: target,
- waypoints: getWaypoints(semantic, source, target)
- }));
- if (is(semantic, 'bpmn:DataAssociation')) {
- // render always on top; this ensures DataAssociations
- // are rendered correctly across different "hacks" people
- // love to model such as cross participant / sub process
- // associations
- parentElement = null;
- }
- // insert sequence flows behind other flow nodes (cf. #727)
- if (is(semantic, 'bpmn:SequenceFlow')) {
- parentIndex = 0;
- }
- this._canvas.addConnection(element, parentElement, parentIndex);
- } else {
- throw new Error(translate('unknown di {di} for element {semantic}', {
- di: elementToString(di),
- semantic: elementToString(semantic)
- }));
- }
- // (optional) LABEL
- if (isLabelExternal(semantic) && getLabel(element)) {
- this.addLabel(semantic, element);
- }
- this._eventBus.fire('bpmnElement.added', { element: element });
- return element;
- };
- /**
- * Attach the boundary element to the given host
- *
- * @param {ModdleElement} boundarySemantic
- * @param {djs.model.Base} boundaryElement
- */
- BpmnImporter.prototype._attachBoundary = function(boundarySemantic, boundaryElement) {
- var translate = this._translate;
- var hostSemantic = boundarySemantic.attachedToRef;
- if (!hostSemantic) {
- throw new Error(translate('missing {semantic}#attachedToRef', {
- semantic: elementToString(boundarySemantic)
- }));
- }
- var host = this._elementRegistry.get(hostSemantic.id),
- attachers = host && host.attachers;
- if (!host) {
- throw notYetDrawn(translate, boundarySemantic, hostSemantic, 'attachedToRef');
- }
- // wire element.host <> host.attachers
- boundaryElement.host = host;
- if (!attachers) {
- host.attachers = attachers = [];
- }
- if (attachers.indexOf(boundaryElement) === -1) {
- attachers.push(boundaryElement);
- }
- };
- /**
- * add label for an element
- */
- BpmnImporter.prototype.addLabel = function(semantic, element) {
- var bounds,
- text,
- label;
- bounds = getExternalLabelBounds(semantic, element);
- text = getLabel(element);
- if (text) {
- // get corrected bounds from actual layouted text
- bounds = this._textRenderer.getExternalLabelBounds(bounds, text);
- }
- label = this._elementFactory.createLabel(elementData(semantic, {
- id: semantic.id + '_label',
- labelTarget: element,
- type: 'label',
- hidden: element.hidden || !getLabel(element),
- x: Math.round(bounds.x),
- y: Math.round(bounds.y),
- width: Math.round(bounds.width),
- height: Math.round(bounds.height)
- }));
- return this._canvas.addShape(label, element.parent);
- };
- /**
- * Return the drawn connection end based on the given side.
- *
- * @throws {Error} if the end is not yet drawn
- */
- BpmnImporter.prototype._getEnd = function(semantic, side) {
- var element,
- refSemantic,
- type = semantic.$type,
- translate = this._translate;
- refSemantic = semantic[side + 'Ref'];
- // handle mysterious isMany DataAssociation#sourceRef
- if (side === 'source' && type === 'bpmn:DataInputAssociation') {
- refSemantic = refSemantic && refSemantic[0];
- }
- // fix source / target for DataInputAssociation / DataOutputAssociation
- if (side === 'source' && type === 'bpmn:DataOutputAssociation' ||
- side === 'target' && type === 'bpmn:DataInputAssociation') {
- refSemantic = semantic.$parent;
- }
- element = refSemantic && this._getElement(refSemantic);
- if (element) {
- return element;
- }
- if (refSemantic) {
- throw notYetDrawn(translate, semantic, refSemantic, side + 'Ref');
- } else {
- throw new Error(translate('{semantic}#{side} Ref not specified', {
- semantic: elementToString(semantic),
- side: side
- }));
- }
- };
- BpmnImporter.prototype._getSource = function(semantic) {
- return this._getEnd(semantic, 'source');
- };
- BpmnImporter.prototype._getTarget = function(semantic) {
- return this._getEnd(semantic, 'target');
- };
- BpmnImporter.prototype._getElement = function(semantic) {
- return this._elementRegistry.get(semantic.id);
- };
- // helpers ////////////////////
- function isPointInsideBBox(bbox, point) {
- var x = point.x,
- y = point.y;
- return x >= bbox.x &&
- x <= bbox.x + bbox.width &&
- y >= bbox.y &&
- y <= bbox.y + bbox.height;
- }
- function isFrameElement(semantic) {
- return is(semantic, 'bpmn:Group');
- }
- var ImportModule = {
- __depends__: [
- TranslateModule
- ],
- bpmnImporter: [ 'type', BpmnImporter ]
- };
- var CoreModule = {
- __depends__: [
- DrawModule,
- ImportModule
- ]
- };
- function getOriginal(event) {
- return event.originalEvent || event.srcEvent;
- }
- function isMac() {
- return (/mac/i).test(navigator.platform);
- }
- function isPrimaryButton(event) {
- // button === 0 -> left áka primary mouse button
- return !(getOriginal(event) || event).button;
- }
- function hasPrimaryModifier(event) {
- var originalEvent = getOriginal(event) || event;
- if (!isPrimaryButton(event)) {
- return false;
- }
- // Use alt as primary modifier key for mac OS
- if (isMac()) {
- return originalEvent.metaKey;
- } else {
- return originalEvent.ctrlKey;
- }
- }
- function allowAll(e) { return true; }
- var LOW_PRIORITY = 500;
- /**
- * A plugin that provides interaction events for diagram elements.
- *
- * It emits the following events:
- *
- * * element.click
- * * element.contextmenu
- * * element.dblclick
- * * element.hover
- * * element.mousedown
- * * element.mousemove
- * * element.mouseup
- * * element.out
- *
- * Each event is a tuple { element, gfx, originalEvent }.
- *
- * Canceling the event via Event#preventDefault()
- * prevents the original DOM operation.
- *
- * @param {EventBus} eventBus
- */
- function InteractionEvents(eventBus, elementRegistry, styles) {
- var self = this;
- /**
- * Fire an interaction event.
- *
- * @param {string} type local event name, e.g. element.click.
- * @param {DOMEvent} event native event
- * @param {djs.model.Base} [element] the diagram element to emit the event on;
- * defaults to the event target
- */
- function fire(type, event, element) {
- if (isIgnored(type, event)) {
- return;
- }
- var target, gfx, returnValue;
- if (!element) {
- target = event.delegateTarget || event.target;
- if (target) {
- gfx = target;
- element = elementRegistry.get(gfx);
- }
- } else {
- gfx = elementRegistry.getGraphics(element);
- }
- if (!gfx || !element) {
- return;
- }
- returnValue = eventBus.fire(type, {
- element: element,
- gfx: gfx,
- originalEvent: event
- });
- if (returnValue === false) {
- event.stopPropagation();
- event.preventDefault();
- }
- }
- // TODO(nikku): document this
- var handlers = {};
- function mouseHandler(localEventName) {
- return handlers[localEventName];
- }
- function isIgnored(localEventName, event) {
- var filter = ignoredFilters[localEventName] || isPrimaryButton;
- // only react on left mouse button interactions
- // except for interaction events that are enabled
- // for secundary mouse button
- return !filter(event);
- }
- var bindings = {
- click: 'element.click',
- contextmenu: 'element.contextmenu',
- dblclick: 'element.dblclick',
- mousedown: 'element.mousedown',
- mousemove: 'element.mousemove',
- mouseover: 'element.hover',
- mouseout: 'element.out',
- mouseup: 'element.mouseup',
- };
- var ignoredFilters = {
- 'element.contextmenu': allowAll
- };
- // manual event trigger //////////
- /**
- * Trigger an interaction event (based on a native dom event)
- * on the target shape or connection.
- *
- * @param {string} eventName the name of the triggered DOM event
- * @param {MouseEvent} event
- * @param {djs.model.Base} targetElement
- */
- function triggerMouseEvent(eventName, event, targetElement) {
- // i.e. element.mousedown...
- var localEventName = bindings[eventName];
- if (!localEventName) {
- throw new Error('unmapped DOM event name <' + eventName + '>');
- }
- return fire(localEventName, event, targetElement);
- }
- var ELEMENT_SELECTOR = 'svg, .djs-element';
- // event handling ///////
- function registerEvent(node, event, localEvent, ignoredFilter) {
- var handler = handlers[localEvent] = function(event) {
- fire(localEvent, event);
- };
- if (ignoredFilter) {
- ignoredFilters[localEvent] = ignoredFilter;
- }
- handler.$delegate = delegateEvents.bind(node, ELEMENT_SELECTOR, event, handler);
- }
- function unregisterEvent(node, event, localEvent) {
- var handler = mouseHandler(localEvent);
- if (!handler) {
- return;
- }
- delegateEvents.unbind(node, event, handler.$delegate);
- }
- function registerEvents(svg) {
- forEach(bindings, function(val, key) {
- registerEvent(svg, key, val);
- });
- }
- function unregisterEvents(svg) {
- forEach(bindings, function(val, key) {
- unregisterEvent(svg, key, val);
- });
- }
- eventBus.on('canvas.destroy', function(event) {
- unregisterEvents(event.svg);
- });
- eventBus.on('canvas.init', function(event) {
- registerEvents(event.svg);
- });
- // hit box updating ////////////////
- eventBus.on([ 'shape.added', 'connection.added' ], function(event) {
- var element = event.element,
- gfx = event.gfx;
- eventBus.fire('interactionEvents.createHit', { element: element, gfx: gfx });
- });
- // Update djs-hit on change.
- // A low priortity is necessary, because djs-hit of labels has to be updated
- // after the label bounds have been updated in the renderer.
- eventBus.on([
- 'shape.changed',
- 'connection.changed'
- ], LOW_PRIORITY, function(event) {
- var element = event.element,
- gfx = event.gfx;
- eventBus.fire('interactionEvents.updateHit', { element: element, gfx: gfx });
- });
- eventBus.on('interactionEvents.createHit', LOW_PRIORITY, function(event) {
- var element = event.element,
- gfx = event.gfx;
- self.createDefaultHit(element, gfx);
- });
- eventBus.on('interactionEvents.updateHit', function(event) {
- var element = event.element,
- gfx = event.gfx;
- self.updateDefaultHit(element, gfx);
- });
- // hit styles ////////////
- var STROKE_HIT_STYLE = createHitStyle('djs-hit djs-hit-stroke');
- var CLICK_STROKE_HIT_STYLE = createHitStyle('djs-hit djs-hit-click-stroke');
- var ALL_HIT_STYLE = createHitStyle('djs-hit djs-hit-all');
- var HIT_TYPES = {
- 'all': ALL_HIT_STYLE,
- 'click-stroke': CLICK_STROKE_HIT_STYLE,
- 'stroke': STROKE_HIT_STYLE
- };
- function createHitStyle(classNames, attrs) {
- attrs = assign({
- stroke: 'white',
- strokeWidth: 15
- }, attrs || {});
- return styles.cls(classNames, [ 'no-fill', 'no-border' ], attrs);
- }
- // style helpers ///////////////
- function applyStyle(hit, type) {
- var attrs = HIT_TYPES[type];
- if (!attrs) {
- throw new Error('invalid hit type <' + type + '>');
- }
- attr(hit, attrs);
- return hit;
- }
- function appendHit(gfx, hit) {
- append(gfx, hit);
- }
- // API
- /**
- * Remove hints on the given graphics.
- *
- * @param {SVGElement} gfx
- */
- this.removeHits = function(gfx) {
- var hits = all('.djs-hit', gfx);
- forEach(hits, remove);
- };
- /**
- * Create default hit for the given element.
- *
- * @param {djs.model.Base} element
- * @param {SVGElement} gfx
- *
- * @return {SVGElement} created hit
- */
- this.createDefaultHit = function(element, gfx) {
- var waypoints = element.waypoints,
- isFrame = element.isFrame,
- boxType;
- if (waypoints) {
- return this.createWaypointsHit(gfx, waypoints);
- } else {
- boxType = isFrame ? 'stroke' : 'all';
- return this.createBoxHit(gfx, boxType, {
- width: element.width,
- height: element.height
- });
- }
- };
- /**
- * Create hits for the given waypoints.
- *
- * @param {SVGElement} gfx
- * @param {Array<Point>} waypoints
- *
- * @return {SVGElement}
- */
- this.createWaypointsHit = function(gfx, waypoints) {
- var hit = createLine(waypoints);
- applyStyle(hit, 'stroke');
- appendHit(gfx, hit);
- return hit;
- };
- /**
- * Create hits for a box.
- *
- * @param {SVGElement} gfx
- * @param {string} hitType
- * @param {Object} attrs
- *
- * @return {SVGElement}
- */
- this.createBoxHit = function(gfx, type, attrs) {
- attrs = assign({
- x: 0,
- y: 0
- }, attrs);
- var hit = create('rect');
- applyStyle(hit, type);
- attr(hit, attrs);
- appendHit(gfx, hit);
- return hit;
- };
- /**
- * Update default hit of the element.
- *
- * @param {djs.model.Base} element
- * @param {SVGElement} gfx
- *
- * @return {SVGElement} updated hit
- */
- this.updateDefaultHit = function(element, gfx) {
- var hit = query('.djs-hit', gfx);
- if (!hit) {
- return;
- }
- if (element.waypoints) {
- updateLine(hit, element.waypoints);
- } else {
- attr(hit, {
- width: element.width,
- height: element.height
- });
- }
- return hit;
- };
- this.fire = fire;
- this.triggerMouseEvent = triggerMouseEvent;
- this.mouseHandler = mouseHandler;
- this.registerEvent = registerEvent;
- this.unregisterEvent = unregisterEvent;
- }
- InteractionEvents.$inject = [
- 'eventBus',
- 'elementRegistry',
- 'styles'
- ];
- /**
- * An event indicating that the mouse hovered over an element
- *
- * @event element.hover
- *
- * @type {Object}
- * @property {djs.model.Base} element
- * @property {SVGElement} gfx
- * @property {Event} originalEvent
- */
- /**
- * An event indicating that the mouse has left an element
- *
- * @event element.out
- *
- * @type {Object}
- * @property {djs.model.Base} element
- * @property {SVGElement} gfx
- * @property {Event} originalEvent
- */
- /**
- * An event indicating that the mouse has clicked an element
- *
- * @event element.click
- *
- * @type {Object}
- * @property {djs.model.Base} element
- * @property {SVGElement} gfx
- * @property {Event} originalEvent
- */
- /**
- * An event indicating that the mouse has double clicked an element
- *
- * @event element.dblclick
- *
- * @type {Object}
- * @property {djs.model.Base} element
- * @property {SVGElement} gfx
- * @property {Event} originalEvent
- */
- /**
- * An event indicating that the mouse has gone down on an element.
- *
- * @event element.mousedown
- *
- * @type {Object}
- * @property {djs.model.Base} element
- * @property {SVGElement} gfx
- * @property {Event} originalEvent
- */
- /**
- * An event indicating that the mouse has gone up on an element.
- *
- * @event element.mouseup
- *
- * @type {Object}
- * @property {djs.model.Base} element
- * @property {SVGElement} gfx
- * @property {Event} originalEvent
- */
- /**
- * An event indicating that the context menu action is triggered
- * via mouse or touch controls.
- *
- * @event element.contextmenu
- *
- * @type {Object}
- * @property {djs.model.Base} element
- * @property {SVGElement} gfx
- * @property {Event} originalEvent
- */
- var InteractionEventsModule = {
- __init__: [ 'interactionEvents' ],
- interactionEvents: [ 'type', InteractionEvents ]
- };
- /**
- * Returns the surrounding bbox for all elements in
- * the array or the element primitive.
- *
- * @param {Array<djs.model.Shape>|djs.model.Shape} elements
- * @param {boolean} stopRecursion
- */
- function getBBox(elements, stopRecursion) {
- stopRecursion = !!stopRecursion;
- if (!isArray(elements)) {
- elements = [elements];
- }
- var minX,
- minY,
- maxX,
- maxY;
- forEach(elements, function(element) {
- // If element is a connection the bbox must be computed first
- var bbox = element;
- if (element.waypoints && !stopRecursion) {
- bbox = getBBox(element.waypoints, true);
- }
- var x = bbox.x,
- y = bbox.y,
- height = bbox.height || 0,
- width = bbox.width || 0;
- if (x < minX || minX === undefined) {
- minX = x;
- }
- if (y < minY || minY === undefined) {
- minY = y;
- }
- if ((x + width) > maxX || maxX === undefined) {
- maxX = x + width;
- }
- if ((y + height) > maxY || maxY === undefined) {
- maxY = y + height;
- }
- });
- return {
- x: minX,
- y: minY,
- height: maxY - minY,
- width: maxX - minX
- };
- }
- function getType(element) {
- if ('waypoints' in element) {
- return 'connection';
- }
- if ('x' in element) {
- return 'shape';
- }
- return 'root';
- }
- function isFrameElement$1(element) {
- return !!(element && element.isFrame);
- }
- var LOW_PRIORITY$1 = 500;
- /**
- * @class
- *
- * A plugin that adds an outline to shapes and connections that may be activated and styled
- * via CSS classes.
- *
- * @param {EventBus} eventBus
- * @param {Styles} styles
- * @param {ElementRegistry} elementRegistry
- */
- function Outline(eventBus, styles, elementRegistry) {
- this.offset = 6;
- var OUTLINE_STYLE = styles.cls('djs-outline', [ 'no-fill' ]);
- var self = this;
- function createOutline(gfx, bounds) {
- var outline = create('rect');
- attr(outline, assign({
- x: 10,
- y: 10,
- width: 100,
- height: 100
- }, OUTLINE_STYLE));
- append(gfx, outline);
- return outline;
- }
- // A low priortity is necessary, because outlines of labels have to be updated
- // after the label bounds have been updated in the renderer.
- eventBus.on([ 'shape.added', 'shape.changed' ], LOW_PRIORITY$1, function(event) {
- var element = event.element,
- gfx = event.gfx;
- var outline = query('.djs-outline', gfx);
- if (!outline) {
- outline = createOutline(gfx);
- }
- self.updateShapeOutline(outline, element);
- });
- eventBus.on([ 'connection.added', 'connection.changed' ], function(event) {
- var element = event.element,
- gfx = event.gfx;
- var outline = query('.djs-outline', gfx);
- if (!outline) {
- outline = createOutline(gfx);
- }
- self.updateConnectionOutline(outline, element);
- });
- }
- /**
- * Updates the outline of a shape respecting the dimension of the
- * element and an outline offset.
- *
- * @param {SVGElement} outline
- * @param {djs.model.Base} element
- */
- Outline.prototype.updateShapeOutline = function(outline, element) {
- attr(outline, {
- x: -this.offset,
- y: -this.offset,
- width: element.width + this.offset * 2,
- height: element.height + this.offset * 2
- });
- };
- /**
- * Updates the outline of a connection respecting the bounding box of
- * the connection and an outline offset.
- *
- * @param {SVGElement} outline
- * @param {djs.model.Base} element
- */
- Outline.prototype.updateConnectionOutline = function(outline, connection) {
- var bbox = getBBox(connection);
- attr(outline, {
- x: bbox.x - this.offset,
- y: bbox.y - this.offset,
- width: bbox.width + this.offset * 2,
- height: bbox.height + this.offset * 2
- });
- };
- Outline.$inject = ['eventBus', 'styles', 'elementRegistry'];
- var OutlineModule = {
- __init__: [ 'outline' ],
- outline: [ 'type', Outline ]
- };
- /**
- * A service that offers the current selection in a diagram.
- * Offers the api to control the selection, too.
- *
- * @class
- *
- * @param {EventBus} eventBus the event bus
- */
- function Selection(eventBus) {
- this._eventBus = eventBus;
- this._selectedElements = [];
- var self = this;
- eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
- var element = e.element;
- self.deselect(element);
- });
- eventBus.on([ 'diagram.clear' ], function(e) {
- self.select(null);
- });
- }
- Selection.$inject = [ 'eventBus' ];
- Selection.prototype.deselect = function(element) {
- var selectedElements = this._selectedElements;
- var idx = selectedElements.indexOf(element);
- if (idx !== -1) {
- var oldSelection = selectedElements.slice();
- selectedElements.splice(idx, 1);
- this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
- }
- };
- Selection.prototype.get = function() {
- return this._selectedElements;
- };
- Selection.prototype.isSelected = function(element) {
- return this._selectedElements.indexOf(element) !== -1;
- };
- /**
- * This method selects one or more elements on the diagram.
- *
- * By passing an additional add parameter you can decide whether or not the element(s)
- * should be added to the already existing selection or not.
- *
- * @method Selection#select
- *
- * @param {Object|Object[]} elements element or array of elements to be selected
- * @param {boolean} [add] whether the element(s) should be appended to the current selection, defaults to false
- */
- Selection.prototype.select = function(elements, add) {
- var selectedElements = this._selectedElements,
- oldSelection = selectedElements.slice();
- if (!isArray(elements)) {
- elements = elements ? [ elements ] : [];
- }
- // selection may be cleared by passing an empty array or null
- // to the method
- if (add) {
- forEach(elements, function(element) {
- if (selectedElements.indexOf(element) !== -1) {
- // already selected
- return;
- } else {
- selectedElements.push(element);
- }
- });
- } else {
- this._selectedElements = selectedElements = elements.slice();
- }
- this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements });
- };
- var MARKER_HOVER = 'hover',
- MARKER_SELECTED = 'selected';
- /**
- * A plugin that adds a visible selection UI to shapes and connections
- * by appending the <code>hover</code> and <code>selected</code> classes to them.
- *
- * @class
- *
- * Makes elements selectable, too.
- *
- * @param {EventBus} events
- * @param {SelectionService} selection
- * @param {Canvas} canvas
- */
- function SelectionVisuals(events, canvas, selection, styles) {
- this._multiSelectionBox = null;
- function addMarker(e, cls) {
- canvas.addMarker(e, cls);
- }
- function removeMarker(e, cls) {
- canvas.removeMarker(e, cls);
- }
- events.on('element.hover', function(event) {
- addMarker(event.element, MARKER_HOVER);
- });
- events.on('element.out', function(event) {
- removeMarker(event.element, MARKER_HOVER);
- });
- events.on('selection.changed', function(event) {
- function deselect(s) {
- removeMarker(s, MARKER_SELECTED);
- }
- function select(s) {
- addMarker(s, MARKER_SELECTED);
- }
- var oldSelection = event.oldSelection,
- newSelection = event.newSelection;
- forEach(oldSelection, function(e) {
- if (newSelection.indexOf(e) === -1) {
- deselect(e);
- }
- });
- forEach(newSelection, function(e) {
- if (oldSelection.indexOf(e) === -1) {
- select(e);
- }
- });
- });
- }
- SelectionVisuals.$inject = [
- 'eventBus',
- 'canvas',
- 'selection',
- 'styles'
- ];
- function SelectionBehavior(
- eventBus, selection, canvas,
- elementRegistry) {
- eventBus.on('create.end', 500, function(e) {
- var context = e.context,
- canExecute = context.canExecute,
- elements = context.elements,
- hints = context.hints || {},
- autoSelect = hints.autoSelect;
- // select elements after they have been created
- if (canExecute) {
- if (autoSelect === false) {
- // select no elements
- return;
- }
- if (isArray(autoSelect)) {
- selection.select(autoSelect);
- } else {
- // select all elements by default
- selection.select(elements.filter(isShown));
- }
- }
- });
- eventBus.on('connect.end', 500, function(e) {
- // select the connect end target
- // after a connect operation
- if (e.context.canExecute && e.context.hover) {
- selection.select(e.context.hover);
- }
- });
- eventBus.on('shape.move.end', 500, function(e) {
- var previousSelection = e.previousSelection || [];
- var shape = elementRegistry.get(e.context.shape.id);
- // make sure at least the main moved element is being
- // selected after a move operation
- var inSelection = find(previousSelection, function(selectedShape) {
- return shape.id === selectedShape.id;
- });
- if (!inSelection) {
- selection.select(shape);
- }
- });
- // Shift + click selection
- eventBus.on('element.click', function(event) {
- var element = event.element;
- // do not select the root element
- // or connections
- if (element === canvas.getRootElement()) {
- element = null;
- }
- var isSelected = selection.isSelected(element),
- isMultiSelect = selection.get().length > 1;
- // mouse-event: SELECTION_KEY
- var add = hasPrimaryModifier(event);
- // select OR deselect element in multi selection
- if (isSelected && isMultiSelect) {
- if (add) {
- return selection.deselect(element);
- } else {
- return selection.select(element);
- }
- } else
- if (!isSelected) {
- selection.select(element, add);
- } else {
- selection.deselect(element);
- }
- });
- }
- SelectionBehavior.$inject = [
- 'eventBus',
- 'selection',
- 'canvas',
- 'elementRegistry'
- ];
- function isShown(element) {
- return !element.hidden;
- }
- var SelectionModule = {
- __init__: [ 'selectionVisuals', 'selectionBehavior' ],
- __depends__: [
- InteractionEventsModule,
- OutlineModule
- ],
- selection: [ 'type', Selection ],
- selectionVisuals: [ 'type', SelectionVisuals ],
- selectionBehavior: [ 'type', SelectionBehavior ]
- };
- /**
- * Util that provides unique IDs.
- *
- * @class djs.util.IdGenerator
- * @constructor
- * @memberOf djs.util
- *
- * The ids can be customized via a given prefix and contain a random value to avoid collisions.
- *
- * @param {string} prefix a prefix to prepend to generated ids (for better readability)
- */
- function IdGenerator(prefix) {
- this._counter = 0;
- this._prefix = (prefix ? prefix + '-' : '') + Math.floor(Math.random() * 1000000000) + '-';
- }
- /**
- * Returns a next unique ID.
- *
- * @method djs.util.IdGenerator#next
- *
- * @returns {string} the id
- */
- IdGenerator.prototype.next = function() {
- return this._prefix + (++this._counter);
- };
- // document wide unique overlay ids
- var ids = new IdGenerator('ov');
- var LOW_PRIORITY$2 = 500;
- /**
- * A service that allows users to attach overlays to diagram elements.
- *
- * The overlay service will take care of overlay positioning during updates.
- *
- * @example
- *
- * // add a pink badge on the top left of the shape
- * overlays.add(someShape, {
- * position: {
- * top: -5,
- * left: -5
- * },
- * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
- * });
- *
- * // or add via shape id
- *
- * overlays.add('some-element-id', {
- * position: {
- * top: -5,
- * left: -5
- * }
- * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
- * });
- *
- * // or add with optional type
- *
- * overlays.add(someShape, 'badge', {
- * position: {
- * top: -5,
- * left: -5
- * }
- * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>'
- * });
- *
- *
- * // remove an overlay
- *
- * var id = overlays.add(...);
- * overlays.remove(id);
- *
- *
- * You may configure overlay defaults during tool by providing a `config` module
- * with `overlays.defaults` as an entry:
- *
- * {
- * overlays: {
- * defaults: {
- * show: {
- * minZoom: 0.7,
- * maxZoom: 5.0
- * },
- * scale: {
- * min: 1
- * }
- * }
- * }
- *
- * @param {Object} config
- * @param {EventBus} eventBus
- * @param {Canvas} canvas
- * @param {ElementRegistry} elementRegistry
- */
- function Overlays(config, eventBus, canvas, elementRegistry) {
- this._eventBus = eventBus;
- this._canvas = canvas;
- this._elementRegistry = elementRegistry;
- this._ids = ids;
- this._overlayDefaults = assign({
- // no show constraints
- show: null,
- // always scale
- scale: true
- }, config && config.defaults);
- /**
- * Mapping overlayId -> overlay
- */
- this._overlays = {};
- /**
- * Mapping elementId -> overlay container
- */
- this._overlayContainers = [];
- // root html element for all overlays
- this._overlayRoot = createRoot(canvas.getContainer());
- this._init();
- }
- Overlays.$inject = [
- 'config.overlays',
- 'eventBus',
- 'canvas',
- 'elementRegistry'
- ];
- /**
- * Returns the overlay with the specified id or a list of overlays
- * for an element with a given type.
- *
- * @example
- *
- * // return the single overlay with the given id
- * overlays.get('some-id');
- *
- * // return all overlays for the shape
- * overlays.get({ element: someShape });
- *
- * // return all overlays on shape with type 'badge'
- * overlays.get({ element: someShape, type: 'badge' });
- *
- * // shape can also be specified as id
- * overlays.get({ element: 'element-id', type: 'badge' });
- *
- *
- * @param {Object} search
- * @param {string} [search.id]
- * @param {string|djs.model.Base} [search.element]
- * @param {string} [search.type]
- *
- * @return {Object|Array<Object>} the overlay(s)
- */
- Overlays.prototype.get = function(search) {
- if (isString(search)) {
- search = { id: search };
- }
- if (isString(search.element)) {
- search.element = this._elementRegistry.get(search.element);
- }
- if (search.element) {
- var container = this._getOverlayContainer(search.element, true);
- // return a list of overlays when searching by element (+type)
- if (container) {
- return search.type ? filter(container.overlays, matchPattern({ type: search.type })) : container.overlays.slice();
- } else {
- return [];
- }
- } else
- if (search.type) {
- return filter(this._overlays, matchPattern({ type: search.type }));
- } else {
- // return single element when searching by id
- return search.id ? this._overlays[search.id] : null;
- }
- };
- /**
- * Adds a HTML overlay to an element.
- *
- * @param {string|djs.model.Base} element attach overlay to this shape
- * @param {string} [type] optional type to assign to the overlay
- * @param {Object} overlay the overlay configuration
- *
- * @param {string|DOMElement} overlay.html html element to use as an overlay
- * @param {Object} [overlay.show] show configuration
- * @param {number} [overlay.show.minZoom] minimal zoom level to show the overlay
- * @param {number} [overlay.show.maxZoom] maximum zoom level to show the overlay
- * @param {Object} overlay.position where to attach the overlay
- * @param {number} [overlay.position.left] relative to element bbox left attachment
- * @param {number} [overlay.position.top] relative to element bbox top attachment
- * @param {number} [overlay.position.bottom] relative to element bbox bottom attachment
- * @param {number} [overlay.position.right] relative to element bbox right attachment
- * @param {boolean|Object} [overlay.scale=true] false to preserve the same size regardless of
- * diagram zoom
- * @param {number} [overlay.scale.min]
- * @param {number} [overlay.scale.max]
- *
- * @return {string} id that may be used to reference the overlay for update or removal
- */
- Overlays.prototype.add = function(element, type, overlay) {
- if (isObject(type)) {
- overlay = type;
- type = null;
- }
- if (!element.id) {
- element = this._elementRegistry.get(element);
- }
- if (!overlay.position) {
- throw new Error('must specifiy overlay position');
- }
- if (!overlay.html) {
- throw new Error('must specifiy overlay html');
- }
- if (!element) {
- throw new Error('invalid element specified');
- }
- var id = this._ids.next();
- overlay = assign({}, this._overlayDefaults, overlay, {
- id: id,
- type: type,
- element: element,
- html: overlay.html
- });
- this._addOverlay(overlay);
- return id;
- };
- /**
- * Remove an overlay with the given id or all overlays matching the given filter.
- *
- * @see Overlays#get for filter options.
- *
- * @param {string} [id]
- * @param {Object} [filter]
- */
- Overlays.prototype.remove = function(filter) {
- var overlays = this.get(filter) || [];
- if (!isArray(overlays)) {
- overlays = [ overlays ];
- }
- var self = this;
- forEach(overlays, function(overlay) {
- var container = self._getOverlayContainer(overlay.element, true);
- if (overlay) {
- remove$1(overlay.html);
- remove$1(overlay.htmlContainer);
- delete overlay.htmlContainer;
- delete overlay.element;
- delete self._overlays[overlay.id];
- }
- if (container) {
- var idx = container.overlays.indexOf(overlay);
- if (idx !== -1) {
- container.overlays.splice(idx, 1);
- }
- }
- });
- };
- Overlays.prototype.show = function() {
- setVisible(this._overlayRoot);
- };
- Overlays.prototype.hide = function() {
- setVisible(this._overlayRoot, false);
- };
- Overlays.prototype.clear = function() {
- this._overlays = {};
- this._overlayContainers = [];
- clear$1(this._overlayRoot);
- };
- Overlays.prototype._updateOverlayContainer = function(container) {
- var element = container.element,
- html = container.html;
- // update container left,top according to the elements x,y coordinates
- // this ensures we can attach child elements relative to this container
- var x = element.x,
- y = element.y;
- if (element.waypoints) {
- var bbox = getBBox(element);
- x = bbox.x;
- y = bbox.y;
- }
- setPosition(html, x, y);
- attr$1(container.html, 'data-container-id', element.id);
- };
- Overlays.prototype._updateOverlay = function(overlay) {
- var position = overlay.position,
- htmlContainer = overlay.htmlContainer,
- element = overlay.element;
- // update overlay html relative to shape because
- // it is already positioned on the element
- // update relative
- var left = position.left,
- top = position.top;
- if (position.right !== undefined) {
- var width;
- if (element.waypoints) {
- width = getBBox(element).width;
- } else {
- width = element.width;
- }
- left = position.right * -1 + width;
- }
- if (position.bottom !== undefined) {
- var height;
- if (element.waypoints) {
- height = getBBox(element).height;
- } else {
- height = element.height;
- }
- top = position.bottom * -1 + height;
- }
- setPosition(htmlContainer, left || 0, top || 0);
- };
- Overlays.prototype._createOverlayContainer = function(element) {
- var html = domify('<div class="djs-overlays" style="position: absolute" />');
- this._overlayRoot.appendChild(html);
- var container = {
- html: html,
- element: element,
- overlays: []
- };
- this._updateOverlayContainer(container);
- this._overlayContainers.push(container);
- return container;
- };
- Overlays.prototype._updateRoot = function(viewbox) {
- var scale = viewbox.scale || 1;
- var matrix = 'matrix(' +
- [
- scale,
- 0,
- 0,
- scale,
- -1 * viewbox.x * scale,
- -1 * viewbox.y * scale
- ].join(',') +
- ')';
- setTransform(this._overlayRoot, matrix);
- };
- Overlays.prototype._getOverlayContainer = function(element, raw) {
- var container = find(this._overlayContainers, function(c) {
- return c.element === element;
- });
- if (!container && !raw) {
- return this._createOverlayContainer(element);
- }
- return container;
- };
- Overlays.prototype._addOverlay = function(overlay) {
- var id = overlay.id,
- element = overlay.element,
- html = overlay.html,
- htmlContainer,
- overlayContainer;
- // unwrap jquery (for those who need it)
- if (html.get && html.constructor.prototype.jquery) {
- html = html.get(0);
- }
- // create proper html elements from
- // overlay HTML strings
- if (isString(html)) {
- html = domify(html);
- }
- overlayContainer = this._getOverlayContainer(element);
- htmlContainer = domify('<div class="djs-overlay" data-overlay-id="' + id + '" style="position: absolute">');
- htmlContainer.appendChild(html);
- if (overlay.type) {
- classes$1(htmlContainer).add('djs-overlay-' + overlay.type);
- }
- overlay.htmlContainer = htmlContainer;
- overlayContainer.overlays.push(overlay);
- overlayContainer.html.appendChild(htmlContainer);
- this._overlays[id] = overlay;
- this._updateOverlay(overlay);
- this._updateOverlayVisibilty(overlay, this._canvas.viewbox());
- };
- Overlays.prototype._updateOverlayVisibilty = function(overlay, viewbox) {
- var show = overlay.show,
- minZoom = show && show.minZoom,
- maxZoom = show && show.maxZoom,
- htmlContainer = overlay.htmlContainer,
- visible = true;
- if (show) {
- if (
- (isDefined(minZoom) && minZoom > viewbox.scale) ||
- (isDefined(maxZoom) && maxZoom < viewbox.scale)
- ) {
- visible = false;
- }
- setVisible(htmlContainer, visible);
- }
- this._updateOverlayScale(overlay, viewbox);
- };
- Overlays.prototype._updateOverlayScale = function(overlay, viewbox) {
- var shouldScale = overlay.scale,
- minScale,
- maxScale,
- htmlContainer = overlay.htmlContainer;
- var scale, transform = '';
- if (shouldScale !== true) {
- if (shouldScale === false) {
- minScale = 1;
- maxScale = 1;
- } else {
- minScale = shouldScale.min;
- maxScale = shouldScale.max;
- }
- if (isDefined(minScale) && viewbox.scale < minScale) {
- scale = (1 / viewbox.scale || 1) * minScale;
- }
- if (isDefined(maxScale) && viewbox.scale > maxScale) {
- scale = (1 / viewbox.scale || 1) * maxScale;
- }
- }
- if (isDefined(scale)) {
- transform = 'scale(' + scale + ',' + scale + ')';
- }
- setTransform(htmlContainer, transform);
- };
- Overlays.prototype._updateOverlaysVisibilty = function(viewbox) {
- var self = this;
- forEach(this._overlays, function(overlay) {
- self._updateOverlayVisibilty(overlay, viewbox);
- });
- };
- Overlays.prototype._init = function() {
- var eventBus = this._eventBus;
- var self = this;
- // scroll/zoom integration
- function updateViewbox(viewbox) {
- self._updateRoot(viewbox);
- self._updateOverlaysVisibilty(viewbox);
- self.show();
- }
- eventBus.on('canvas.viewbox.changing', function(event) {
- self.hide();
- });
- eventBus.on('canvas.viewbox.changed', function(event) {
- updateViewbox(event.viewbox);
- });
- // remove integration
- eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
- var element = e.element;
- var overlays = self.get({ element: element });
- forEach(overlays, function(o) {
- self.remove(o.id);
- });
- var container = self._getOverlayContainer(element);
- if (container) {
- remove$1(container.html);
- var i = self._overlayContainers.indexOf(container);
- if (i !== -1) {
- self._overlayContainers.splice(i, 1);
- }
- }
- });
- // move integration
- eventBus.on('element.changed', LOW_PRIORITY$2, function(e) {
- var element = e.element;
- var container = self._getOverlayContainer(element, true);
- if (container) {
- forEach(container.overlays, function(overlay) {
- self._updateOverlay(overlay);
- });
- self._updateOverlayContainer(container);
- }
- });
- // marker integration, simply add them on the overlays as classes, too.
- eventBus.on('element.marker.update', function(e) {
- var container = self._getOverlayContainer(e.element, true);
- if (container) {
- classes$1(container.html)[e.add ? 'add' : 'remove'](e.marker);
- }
- });
- // clear overlays with diagram
- eventBus.on('diagram.clear', this.clear, this);
- };
- // helpers /////////////////////////////
- function createRoot(parentNode) {
- var root = domify(
- '<div class="djs-overlay-container" style="position: absolute; width: 0; height: 0;" />'
- );
- parentNode.insertBefore(root, parentNode.firstChild);
- return root;
- }
- function setPosition(el, x, y) {
- assign(el.style, { left: x + 'px', top: y + 'px' });
- }
- function setVisible(el, visible) {
- el.style.display = visible === false ? 'none' : '';
- }
- function setTransform(el, transform) {
- el.style['transform-origin'] = 'top left';
- [ '', '-ms-', '-webkit-' ].forEach(function(prefix) {
- el.style[prefix + 'transform'] = transform;
- });
- }
- var OverlaysModule = {
- __init__: [ 'overlays' ],
- overlays: [ 'type', Overlays ]
- };
- var CLASS_PATTERN = /^class /;
- function isClass(fn) {
- return CLASS_PATTERN.test(fn.toString());
- }
- function isArray$1(obj) {
- return Object.prototype.toString.call(obj) === '[object Array]';
- }
- function annotate() {
- var args = Array.prototype.slice.call(arguments);
- if (args.length === 1 && isArray$1(args[0])) {
- args = args[0];
- }
- var fn = args.pop();
- fn.$inject = args;
- return fn;
- }
- // Current limitations:
- // - can't put into "function arg" comments
- // function /* (no parenthesis like this) */ (){}
- // function abc( /* xx (no parenthesis like this) */ a, b) {}
- //
- // Just put the comment before function or inside:
- // /* (((this is fine))) */ function(a, b) {}
- // function abc(a) { /* (((this is fine))) */}
- //
- // - can't reliably auto-annotate constructor; we'll match the
- // first constructor(...) pattern found which may be the one
- // of a nested class, too.
- var CONSTRUCTOR_ARGS = /constructor\s*[^(]*\(\s*([^)]*)\)/m;
- var FN_ARGS = /^function\s*[^(]*\(\s*([^)]*)\)/m;
- var FN_ARG = /\/\*([^*]*)\*\//m;
- function parse$2(fn) {
- if (typeof fn !== 'function') {
- throw new Error('Cannot annotate "' + fn + '". Expected a function!');
- }
- var match = fn.toString().match(isClass(fn) ? CONSTRUCTOR_ARGS : FN_ARGS);
- // may parse class without constructor
- if (!match) {
- return [];
- }
- return match[1] && match[1].split(',').map(function (arg) {
- match = arg.match(FN_ARG);
- return match ? match[1].trim() : arg.trim();
- }) || [];
- }
- function Module() {
- var providers = [];
- this.factory = function (name, factory) {
- providers.push([name, 'factory', factory]);
- return this;
- };
- this.value = function (name, value) {
- providers.push([name, 'value', value]);
- return this;
- };
- this.type = function (name, type) {
- providers.push([name, 'type', type]);
- return this;
- };
- this.forEach = function (iterator) {
- providers.forEach(iterator);
- };
- }
- var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
- function Injector(modules, parent) {
- parent = parent || {
- get: function get(name, strict) {
- currentlyResolving.push(name);
- if (strict === false) {
- return null;
- } else {
- throw error('No provider for "' + name + '"!');
- }
- }
- };
- var currentlyResolving = [];
- var providers = this._providers = Object.create(parent._providers || null);
- var instances = this._instances = Object.create(null);
- var self = instances.injector = this;
- var error = function error(msg) {
- var stack = currentlyResolving.join(' -> ');
- currentlyResolving.length = 0;
- return new Error(stack ? msg + ' (Resolving: ' + stack + ')' : msg);
- };
- /**
- * Return a named service.
- *
- * @param {String} name
- * @param {Boolean} [strict=true] if false, resolve missing services to null
- *
- * @return {Object}
- */
- var get = function get(name, strict) {
- if (!providers[name] && name.indexOf('.') !== -1) {
- var parts = name.split('.');
- var pivot = get(parts.shift());
- while (parts.length) {
- pivot = pivot[parts.shift()];
- }
- return pivot;
- }
- if (hasProp(instances, name)) {
- return instances[name];
- }
- if (hasProp(providers, name)) {
- if (currentlyResolving.indexOf(name) !== -1) {
- currentlyResolving.push(name);
- throw error('Cannot resolve circular dependency!');
- }
- currentlyResolving.push(name);
- instances[name] = providers[name][0](providers[name][1]);
- currentlyResolving.pop();
- return instances[name];
- }
- return parent.get(name, strict);
- };
- var fnDef = function fnDef(fn) {
- var locals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- if (typeof fn !== 'function') {
- if (isArray$1(fn)) {
- fn = annotate(fn.slice());
- } else {
- throw new Error('Cannot invoke "' + fn + '". Expected a function!');
- }
- }
- var inject = fn.$inject || parse$2(fn);
- var dependencies = inject.map(function (dep) {
- if (hasProp(locals, dep)) {
- return locals[dep];
- } else {
- return get(dep);
- }
- });
- return {
- fn: fn,
- dependencies: dependencies
- };
- };
- var instantiate = function instantiate(Type) {
- var _fnDef = fnDef(Type),
- dependencies = _fnDef.dependencies,
- fn = _fnDef.fn;
- return new (Function.prototype.bind.apply(fn, [null].concat(_toConsumableArray(dependencies))))();
- };
- var invoke = function invoke(func, context, locals) {
- var _fnDef2 = fnDef(func, locals),
- dependencies = _fnDef2.dependencies,
- fn = _fnDef2.fn;
- return fn.call.apply(fn, [context].concat(_toConsumableArray(dependencies)));
- };
- var createPrivateInjectorFactory = function createPrivateInjectorFactory(privateChildInjector) {
- return annotate(function (key) {
- return privateChildInjector.get(key);
- });
- };
- var createChild = function createChild(modules, forceNewInstances) {
- if (forceNewInstances && forceNewInstances.length) {
- var fromParentModule = Object.create(null);
- var matchedScopes = Object.create(null);
- var privateInjectorsCache = [];
- var privateChildInjectors = [];
- var privateChildFactories = [];
- var provider;
- var cacheIdx;
- var privateChildInjector;
- var privateChildInjectorFactory;
- for (var name in providers) {
- provider = providers[name];
- if (forceNewInstances.indexOf(name) !== -1) {
- if (provider[2] === 'private') {
- cacheIdx = privateInjectorsCache.indexOf(provider[3]);
- if (cacheIdx === -1) {
- privateChildInjector = provider[3].createChild([], forceNewInstances);
- privateChildInjectorFactory = createPrivateInjectorFactory(privateChildInjector);
- privateInjectorsCache.push(provider[3]);
- privateChildInjectors.push(privateChildInjector);
- privateChildFactories.push(privateChildInjectorFactory);
- fromParentModule[name] = [privateChildInjectorFactory, name, 'private', privateChildInjector];
- } else {
- fromParentModule[name] = [privateChildFactories[cacheIdx], name, 'private', privateChildInjectors[cacheIdx]];
- }
- } else {
- fromParentModule[name] = [provider[2], provider[1]];
- }
- matchedScopes[name] = true;
- }
- if ((provider[2] === 'factory' || provider[2] === 'type') && provider[1].$scope) {
- /* jshint -W083 */
- forceNewInstances.forEach(function (scope) {
- if (provider[1].$scope.indexOf(scope) !== -1) {
- fromParentModule[name] = [provider[2], provider[1]];
- matchedScopes[scope] = true;
- }
- });
- }
- }
- forceNewInstances.forEach(function (scope) {
- if (!matchedScopes[scope]) {
- throw new Error('No provider for "' + scope + '". Cannot use provider from the parent!');
- }
- });
- modules.unshift(fromParentModule);
- }
- return new Injector(modules, self);
- };
- var factoryMap = {
- factory: invoke,
- type: instantiate,
- value: function value(_value) {
- return _value;
- }
- };
- modules.forEach(function (module) {
- function arrayUnwrap(type, value) {
- if (type !== 'value' && isArray$1(value)) {
- value = annotate(value.slice());
- }
- return value;
- }
- // TODO(vojta): handle wrong inputs (modules)
- if (module instanceof Module) {
- module.forEach(function (provider) {
- var name = provider[0];
- var type = provider[1];
- var value = provider[2];
- providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
- });
- } else if ((typeof module === 'undefined' ? 'undefined' : _typeof(module)) === 'object') {
- if (module.__exports__) {
- var clonedModule = Object.keys(module).reduce(function (m, key) {
- if (key.substring(0, 2) !== '__') {
- m[key] = module[key];
- }
- return m;
- }, Object.create(null));
- var privateInjector = new Injector((module.__modules__ || []).concat([clonedModule]), self);
- var getFromPrivateInjector = annotate(function (key) {
- return privateInjector.get(key);
- });
- module.__exports__.forEach(function (key) {
- providers[key] = [getFromPrivateInjector, key, 'private', privateInjector];
- });
- } else {
- Object.keys(module).forEach(function (name) {
- if (module[name][2] === 'private') {
- providers[name] = module[name];
- return;
- }
- var type = module[name][0];
- var value = module[name][1];
- providers[name] = [factoryMap[type], arrayUnwrap(type, value), type];
- });
- }
- }
- });
- // public API
- this.get = get;
- this.invoke = invoke;
- this.instantiate = instantiate;
- this.createChild = createChild;
- }
- // helpers /////////////////
- function hasProp(obj, prop) {
- return Object.hasOwnProperty.call(obj, prop);
- }
- // apply default renderer with lowest possible priority
- // so that it only kicks in if noone else could render
- var DEFAULT_RENDER_PRIORITY$1 = 1;
- /**
- * The default renderer used for shapes and connections.
- *
- * @param {EventBus} eventBus
- * @param {Styles} styles
- */
- function DefaultRenderer(eventBus, styles) {
- //
- BaseRenderer.call(this, eventBus, DEFAULT_RENDER_PRIORITY$1);
- this.CONNECTION_STYLE = styles.style([ 'no-fill' ], { strokeWidth: 5, stroke: 'fuchsia' });
- this.SHAPE_STYLE = styles.style({ fill: 'white', stroke: 'fuchsia', strokeWidth: 2 });
- this.FRAME_STYLE = styles.style([ 'no-fill' ], { stroke: 'fuchsia', strokeDasharray: 4, strokeWidth: 2 });
- }
- inherits_browser(DefaultRenderer, BaseRenderer);
- DefaultRenderer.prototype.canRender = function() {
- return true;
- };
- DefaultRenderer.prototype.drawShape = function drawShape(visuals, element) {
- var rect = create('rect');
- attr(rect, {
- x: 0,
- y: 0,
- width: element.width || 0,
- height: element.height || 0
- });
- if (isFrameElement$1(element)) {
- attr(rect, this.FRAME_STYLE);
- } else {
- attr(rect, this.SHAPE_STYLE);
- }
- append(visuals, rect);
- return rect;
- };
- DefaultRenderer.prototype.drawConnection = function drawConnection(visuals, connection) {
- var line = createLine(connection.waypoints, this.CONNECTION_STYLE);
- append(visuals, line);
- return line;
- };
- DefaultRenderer.prototype.getShapePath = function getShapePath(shape) {
- var x = shape.x,
- y = shape.y,
- width = shape.width,
- height = shape.height;
- var shapePath = [
- ['M', x, y],
- ['l', width, 0],
- ['l', 0, height],
- ['l', -width, 0],
- ['z']
- ];
- return componentsToPath(shapePath);
- };
- DefaultRenderer.prototype.getConnectionPath = function getConnectionPath(connection) {
- var waypoints = connection.waypoints;
- var idx, point, connectionPath = [];
- for (idx = 0; (point = waypoints[idx]); idx++) {
- // take invisible docking into account
- // when creating the path
- point = point.original || point;
- connectionPath.push([ idx === 0 ? 'M' : 'L', point.x, point.y ]);
- }
- return componentsToPath(connectionPath);
- };
- DefaultRenderer.$inject = [ 'eventBus', 'styles' ];
- /**
- * A component that manages shape styles
- */
- function Styles() {
- var defaultTraits = {
- 'no-fill': {
- fill: 'none'
- },
- 'no-border': {
- strokeOpacity: 0.0
- },
- 'no-events': {
- pointerEvents: 'none'
- }
- };
- var self = this;
- /**
- * Builds a style definition from a className, a list of traits and an object of additional attributes.
- *
- * @param {string} className
- * @param {Array<string>} traits
- * @param {Object} additionalAttrs
- *
- * @return {Object} the style defintion
- */
- this.cls = function(className, traits, additionalAttrs) {
- var attrs = this.style(traits, additionalAttrs);
- return assign(attrs, { 'class': className });
- };
- /**
- * Builds a style definition from a list of traits and an object of additional attributes.
- *
- * @param {Array<string>} traits
- * @param {Object} additionalAttrs
- *
- * @return {Object} the style defintion
- */
- this.style = function(traits, additionalAttrs) {
- if (!isArray(traits) && !additionalAttrs) {
- additionalAttrs = traits;
- traits = [];
- }
- var attrs = reduce(traits, function(attrs, t) {
- return assign(attrs, defaultTraits[t] || {});
- }, {});
- return additionalAttrs ? assign(attrs, additionalAttrs) : attrs;
- };
- this.computeStyle = function(custom, traits, defaultStyles) {
- if (!isArray(traits)) {
- defaultStyles = traits;
- traits = [];
- }
- return self.style(traits || [], assign({}, defaultStyles, custom || {}));
- };
- }
- var DrawModule$1 = {
- __init__: [ 'defaultRenderer' ],
- defaultRenderer: [ 'type', DefaultRenderer ],
- styles: [ 'type', Styles ]
- };
- /**
- * Failsafe remove an element from a collection
- *
- * @param {Array<Object>} [collection]
- * @param {Object} [element]
- *
- * @return {number} the previous index of the element
- */
- function remove$2(collection, element) {
- if (!collection || !element) {
- return -1;
- }
- var idx = collection.indexOf(element);
- if (idx !== -1) {
- collection.splice(idx, 1);
- }
- return idx;
- }
- /**
- * Fail save add an element to the given connection, ensuring
- * it does not yet exist.
- *
- * @param {Array<Object>} collection
- * @param {Object} element
- * @param {number} idx
- */
- function add(collection, element, idx) {
- if (!collection || !element) {
- return;
- }
- if (typeof idx !== 'number') {
- idx = -1;
- }
- var currentIdx = collection.indexOf(element);
- if (currentIdx !== -1) {
- if (currentIdx === idx) {
- // nothing to do, position has not changed
- return;
- } else {
- if (idx !== -1) {
- // remove from current position
- collection.splice(currentIdx, 1);
- } else {
- // already exists in collection
- return;
- }
- }
- }
- if (idx !== -1) {
- // insert at specified position
- collection.splice(idx, 0, element);
- } else {
- // push to end
- collection.push(element);
- }
- }
- function round(number, resolution) {
- return Math.round(number * resolution) / resolution;
- }
- function ensurePx(number) {
- return isNumber(number) ? number + 'px' : number;
- }
- /**
- * Creates a HTML container element for a SVG element with
- * the given configuration
- *
- * @param {Object} options
- * @return {HTMLElement} the container element
- */
- function createContainer(options) {
- options = assign({}, { width: '100%', height: '100%' }, options);
- var container = options.container || document.body;
- // create a <div> around the svg element with the respective size
- // this way we can always get the correct container size
- // (this is impossible for <svg> elements at the moment)
- var parent = document.createElement('div');
- parent.setAttribute('class', 'djs-container');
- assign(parent.style, {
- position: 'relative',
- overflow: 'hidden',
- width: ensurePx(options.width),
- height: ensurePx(options.height)
- });
- container.appendChild(parent);
- return parent;
- }
- function createGroup(parent, cls, childIndex) {
- var group = create('g');
- classes(group).add(cls);
- var index = childIndex !== undefined ? childIndex : parent.childNodes.length - 1;
- // must ensure second argument is node or _null_
- // cf. https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
- parent.insertBefore(group, parent.childNodes[index] || null);
- return group;
- }
- var BASE_LAYER = 'base';
- var REQUIRED_MODEL_ATTRS = {
- shape: [ 'x', 'y', 'width', 'height' ],
- connection: [ 'waypoints' ]
- };
- /**
- * The main drawing canvas.
- *
- * @class
- * @constructor
- *
- * @emits Canvas#canvas.init
- *
- * @param {Object} config
- * @param {EventBus} eventBus
- * @param {GraphicsFactory} graphicsFactory
- * @param {ElementRegistry} elementRegistry
- */
- function Canvas(config, eventBus, graphicsFactory, elementRegistry) {
- this._eventBus = eventBus;
- this._elementRegistry = elementRegistry;
- this._graphicsFactory = graphicsFactory;
- this._init(config || {});
- }
- Canvas.$inject = [
- 'config.canvas',
- 'eventBus',
- 'graphicsFactory',
- 'elementRegistry'
- ];
- Canvas.prototype._init = function(config) {
- var eventBus = this._eventBus;
- // Creates a <svg> element that is wrapped into a <div>.
- // This way we are always able to correctly figure out the size of the svg element
- // by querying the parent node.
- //
- // (It is not possible to get the size of a svg element cross browser @ 2014-04-01)
- //
- // <div class="djs-container" style="width: {desired-width}, height: {desired-height}">
- // <svg width="100%" height="100%">
- // ...
- // </svg>
- // </div>
- // html container
- var container = this._container = createContainer(config);
- var svg = this._svg = create('svg');
- attr(svg, { width: '100%', height: '100%' });
- append(container, svg);
- var viewport = this._viewport = createGroup(svg, 'viewport');
- this._layers = {};
- // debounce canvas.viewbox.changed events
- // for smoother diagram interaction
- if (config.deferUpdate !== false) {
- this._viewboxChanged = debounce(bind(this._viewboxChanged, this), 300);
- }
- eventBus.on('diagram.init', function() {
- /**
- * An event indicating that the canvas is ready to be drawn on.
- *
- * @memberOf Canvas
- *
- * @event canvas.init
- *
- * @type {Object}
- * @property {SVGElement} svg the created svg element
- * @property {SVGElement} viewport the direct parent of diagram elements and shapes
- */
- eventBus.fire('canvas.init', {
- svg: svg,
- viewport: viewport
- });
- }, this);
- // reset viewbox on shape changes to
- // recompute the viewbox
- eventBus.on([
- 'shape.added',
- 'connection.added',
- 'shape.removed',
- 'connection.removed',
- 'elements.changed'
- ], function() {
- delete this._cachedViewbox;
- }, this);
- eventBus.on('diagram.destroy', 500, this._destroy, this);
- eventBus.on('diagram.clear', 500, this._clear, this);
- };
- Canvas.prototype._destroy = function(emit) {
- this._eventBus.fire('canvas.destroy', {
- svg: this._svg,
- viewport: this._viewport
- });
- var parent = this._container.parentNode;
- if (parent) {
- parent.removeChild(this._container);
- }
- delete this._svg;
- delete this._container;
- delete this._layers;
- delete this._rootElement;
- delete this._viewport;
- };
- Canvas.prototype._clear = function() {
- var self = this;
- var allElements = this._elementRegistry.getAll();
- // remove all elements
- allElements.forEach(function(element) {
- var type = getType(element);
- if (type === 'root') {
- self.setRootElement(null, true);
- } else {
- self._removeElement(element, type);
- }
- });
- // force recomputation of view box
- delete this._cachedViewbox;
- };
- /**
- * Returns the default layer on which
- * all elements are drawn.
- *
- * @returns {SVGElement}
- */
- Canvas.prototype.getDefaultLayer = function() {
- return this.getLayer(BASE_LAYER, 0);
- };
- /**
- * Returns a layer that is used to draw elements
- * or annotations on it.
- *
- * Non-existing layers retrieved through this method
- * will be created. During creation, the optional index
- * may be used to create layers below or above existing layers.
- * A layer with a certain index is always created above all
- * existing layers with the same index.
- *
- * @param {string} name
- * @param {number} index
- *
- * @returns {SVGElement}
- */
- Canvas.prototype.getLayer = function(name, index) {
- if (!name) {
- throw new Error('must specify a name');
- }
- var layer = this._layers[name];
- if (!layer) {
- layer = this._layers[name] = this._createLayer(name, index);
- }
- // throw an error if layer creation / retrival is
- // requested on different index
- if (typeof index !== 'undefined' && layer.index !== index) {
- throw new Error('layer <' + name + '> already created at index <' + index + '>');
- }
- return layer.group;
- };
- /**
- * Creates a given layer and returns it.
- *
- * @param {string} name
- * @param {number} [index=0]
- *
- * @return {Object} layer descriptor with { index, group: SVGGroup }
- */
- Canvas.prototype._createLayer = function(name, index) {
- if (!index) {
- index = 0;
- }
- var childIndex = reduce(this._layers, function(childIndex, layer) {
- if (index >= layer.index) {
- childIndex++;
- }
- return childIndex;
- }, 0);
- return {
- group: createGroup(this._viewport, 'layer-' + name, childIndex),
- index: index
- };
- };
- /**
- * Returns the html element that encloses the
- * drawing canvas.
- *
- * @return {DOMNode}
- */
- Canvas.prototype.getContainer = function() {
- return this._container;
- };
- // markers //////////////////////
- Canvas.prototype._updateMarker = function(element, marker, add) {
- var container;
- if (!element.id) {
- element = this._elementRegistry.get(element);
- }
- // we need to access all
- container = this._elementRegistry._elements[element.id];
- if (!container) {
- return;
- }
- forEach([ container.gfx, container.secondaryGfx ], function(gfx) {
- if (gfx) {
- // invoke either addClass or removeClass based on mode
- if (add) {
- classes(gfx).add(marker);
- } else {
- classes(gfx).remove(marker);
- }
- }
- });
- /**
- * An event indicating that a marker has been updated for an element
- *
- * @event element.marker.update
- * @type {Object}
- * @property {djs.model.Element} element the shape
- * @property {Object} gfx the graphical representation of the shape
- * @property {string} marker
- * @property {boolean} add true if the marker was added, false if it got removed
- */
- this._eventBus.fire('element.marker.update', { element: element, gfx: container.gfx, marker: marker, add: !!add });
- };
- /**
- * Adds a marker to an element (basically a css class).
- *
- * Fires the element.marker.update event, making it possible to
- * integrate extension into the marker life-cycle, too.
- *
- * @example
- * canvas.addMarker('foo', 'some-marker');
- *
- * var fooGfx = canvas.getGraphics('foo');
- *
- * fooGfx; // <g class="... some-marker"> ... </g>
- *
- * @param {string|djs.model.Base} element
- * @param {string} marker
- */
- Canvas.prototype.addMarker = function(element, marker) {
- this._updateMarker(element, marker, true);
- };
- /**
- * Remove a marker from an element.
- *
- * Fires the element.marker.update event, making it possible to
- * integrate extension into the marker life-cycle, too.
- *
- * @param {string|djs.model.Base} element
- * @param {string} marker
- */
- Canvas.prototype.removeMarker = function(element, marker) {
- this._updateMarker(element, marker, false);
- };
- /**
- * Check the existence of a marker on element.
- *
- * @param {string|djs.model.Base} element
- * @param {string} marker
- */
- Canvas.prototype.hasMarker = function(element, marker) {
- if (!element.id) {
- element = this._elementRegistry.get(element);
- }
- var gfx = this.getGraphics(element);
- return classes(gfx).has(marker);
- };
- /**
- * Toggles a marker on an element.
- *
- * Fires the element.marker.update event, making it possible to
- * integrate extension into the marker life-cycle, too.
- *
- * @param {string|djs.model.Base} element
- * @param {string} marker
- */
- Canvas.prototype.toggleMarker = function(element, marker) {
- if (this.hasMarker(element, marker)) {
- this.removeMarker(element, marker);
- } else {
- this.addMarker(element, marker);
- }
- };
- Canvas.prototype.getRootElement = function() {
- if (!this._rootElement) {
- this.setRootElement({ id: '__implicitroot', children: [] });
- }
- return this._rootElement;
- };
- // root element handling //////////////////////
- /**
- * Sets a given element as the new root element for the canvas
- * and returns the new root element.
- *
- * @param {Object|djs.model.Root} element
- * @param {boolean} [override] whether to override the current root element, if any
- *
- * @return {Object|djs.model.Root} new root element
- */
- Canvas.prototype.setRootElement = function(element, override) {
- if (element) {
- this._ensureValid('root', element);
- }
- var currentRoot = this._rootElement,
- elementRegistry = this._elementRegistry,
- eventBus = this._eventBus;
- if (currentRoot) {
- if (!override) {
- throw new Error('rootElement already set, need to specify override');
- }
- // simulate element remove event sequence
- eventBus.fire('root.remove', { element: currentRoot });
- eventBus.fire('root.removed', { element: currentRoot });
- elementRegistry.remove(currentRoot);
- }
- if (element) {
- var gfx = this.getDefaultLayer();
- // resemble element add event sequence
- eventBus.fire('root.add', { element: element });
- elementRegistry.add(element, gfx, this._svg);
- eventBus.fire('root.added', { element: element, gfx: gfx });
- }
- this._rootElement = element;
- return element;
- };
- // add functionality //////////////////////
- Canvas.prototype._ensureValid = function(type, element) {
- if (!element.id) {
- throw new Error('element must have an id');
- }
- if (this._elementRegistry.get(element.id)) {
- throw new Error('element with id ' + element.id + ' already exists');
- }
- var requiredAttrs = REQUIRED_MODEL_ATTRS[type];
- var valid = every(requiredAttrs, function(attr) {
- return typeof element[attr] !== 'undefined';
- });
- if (!valid) {
- throw new Error(
- 'must supply { ' + requiredAttrs.join(', ') + ' } with ' + type);
- }
- };
- Canvas.prototype._setParent = function(element, parent, parentIndex) {
- add(parent.children, element, parentIndex);
- element.parent = parent;
- };
- /**
- * Adds an element to the canvas.
- *
- * This wires the parent <-> child relationship between the element and
- * a explicitly specified parent or an implicit root element.
- *
- * During add it emits the events
- *
- * * <{type}.add> (element, parent)
- * * <{type}.added> (element, gfx)
- *
- * Extensions may hook into these events to perform their magic.
- *
- * @param {string} type
- * @param {Object|djs.model.Base} element
- * @param {Object|djs.model.Base} [parent]
- * @param {number} [parentIndex]
- *
- * @return {Object|djs.model.Base} the added element
- */
- Canvas.prototype._addElement = function(type, element, parent, parentIndex) {
- parent = parent || this.getRootElement();
- var eventBus = this._eventBus,
- graphicsFactory = this._graphicsFactory;
- this._ensureValid(type, element);
- eventBus.fire(type + '.add', { element: element, parent: parent });
- this._setParent(element, parent, parentIndex);
- // create graphics
- var gfx = graphicsFactory.create(type, element, parentIndex);
- this._elementRegistry.add(element, gfx);
- // update its visual
- graphicsFactory.update(type, element, gfx);
- eventBus.fire(type + '.added', { element: element, gfx: gfx });
- return element;
- };
- /**
- * Adds a shape to the canvas
- *
- * @param {Object|djs.model.Shape} shape to add to the diagram
- * @param {djs.model.Base} [parent]
- * @param {number} [parentIndex]
- *
- * @return {djs.model.Shape} the added shape
- */
- Canvas.prototype.addShape = function(shape, parent, parentIndex) {
- return this._addElement('shape', shape, parent, parentIndex);
- };
- /**
- * Adds a connection to the canvas
- *
- * @param {Object|djs.model.Connection} connection to add to the diagram
- * @param {djs.model.Base} [parent]
- * @param {number} [parentIndex]
- *
- * @return {djs.model.Connection} the added connection
- */
- Canvas.prototype.addConnection = function(connection, parent, parentIndex) {
- return this._addElement('connection', connection, parent, parentIndex);
- };
- /**
- * Internal remove element
- */
- Canvas.prototype._removeElement = function(element, type) {
- var elementRegistry = this._elementRegistry,
- graphicsFactory = this._graphicsFactory,
- eventBus = this._eventBus;
- element = elementRegistry.get(element.id || element);
- if (!element) {
- // element was removed already
- return;
- }
- eventBus.fire(type + '.remove', { element: element });
- graphicsFactory.remove(element);
- // unset parent <-> child relationship
- remove$2(element.parent && element.parent.children, element);
- element.parent = null;
- eventBus.fire(type + '.removed', { element: element });
- elementRegistry.remove(element);
- return element;
- };
- /**
- * Removes a shape from the canvas
- *
- * @param {string|djs.model.Shape} shape or shape id to be removed
- *
- * @return {djs.model.Shape} the removed shape
- */
- Canvas.prototype.removeShape = function(shape) {
- /**
- * An event indicating that a shape is about to be removed from the canvas.
- *
- * @memberOf Canvas
- *
- * @event shape.remove
- * @type {Object}
- * @property {djs.model.Shape} element the shape descriptor
- * @property {Object} gfx the graphical representation of the shape
- */
- /**
- * An event indicating that a shape has been removed from the canvas.
- *
- * @memberOf Canvas
- *
- * @event shape.removed
- * @type {Object}
- * @property {djs.model.Shape} element the shape descriptor
- * @property {Object} gfx the graphical representation of the shape
- */
- return this._removeElement(shape, 'shape');
- };
- /**
- * Removes a connection from the canvas
- *
- * @param {string|djs.model.Connection} connection or connection id to be removed
- *
- * @return {djs.model.Connection} the removed connection
- */
- Canvas.prototype.removeConnection = function(connection) {
- /**
- * An event indicating that a connection is about to be removed from the canvas.
- *
- * @memberOf Canvas
- *
- * @event connection.remove
- * @type {Object}
- * @property {djs.model.Connection} element the connection descriptor
- * @property {Object} gfx the graphical representation of the connection
- */
- /**
- * An event indicating that a connection has been removed from the canvas.
- *
- * @memberOf Canvas
- *
- * @event connection.removed
- * @type {Object}
- * @property {djs.model.Connection} element the connection descriptor
- * @property {Object} gfx the graphical representation of the connection
- */
- return this._removeElement(connection, 'connection');
- };
- /**
- * Return the graphical object underlaying a certain diagram element
- *
- * @param {string|djs.model.Base} element descriptor of the element
- * @param {boolean} [secondary=false] whether to return the secondary connected element
- *
- * @return {SVGElement}
- */
- Canvas.prototype.getGraphics = function(element, secondary) {
- return this._elementRegistry.getGraphics(element, secondary);
- };
- /**
- * Perform a viewbox update via a given change function.
- *
- * @param {Function} changeFn
- */
- Canvas.prototype._changeViewbox = function(changeFn) {
- // notify others of the upcoming viewbox change
- this._eventBus.fire('canvas.viewbox.changing');
- // perform actual change
- changeFn.apply(this);
- // reset the cached viewbox so that
- // a new get operation on viewbox or zoom
- // triggers a viewbox re-computation
- this._cachedViewbox = null;
- // notify others of the change; this step
- // may or may not be debounced
- this._viewboxChanged();
- };
- Canvas.prototype._viewboxChanged = function() {
- this._eventBus.fire('canvas.viewbox.changed', { viewbox: this.viewbox() });
- };
- /**
- * Gets or sets the view box of the canvas, i.e. the
- * area that is currently displayed.
- *
- * The getter may return a cached viewbox (if it is currently
- * changing). To force a recomputation, pass `false` as the first argument.
- *
- * @example
- *
- * canvas.viewbox({ x: 100, y: 100, width: 500, height: 500 })
- *
- * // sets the visible area of the diagram to (100|100) -> (600|100)
- * // and and scales it according to the diagram width
- *
- * var viewbox = canvas.viewbox(); // pass `false` to force recomputing the box.
- *
- * console.log(viewbox);
- * // {
- * // inner: Dimensions,
- * // outer: Dimensions,
- * // scale,
- * // x, y,
- * // width, height
- * // }
- *
- * // if the current diagram is zoomed and scrolled, you may reset it to the
- * // default zoom via this method, too:
- *
- * var zoomedAndScrolledViewbox = canvas.viewbox();
- *
- * canvas.viewbox({
- * x: 0,
- * y: 0,
- * width: zoomedAndScrolledViewbox.outer.width,
- * height: zoomedAndScrolledViewbox.outer.height
- * });
- *
- * @param {Object} [box] the new view box to set
- * @param {number} box.x the top left X coordinate of the canvas visible in view box
- * @param {number} box.y the top left Y coordinate of the canvas visible in view box
- * @param {number} box.width the visible width
- * @param {number} box.height
- *
- * @return {Object} the current view box
- */
- Canvas.prototype.viewbox = function(box) {
- if (box === undefined && this._cachedViewbox) {
- return this._cachedViewbox;
- }
- var viewport = this._viewport,
- innerBox,
- outerBox = this.getSize(),
- matrix,
- transform$1,
- scale,
- x, y;
- if (!box) {
- // compute the inner box based on the
- // diagrams default layer. This allows us to exclude
- // external components, such as overlays
- innerBox = this.getDefaultLayer().getBBox();
- transform$1 = transform(viewport);
- matrix = transform$1 ? transform$1.matrix : createMatrix();
- scale = round(matrix.a, 1000);
- x = round(-matrix.e || 0, 1000);
- y = round(-matrix.f || 0, 1000);
- box = this._cachedViewbox = {
- x: x ? x / scale : 0,
- y: y ? y / scale : 0,
- width: outerBox.width / scale,
- height: outerBox.height / scale,
- scale: scale,
- inner: {
- width: innerBox.width,
- height: innerBox.height,
- x: innerBox.x,
- y: innerBox.y
- },
- outer: outerBox
- };
- return box;
- } else {
- this._changeViewbox(function() {
- scale = Math.min(outerBox.width / box.width, outerBox.height / box.height);
- var matrix = this._svg.createSVGMatrix()
- .scale(scale)
- .translate(-box.x, -box.y);
- transform(viewport, matrix);
- });
- }
- return box;
- };
- /**
- * Gets or sets the scroll of the canvas.
- *
- * @param {Object} [delta] the new scroll to apply.
- *
- * @param {number} [delta.dx]
- * @param {number} [delta.dy]
- */
- Canvas.prototype.scroll = function(delta) {
- var node = this._viewport;
- var matrix = node.getCTM();
- if (delta) {
- this._changeViewbox(function() {
- delta = assign({ dx: 0, dy: 0 }, delta || {});
- matrix = this._svg.createSVGMatrix().translate(delta.dx, delta.dy).multiply(matrix);
- setCTM(node, matrix);
- });
- }
- return { x: matrix.e, y: matrix.f };
- };
- /**
- * Gets or sets the current zoom of the canvas, optionally zooming
- * to the specified position.
- *
- * The getter may return a cached zoom level. Call it with `false` as
- * the first argument to force recomputation of the current level.
- *
- * @param {string|number} [newScale] the new zoom level, either a number, i.e. 0.9,
- * or `fit-viewport` to adjust the size to fit the current viewport
- * @param {string|Point} [center] the reference point { x: .., y: ..} to zoom to, 'auto' to zoom into mid or null
- *
- * @return {number} the current scale
- */
- Canvas.prototype.zoom = function(newScale, center) {
- if (!newScale) {
- return this.viewbox(newScale).scale;
- }
- if (newScale === 'fit-viewport') {
- return this._fitViewport(center);
- }
- var outer,
- matrix;
- this._changeViewbox(function() {
- if (typeof center !== 'object') {
- outer = this.viewbox().outer;
- center = {
- x: outer.width / 2,
- y: outer.height / 2
- };
- }
- matrix = this._setZoom(newScale, center);
- });
- return round(matrix.a, 1000);
- };
- function setCTM(node, m) {
- var mstr = 'matrix(' + m.a + ',' + m.b + ',' + m.c + ',' + m.d + ',' + m.e + ',' + m.f + ')';
- node.setAttribute('transform', mstr);
- }
- Canvas.prototype._fitViewport = function(center) {
- var vbox = this.viewbox(),
- outer = vbox.outer,
- inner = vbox.inner,
- newScale,
- newViewbox;
- // display the complete diagram without zooming in.
- // instead of relying on internal zoom, we perform a
- // hard reset on the canvas viewbox to realize this
- //
- // if diagram does not need to be zoomed in, we focus it around
- // the diagram origin instead
- if (inner.x >= 0 &&
- inner.y >= 0 &&
- inner.x + inner.width <= outer.width &&
- inner.y + inner.height <= outer.height &&
- !center) {
- newViewbox = {
- x: 0,
- y: 0,
- width: Math.max(inner.width + inner.x, outer.width),
- height: Math.max(inner.height + inner.y, outer.height)
- };
- } else {
- newScale = Math.min(1, outer.width / inner.width, outer.height / inner.height);
- newViewbox = {
- x: inner.x + (center ? inner.width / 2 - outer.width / newScale / 2 : 0),
- y: inner.y + (center ? inner.height / 2 - outer.height / newScale / 2 : 0),
- width: outer.width / newScale,
- height: outer.height / newScale
- };
- }
- this.viewbox(newViewbox);
- return this.viewbox(false).scale;
- };
- Canvas.prototype._setZoom = function(scale, center) {
- var svg = this._svg,
- viewport = this._viewport;
- var matrix = svg.createSVGMatrix();
- var point = svg.createSVGPoint();
- var centerPoint,
- originalPoint,
- currentMatrix,
- scaleMatrix,
- newMatrix;
- currentMatrix = viewport.getCTM();
- var currentScale = currentMatrix.a;
- if (center) {
- centerPoint = assign(point, center);
- // revert applied viewport transformations
- originalPoint = centerPoint.matrixTransform(currentMatrix.inverse());
- // create scale matrix
- scaleMatrix = matrix
- .translate(originalPoint.x, originalPoint.y)
- .scale(1 / currentScale * scale)
- .translate(-originalPoint.x, -originalPoint.y);
- newMatrix = currentMatrix.multiply(scaleMatrix);
- } else {
- newMatrix = matrix.scale(scale);
- }
- setCTM(this._viewport, newMatrix);
- return newMatrix;
- };
- /**
- * Returns the size of the canvas
- *
- * @return {Dimensions}
- */
- Canvas.prototype.getSize = function() {
- return {
- width: this._container.clientWidth,
- height: this._container.clientHeight
- };
- };
- /**
- * Return the absolute bounding box for the given element
- *
- * The absolute bounding box may be used to display overlays in the
- * callers (browser) coordinate system rather than the zoomed in/out
- * canvas coordinates.
- *
- * @param {ElementDescriptor} element
- * @return {Bounds} the absolute bounding box
- */
- Canvas.prototype.getAbsoluteBBox = function(element) {
- var vbox = this.viewbox();
- var bbox;
- // connection
- // use svg bbox
- if (element.waypoints) {
- var gfx = this.getGraphics(element);
- bbox = gfx.getBBox();
- }
- // shapes
- // use data
- else {
- bbox = element;
- }
- var x = bbox.x * vbox.scale - vbox.x * vbox.scale;
- var y = bbox.y * vbox.scale - vbox.y * vbox.scale;
- var width = bbox.width * vbox.scale;
- var height = bbox.height * vbox.scale;
- return {
- x: x,
- y: y,
- width: width,
- height: height
- };
- };
- /**
- * Fires an event in order other modules can react to the
- * canvas resizing
- */
- Canvas.prototype.resized = function() {
- // force recomputation of view box
- delete this._cachedViewbox;
- this._eventBus.fire('canvas.resized');
- };
- var ELEMENT_ID = 'data-element-id';
- /**
- * @class
- *
- * A registry that keeps track of all shapes in the diagram.
- */
- function ElementRegistry(eventBus) {
- this._elements = {};
- this._eventBus = eventBus;
- }
- ElementRegistry.$inject = [ 'eventBus' ];
- /**
- * Register a pair of (element, gfx, (secondaryGfx)).
- *
- * @param {djs.model.Base} element
- * @param {SVGElement} gfx
- * @param {SVGElement} [secondaryGfx] optional other element to register, too
- */
- ElementRegistry.prototype.add = function(element, gfx, secondaryGfx) {
- var id = element.id;
- this._validateId(id);
- // associate dom node with element
- attr(gfx, ELEMENT_ID, id);
- if (secondaryGfx) {
- attr(secondaryGfx, ELEMENT_ID, id);
- }
- this._elements[id] = { element: element, gfx: gfx, secondaryGfx: secondaryGfx };
- };
- /**
- * Removes an element from the registry.
- *
- * @param {djs.model.Base} element
- */
- ElementRegistry.prototype.remove = function(element) {
- var elements = this._elements,
- id = element.id || element,
- container = id && elements[id];
- if (container) {
- // unset element id on gfx
- attr(container.gfx, ELEMENT_ID, '');
- if (container.secondaryGfx) {
- attr(container.secondaryGfx, ELEMENT_ID, '');
- }
- delete elements[id];
- }
- };
- /**
- * Update the id of an element
- *
- * @param {djs.model.Base} element
- * @param {string} newId
- */
- ElementRegistry.prototype.updateId = function(element, newId) {
- this._validateId(newId);
- if (typeof element === 'string') {
- element = this.get(element);
- }
- this._eventBus.fire('element.updateId', {
- element: element,
- newId: newId
- });
- var gfx = this.getGraphics(element),
- secondaryGfx = this.getGraphics(element, true);
- this.remove(element);
- element.id = newId;
- this.add(element, gfx, secondaryGfx);
- };
- /**
- * Return the model element for a given id or graphics.
- *
- * @example
- *
- * elementRegistry.get('SomeElementId_1');
- * elementRegistry.get(gfx);
- *
- *
- * @param {string|SVGElement} filter for selecting the element
- *
- * @return {djs.model.Base}
- */
- ElementRegistry.prototype.get = function(filter) {
- var id;
- if (typeof filter === 'string') {
- id = filter;
- } else {
- id = filter && attr(filter, ELEMENT_ID);
- }
- var container = this._elements[id];
- return container && container.element;
- };
- /**
- * Return all elements that match a given filter function.
- *
- * @param {Function} fn
- *
- * @return {Array<djs.model.Base>}
- */
- ElementRegistry.prototype.filter = function(fn) {
- var filtered = [];
- this.forEach(function(element, gfx) {
- if (fn(element, gfx)) {
- filtered.push(element);
- }
- });
- return filtered;
- };
- /**
- * Return all rendered model elements.
- *
- * @return {Array<djs.model.Base>}
- */
- ElementRegistry.prototype.getAll = function() {
- return this.filter(function(e) { return e; });
- };
- /**
- * Iterate over all diagram elements.
- *
- * @param {Function} fn
- */
- ElementRegistry.prototype.forEach = function(fn) {
- var map = this._elements;
- Object.keys(map).forEach(function(id) {
- var container = map[id],
- element = container.element,
- gfx = container.gfx;
- return fn(element, gfx);
- });
- };
- /**
- * Return the graphical representation of an element or its id.
- *
- * @example
- * elementRegistry.getGraphics('SomeElementId_1');
- * elementRegistry.getGraphics(rootElement); // <g ...>
- *
- * elementRegistry.getGraphics(rootElement, true); // <svg ...>
- *
- *
- * @param {string|djs.model.Base} filter
- * @param {boolean} [secondary=false] whether to return the secondary connected element
- *
- * @return {SVGElement}
- */
- ElementRegistry.prototype.getGraphics = function(filter, secondary) {
- var id = filter.id || filter;
- var container = this._elements[id];
- return container && (secondary ? container.secondaryGfx : container.gfx);
- };
- /**
- * Validate the suitability of the given id and signals a problem
- * with an exception.
- *
- * @param {string} id
- *
- * @throws {Error} if id is empty or already assigned
- */
- ElementRegistry.prototype._validateId = function(id) {
- if (!id) {
- throw new Error('element must have an id');
- }
- if (this._elements[id]) {
- throw new Error('element with id ' + id + ' already added');
- }
- };
- /**
- * An empty collection stub. Use {@link RefsCollection.extend} to extend a
- * collection with ref semantics.
- *
- * @class RefsCollection
- */
- /**
- * Extends a collection with {@link Refs} aware methods
- *
- * @memberof RefsCollection
- * @static
- *
- * @param {Array<Object>} collection
- * @param {Refs} refs instance
- * @param {Object} property represented by the collection
- * @param {Object} target object the collection is attached to
- *
- * @return {RefsCollection<Object>} the extended array
- */
- function extend$1(collection, refs, property, target) {
- var inverseProperty = property.inverse;
- /**
- * Removes the given element from the array and returns it.
- *
- * @method RefsCollection#remove
- *
- * @param {Object} element the element to remove
- */
- Object.defineProperty(collection, 'remove', {
- value: function(element) {
- var idx = this.indexOf(element);
- if (idx !== -1) {
- this.splice(idx, 1);
- // unset inverse
- refs.unset(element, inverseProperty, target);
- }
- return element;
- }
- });
- /**
- * Returns true if the collection contains the given element
- *
- * @method RefsCollection#contains
- *
- * @param {Object} element the element to check for
- */
- Object.defineProperty(collection, 'contains', {
- value: function(element) {
- return this.indexOf(element) !== -1;
- }
- });
- /**
- * Adds an element to the array, unless it exists already (set semantics).
- *
- * @method RefsCollection#add
- *
- * @param {Object} element the element to add
- * @param {Number} optional index to add element to
- * (possibly moving other elements around)
- */
- Object.defineProperty(collection, 'add', {
- value: function(element, idx) {
- var currentIdx = this.indexOf(element);
- if (typeof idx === 'undefined') {
- if (currentIdx !== -1) {
- // element already in collection (!)
- return;
- }
- // add to end of array, as no idx is specified
- idx = this.length;
- }
- // handle already in collection
- if (currentIdx !== -1) {
- // remove element from currentIdx
- this.splice(currentIdx, 1);
- }
- // add element at idx
- this.splice(idx, 0, element);
- if (currentIdx === -1) {
- // set inverse, unless element was
- // in collection already
- refs.set(element, inverseProperty, target);
- }
- }
- });
- // a simple marker, identifying this element
- // as being a refs collection
- Object.defineProperty(collection, '__refs_collection', {
- value: true
- });
- return collection;
- }
- function isExtended(collection) {
- return collection.__refs_collection === true;
- }
- var extend_1 = extend$1;
- var isExtended_1 = isExtended;
- var collection = {
- extend: extend_1,
- isExtended: isExtended_1
- };
- function hasOwnProperty(e, property) {
- return Object.prototype.hasOwnProperty.call(e, property.name || property);
- }
- function defineCollectionProperty(ref, property, target) {
- var collection$1 = collection.extend(target[property.name] || [], ref, property, target);
- Object.defineProperty(target, property.name, {
- enumerable: property.enumerable,
- value: collection$1
- });
- if (collection$1.length) {
- collection$1.forEach(function(o) {
- ref.set(o, property.inverse, target);
- });
- }
- }
- function defineProperty(ref, property, target) {
- var inverseProperty = property.inverse;
- var _value = target[property.name];
- Object.defineProperty(target, property.name, {
- configurable: property.configurable,
- enumerable: property.enumerable,
- get: function() {
- return _value;
- },
- set: function(value) {
- // return if we already performed all changes
- if (value === _value) {
- return;
- }
- var old = _value;
- // temporary set null
- _value = null;
- if (old) {
- ref.unset(old, inverseProperty, target);
- }
- // set new value
- _value = value;
- // set inverse value
- ref.set(_value, inverseProperty, target);
- }
- });
- }
- /**
- * Creates a new references object defining two inversly related
- * attribute descriptors a and b.
- *
- * <p>
- * When bound to an object using {@link Refs#bind} the references
- * get activated and ensure that add and remove operations are applied
- * reversely, too.
- * </p>
- *
- * <p>
- * For attributes represented as collections {@link Refs} provides the
- * {@link RefsCollection#add}, {@link RefsCollection#remove} and {@link RefsCollection#contains} extensions
- * that must be used to properly hook into the inverse change mechanism.
- * </p>
- *
- * @class Refs
- *
- * @classdesc A bi-directional reference between two attributes.
- *
- * @param {Refs.AttributeDescriptor} a property descriptor
- * @param {Refs.AttributeDescriptor} b property descriptor
- *
- * @example
- *
- * var refs = Refs({ name: 'wheels', collection: true, enumerable: true }, { name: 'car' });
- *
- * var car = { name: 'toyota' };
- * var wheels = [{ pos: 'front-left' }, { pos: 'front-right' }];
- *
- * refs.bind(car, 'wheels');
- *
- * car.wheels // []
- * car.wheels.add(wheels[0]);
- * car.wheels.add(wheels[1]);
- *
- * car.wheels // [{ pos: 'front-left' }, { pos: 'front-right' }]
- *
- * wheels[0].car // { name: 'toyota' };
- * car.wheels.remove(wheels[0]);
- *
- * wheels[0].car // undefined
- */
- function Refs(a, b) {
- if (!(this instanceof Refs)) {
- return new Refs(a, b);
- }
- // link
- a.inverse = b;
- b.inverse = a;
- this.props = {};
- this.props[a.name] = a;
- this.props[b.name] = b;
- }
- /**
- * Binds one side of a bi-directional reference to a
- * target object.
- *
- * @memberOf Refs
- *
- * @param {Object} target
- * @param {String} property
- */
- Refs.prototype.bind = function(target, property) {
- if (typeof property === 'string') {
- if (!this.props[property]) {
- throw new Error('no property <' + property + '> in ref');
- }
- property = this.props[property];
- }
- if (property.collection) {
- defineCollectionProperty(this, property, target);
- } else {
- defineProperty(this, property, target);
- }
- };
- Refs.prototype.ensureRefsCollection = function(target, property) {
- var collection$1 = target[property.name];
- if (!collection.isExtended(collection$1)) {
- defineCollectionProperty(this, property, target);
- }
- return collection$1;
- };
- Refs.prototype.ensureBound = function(target, property) {
- if (!hasOwnProperty(target, property)) {
- this.bind(target, property);
- }
- };
- Refs.prototype.unset = function(target, property, value) {
- if (target) {
- this.ensureBound(target, property);
- if (property.collection) {
- this.ensureRefsCollection(target, property).remove(value);
- } else {
- target[property.name] = undefined;
- }
- }
- };
- Refs.prototype.set = function(target, property, value) {
- if (target) {
- this.ensureBound(target, property);
- if (property.collection) {
- this.ensureRefsCollection(target, property).add(value);
- } else {
- target[property.name] = value;
- }
- }
- };
- var refs = Refs;
- var objectRefs = refs;
- var Collection = collection;
- objectRefs.Collection = Collection;
- var parentRefs = new objectRefs({ name: 'children', enumerable: true, collection: true }, { name: 'parent' }),
- labelRefs = new objectRefs({ name: 'labels', enumerable: true, collection: true }, { name: 'labelTarget' }),
- attacherRefs = new objectRefs({ name: 'attachers', collection: true }, { name: 'host' }),
- outgoingRefs = new objectRefs({ name: 'outgoing', collection: true }, { name: 'source' }),
- incomingRefs = new objectRefs({ name: 'incoming', collection: true }, { name: 'target' });
- /**
- * @namespace djs.model
- */
- /**
- * @memberOf djs.model
- */
- /**
- * The basic graphical representation
- *
- * @class
- *
- * @abstract
- */
- function Base() {
- /**
- * The object that backs up the shape
- *
- * @name Base#businessObject
- * @type Object
- */
- Object.defineProperty(this, 'businessObject', {
- writable: true
- });
- /**
- * Single label support, will mapped to multi label array
- *
- * @name Base#label
- * @type Object
- */
- Object.defineProperty(this, 'label', {
- get: function() {
- return this.labels[0];
- },
- set: function(newLabel) {
- var label = this.label,
- labels = this.labels;
- if (!newLabel && label) {
- labels.remove(label);
- } else {
- labels.add(newLabel, 0);
- }
- }
- });
- /**
- * The parent shape
- *
- * @name Base#parent
- * @type Shape
- */
- parentRefs.bind(this, 'parent');
- /**
- * The list of labels
- *
- * @name Base#labels
- * @type Label
- */
- labelRefs.bind(this, 'labels');
- /**
- * The list of outgoing connections
- *
- * @name Base#outgoing
- * @type Array<Connection>
- */
- outgoingRefs.bind(this, 'outgoing');
- /**
- * The list of incoming connections
- *
- * @name Base#incoming
- * @type Array<Connection>
- */
- incomingRefs.bind(this, 'incoming');
- }
- /**
- * A graphical object
- *
- * @class
- * @constructor
- *
- * @extends Base
- */
- function Shape() {
- Base.call(this);
- /**
- * Indicates frame shapes
- *
- * @name Shape#isFrame
- * @type boolean
- */
- /**
- * The list of children
- *
- * @name Shape#children
- * @type Array<Base>
- */
- parentRefs.bind(this, 'children');
- /**
- * @name Shape#host
- * @type Shape
- */
- attacherRefs.bind(this, 'host');
- /**
- * @name Shape#attachers
- * @type Shape
- */
- attacherRefs.bind(this, 'attachers');
- }
- inherits_browser(Shape, Base);
- /**
- * A root graphical object
- *
- * @class
- * @constructor
- *
- * @extends Shape
- */
- function Root() {
- Shape.call(this);
- }
- inherits_browser(Root, Shape);
- /**
- * A label for an element
- *
- * @class
- * @constructor
- *
- * @extends Shape
- */
- function Label() {
- Shape.call(this);
- /**
- * The labeled element
- *
- * @name Label#labelTarget
- * @type Base
- */
- labelRefs.bind(this, 'labelTarget');
- }
- inherits_browser(Label, Shape);
- /**
- * A connection between two elements
- *
- * @class
- * @constructor
- *
- * @extends Base
- */
- function Connection() {
- Base.call(this);
- /**
- * The element this connection originates from
- *
- * @name Connection#source
- * @type Base
- */
- outgoingRefs.bind(this, 'source');
- /**
- * The element this connection points to
- *
- * @name Connection#target
- * @type Base
- */
- incomingRefs.bind(this, 'target');
- }
- inherits_browser(Connection, Base);
- var types = {
- connection: Connection,
- shape: Shape,
- label: Label,
- root: Root
- };
- /**
- * Creates a new model element of the specified type
- *
- * @method create
- *
- * @example
- *
- * var shape1 = Model.create('shape', { x: 10, y: 10, width: 100, height: 100 });
- * var shape2 = Model.create('shape', { x: 210, y: 210, width: 100, height: 100 });
- *
- * var connection = Model.create('connection', { waypoints: [ { x: 110, y: 55 }, {x: 210, y: 55 } ] });
- *
- * @param {string} type lower-cased model name
- * @param {Object} attrs attributes to initialize the new model instance with
- *
- * @return {Base} the new model instance
- */
- function create$1(type, attrs) {
- var Type = types[type];
- if (!Type) {
- throw new Error('unknown type: <' + type + '>');
- }
- return assign(new Type(), attrs);
- }
- /**
- * A factory for diagram-js shapes
- */
- function ElementFactory() {
- this._uid = 12;
- }
- ElementFactory.prototype.createRoot = function(attrs) {
- return this.create('root', attrs);
- };
- ElementFactory.prototype.createLabel = function(attrs) {
- return this.create('label', attrs);
- };
- ElementFactory.prototype.createShape = function(attrs) {
- return this.create('shape', attrs);
- };
- ElementFactory.prototype.createConnection = function(attrs) {
- return this.create('connection', attrs);
- };
- /**
- * Create a model element with the given type and
- * a number of pre-set attributes.
- *
- * @param {string} type
- * @param {Object} attrs
- * @return {djs.model.Base} the newly created model instance
- */
- ElementFactory.prototype.create = function(type, attrs) {
- attrs = assign({}, attrs || {});
- if (!attrs.id) {
- attrs.id = type + '_' + (this._uid++);
- }
- return create$1(type, attrs);
- };
- var FN_REF = '__fn';
- var DEFAULT_PRIORITY = 1000;
- var slice$1 = Array.prototype.slice;
- /**
- * A general purpose event bus.
- *
- * This component is used to communicate across a diagram instance.
- * Other parts of a diagram can use it to listen to and broadcast events.
- *
- *
- * ## Registering for Events
- *
- * The event bus provides the {@link EventBus#on} and {@link EventBus#once}
- * methods to register for events. {@link EventBus#off} can be used to
- * remove event registrations. Listeners receive an instance of {@link Event}
- * as the first argument. It allows them to hook into the event execution.
- *
- * ```javascript
- *
- * // listen for event
- * eventBus.on('foo', function(event) {
- *
- * // access event type
- * event.type; // 'foo'
- *
- * // stop propagation to other listeners
- * event.stopPropagation();
- *
- * // prevent event default
- * event.preventDefault();
- * });
- *
- * // listen for event with custom payload
- * eventBus.on('bar', function(event, payload) {
- * console.log(payload);
- * });
- *
- * // listen for event returning value
- * eventBus.on('foobar', function(event) {
- *
- * // stop event propagation + prevent default
- * return false;
- *
- * // stop event propagation + return custom result
- * return {
- * complex: 'listening result'
- * };
- * });
- *
- *
- * // listen with custom priority (default=1000, higher is better)
- * eventBus.on('priorityfoo', 1500, function(event) {
- * console.log('invoked first!');
- * });
- *
- *
- * // listen for event and pass the context (`this`)
- * eventBus.on('foobar', function(event) {
- * this.foo();
- * }, this);
- * ```
- *
- *
- * ## Emitting Events
- *
- * Events can be emitted via the event bus using {@link EventBus#fire}.
- *
- * ```javascript
- *
- * // false indicates that the default action
- * // was prevented by listeners
- * if (eventBus.fire('foo') === false) {
- * console.log('default has been prevented!');
- * };
- *
- *
- * // custom args + return value listener
- * eventBus.on('sum', function(event, a, b) {
- * return a + b;
- * });
- *
- * // you can pass custom arguments + retrieve result values.
- * var sum = eventBus.fire('sum', 1, 2);
- * console.log(sum); // 3
- * ```
- */
- function EventBus() {
- this._listeners = {};
- // cleanup on destroy on lowest priority to allow
- // message passing until the bitter end
- this.on('diagram.destroy', 1, this._destroy, this);
- }
- /**
- * Register an event listener for events with the given name.
- *
- * The callback will be invoked with `event, ...additionalArguments`
- * that have been passed to {@link EventBus#fire}.
- *
- * Returning false from a listener will prevent the events default action
- * (if any is specified). To stop an event from being processed further in
- * other listeners execute {@link Event#stopPropagation}.
- *
- * Returning anything but `undefined` from a listener will stop the listener propagation.
- *
- * @param {string|Array<string>} events
- * @param {number} [priority=1000] the priority in which this listener is called, larger is higher
- * @param {Function} callback
- * @param {Object} [that] Pass context (`this`) to the callback
- */
- EventBus.prototype.on = function(events, priority, callback, that) {
- events = isArray(events) ? events : [ events ];
- if (isFunction(priority)) {
- that = callback;
- callback = priority;
- priority = DEFAULT_PRIORITY;
- }
- if (!isNumber(priority)) {
- throw new Error('priority must be a number');
- }
- var actualCallback = callback;
- if (that) {
- actualCallback = bind(callback, that);
- // make sure we remember and are able to remove
- // bound callbacks via {@link #off} using the original
- // callback
- actualCallback[FN_REF] = callback[FN_REF] || callback;
- }
- var self = this;
- events.forEach(function(e) {
- self._addListener(e, {
- priority: priority,
- callback: actualCallback,
- next: null
- });
- });
- };
- /**
- * Register an event listener that is executed only once.
- *
- * @param {string} event the event name to register for
- * @param {number} [priority=1000] the priority in which this listener is called, larger is higher
- * @param {Function} callback the callback to execute
- * @param {Object} [that] Pass context (`this`) to the callback
- */
- EventBus.prototype.once = function(event, priority, callback, that) {
- var self = this;
- if (isFunction(priority)) {
- that = callback;
- callback = priority;
- priority = DEFAULT_PRIORITY;
- }
- if (!isNumber(priority)) {
- throw new Error('priority must be a number');
- }
- function wrappedCallback() {
- var result = callback.apply(that, arguments);
- self.off(event, wrappedCallback);
- return result;
- }
- // make sure we remember and are able to remove
- // bound callbacks via {@link #off} using the original
- // callback
- wrappedCallback[FN_REF] = callback;
- this.on(event, priority, wrappedCallback);
- };
- /**
- * Removes event listeners by event and callback.
- *
- * If no callback is given, all listeners for a given event name are being removed.
- *
- * @param {string|Array<string>} events
- * @param {Function} [callback]
- */
- EventBus.prototype.off = function(events, callback) {
- events = isArray(events) ? events : [ events ];
- var self = this;
- events.forEach(function(event) {
- self._removeListener(event, callback);
- });
- };
- /**
- * Create an EventBus event.
- *
- * @param {Object} data
- *
- * @return {Object} event, recognized by the eventBus
- */
- EventBus.prototype.createEvent = function(data) {
- var event = new InternalEvent();
- event.init(data);
- return event;
- };
- /**
- * Fires a named event.
- *
- * @example
- *
- * // fire event by name
- * events.fire('foo');
- *
- * // fire event object with nested type
- * var event = { type: 'foo' };
- * events.fire(event);
- *
- * // fire event with explicit type
- * var event = { x: 10, y: 20 };
- * events.fire('element.moved', event);
- *
- * // pass additional arguments to the event
- * events.on('foo', function(event, bar) {
- * alert(bar);
- * });
- *
- * events.fire({ type: 'foo' }, 'I am bar!');
- *
- * @param {string} [name] the optional event name
- * @param {Object} [event] the event object
- * @param {...Object} additional arguments to be passed to the callback functions
- *
- * @return {boolean} the events return value, if specified or false if the
- * default action was prevented by listeners
- */
- EventBus.prototype.fire = function(type, data) {
- var event,
- firstListener,
- returnValue,
- args;
- args = slice$1.call(arguments);
- if (typeof type === 'object') {
- data = type;
- type = data.type;
- }
- if (!type) {
- throw new Error('no event type specified');
- }
- firstListener = this._listeners[type];
- if (!firstListener) {
- return;
- }
- // we make sure we fire instances of our home made
- // events here. We wrap them only once, though
- if (data instanceof InternalEvent) {
- // we are fine, we alread have an event
- event = data;
- } else {
- event = this.createEvent(data);
- }
- // ensure we pass the event as the first parameter
- args[0] = event;
- // original event type (in case we delegate)
- var originalType = event.type;
- // update event type before delegation
- if (type !== originalType) {
- event.type = type;
- }
- try {
- returnValue = this._invokeListeners(event, args, firstListener);
- } finally {
- // reset event type after delegation
- if (type !== originalType) {
- event.type = originalType;
- }
- }
- // set the return value to false if the event default
- // got prevented and no other return value exists
- if (returnValue === undefined && event.defaultPrevented) {
- returnValue = false;
- }
- return returnValue;
- };
- EventBus.prototype.handleError = function(error) {
- return this.fire('error', { error: error }) === false;
- };
- EventBus.prototype._destroy = function() {
- this._listeners = {};
- };
- EventBus.prototype._invokeListeners = function(event, args, listener) {
- var returnValue;
- while (listener) {
- // handle stopped propagation
- if (event.cancelBubble) {
- break;
- }
- returnValue = this._invokeListener(event, args, listener);
- listener = listener.next;
- }
- return returnValue;
- };
- EventBus.prototype._invokeListener = function(event, args, listener) {
- var returnValue;
- try {
- // returning false prevents the default action
- returnValue = invokeFunction(listener.callback, args);
- // stop propagation on return value
- if (returnValue !== undefined) {
- event.returnValue = returnValue;
- event.stopPropagation();
- }
- // prevent default on return false
- if (returnValue === false) {
- event.preventDefault();
- }
- } catch (e) {
- if (!this.handleError(e)) {
- console.error('unhandled error in event listener');
- console.error(e.stack);
- throw e;
- }
- }
- return returnValue;
- };
- /*
- * Add new listener with a certain priority to the list
- * of listeners (for the given event).
- *
- * The semantics of listener registration / listener execution are
- * first register, first serve: New listeners will always be inserted
- * after existing listeners with the same priority.
- *
- * Example: Inserting two listeners with priority 1000 and 1300
- *
- * * before: [ 1500, 1500, 1000, 1000 ]
- * * after: [ 1500, 1500, (new=1300), 1000, 1000, (new=1000) ]
- *
- * @param {string} event
- * @param {Object} listener { priority, callback }
- */
- EventBus.prototype._addListener = function(event, newListener) {
- var listener = this._getListeners(event),
- previousListener;
- // no prior listeners
- if (!listener) {
- this._setListeners(event, newListener);
- return;
- }
- // ensure we order listeners by priority from
- // 0 (high) to n > 0 (low)
- while (listener) {
- if (listener.priority < newListener.priority) {
- newListener.next = listener;
- if (previousListener) {
- previousListener.next = newListener;
- } else {
- this._setListeners(event, newListener);
- }
- return;
- }
- previousListener = listener;
- listener = listener.next;
- }
- // add new listener to back
- previousListener.next = newListener;
- };
- EventBus.prototype._getListeners = function(name) {
- return this._listeners[name];
- };
- EventBus.prototype._setListeners = function(name, listener) {
- this._listeners[name] = listener;
- };
- EventBus.prototype._removeListener = function(event, callback) {
- var listener = this._getListeners(event),
- nextListener,
- previousListener,
- listenerCallback;
- if (!callback) {
- // clear listeners
- this._setListeners(event, null);
- return;
- }
- while (listener) {
- nextListener = listener.next;
- listenerCallback = listener.callback;
- if (listenerCallback === callback || listenerCallback[FN_REF] === callback) {
- if (previousListener) {
- previousListener.next = nextListener;
- } else {
- // new first listener
- this._setListeners(event, nextListener);
- }
- }
- previousListener = listener;
- listener = nextListener;
- }
- };
- /**
- * A event that is emitted via the event bus.
- */
- function InternalEvent() { }
- InternalEvent.prototype.stopPropagation = function() {
- this.cancelBubble = true;
- };
- InternalEvent.prototype.preventDefault = function() {
- this.defaultPrevented = true;
- };
- InternalEvent.prototype.init = function(data) {
- assign(this, data || {});
- };
- /**
- * Invoke function. Be fast...
- *
- * @param {Function} fn
- * @param {Array<Object>} args
- *
- * @return {Any}
- */
- function invokeFunction(fn, args) {
- return fn.apply(null, args);
- }
- /**
- * SVGs for elements are generated by the {@link GraphicsFactory}.
- *
- * This utility gives quick access to the important semantic
- * parts of an element.
- */
- /**
- * Returns the visual part of a diagram element
- *
- * @param {Snap<SVGElement>} gfx
- *
- * @return {Snap<SVGElement>}
- */
- function getVisual(gfx) {
- return gfx.childNodes[0];
- }
- /**
- * Returns the children for a given diagram element.
- *
- * @param {Snap<SVGElement>} gfx
- * @return {Snap<SVGElement>}
- */
- function getChildren(gfx) {
- return gfx.parentNode.childNodes[1];
- }
- /**
- * A factory that creates graphical elements
- *
- * @param {EventBus} eventBus
- * @param {ElementRegistry} elementRegistry
- */
- function GraphicsFactory(eventBus, elementRegistry) {
- this._eventBus = eventBus;
- this._elementRegistry = elementRegistry;
- }
- GraphicsFactory.$inject = [ 'eventBus' , 'elementRegistry' ];
- GraphicsFactory.prototype._getChildrenContainer = function(element) {
- var gfx = this._elementRegistry.getGraphics(element);
- var childrenGfx;
- // root element
- if (!element.parent) {
- childrenGfx = gfx;
- } else {
- childrenGfx = getChildren(gfx);
- if (!childrenGfx) {
- childrenGfx = create('g');
- classes(childrenGfx).add('djs-children');
- append(gfx.parentNode, childrenGfx);
- }
- }
- return childrenGfx;
- };
- /**
- * Clears the graphical representation of the element and returns the
- * cleared visual (the <g class="djs-visual" /> element).
- */
- GraphicsFactory.prototype._clear = function(gfx) {
- var visual = getVisual(gfx);
- clear$1(visual);
- return visual;
- };
- /**
- * Creates a gfx container for shapes and connections
- *
- * The layout is as follows:
- *
- * <g class="djs-group">
- *
- * <!-- the gfx -->
- * <g class="djs-element djs-(shape|connection|frame)">
- * <g class="djs-visual">
- * <!-- the renderer draws in here -->
- * </g>
- *
- * <!-- extensions (overlays, click box, ...) goes here
- * </g>
- *
- * <!-- the gfx child nodes -->
- * <g class="djs-children"></g>
- * </g>
- *
- * @param {string} type the type of the element, i.e. shape | connection
- * @param {SVGElement} [childrenGfx]
- * @param {number} [parentIndex] position to create container in parent
- * @param {boolean} [isFrame] is frame element
- *
- * @return {SVGElement}
- */
- GraphicsFactory.prototype._createContainer = function(
- type, childrenGfx, parentIndex, isFrame
- ) {
- var outerGfx = create('g');
- classes(outerGfx).add('djs-group');
- // insert node at position
- if (typeof parentIndex !== 'undefined') {
- prependTo(outerGfx, childrenGfx, childrenGfx.childNodes[parentIndex]);
- } else {
- append(childrenGfx, outerGfx);
- }
- var gfx = create('g');
- classes(gfx).add('djs-element');
- classes(gfx).add('djs-' + type);
- if (isFrame) {
- classes(gfx).add('djs-frame');
- }
- append(outerGfx, gfx);
- // create visual
- var visual = create('g');
- classes(visual).add('djs-visual');
- append(gfx, visual);
- return gfx;
- };
- GraphicsFactory.prototype.create = function(type, element, parentIndex) {
- var childrenGfx = this._getChildrenContainer(element.parent);
- return this._createContainer(type, childrenGfx, parentIndex, isFrameElement$1(element));
- };
- GraphicsFactory.prototype.updateContainments = function(elements) {
- var self = this,
- elementRegistry = this._elementRegistry,
- parents;
- parents = reduce(elements, function(map, e) {
- if (e.parent) {
- map[e.parent.id] = e.parent;
- }
- return map;
- }, {});
- // update all parents of changed and reorganized their children
- // in the correct order (as indicated in our model)
- forEach(parents, function(parent) {
- var children = parent.children;
- if (!children) {
- return;
- }
- var childrenGfx = self._getChildrenContainer(parent);
- forEach(children.slice().reverse(), function(child) {
- var childGfx = elementRegistry.getGraphics(child);
- prependTo(childGfx.parentNode, childrenGfx);
- });
- });
- };
- GraphicsFactory.prototype.drawShape = function(visual, element) {
- var eventBus = this._eventBus;
- return eventBus.fire('render.shape', { gfx: visual, element: element });
- };
- GraphicsFactory.prototype.getShapePath = function(element) {
- var eventBus = this._eventBus;
- return eventBus.fire('render.getShapePath', element);
- };
- GraphicsFactory.prototype.drawConnection = function(visual, element) {
- var eventBus = this._eventBus;
- return eventBus.fire('render.connection', { gfx: visual, element: element });
- };
- GraphicsFactory.prototype.getConnectionPath = function(waypoints) {
- var eventBus = this._eventBus;
- return eventBus.fire('render.getConnectionPath', waypoints);
- };
- GraphicsFactory.prototype.update = function(type, element, gfx) {
- // do NOT update root element
- if (!element.parent) {
- return;
- }
- var visual = this._clear(gfx);
- // redraw
- if (type === 'shape') {
- this.drawShape(visual, element);
- // update positioning
- translate(gfx, element.x, element.y);
- } else
- if (type === 'connection') {
- this.drawConnection(visual, element);
- } else {
- throw new Error('unknown type: ' + type);
- }
- if (element.hidden) {
- attr(gfx, 'display', 'none');
- } else {
- attr(gfx, 'display', 'block');
- }
- };
- GraphicsFactory.prototype.remove = function(element) {
- var gfx = this._elementRegistry.getGraphics(element);
- // remove
- remove(gfx.parentNode);
- };
- // helpers //////////
- function prependTo(newNode, parentNode, siblingNode) {
- var node = siblingNode || parentNode.firstChild;
- // do not prepend node to itself to prevent IE from crashing
- // https://github.com/bpmn-io/bpmn-js/issues/746
- if (newNode === node) {
- return;
- }
- parentNode.insertBefore(newNode, node);
- }
- var CoreModule$1 = {
- __depends__: [ DrawModule$1 ],
- __init__: [ 'canvas' ],
- canvas: [ 'type', Canvas ],
- elementRegistry: [ 'type', ElementRegistry ],
- elementFactory: [ 'type', ElementFactory ],
- eventBus: [ 'type', EventBus ],
- graphicsFactory: [ 'type', GraphicsFactory ]
- };
- /**
- * Bootstrap an injector from a list of modules, instantiating a number of default components
- *
- * @ignore
- * @param {Array<didi.Module>} bootstrapModules
- *
- * @return {didi.Injector} a injector to use to access the components
- */
- function bootstrap(bootstrapModules) {
- var modules = [],
- components = [];
- function hasModule(m) {
- return modules.indexOf(m) >= 0;
- }
- function addModule(m) {
- modules.push(m);
- }
- function visit(m) {
- if (hasModule(m)) {
- return;
- }
- (m.__depends__ || []).forEach(visit);
- if (hasModule(m)) {
- return;
- }
- addModule(m);
- (m.__init__ || []).forEach(function(c) {
- components.push(c);
- });
- }
- bootstrapModules.forEach(visit);
- var injector = new Injector(modules);
- components.forEach(function(c) {
- try {
- // eagerly resolve component (fn or string)
- injector[typeof c === 'string' ? 'get' : 'invoke'](c);
- } catch (e) {
- console.error('Failed to instantiate component');
- console.error(e.stack);
- throw e;
- }
- });
- return injector;
- }
- /**
- * Creates an injector from passed options.
- *
- * @ignore
- * @param {Object} options
- * @return {didi.Injector}
- */
- function createInjector(options) {
- options = options || {};
- var configModule = {
- 'config': ['value', options]
- };
- var modules = [ configModule, CoreModule$1 ].concat(options.modules || []);
- return bootstrap(modules);
- }
- /**
- * The main diagram-js entry point that bootstraps the diagram with the given
- * configuration.
- *
- * To register extensions with the diagram, pass them as Array<didi.Module> to the constructor.
- *
- * @class djs.Diagram
- * @memberOf djs
- * @constructor
- *
- * @example
- *
- * <caption>Creating a plug-in that logs whenever a shape is added to the canvas.</caption>
- *
- * // plug-in implemenentation
- * function MyLoggingPlugin(eventBus) {
- * eventBus.on('shape.added', function(event) {
- * console.log('shape ', event.shape, ' was added to the diagram');
- * });
- * }
- *
- * // export as module
- * export default {
- * __init__: [ 'myLoggingPlugin' ],
- * myLoggingPlugin: [ 'type', MyLoggingPlugin ]
- * };
- *
- *
- * // instantiate the diagram with the new plug-in
- *
- * import MyLoggingModule from 'path-to-my-logging-plugin';
- *
- * var diagram = new Diagram({
- * modules: [
- * MyLoggingModule
- * ]
- * });
- *
- * diagram.invoke([ 'canvas', function(canvas) {
- * // add shape to drawing canvas
- * canvas.addShape({ x: 10, y: 10 });
- * });
- *
- * // 'shape ... was added to the diagram' logged to console
- *
- * @param {Object} options
- * @param {Array<didi.Module>} [options.modules] external modules to instantiate with the diagram
- * @param {didi.Injector} [injector] an (optional) injector to bootstrap the diagram with
- */
- function Diagram(options, injector) {
- // create injector unless explicitly specified
- this.injector = injector = injector || createInjector(options);
- // API
- /**
- * Resolves a diagram service
- *
- * @method Diagram#get
- *
- * @param {string} name the name of the diagram service to be retrieved
- * @param {boolean} [strict=true] if false, resolve missing services to null
- */
- this.get = injector.get;
- /**
- * Executes a function into which diagram services are injected
- *
- * @method Diagram#invoke
- *
- * @param {Function|Object[]} fn the function to resolve
- * @param {Object} locals a number of locals to use to resolve certain dependencies
- */
- this.invoke = injector.invoke;
- // init
- // indicate via event
- /**
- * An event indicating that all plug-ins are loaded.
- *
- * Use this event to fire other events to interested plug-ins
- *
- * @memberOf Diagram
- *
- * @event diagram.init
- *
- * @example
- *
- * eventBus.on('diagram.init', function() {
- * eventBus.fire('my-custom-event', { foo: 'BAR' });
- * });
- *
- * @type {Object}
- */
- this.get('eventBus').fire('diagram.init');
- }
- /**
- * Destroys the diagram
- *
- * @method Diagram#destroy
- */
- Diagram.prototype.destroy = function() {
- this.get('eventBus').fire('diagram.destroy');
- };
- /**
- * Clear the diagram, removing all contents.
- */
- Diagram.prototype.clear = function() {
- this.get('eventBus').fire('diagram.clear');
- };
- /**
- * Moddle base element.
- */
- function Base$1() { }
- Base$1.prototype.get = function(name) {
- return this.$model.properties.get(this, name);
- };
- Base$1.prototype.set = function(name, value) {
- this.$model.properties.set(this, name, value);
- };
- /**
- * A model element factory.
- *
- * @param {Moddle} model
- * @param {Properties} properties
- */
- function Factory(model, properties) {
- this.model = model;
- this.properties = properties;
- }
- Factory.prototype.createType = function(descriptor) {
- var model = this.model;
- var props = this.properties,
- prototype = Object.create(Base$1.prototype);
- // initialize default values
- forEach(descriptor.properties, function(p) {
- if (!p.isMany && p.default !== undefined) {
- prototype[p.name] = p.default;
- }
- });
- props.defineModel(prototype, model);
- props.defineDescriptor(prototype, descriptor);
- var name = descriptor.ns.name;
- /**
- * The new type constructor
- */
- function ModdleElement(attrs) {
- props.define(this, '$type', { value: name, enumerable: true });
- props.define(this, '$attrs', { value: {} });
- props.define(this, '$parent', { writable: true });
- forEach(attrs, bind(function(val, key) {
- this.set(key, val);
- }, this));
- }
- ModdleElement.prototype = prototype;
- ModdleElement.hasType = prototype.$instanceOf = this.model.hasType;
- // static links
- props.defineModel(ModdleElement, model);
- props.defineDescriptor(ModdleElement, descriptor);
- return ModdleElement;
- };
- /**
- * Built-in moddle types
- */
- var BUILTINS = {
- String: true,
- Boolean: true,
- Integer: true,
- Real: true,
- Element: true
- };
- /**
- * Converters for built in types from string representations
- */
- var TYPE_CONVERTERS = {
- String: function(s) { return s; },
- Boolean: function(s) { return s === 'true'; },
- Integer: function(s) { return parseInt(s, 10); },
- Real: function(s) { return parseFloat(s, 10); }
- };
- /**
- * Convert a type to its real representation
- */
- function coerceType(type, value) {
- var converter = TYPE_CONVERTERS[type];
- if (converter) {
- return converter(value);
- } else {
- return value;
- }
- }
- /**
- * Return whether the given type is built-in
- */
- function isBuiltIn(type) {
- return !!BUILTINS[type];
- }
- /**
- * Return whether the given type is simple
- */
- function isSimple(type) {
- return !!TYPE_CONVERTERS[type];
- }
- /**
- * Parses a namespaced attribute name of the form (ns:)localName to an object,
- * given a default prefix to assume in case no explicit namespace is given.
- *
- * @param {String} name
- * @param {String} [defaultPrefix] the default prefix to take, if none is present.
- *
- * @return {Object} the parsed name
- */
- function parseName(name, defaultPrefix) {
- var parts = name.split(/:/),
- localName, prefix;
- // no prefix (i.e. only local name)
- if (parts.length === 1) {
- localName = name;
- prefix = defaultPrefix;
- } else
- // prefix + local name
- if (parts.length === 2) {
- localName = parts[1];
- prefix = parts[0];
- } else {
- throw new Error('expected <prefix:localName> or <localName>, got ' + name);
- }
- name = (prefix ? prefix + ':' : '') + localName;
- return {
- name: name,
- prefix: prefix,
- localName: localName
- };
- }
- /**
- * A utility to build element descriptors.
- */
- function DescriptorBuilder(nameNs) {
- this.ns = nameNs;
- this.name = nameNs.name;
- this.allTypes = [];
- this.allTypesByName = {};
- this.properties = [];
- this.propertiesByName = {};
- }
- DescriptorBuilder.prototype.build = function() {
- return pick(this, [
- 'ns',
- 'name',
- 'allTypes',
- 'allTypesByName',
- 'properties',
- 'propertiesByName',
- 'bodyProperty',
- 'idProperty'
- ]);
- };
- /**
- * Add property at given index.
- *
- * @param {Object} p
- * @param {Number} [idx]
- * @param {Boolean} [validate=true]
- */
- DescriptorBuilder.prototype.addProperty = function(p, idx, validate) {
- if (typeof idx === 'boolean') {
- validate = idx;
- idx = undefined;
- }
- this.addNamedProperty(p, validate !== false);
- var properties = this.properties;
- if (idx !== undefined) {
- properties.splice(idx, 0, p);
- } else {
- properties.push(p);
- }
- };
- DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty, replace) {
- var oldNameNs = oldProperty.ns;
- var props = this.properties,
- propertiesByName = this.propertiesByName,
- rename = oldProperty.name !== newProperty.name;
- if (oldProperty.isId) {
- if (!newProperty.isId) {
- throw new Error(
- 'property <' + newProperty.ns.name + '> must be id property ' +
- 'to refine <' + oldProperty.ns.name + '>');
- }
- this.setIdProperty(newProperty, false);
- }
- if (oldProperty.isBody) {
- if (!newProperty.isBody) {
- throw new Error(
- 'property <' + newProperty.ns.name + '> must be body property ' +
- 'to refine <' + oldProperty.ns.name + '>');
- }
- // TODO: Check compatibility
- this.setBodyProperty(newProperty, false);
- }
- // validate existence and get location of old property
- var idx = props.indexOf(oldProperty);
- if (idx === -1) {
- throw new Error('property <' + oldNameNs.name + '> not found in property list');
- }
- // remove old property
- props.splice(idx, 1);
- // replacing the named property is intentional
- //
- // * validate only if this is a "rename" operation
- // * add at specific index unless we "replace"
- //
- this.addProperty(newProperty, replace ? undefined : idx, rename);
- // make new property available under old name
- propertiesByName[oldNameNs.name] = propertiesByName[oldNameNs.localName] = newProperty;
- };
- DescriptorBuilder.prototype.redefineProperty = function(p, targetPropertyName, replace) {
- var nsPrefix = p.ns.prefix;
- var parts = targetPropertyName.split('#');
- var name = parseName(parts[0], nsPrefix);
- var attrName = parseName(parts[1], name.prefix).name;
- var redefinedProperty = this.propertiesByName[attrName];
- if (!redefinedProperty) {
- throw new Error('refined property <' + attrName + '> not found');
- } else {
- this.replaceProperty(redefinedProperty, p, replace);
- }
- delete p.redefines;
- };
- DescriptorBuilder.prototype.addNamedProperty = function(p, validate) {
- var ns = p.ns,
- propsByName = this.propertiesByName;
- if (validate) {
- this.assertNotDefined(p, ns.name);
- this.assertNotDefined(p, ns.localName);
- }
- propsByName[ns.name] = propsByName[ns.localName] = p;
- };
- DescriptorBuilder.prototype.removeNamedProperty = function(p) {
- var ns = p.ns,
- propsByName = this.propertiesByName;
- delete propsByName[ns.name];
- delete propsByName[ns.localName];
- };
- DescriptorBuilder.prototype.setBodyProperty = function(p, validate) {
- if (validate && this.bodyProperty) {
- throw new Error(
- 'body property defined multiple times ' +
- '(<' + this.bodyProperty.ns.name + '>, <' + p.ns.name + '>)');
- }
- this.bodyProperty = p;
- };
- DescriptorBuilder.prototype.setIdProperty = function(p, validate) {
- if (validate && this.idProperty) {
- throw new Error(
- 'id property defined multiple times ' +
- '(<' + this.idProperty.ns.name + '>, <' + p.ns.name + '>)');
- }
- this.idProperty = p;
- };
- DescriptorBuilder.prototype.assertNotDefined = function(p, name) {
- var propertyName = p.name,
- definedProperty = this.propertiesByName[propertyName];
- if (definedProperty) {
- throw new Error(
- 'property <' + propertyName + '> already defined; ' +
- 'override of <' + definedProperty.definedBy.ns.name + '#' + definedProperty.ns.name + '> by ' +
- '<' + p.definedBy.ns.name + '#' + p.ns.name + '> not allowed without redefines');
- }
- };
- DescriptorBuilder.prototype.hasProperty = function(name) {
- return this.propertiesByName[name];
- };
- DescriptorBuilder.prototype.addTrait = function(t, inherited) {
- var typesByName = this.allTypesByName,
- types = this.allTypes;
- var typeName = t.name;
- if (typeName in typesByName) {
- return;
- }
- forEach(t.properties, bind(function(p) {
- // clone property to allow extensions
- p = assign({}, p, {
- name: p.ns.localName,
- inherited: inherited
- });
- Object.defineProperty(p, 'definedBy', {
- value: t
- });
- var replaces = p.replaces,
- redefines = p.redefines;
- // add replace/redefine support
- if (replaces || redefines) {
- this.redefineProperty(p, replaces || redefines, replaces);
- } else {
- if (p.isBody) {
- this.setBodyProperty(p);
- }
- if (p.isId) {
- this.setIdProperty(p);
- }
- this.addProperty(p);
- }
- }, this));
- types.push(t);
- typesByName[typeName] = t;
- };
- /**
- * A registry of Moddle packages.
- *
- * @param {Array<Package>} packages
- * @param {Properties} properties
- */
- function Registry(packages, properties) {
- this.packageMap = {};
- this.typeMap = {};
- this.packages = [];
- this.properties = properties;
- forEach(packages, bind(this.registerPackage, this));
- }
- Registry.prototype.getPackage = function(uriOrPrefix) {
- return this.packageMap[uriOrPrefix];
- };
- Registry.prototype.getPackages = function() {
- return this.packages;
- };
- Registry.prototype.registerPackage = function(pkg) {
- // copy package
- pkg = assign({}, pkg);
- var pkgMap = this.packageMap;
- ensureAvailable(pkgMap, pkg, 'prefix');
- ensureAvailable(pkgMap, pkg, 'uri');
- // register types
- forEach(pkg.types, bind(function(descriptor) {
- this.registerType(descriptor, pkg);
- }, this));
- pkgMap[pkg.uri] = pkgMap[pkg.prefix] = pkg;
- this.packages.push(pkg);
- };
- /**
- * Register a type from a specific package with us
- */
- Registry.prototype.registerType = function(type, pkg) {
- type = assign({}, type, {
- superClass: (type.superClass || []).slice(),
- extends: (type.extends || []).slice(),
- properties: (type.properties || []).slice(),
- meta: assign((type.meta || {}))
- });
- var ns = parseName(type.name, pkg.prefix),
- name = ns.name,
- propertiesByName = {};
- // parse properties
- forEach(type.properties, bind(function(p) {
- // namespace property names
- var propertyNs = parseName(p.name, ns.prefix),
- propertyName = propertyNs.name;
- // namespace property types
- if (!isBuiltIn(p.type)) {
- p.type = parseName(p.type, propertyNs.prefix).name;
- }
- assign(p, {
- ns: propertyNs,
- name: propertyName
- });
- propertiesByName[propertyName] = p;
- }, this));
- // update ns + name
- assign(type, {
- ns: ns,
- name: name,
- propertiesByName: propertiesByName
- });
- forEach(type.extends, bind(function(extendsName) {
- var extended = this.typeMap[extendsName];
- extended.traits = extended.traits || [];
- extended.traits.push(name);
- }, this));
- // link to package
- this.definePackage(type, pkg);
- // register
- this.typeMap[name] = type;
- };
- /**
- * Traverse the type hierarchy from bottom to top,
- * calling iterator with (type, inherited) for all elements in
- * the inheritance chain.
- *
- * @param {Object} nsName
- * @param {Function} iterator
- * @param {Boolean} [trait=false]
- */
- Registry.prototype.mapTypes = function(nsName, iterator, trait) {
- var type = isBuiltIn(nsName.name) ? { name: nsName.name } : this.typeMap[nsName.name];
- var self = this;
- /**
- * Traverse the selected trait.
- *
- * @param {String} cls
- */
- function traverseTrait(cls) {
- return traverseSuper(cls, true);
- }
- /**
- * Traverse the selected super type or trait
- *
- * @param {String} cls
- * @param {Boolean} [trait=false]
- */
- function traverseSuper(cls, trait) {
- var parentNs = parseName(cls, isBuiltIn(cls) ? '' : nsName.prefix);
- self.mapTypes(parentNs, iterator, trait);
- }
- if (!type) {
- throw new Error('unknown type <' + nsName.name + '>');
- }
- forEach(type.superClass, trait ? traverseTrait : traverseSuper);
- // call iterator with (type, inherited=!trait)
- iterator(type, !trait);
- forEach(type.traits, traverseTrait);
- };
- /**
- * Returns the effective descriptor for a type.
- *
- * @param {String} type the namespaced name (ns:localName) of the type
- *
- * @return {Descriptor} the resulting effective descriptor
- */
- Registry.prototype.getEffectiveDescriptor = function(name) {
- var nsName = parseName(name);
- var builder = new DescriptorBuilder(nsName);
- this.mapTypes(nsName, function(type, inherited) {
- builder.addTrait(type, inherited);
- });
- var descriptor = builder.build();
- // define package link
- this.definePackage(descriptor, descriptor.allTypes[descriptor.allTypes.length - 1].$pkg);
- return descriptor;
- };
- Registry.prototype.definePackage = function(target, pkg) {
- this.properties.define(target, '$pkg', { value: pkg });
- };
- ///////// helpers ////////////////////////////
- function ensureAvailable(packageMap, pkg, identifierKey) {
- var value = pkg[identifierKey];
- if (value in packageMap) {
- throw new Error('package with ' + identifierKey + ' <' + value + '> already defined');
- }
- }
- /**
- * A utility that gets and sets properties of model elements.
- *
- * @param {Model} model
- */
- function Properties(model) {
- this.model = model;
- }
- /**
- * Sets a named property on the target element.
- * If the value is undefined, the property gets deleted.
- *
- * @param {Object} target
- * @param {String} name
- * @param {Object} value
- */
- Properties.prototype.set = function(target, name, value) {
- var property = this.model.getPropertyDescriptor(target, name);
- var propertyName = property && property.name;
- if (isUndefined$1(value)) {
- // unset the property, if the specified value is undefined;
- // delete from $attrs (for extensions) or the target itself
- if (property) {
- delete target[propertyName];
- } else {
- delete target.$attrs[name];
- }
- } else {
- // set the property, defining well defined properties on the fly
- // or simply updating them in target.$attrs (for extensions)
- if (property) {
- if (propertyName in target) {
- target[propertyName] = value;
- } else {
- defineProperty$1(target, property, value);
- }
- } else {
- target.$attrs[name] = value;
- }
- }
- };
- /**
- * Returns the named property of the given element
- *
- * @param {Object} target
- * @param {String} name
- *
- * @return {Object}
- */
- Properties.prototype.get = function(target, name) {
- var property = this.model.getPropertyDescriptor(target, name);
- if (!property) {
- return target.$attrs[name];
- }
- var propertyName = property.name;
- // check if access to collection property and lazily initialize it
- if (!target[propertyName] && property.isMany) {
- defineProperty$1(target, property, []);
- }
- return target[propertyName];
- };
- /**
- * Define a property on the target element
- *
- * @param {Object} target
- * @param {String} name
- * @param {Object} options
- */
- Properties.prototype.define = function(target, name, options) {
- Object.defineProperty(target, name, options);
- };
- /**
- * Define the descriptor for an element
- */
- Properties.prototype.defineDescriptor = function(target, descriptor) {
- this.define(target, '$descriptor', { value: descriptor });
- };
- /**
- * Define the model for an element
- */
- Properties.prototype.defineModel = function(target, model) {
- this.define(target, '$model', { value: model });
- };
- function isUndefined$1(val) {
- return typeof val === 'undefined';
- }
- function defineProperty$1(target, property, value) {
- Object.defineProperty(target, property.name, {
- enumerable: !property.isReference,
- writable: true,
- value: value,
- configurable: true
- });
- }
- //// Moddle implementation /////////////////////////////////////////////////
- /**
- * @class Moddle
- *
- * A model that can be used to create elements of a specific type.
- *
- * @example
- *
- * var Moddle = require('moddle');
- *
- * var pkg = {
- * name: 'mypackage',
- * prefix: 'my',
- * types: [
- * { name: 'Root' }
- * ]
- * };
- *
- * var moddle = new Moddle([pkg]);
- *
- * @param {Array<Package>} packages the packages to contain
- */
- function Moddle(packages) {
- this.properties = new Properties(this);
- this.factory = new Factory(this, this.properties);
- this.registry = new Registry(packages, this.properties);
- this.typeCache = {};
- }
- /**
- * Create an instance of the specified type.
- *
- * @method Moddle#create
- *
- * @example
- *
- * var foo = moddle.create('my:Foo');
- * var bar = moddle.create('my:Bar', { id: 'BAR_1' });
- *
- * @param {String|Object} descriptor the type descriptor or name know to the model
- * @param {Object} attrs a number of attributes to initialize the model instance with
- * @return {Object} model instance
- */
- Moddle.prototype.create = function(descriptor, attrs) {
- var Type = this.getType(descriptor);
- if (!Type) {
- throw new Error('unknown type <' + descriptor + '>');
- }
- return new Type(attrs);
- };
- /**
- * Returns the type representing a given descriptor
- *
- * @method Moddle#getType
- *
- * @example
- *
- * var Foo = moddle.getType('my:Foo');
- * var foo = new Foo({ 'id' : 'FOO_1' });
- *
- * @param {String|Object} descriptor the type descriptor or name know to the model
- * @return {Object} the type representing the descriptor
- */
- Moddle.prototype.getType = function(descriptor) {
- var cache = this.typeCache;
- var name = isString(descriptor) ? descriptor : descriptor.ns.name;
- var type = cache[name];
- if (!type) {
- descriptor = this.registry.getEffectiveDescriptor(name);
- type = cache[name] = this.factory.createType(descriptor);
- }
- return type;
- };
- /**
- * Creates an any-element type to be used within model instances.
- *
- * This can be used to create custom elements that lie outside the meta-model.
- * The created element contains all the meta-data required to serialize it
- * as part of meta-model elements.
- *
- * @method Moddle#createAny
- *
- * @example
- *
- * var foo = moddle.createAny('vendor:Foo', 'http://vendor', {
- * value: 'bar'
- * });
- *
- * var container = moddle.create('my:Container', 'http://my', {
- * any: [ foo ]
- * });
- *
- * // go ahead and serialize the stuff
- *
- *
- * @param {String} name the name of the element
- * @param {String} nsUri the namespace uri of the element
- * @param {Object} [properties] a map of properties to initialize the instance with
- * @return {Object} the any type instance
- */
- Moddle.prototype.createAny = function(name, nsUri, properties) {
- var nameNs = parseName(name);
- var element = {
- $type: name,
- $instanceOf: function(type) {
- return type === this.$type;
- }
- };
- var descriptor = {
- name: name,
- isGeneric: true,
- ns: {
- prefix: nameNs.prefix,
- localName: nameNs.localName,
- uri: nsUri
- }
- };
- this.properties.defineDescriptor(element, descriptor);
- this.properties.defineModel(element, this);
- this.properties.define(element, '$parent', { enumerable: false, writable: true });
- forEach(properties, function(a, key) {
- if (isObject(a) && a.value !== undefined) {
- element[a.name] = a.value;
- } else {
- element[key] = a;
- }
- });
- return element;
- };
- /**
- * Returns a registered package by uri or prefix
- *
- * @return {Object} the package
- */
- Moddle.prototype.getPackage = function(uriOrPrefix) {
- return this.registry.getPackage(uriOrPrefix);
- };
- /**
- * Returns a snapshot of all known packages
- *
- * @return {Object} the package
- */
- Moddle.prototype.getPackages = function() {
- return this.registry.getPackages();
- };
- /**
- * Returns the descriptor for an element
- */
- Moddle.prototype.getElementDescriptor = function(element) {
- return element.$descriptor;
- };
- /**
- * Returns true if the given descriptor or instance
- * represents the given type.
- *
- * May be applied to this, if element is omitted.
- */
- Moddle.prototype.hasType = function(element, type) {
- if (type === undefined) {
- type = element;
- element = this;
- }
- var descriptor = element.$model.getElementDescriptor(element);
- return (type in descriptor.allTypesByName);
- };
- /**
- * Returns the descriptor of an elements named property
- */
- Moddle.prototype.getPropertyDescriptor = function(element, property) {
- return this.getElementDescriptor(element).propertiesByName[property];
- };
- /**
- * Returns a mapped type's descriptor
- */
- Moddle.prototype.getTypeDescriptor = function(type) {
- return this.registry.typeMap[type];
- };
- var fromCharCode = String.fromCharCode;
- var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
- var ENTITY_PATTERN = /&#(\d+);|&#x([0-9a-f]+);|&(\w+);/ig;
- var ENTITY_MAPPING = {
- 'amp': '&',
- 'apos': '\'',
- 'gt': '>',
- 'lt': '<',
- 'quot': '"'
- };
- // map UPPERCASE variants of supported special chars
- Object.keys(ENTITY_MAPPING).forEach(function(k) {
- ENTITY_MAPPING[k.toUpperCase()] = ENTITY_MAPPING[k];
- });
- function replaceEntities(_, d, x, z) {
- // reserved names, i.e.
- if (z) {
- if (hasOwnProperty$1.call(ENTITY_MAPPING, z)) {
- return ENTITY_MAPPING[z];
- } else {
- // fall back to original value
- return '&' + z + ';';
- }
- }
- // decimal encoded char
- if (d) {
- return fromCharCode(d);
- }
- // hex encoded char
- return fromCharCode(parseInt(x, 16));
- }
- /**
- * A basic entity decoder that can decode a minimal
- * sub-set of reserved names (&) as well as
- * hex (ય) and decimal (ӏ) encoded characters.
- *
- * @param {string} str
- *
- * @return {string} decoded string
- */
- function decodeEntities(s) {
- if (s.length > 3 && s.indexOf('&') !== -1) {
- return s.replace(ENTITY_PATTERN, replaceEntities);
- }
- return s;
- }
- var XSI_URI = 'http://www.w3.org/2001/XMLSchema-instance';
- var XSI_PREFIX = 'xsi';
- var XSI_TYPE = 'xsi:type';
- var NON_WHITESPACE_OUTSIDE_ROOT_NODE = 'non-whitespace outside of root node';
- function error(msg) {
- return new Error(msg);
- }
- function missingNamespaceForPrefix(prefix) {
- return 'missing namespace for prefix <' + prefix + '>';
- }
- function getter(getFn) {
- return {
- 'get': getFn,
- 'enumerable': true
- };
- }
- function cloneNsMatrix(nsMatrix) {
- var clone = {}, key;
- for (key in nsMatrix) {
- clone[key] = nsMatrix[key];
- }
- return clone;
- }
- function uriPrefix(prefix) {
- return prefix + '$uri';
- }
- function buildNsMatrix(nsUriToPrefix) {
- var nsMatrix = {},
- uri,
- prefix;
- for (uri in nsUriToPrefix) {
- prefix = nsUriToPrefix[uri];
- nsMatrix[prefix] = prefix;
- nsMatrix[uriPrefix(prefix)] = uri;
- }
- return nsMatrix;
- }
- function noopGetContext() {
- return { 'line': 0, 'column': 0 };
- }
- function throwFunc(err) {
- throw err;
- }
- /**
- * Creates a new parser with the given options.
- *
- * @constructor
- *
- * @param {!Object<string, ?>=} options
- */
- function Parser(options) {
- if (!this) {
- return new Parser(options);
- }
- var proxy = options && options['proxy'];
- var onText,
- onOpenTag,
- onCloseTag,
- onCDATA,
- onError = throwFunc,
- onWarning,
- onComment,
- onQuestion,
- onAttention;
- var getContext = noopGetContext;
- /**
- * Do we need to parse the current elements attributes for namespaces?
- *
- * @type {boolean}
- */
- var maybeNS = false;
- /**
- * Do we process namespaces at all?
- *
- * @type {boolean}
- */
- var isNamespace = false;
- /**
- * The caught error returned on parse end
- *
- * @type {Error}
- */
- var returnError = null;
- /**
- * Should we stop parsing?
- *
- * @type {boolean}
- */
- var parseStop = false;
- /**
- * A map of { uri: prefix } used by the parser.
- *
- * This map will ensure we can normalize prefixes during processing;
- * for each uri, only one prefix will be exposed to the handlers.
- *
- * @type {!Object<string, string>}}
- */
- var nsUriToPrefix;
- /**
- * Handle parse error.
- *
- * @param {string|Error} err
- */
- function handleError(err) {
- if (!(err instanceof Error)) {
- err = error(err);
- }
- returnError = err;
- onError(err, getContext);
- }
- /**
- * Handle parse error.
- *
- * @param {string|Error} err
- */
- function handleWarning(err) {
- if (!onWarning) {
- return;
- }
- if (!(err instanceof Error)) {
- err = error(err);
- }
- onWarning(err, getContext);
- }
- /**
- * Register parse listener.
- *
- * @param {string} name
- * @param {Function} cb
- *
- * @return {Parser}
- */
- this['on'] = function(name, cb) {
- if (typeof cb !== 'function') {
- throw error('required args <name, cb>');
- }
- switch (name) {
- case 'openTag': onOpenTag = cb; break;
- case 'text': onText = cb; break;
- case 'closeTag': onCloseTag = cb; break;
- case 'error': onError = cb; break;
- case 'warn': onWarning = cb; break;
- case 'cdata': onCDATA = cb; break;
- case 'attention': onAttention = cb; break; // <!XXXXX zzzz="eeee">
- case 'question': onQuestion = cb; break; // <? .... ?>
- case 'comment': onComment = cb; break;
- default:
- throw error('unsupported event: ' + name);
- }
- return this;
- };
- /**
- * Set the namespace to prefix mapping.
- *
- * @example
- *
- * parser.ns({
- * 'http://foo': 'foo',
- * 'http://bar': 'bar'
- * });
- *
- * @param {!Object<string, string>} nsMap
- *
- * @return {Parser}
- */
- this['ns'] = function(nsMap) {
- if (typeof nsMap === 'undefined') {
- nsMap = {};
- }
- if (typeof nsMap !== 'object') {
- throw error('required args <nsMap={}>');
- }
- var _nsUriToPrefix = {}, k;
- for (k in nsMap) {
- _nsUriToPrefix[k] = nsMap[k];
- }
- // FORCE default mapping for schema instance
- _nsUriToPrefix[XSI_URI] = XSI_PREFIX;
- isNamespace = true;
- nsUriToPrefix = _nsUriToPrefix;
- return this;
- };
- /**
- * Parse xml string.
- *
- * @param {string} xml
- *
- * @return {Error} returnError, if not thrown
- */
- this['parse'] = function(xml) {
- if (typeof xml !== 'string') {
- throw error('required args <xml=string>');
- }
- returnError = null;
- parse(xml);
- getContext = noopGetContext;
- parseStop = false;
- return returnError;
- };
- /**
- * Stop parsing.
- */
- this['stop'] = function() {
- parseStop = true;
- };
- /**
- * Parse string, invoking configured listeners on element.
- *
- * @param {string} xml
- */
- function parse(xml) {
- var nsMatrixStack = isNamespace ? [] : null,
- nsMatrix = isNamespace ? buildNsMatrix(nsUriToPrefix) : null,
- _nsMatrix,
- nodeStack = [],
- anonymousNsCount = 0,
- tagStart = false,
- tagEnd = false,
- i = 0, j = 0,
- x, y, q, w, v,
- xmlns,
- elementName,
- _elementName,
- elementProxy
- ;
- var attrsString = '',
- attrsStart = 0,
- cachedAttrs // false = parsed with errors, null = needs parsing
- ;
- /**
- * Parse attributes on demand and returns the parsed attributes.
- *
- * Return semantics: (1) `false` on attribute parse error,
- * (2) object hash on extracted attrs.
- *
- * @return {boolean|Object}
- */
- function getAttrs() {
- if (cachedAttrs !== null) {
- return cachedAttrs;
- }
- var nsUri,
- nsUriPrefix,
- nsName,
- defaultAlias = isNamespace && nsMatrix['xmlns'],
- attrList = isNamespace && maybeNS ? [] : null,
- i = attrsStart,
- s = attrsString,
- l = s.length,
- hasNewMatrix,
- newalias,
- value,
- alias,
- name,
- attrs = {},
- seenAttrs = {},
- skipAttr,
- w,
- j;
- parseAttr:
- for (; i < l; i++) {
- skipAttr = false;
- w = s.charCodeAt(i);
- if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE={ \f\n\r\t\v}
- continue;
- }
- // wait for non whitespace character
- if (w < 65 || w > 122 || (w > 90 && w < 97)) {
- if (w !== 95 && w !== 58) { // char 95"_" 58":"
- handleWarning('illegal first char attribute name');
- skipAttr = true;
- }
- }
- // parse attribute name
- for (j = i + 1; j < l; j++) {
- w = s.charCodeAt(j);
- if (
- w > 96 && w < 123 ||
- w > 64 && w < 91 ||
- w > 47 && w < 59 ||
- w === 46 || // '.'
- w === 45 || // '-'
- w === 95 // '_'
- ) {
- continue;
- }
- // unexpected whitespace
- if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
- handleWarning('missing attribute value');
- i = j;
- continue parseAttr;
- }
- // expected "="
- if (w === 61) { // "=" == 61
- break;
- }
- handleWarning('illegal attribute name char');
- skipAttr = true;
- }
- name = s.substring(i, j);
- if (name === 'xmlns:xmlns') {
- handleWarning('illegal declaration of xmlns');
- skipAttr = true;
- }
- w = s.charCodeAt(j + 1);
- if (w === 34) { // '"'
- j = s.indexOf('"', i = j + 2);
- if (j === -1) {
- j = s.indexOf('\'', i);
- if (j !== -1) {
- handleWarning('attribute value quote missmatch');
- skipAttr = true;
- }
- }
- } else if (w === 39) { // "'"
- j = s.indexOf('\'', i = j + 2);
- if (j === -1) {
- j = s.indexOf('"', i);
- if (j !== -1) {
- handleWarning('attribute value quote missmatch');
- skipAttr = true;
- }
- }
- } else {
- handleWarning('missing attribute value quotes');
- skipAttr = true;
- // skip to next space
- for (j = j + 1; j < l; j++) {
- w = s.charCodeAt(j + 1);
- if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
- break;
- }
- }
- }
- if (j === -1) {
- handleWarning('missing closing quotes');
- j = l;
- skipAttr = true;
- }
- if (!skipAttr) {
- value = s.substring(i, j);
- }
- i = j;
- // ensure SPACE follows attribute
- // skip illegal content otherwise
- // example a="b"c
- for (; j + 1 < l; j++) {
- w = s.charCodeAt(j + 1);
- if (w === 32 || (w < 14 && w > 8)) { // WHITESPACE
- break;
- }
- // FIRST ILLEGAL CHAR
- if (i === j) {
- handleWarning('illegal character after attribute end');
- skipAttr = true;
- }
- }
- // advance cursor to next attribute
- i = j + 1;
- if (skipAttr) {
- continue parseAttr;
- }
- // check attribute re-declaration
- if (name in seenAttrs) {
- handleWarning('attribute <' + name + '> already defined');
- continue;
- }
- seenAttrs[name] = true;
- if (!isNamespace) {
- attrs[name] = value;
- continue;
- }
- // try to extract namespace information
- if (maybeNS) {
- newalias = (
- name === 'xmlns'
- ? 'xmlns'
- : (name.charCodeAt(0) === 120 && name.substr(0, 6) === 'xmlns:')
- ? name.substr(6)
- : null
- );
- // handle xmlns(:alias) assignment
- if (newalias !== null) {
- nsUri = decodeEntities(value);
- nsUriPrefix = uriPrefix(newalias);
- alias = nsUriToPrefix[nsUri];
- if (!alias) {
- // no prefix defined or prefix collision
- if (
- (newalias === 'xmlns') ||
- (nsUriPrefix in nsMatrix && nsMatrix[nsUriPrefix] !== nsUri)
- ) {
- // alocate free ns prefix
- do {
- alias = 'ns' + (anonymousNsCount++);
- } while (typeof nsMatrix[alias] !== 'undefined');
- } else {
- alias = newalias;
- }
- nsUriToPrefix[nsUri] = alias;
- }
- if (nsMatrix[newalias] !== alias) {
- if (!hasNewMatrix) {
- nsMatrix = cloneNsMatrix(nsMatrix);
- hasNewMatrix = true;
- }
- nsMatrix[newalias] = alias;
- if (newalias === 'xmlns') {
- nsMatrix[uriPrefix(alias)] = nsUri;
- defaultAlias = alias;
- }
- nsMatrix[nsUriPrefix] = nsUri;
- }
- // expose xmlns(:asd)="..." in attributes
- attrs[name] = value;
- continue;
- }
- // collect attributes until all namespace
- // declarations are processed
- attrList.push(name, value);
- continue;
- } /** end if (maybeNs) */
- // handle attributes on element without
- // namespace declarations
- w = name.indexOf(':');
- if (w === -1) {
- attrs[name] = value;
- continue;
- }
- // normalize ns attribute name
- if (!(nsName = nsMatrix[name.substring(0, w)])) {
- handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
- continue;
- }
- name = defaultAlias === nsName
- ? name.substr(w + 1)
- : nsName + name.substr(w);
- // end: normalize ns attribute name
- // normalize xsi:type ns attribute value
- if (name === XSI_TYPE) {
- w = value.indexOf(':');
- if (w !== -1) {
- nsName = value.substring(0, w);
- // handle default prefixes, i.e. xs:String gracefully
- nsName = nsMatrix[nsName] || nsName;
- value = nsName + value.substring(w);
- } else {
- value = defaultAlias + ':' + value;
- }
- }
- // end: normalize xsi:type ns attribute value
- attrs[name] = value;
- }
- // handle deferred, possibly namespaced attributes
- if (maybeNS) {
- // normalize captured attributes
- for (i = 0, l = attrList.length; i < l; i++) {
- name = attrList[i++];
- value = attrList[i];
- w = name.indexOf(':');
- if (w !== -1) {
- // normalize ns attribute name
- if (!(nsName = nsMatrix[name.substring(0, w)])) {
- handleWarning(missingNamespaceForPrefix(name.substring(0, w)));
- continue;
- }
- name = defaultAlias === nsName
- ? name.substr(w + 1)
- : nsName + name.substr(w);
- // end: normalize ns attribute name
- // normalize xsi:type ns attribute value
- if (name === XSI_TYPE) {
- w = value.indexOf(':');
- if (w !== -1) {
- nsName = value.substring(0, w);
- // handle default prefixes, i.e. xs:String gracefully
- nsName = nsMatrix[nsName] || nsName;
- value = nsName + value.substring(w);
- } else {
- value = defaultAlias + ':' + value;
- }
- }
- // end: normalize xsi:type ns attribute value
- }
- attrs[name] = value;
- }
- // end: normalize captured attributes
- }
- return cachedAttrs = attrs;
- }
- /**
- * Extract the parse context { line, column, part }
- * from the current parser position.
- *
- * @return {Object} parse context
- */
- function getParseContext() {
- var splitsRe = /(\r\n|\r|\n)/g;
- var line = 0;
- var column = 0;
- var startOfLine = 0;
- var endOfLine = j;
- var match;
- var data;
- while (i >= startOfLine) {
- match = splitsRe.exec(xml);
- if (!match) {
- break;
- }
- // end of line = (break idx + break chars)
- endOfLine = match[0].length + match.index;
- if (endOfLine > i) {
- break;
- }
- // advance to next line
- line += 1;
- startOfLine = endOfLine;
- }
- // EOF errors
- if (i == -1) {
- column = endOfLine;
- data = xml.substring(j);
- } else
- // start errors
- if (j === 0) {
- data = xml.substring(j, i);
- }
- // other errors
- else {
- column = i - startOfLine;
- data = (j == -1 ? xml.substring(i) : xml.substring(i, j + 1));
- }
- return {
- 'data': data,
- 'line': line,
- 'column': column
- };
- }
- getContext = getParseContext;
- if (proxy) {
- elementProxy = Object.create({}, {
- 'name': getter(function() {
- return elementName;
- }),
- 'originalName': getter(function() {
- return _elementName;
- }),
- 'attrs': getter(getAttrs),
- 'ns': getter(function() {
- return nsMatrix;
- })
- });
- }
- // actual parse logic
- while (j !== -1) {
- if (xml.charCodeAt(j) === 60) { // "<"
- i = j;
- } else {
- i = xml.indexOf('<', j);
- }
- // parse end
- if (i === -1) {
- if (nodeStack.length) {
- return handleError('unexpected end of file');
- }
- if (j === 0) {
- return handleError('missing start tag');
- }
- if (j < xml.length) {
- if (xml.substring(j).trim()) {
- handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
- }
- }
- return;
- }
- // parse text
- if (j !== i) {
- if (nodeStack.length) {
- if (onText) {
- onText(xml.substring(j, i), decodeEntities, getContext);
- if (parseStop) {
- return;
- }
- }
- } else {
- if (xml.substring(j, i).trim()) {
- handleWarning(NON_WHITESPACE_OUTSIDE_ROOT_NODE);
- if (parseStop) {
- return;
- }
- }
- }
- }
- w = xml.charCodeAt(i+1);
- // parse comments + CDATA
- if (w === 33) { // "!"
- q = xml.charCodeAt(i+2);
- // CDATA section
- if (q === 91 && xml.substr(i + 3, 6) === 'CDATA[') { // 91 == "["
- j = xml.indexOf(']]>', i);
- if (j === -1) {
- return handleError('unclosed cdata');
- }
- if (onCDATA) {
- onCDATA(xml.substring(i + 9, j), getContext);
- if (parseStop) {
- return;
- }
- }
- j += 3;
- continue;
- }
- // comment
- if (q === 45 && xml.charCodeAt(i + 3) === 45) { // 45 == "-"
- j = xml.indexOf('-->', i);
- if (j === -1) {
- return handleError('unclosed comment');
- }
- if (onComment) {
- onComment(xml.substring(i + 4, j), decodeEntities, getContext);
- if (parseStop) {
- return;
- }
- }
- j += 3;
- continue;
- }
- }
- // parse question <? ... ?>
- if (w === 63) { // "?"
- j = xml.indexOf('?>', i);
- if (j === -1) {
- return handleError('unclosed question');
- }
- if (onQuestion) {
- onQuestion(xml.substring(i, j + 2), getContext);
- if (parseStop) {
- return;
- }
- }
- j += 2;
- continue;
- }
- // find matching closing tag for attention or standard tags
- // for that we must skip through attribute values
- // (enclosed in single or double quotes)
- for (x = i + 1; ; x++) {
- v = xml.charCodeAt(x);
- if (isNaN(v)) {
- j = -1;
- return handleError('unclosed tag');
- }
- // [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"
- // skips the quoted string
- // (double quotes) does not appear in a literal enclosed by (double quotes)
- // (single quote) does not appear in a literal enclosed by (single quote)
- if (v === 34) { // '"'
- q = xml.indexOf('"', x + 1);
- x = q !== -1 ? q : x;
- } else if (v === 39) { // "'"
- q = xml.indexOf("'", x + 1);
- x = q !== -1 ? q : x;
- } else if (v === 62) { // '>'
- j = x;
- break;
- }
- }
- // parse attention <! ...>
- // previously comment and CDATA have already been parsed
- if (w === 33) { // "!"
- if (onAttention) {
- onAttention(xml.substring(i, j + 1), decodeEntities, getContext);
- if (parseStop) {
- return;
- }
- }
- j += 1;
- continue;
- }
- // don't process attributes;
- // there are none
- cachedAttrs = {};
- // if (xml.charCodeAt(i+1) === 47) { // </...
- if (w === 47) { // </...
- tagStart = false;
- tagEnd = true;
- if (!nodeStack.length) {
- return handleError('missing open tag');
- }
- // verify open <-> close tag match
- x = elementName = nodeStack.pop();
- q = i + 2 + x.length;
- if (xml.substring(i + 2, q) !== x) {
- return handleError('closing tag mismatch');
- }
- // verify chars in close tag
- for (; q < j; q++) {
- w = xml.charCodeAt(q);
- if (w === 32 || (w > 8 && w < 14)) { // \f\n\r\t\v space
- continue;
- }
- return handleError('close tag');
- }
- } else {
- if (xml.charCodeAt(j - 1) === 47) { // .../>
- x = elementName = xml.substring(i + 1, j - 1);
- tagStart = true;
- tagEnd = true;
- } else {
- x = elementName = xml.substring(i + 1, j);
- tagStart = true;
- tagEnd = false;
- }
- if (!(w > 96 && w < 123 || w > 64 && w < 91 || w === 95 || w === 58)) { // char 95"_" 58":"
- return handleError('illegal first char nodeName');
- }
- for (q = 1, y = x.length; q < y; q++) {
- w = x.charCodeAt(q);
- if (w > 96 && w < 123 || w > 64 && w < 91 || w > 47 && w < 59 || w === 45 || w === 95 || w == 46) {
- continue;
- }
- if (w === 32 || (w < 14 && w > 8)) { // \f\n\r\t\v space
- elementName = x.substring(0, q);
- // maybe there are attributes
- cachedAttrs = null;
- break;
- }
- return handleError('invalid nodeName');
- }
- if (!tagEnd) {
- nodeStack.push(elementName);
- }
- }
- if (isNamespace) {
- _nsMatrix = nsMatrix;
- if (tagStart) {
- // remember old namespace
- // unless we're self-closing
- if (!tagEnd) {
- nsMatrixStack.push(_nsMatrix);
- }
- if (cachedAttrs === null) {
- // quick check, whether there may be namespace
- // declarations on the node; if that is the case
- // we need to eagerly parse the node attributes
- if ((maybeNS = x.indexOf('xmlns', q) !== -1)) {
- attrsStart = q;
- attrsString = x;
- getAttrs();
- maybeNS = false;
- }
- }
- }
- _elementName = elementName;
- w = elementName.indexOf(':');
- if (w !== -1) {
- xmlns = nsMatrix[elementName.substring(0, w)];
- // prefix given; namespace must exist
- if (!xmlns) {
- return handleError('missing namespace on <' + _elementName + '>');
- }
- elementName = elementName.substr(w + 1);
- } else {
- xmlns = nsMatrix['xmlns'];
- // if no default namespace is defined,
- // we'll import the element as anonymous.
- //
- // it is up to users to correct that to the document defined
- // targetNamespace, or whatever their undersanding of the
- // XML spec mandates.
- }
- // adjust namespace prefixs as configured
- if (xmlns) {
- elementName = xmlns + ':' + elementName;
- }
- }
- if (tagStart) {
- attrsStart = q;
- attrsString = x;
- if (onOpenTag) {
- if (proxy) {
- onOpenTag(elementProxy, decodeEntities, tagEnd, getContext);
- } else {
- onOpenTag(elementName, getAttrs, decodeEntities, tagEnd, getContext);
- }
- if (parseStop) {
- return;
- }
- }
- }
- if (tagEnd) {
- if (onCloseTag) {
- onCloseTag(proxy ? elementProxy : elementName, decodeEntities, tagStart, getContext);
- if (parseStop) {
- return;
- }
- }
- // restore old namespace
- if (isNamespace) {
- if (!tagStart) {
- nsMatrix = nsMatrixStack.pop();
- } else {
- nsMatrix = _nsMatrix;
- }
- }
- }
- j += 1;
- }
- } /** end parse */
- }
- function hasLowerCaseAlias(pkg) {
- return pkg.xml && pkg.xml.tagAlias === 'lowerCase';
- }
- var DEFAULT_NS_MAP = {
- 'xsi': 'http://www.w3.org/2001/XMLSchema-instance'
- };
- var XSI_TYPE$1 = 'xsi:type';
- function serializeFormat(element) {
- return element.xml && element.xml.serialize;
- }
- function serializeAsType(element) {
- return serializeFormat(element) === XSI_TYPE$1;
- }
- function serializeAsProperty(element) {
- return serializeFormat(element) === 'property';
- }
- function capitalize(str) {
- return str.charAt(0).toUpperCase() + str.slice(1);
- }
- function aliasToName(aliasNs, pkg) {
- if (!hasLowerCaseAlias(pkg)) {
- return aliasNs.name;
- }
- return aliasNs.prefix + ':' + capitalize(aliasNs.localName);
- }
- function prefixedToName(nameNs, pkg) {
- var name = nameNs.name,
- localName = nameNs.localName;
- var typePrefix = pkg.xml && pkg.xml.typePrefix;
- if (typePrefix && localName.indexOf(typePrefix) === 0) {
- return nameNs.prefix + ':' + localName.slice(typePrefix.length);
- } else {
- return name;
- }
- }
- function normalizeXsiTypeName(name, model) {
- var nameNs = parseName(name);
- var pkg = model.getPackage(nameNs.prefix);
- return prefixedToName(nameNs, pkg);
- }
- function error$1(message) {
- return new Error(message);
- }
- /**
- * Get the moddle descriptor for a given instance or type.
- *
- * @param {ModdleElement|Function} element
- *
- * @return {Object} the moddle descriptor
- */
- function getModdleDescriptor(element) {
- return element.$descriptor;
- }
- function defer(fn) {
- setTimeout(fn, 0);
- }
- /**
- * A parse context.
- *
- * @class
- *
- * @param {Object} options
- * @param {ElementHandler} options.rootHandler the root handler for parsing a document
- * @param {boolean} [options.lax=false] whether or not to ignore invalid elements
- */
- function Context(options) {
- /**
- * @property {ElementHandler} rootHandler
- */
- /**
- * @property {Boolean} lax
- */
- assign(this, options);
- this.elementsById = {};
- this.references = [];
- this.warnings = [];
- /**
- * Add an unresolved reference.
- *
- * @param {Object} reference
- */
- this.addReference = function(reference) {
- this.references.push(reference);
- };
- /**
- * Add a processed element.
- *
- * @param {ModdleElement} element
- */
- this.addElement = function(element) {
- if (!element) {
- throw error$1('expected element');
- }
- var elementsById = this.elementsById;
- var descriptor = getModdleDescriptor(element);
- var idProperty = descriptor.idProperty,
- id;
- if (idProperty) {
- id = element.get(idProperty.name);
- if (id) {
- // for QName validation as per http://www.w3.org/TR/REC-xml/#NT-NameChar
- if (!/^([a-z][\w-.]*:)?[a-z_][\w-.]*$/i.test(id)) {
- throw new Error('illegal ID <' + id + '>');
- }
- if (elementsById[id]) {
- throw error$1('duplicate ID <' + id + '>');
- }
- elementsById[id] = element;
- }
- }
- };
- /**
- * Add an import warning.
- *
- * @param {Object} warning
- * @param {String} warning.message
- * @param {Error} [warning.error]
- */
- this.addWarning = function(warning) {
- this.warnings.push(warning);
- };
- }
- function BaseHandler() {}
- BaseHandler.prototype.handleEnd = function() {};
- BaseHandler.prototype.handleText = function() {};
- BaseHandler.prototype.handleNode = function() {};
- /**
- * A simple pass through handler that does nothing except for
- * ignoring all input it receives.
- *
- * This is used to ignore unknown elements and
- * attributes.
- */
- function NoopHandler() { }
- NoopHandler.prototype = Object.create(BaseHandler.prototype);
- NoopHandler.prototype.handleNode = function() {
- return this;
- };
- function BodyHandler() {}
- BodyHandler.prototype = Object.create(BaseHandler.prototype);
- BodyHandler.prototype.handleText = function(text) {
- this.body = (this.body || '') + text;
- };
- function ReferenceHandler(property, context) {
- this.property = property;
- this.context = context;
- }
- ReferenceHandler.prototype = Object.create(BodyHandler.prototype);
- ReferenceHandler.prototype.handleNode = function(node) {
- if (this.element) {
- throw error$1('expected no sub nodes');
- } else {
- this.element = this.createReference(node);
- }
- return this;
- };
- ReferenceHandler.prototype.handleEnd = function() {
- this.element.id = this.body;
- };
- ReferenceHandler.prototype.createReference = function(node) {
- return {
- property: this.property.ns.name,
- id: ''
- };
- };
- function ValueHandler(propertyDesc, element) {
- this.element = element;
- this.propertyDesc = propertyDesc;
- }
- ValueHandler.prototype = Object.create(BodyHandler.prototype);
- ValueHandler.prototype.handleEnd = function() {
- var value = this.body || '',
- element = this.element,
- propertyDesc = this.propertyDesc;
- value = coerceType(propertyDesc.type, value);
- if (propertyDesc.isMany) {
- element.get(propertyDesc.name).push(value);
- } else {
- element.set(propertyDesc.name, value);
- }
- };
- function BaseElementHandler() {}
- BaseElementHandler.prototype = Object.create(BodyHandler.prototype);
- BaseElementHandler.prototype.handleNode = function(node) {
- var parser = this,
- element = this.element;
- if (!element) {
- element = this.element = this.createElement(node);
- this.context.addElement(element);
- } else {
- parser = this.handleChild(node);
- }
- return parser;
- };
- /**
- * @class Reader.ElementHandler
- *
- */
- function ElementHandler(model, typeName, context) {
- this.model = model;
- this.type = model.getType(typeName);
- this.context = context;
- }
- ElementHandler.prototype = Object.create(BaseElementHandler.prototype);
- ElementHandler.prototype.addReference = function(reference) {
- this.context.addReference(reference);
- };
- ElementHandler.prototype.handleText = function(text) {
- var element = this.element,
- descriptor = getModdleDescriptor(element),
- bodyProperty = descriptor.bodyProperty;
- if (!bodyProperty) {
- throw error$1('unexpected body text <' + text + '>');
- }
- BodyHandler.prototype.handleText.call(this, text);
- };
- ElementHandler.prototype.handleEnd = function() {
- var value = this.body,
- element = this.element,
- descriptor = getModdleDescriptor(element),
- bodyProperty = descriptor.bodyProperty;
- if (bodyProperty && value !== undefined) {
- value = coerceType(bodyProperty.type, value);
- element.set(bodyProperty.name, value);
- }
- };
- /**
- * Create an instance of the model from the given node.
- *
- * @param {Element} node the xml node
- */
- ElementHandler.prototype.createElement = function(node) {
- var attributes = node.attributes,
- Type = this.type,
- descriptor = getModdleDescriptor(Type),
- context = this.context,
- instance = new Type({}),
- model = this.model,
- propNameNs;
- forEach(attributes, function(value, name) {
- var prop = descriptor.propertiesByName[name],
- values;
- if (prop && prop.isReference) {
- if (!prop.isMany) {
- context.addReference({
- element: instance,
- property: prop.ns.name,
- id: value
- });
- } else {
- // IDREFS: parse references as whitespace-separated list
- values = value.split(' ');
- forEach(values, function(v) {
- context.addReference({
- element: instance,
- property: prop.ns.name,
- id: v
- });
- });
- }
- } else {
- if (prop) {
- value = coerceType(prop.type, value);
- } else
- if (name !== 'xmlns') {
- propNameNs = parseName(name, descriptor.ns.prefix);
- // check whether attribute is defined in a well-known namespace
- // if that is the case we emit a warning to indicate potential misuse
- if (model.getPackage(propNameNs.prefix)) {
- context.addWarning({
- message: 'unknown attribute <' + name + '>',
- element: instance,
- property: name,
- value: value
- });
- }
- }
- instance.set(name, value);
- }
- });
- return instance;
- };
- ElementHandler.prototype.getPropertyForNode = function(node) {
- var name = node.name;
- var nameNs = parseName(name);
- var type = this.type,
- model = this.model,
- descriptor = getModdleDescriptor(type);
- var propertyName = nameNs.name,
- property = descriptor.propertiesByName[propertyName],
- elementTypeName,
- elementType;
- // search for properties by name first
- if (property && !property.isAttr) {
- if (serializeAsType(property)) {
- elementTypeName = node.attributes[XSI_TYPE$1];
- // xsi type is optional, if it does not exists the
- // default type is assumed
- if (elementTypeName) {
- // take possible type prefixes from XML
- // into account, i.e.: xsi:type="t{ActualType}"
- elementTypeName = normalizeXsiTypeName(elementTypeName, model);
- elementType = model.getType(elementTypeName);
- return assign({}, property, {
- effectiveType: getModdleDescriptor(elementType).name
- });
- }
- }
- // search for properties by name first
- return property;
- }
- var pkg = model.getPackage(nameNs.prefix);
- if (pkg) {
- elementTypeName = aliasToName(nameNs, pkg);
- elementType = model.getType(elementTypeName);
- // search for collection members later
- property = find(descriptor.properties, function(p) {
- return !p.isVirtual && !p.isReference && !p.isAttribute && elementType.hasType(p.type);
- });
- if (property) {
- return assign({}, property, {
- effectiveType: getModdleDescriptor(elementType).name
- });
- }
- } else {
- // parse unknown element (maybe extension)
- property = find(descriptor.properties, function(p) {
- return !p.isReference && !p.isAttribute && p.type === 'Element';
- });
- if (property) {
- return property;
- }
- }
- throw error$1('unrecognized element <' + nameNs.name + '>');
- };
- ElementHandler.prototype.toString = function() {
- return 'ElementDescriptor[' + getModdleDescriptor(this.type).name + ']';
- };
- ElementHandler.prototype.valueHandler = function(propertyDesc, element) {
- return new ValueHandler(propertyDesc, element);
- };
- ElementHandler.prototype.referenceHandler = function(propertyDesc) {
- return new ReferenceHandler(propertyDesc, this.context);
- };
- ElementHandler.prototype.handler = function(type) {
- if (type === 'Element') {
- return new GenericElementHandler(this.model, type, this.context);
- } else {
- return new ElementHandler(this.model, type, this.context);
- }
- };
- /**
- * Handle the child element parsing
- *
- * @param {Element} node the xml node
- */
- ElementHandler.prototype.handleChild = function(node) {
- var propertyDesc, type, element, childHandler;
- propertyDesc = this.getPropertyForNode(node);
- element = this.element;
- type = propertyDesc.effectiveType || propertyDesc.type;
- if (isSimple(type)) {
- return this.valueHandler(propertyDesc, element);
- }
- if (propertyDesc.isReference) {
- childHandler = this.referenceHandler(propertyDesc).handleNode(node);
- } else {
- childHandler = this.handler(type).handleNode(node);
- }
- var newElement = childHandler.element;
- // child handles may decide to skip elements
- // by not returning anything
- if (newElement !== undefined) {
- if (propertyDesc.isMany) {
- element.get(propertyDesc.name).push(newElement);
- } else {
- element.set(propertyDesc.name, newElement);
- }
- if (propertyDesc.isReference) {
- assign(newElement, {
- element: element
- });
- this.context.addReference(newElement);
- } else {
- // establish child -> parent relationship
- newElement.$parent = element;
- }
- }
- return childHandler;
- };
- /**
- * An element handler that performs special validation
- * to ensure the node it gets initialized with matches
- * the handlers type (namespace wise).
- *
- * @param {Moddle} model
- * @param {String} typeName
- * @param {Context} context
- */
- function RootElementHandler(model, typeName, context) {
- ElementHandler.call(this, model, typeName, context);
- }
- RootElementHandler.prototype = Object.create(ElementHandler.prototype);
- RootElementHandler.prototype.createElement = function(node) {
- var name = node.name,
- nameNs = parseName(name),
- model = this.model,
- type = this.type,
- pkg = model.getPackage(nameNs.prefix),
- typeName = pkg && aliasToName(nameNs, pkg) || name;
- // verify the correct namespace if we parse
- // the first element in the handler tree
- //
- // this ensures we don't mistakenly import wrong namespace elements
- if (!type.hasType(typeName)) {
- throw error$1('unexpected element <' + node.originalName + '>');
- }
- return ElementHandler.prototype.createElement.call(this, node);
- };
- function GenericElementHandler(model, typeName, context) {
- this.model = model;
- this.context = context;
- }
- GenericElementHandler.prototype = Object.create(BaseElementHandler.prototype);
- GenericElementHandler.prototype.createElement = function(node) {
- var name = node.name,
- ns = parseName(name),
- prefix = ns.prefix,
- uri = node.ns[prefix + '$uri'],
- attributes = node.attributes;
- return this.model.createAny(name, uri, attributes);
- };
- GenericElementHandler.prototype.handleChild = function(node) {
- var handler = new GenericElementHandler(this.model, 'Element', this.context).handleNode(node),
- element = this.element;
- var newElement = handler.element,
- children;
- if (newElement !== undefined) {
- children = element.$children = element.$children || [];
- children.push(newElement);
- // establish child -> parent relationship
- newElement.$parent = element;
- }
- return handler;
- };
- GenericElementHandler.prototype.handleEnd = function() {
- if (this.body) {
- this.element.$body = this.body;
- }
- };
- /**
- * A reader for a meta-model
- *
- * @param {Object} options
- * @param {Model} options.model used to read xml files
- * @param {Boolean} options.lax whether to make parse errors warnings
- */
- function Reader(options) {
- if (options instanceof Moddle) {
- options = {
- model: options
- };
- }
- assign(this, { lax: false }, options);
- }
- /**
- * Parse the given XML into a moddle document tree.
- *
- * @param {String} xml
- * @param {ElementHandler|Object} options or rootHandler
- * @param {Function} done
- */
- Reader.prototype.fromXML = function(xml, options, done) {
- var rootHandler = options.rootHandler;
- if (options instanceof ElementHandler) {
- // root handler passed via (xml, { rootHandler: ElementHandler }, ...)
- rootHandler = options;
- options = {};
- } else {
- if (typeof options === 'string') {
- // rootHandler passed via (xml, 'someString', ...)
- rootHandler = this.handler(options);
- options = {};
- } else if (typeof rootHandler === 'string') {
- // rootHandler passed via (xml, { rootHandler: 'someString' }, ...)
- rootHandler = this.handler(rootHandler);
- }
- }
- var model = this.model,
- lax = this.lax;
- var context = new Context(assign({}, options, { rootHandler: rootHandler })),
- parser = new Parser({ proxy: true }),
- stack = createStack();
- rootHandler.context = context;
- // push root handler
- stack.push(rootHandler);
- /**
- * Handle error.
- *
- * @param {Error} err
- * @param {Function} getContext
- * @param {boolean} lax
- *
- * @return {boolean} true if handled
- */
- function handleError(err, getContext, lax) {
- var ctx = getContext();
- var line = ctx.line,
- column = ctx.column,
- data = ctx.data;
- // we receive the full context data here,
- // for elements trim down the information
- // to the tag name, only
- if (data.charAt(0) === '<' && data.indexOf(' ') !== -1) {
- data = data.slice(0, data.indexOf(' ')) + '>';
- }
- var message =
- 'unparsable content ' + (data ? data + ' ' : '') + 'detected\n\t' +
- 'line: ' + line + '\n\t' +
- 'column: ' + column + '\n\t' +
- 'nested error: ' + err.message;
- if (lax) {
- context.addWarning({
- message: message,
- error: err
- });
- return true;
- } else {
- throw error$1(message);
- }
- }
- function handleWarning(err, getContext) {
- // just like handling errors in <lax=true> mode
- return handleError(err, getContext, true);
- }
- /**
- * Resolve collected references on parse end.
- */
- function resolveReferences() {
- var elementsById = context.elementsById;
- var references = context.references;
- var i, r;
- for (i = 0; (r = references[i]); i++) {
- var element = r.element;
- var reference = elementsById[r.id];
- var property = getModdleDescriptor(element).propertiesByName[r.property];
- if (!reference) {
- context.addWarning({
- message: 'unresolved reference <' + r.id + '>',
- element: r.element,
- property: r.property,
- value: r.id
- });
- }
- if (property.isMany) {
- var collection = element.get(property.name),
- idx = collection.indexOf(r);
- // we replace an existing place holder (idx != -1) or
- // append to the collection instead
- if (idx === -1) {
- idx = collection.length;
- }
- if (!reference) {
- // remove unresolvable reference
- collection.splice(idx, 1);
- } else {
- // add or update reference in collection
- collection[idx] = reference;
- }
- } else {
- element.set(property.name, reference);
- }
- }
- }
- function handleClose() {
- stack.pop().handleEnd();
- }
- var PREAMBLE_START_PATTERN = /^<\?xml /i;
- var ENCODING_PATTERN = / encoding="([^"]+)"/i;
- var UTF_8_PATTERN = /^utf-8$/i;
- function handleQuestion(question) {
- if (!PREAMBLE_START_PATTERN.test(question)) {
- return;
- }
- var match = ENCODING_PATTERN.exec(question);
- var encoding = match && match[1];
- if (!encoding || UTF_8_PATTERN.test(encoding)) {
- return;
- }
- context.addWarning({
- message:
- 'unsupported document encoding <' + encoding + '>, ' +
- 'falling back to UTF-8'
- });
- }
- function handleOpen(node, getContext) {
- var handler = stack.peek();
- try {
- stack.push(handler.handleNode(node));
- } catch (err) {
- if (handleError(err, getContext, lax)) {
- stack.push(new NoopHandler());
- }
- }
- }
- function handleCData(text, getContext) {
- try {
- stack.peek().handleText(text);
- } catch (err) {
- handleWarning(err, getContext);
- }
- }
- function handleText(text, getContext) {
- // strip whitespace only nodes, i.e. before
- // <!CDATA[ ... ]> sections and in between tags
- text = text.trim();
- if (!text) {
- return;
- }
- handleCData(text, getContext);
- }
- var uriMap = model.getPackages().reduce(function(uriMap, p) {
- uriMap[p.uri] = p.prefix;
- return uriMap;
- }, {});
- parser
- .ns(uriMap)
- .on('openTag', function(obj, decodeStr, selfClosing, getContext) {
- // gracefully handle unparsable attributes (attrs=false)
- var attrs = obj.attrs || {};
- var decodedAttrs = Object.keys(attrs).reduce(function(d, key) {
- var value = decodeStr(attrs[key]);
- d[key] = value;
- return d;
- }, {});
- var node = {
- name: obj.name,
- originalName: obj.originalName,
- attributes: decodedAttrs,
- ns: obj.ns
- };
- handleOpen(node, getContext);
- })
- .on('question', handleQuestion)
- .on('closeTag', handleClose)
- .on('cdata', handleCData)
- .on('text', function(text, decodeEntities, getContext) {
- handleText(decodeEntities(text), getContext);
- })
- .on('error', handleError)
- .on('warn', handleWarning);
- // deferred parse XML to make loading really ascnchronous
- // this ensures the execution environment (node or browser)
- // is kept responsive and that certain optimization strategies
- // can kick in
- defer(function() {
- var err;
- try {
- parser.parse(xml);
- resolveReferences();
- } catch (e) {
- err = e;
- }
- var element = rootHandler.element;
- // handle the situation that we could not extract
- // the desired root element from the document
- if (!err && !element) {
- err = error$1('failed to parse document as <' + rootHandler.type.$descriptor.name + '>');
- }
- done(err, err ? undefined : element, context);
- });
- };
- Reader.prototype.handler = function(name) {
- return new RootElementHandler(this.model, name);
- };
- // helpers //////////////////////////
- function createStack() {
- var stack = [];
- Object.defineProperty(stack, 'peek', {
- value: function() {
- return this[this.length - 1];
- }
- });
- return stack;
- }
- var XML_PREAMBLE = '<?xml version="1.0" encoding="UTF-8"?>\n';
- var ESCAPE_ATTR_CHARS = /<|>|'|"|&|\n\r|\n/g;
- var ESCAPE_CHARS = /<|>|&/g;
- function Namespaces(parent) {
- var prefixMap = {};
- var uriMap = {};
- var used = {};
- var wellknown = [];
- var custom = [];
- // API
- this.byUri = function(uri) {
- return uriMap[uri] || (
- parent && parent.byUri(uri)
- );
- };
- this.add = function(ns, isWellknown) {
- uriMap[ns.uri] = ns;
- if (isWellknown) {
- wellknown.push(ns);
- } else {
- custom.push(ns);
- }
- this.mapPrefix(ns.prefix, ns.uri);
- };
- this.uriByPrefix = function(prefix) {
- return prefixMap[prefix || 'xmlns'];
- };
- this.mapPrefix = function(prefix, uri) {
- prefixMap[prefix || 'xmlns'] = uri;
- };
- this.getNSKey = function(ns) {
- return (ns.prefix !== undefined) ? (ns.uri + '|' + ns.prefix) : ns.uri;
- };
- this.logUsed = function(ns) {
- var uri = ns.uri;
- var nsKey = this.getNSKey(ns);
- used[nsKey] = this.byUri(uri);
- // Inform parent recursively about the usage of this NS
- if (parent) {
- parent.logUsed(ns);
- }
- };
- this.getUsed = function(ns) {
- function isUsed(ns) {
- var nsKey = self.getNSKey(ns);
- return used[nsKey];
- }
- var self = this;
- var allNs = [].concat(wellknown, custom);
- return allNs.filter(isUsed);
- };
- }
- function lower(string) {
- return string.charAt(0).toLowerCase() + string.slice(1);
- }
- function nameToAlias(name, pkg) {
- if (hasLowerCaseAlias(pkg)) {
- return lower(name);
- } else {
- return name;
- }
- }
- function inherits(ctor, superCtor) {
- ctor.super_ = superCtor;
- ctor.prototype = Object.create(superCtor.prototype, {
- constructor: {
- value: ctor,
- enumerable: false,
- writable: true,
- configurable: true
- }
- });
- }
- function nsName(ns) {
- if (isString(ns)) {
- return ns;
- } else {
- return (ns.prefix ? ns.prefix + ':' : '') + ns.localName;
- }
- }
- function getNsAttrs(namespaces) {
- return map(namespaces.getUsed(), function(ns) {
- var name = 'xmlns' + (ns.prefix ? ':' + ns.prefix : '');
- return { name: name, value: ns.uri };
- });
- }
- function getElementNs(ns, descriptor) {
- if (descriptor.isGeneric) {
- return assign({ localName: descriptor.ns.localName }, ns);
- } else {
- return assign({ localName: nameToAlias(descriptor.ns.localName, descriptor.$pkg) }, ns);
- }
- }
- function getPropertyNs(ns, descriptor) {
- return assign({ localName: descriptor.ns.localName }, ns);
- }
- function getSerializableProperties(element) {
- var descriptor = element.$descriptor;
- return filter(descriptor.properties, function(p) {
- var name = p.name;
- if (p.isVirtual) {
- return false;
- }
- // do not serialize defaults
- if (!element.hasOwnProperty(name)) {
- return false;
- }
- var value = element[name];
- // do not serialize default equals
- if (value === p.default) {
- return false;
- }
- // do not serialize null properties
- if (value === null) {
- return false;
- }
- return p.isMany ? value.length : true;
- });
- }
- var ESCAPE_ATTR_MAP = {
- '\n': '#10',
- '\n\r': '#10',
- '"': '#34',
- '\'': '#39',
- '<': '#60',
- '>': '#62',
- '&': '#38'
- };
- var ESCAPE_MAP = {
- '<': 'lt',
- '>': 'gt',
- '&': 'amp'
- };
- function escape$1(str, charPattern, replaceMap) {
- // ensure we are handling strings here
- str = isString(str) ? str : '' + str;
- return str.replace(charPattern, function(s) {
- return '&' + replaceMap[s] + ';';
- });
- }
- /**
- * Escape a string attribute to not contain any bad values (line breaks, '"', ...)
- *
- * @param {String} str the string to escape
- * @return {String} the escaped string
- */
- function escapeAttr(str) {
- return escape$1(str, ESCAPE_ATTR_CHARS, ESCAPE_ATTR_MAP);
- }
- function escapeBody(str) {
- return escape$1(str, ESCAPE_CHARS, ESCAPE_MAP);
- }
- function filterAttributes(props) {
- return filter(props, function(p) { return p.isAttr; });
- }
- function filterContained(props) {
- return filter(props, function(p) { return !p.isAttr; });
- }
- function ReferenceSerializer(tagName) {
- this.tagName = tagName;
- }
- ReferenceSerializer.prototype.build = function(element) {
- this.element = element;
- return this;
- };
- ReferenceSerializer.prototype.serializeTo = function(writer) {
- writer
- .appendIndent()
- .append('<' + this.tagName + '>' + this.element.id + '</' + this.tagName + '>')
- .appendNewLine();
- };
- function BodySerializer() {}
- BodySerializer.prototype.serializeValue =
- BodySerializer.prototype.serializeTo = function(writer) {
- writer.append(
- this.escape
- ? escapeBody(this.value)
- : this.value
- );
- };
- BodySerializer.prototype.build = function(prop, value) {
- this.value = value;
- if (prop.type === 'String' && value.search(ESCAPE_CHARS) !== -1) {
- this.escape = true;
- }
- return this;
- };
- function ValueSerializer(tagName) {
- this.tagName = tagName;
- }
- inherits(ValueSerializer, BodySerializer);
- ValueSerializer.prototype.serializeTo = function(writer) {
- writer
- .appendIndent()
- .append('<' + this.tagName + '>');
- this.serializeValue(writer);
- writer
- .append('</' + this.tagName + '>')
- .appendNewLine();
- };
- function ElementSerializer(parent, propertyDescriptor) {
- this.body = [];
- this.attrs = [];
- this.parent = parent;
- this.propertyDescriptor = propertyDescriptor;
- }
- ElementSerializer.prototype.build = function(element) {
- this.element = element;
- var elementDescriptor = element.$descriptor,
- propertyDescriptor = this.propertyDescriptor;
- var otherAttrs,
- properties;
- var isGeneric = elementDescriptor.isGeneric;
- if (isGeneric) {
- otherAttrs = this.parseGeneric(element);
- } else {
- otherAttrs = this.parseNsAttributes(element);
- }
- if (propertyDescriptor) {
- this.ns = this.nsPropertyTagName(propertyDescriptor);
- } else {
- this.ns = this.nsTagName(elementDescriptor);
- }
- // compute tag name
- this.tagName = this.addTagName(this.ns);
- if (!isGeneric) {
- properties = getSerializableProperties(element);
- this.parseAttributes(filterAttributes(properties));
- this.parseContainments(filterContained(properties));
- }
- this.parseGenericAttributes(element, otherAttrs);
- return this;
- };
- ElementSerializer.prototype.nsTagName = function(descriptor) {
- var effectiveNs = this.logNamespaceUsed(descriptor.ns);
- return getElementNs(effectiveNs, descriptor);
- };
- ElementSerializer.prototype.nsPropertyTagName = function(descriptor) {
- var effectiveNs = this.logNamespaceUsed(descriptor.ns);
- return getPropertyNs(effectiveNs, descriptor);
- };
- ElementSerializer.prototype.isLocalNs = function(ns) {
- return ns.uri === this.ns.uri;
- };
- /**
- * Get the actual ns attribute name for the given element.
- *
- * @param {Object} element
- * @param {Boolean} [element.inherited=false]
- *
- * @return {Object} nsName
- */
- ElementSerializer.prototype.nsAttributeName = function(element) {
- var ns;
- if (isString(element)) {
- ns = parseName(element);
- } else {
- ns = element.ns;
- }
- // return just local name for inherited attributes
- if (element.inherited) {
- return { localName: ns.localName };
- }
- // parse + log effective ns
- var effectiveNs = this.logNamespaceUsed(ns);
- // LOG ACTUAL namespace use
- this.getNamespaces().logUsed(effectiveNs);
- // strip prefix if same namespace like parent
- if (this.isLocalNs(effectiveNs)) {
- return { localName: ns.localName };
- } else {
- return assign({ localName: ns.localName }, effectiveNs);
- }
- };
- ElementSerializer.prototype.parseGeneric = function(element) {
- var self = this,
- body = this.body;
- var attributes = [];
- forEach(element, function(val, key) {
- var nonNsAttr;
- if (key === '$body') {
- body.push(new BodySerializer().build({ type: 'String' }, val));
- } else
- if (key === '$children') {
- forEach(val, function(child) {
- body.push(new ElementSerializer(self).build(child));
- });
- } else
- if (key.indexOf('$') !== 0) {
- nonNsAttr = self.parseNsAttribute(element, key, val);
- if (nonNsAttr) {
- attributes.push({ name: key, value: val });
- }
- }
- });
- return attributes;
- };
- ElementSerializer.prototype.parseNsAttribute = function(element, name, value) {
- var model = element.$model;
- var nameNs = parseName(name);
- var ns;
- // parse xmlns:foo="http://foo.bar"
- if (nameNs.prefix === 'xmlns') {
- ns = { prefix: nameNs.localName, uri: value };
- }
- // parse xmlns="http://foo.bar"
- if (!nameNs.prefix && nameNs.localName === 'xmlns') {
- ns = { uri: value };
- }
- if (!ns) {
- return {
- name: name,
- value: value
- };
- }
- if (model && model.getPackage(value)) {
- // register well known namespace
- this.logNamespace(ns, true, true);
- } else {
- // log custom namespace directly as used
- var actualNs = this.logNamespaceUsed(ns, true);
- this.getNamespaces().logUsed(actualNs);
- }
- };
- /**
- * Parse namespaces and return a list of left over generic attributes
- *
- * @param {Object} element
- * @return {Array<Object>}
- */
- ElementSerializer.prototype.parseNsAttributes = function(element, attrs) {
- var self = this;
- var genericAttrs = element.$attrs;
- var attributes = [];
- // parse namespace attributes first
- // and log them. push non namespace attributes to a list
- // and process them later
- forEach(genericAttrs, function(value, name) {
- var nonNsAttr = self.parseNsAttribute(element, name, value);
- if (nonNsAttr) {
- attributes.push(nonNsAttr);
- }
- });
- return attributes;
- };
- ElementSerializer.prototype.parseGenericAttributes = function(element, attributes) {
- var self = this;
- forEach(attributes, function(attr) {
- // do not serialize xsi:type attribute
- // it is set manually based on the actual implementation type
- if (attr.name === XSI_TYPE$1) {
- return;
- }
- try {
- self.addAttribute(self.nsAttributeName(attr.name), attr.value);
- } catch (e) {
- console.warn(
- 'missing namespace information for ',
- attr.name, '=', attr.value, 'on', element,
- e);
- }
- });
- };
- ElementSerializer.prototype.parseContainments = function(properties) {
- var self = this,
- body = this.body,
- element = this.element;
- forEach(properties, function(p) {
- var value = element.get(p.name),
- isReference = p.isReference,
- isMany = p.isMany;
- if (!isMany) {
- value = [ value ];
- }
- if (p.isBody) {
- body.push(new BodySerializer().build(p, value[0]));
- } else
- if (isSimple(p.type)) {
- forEach(value, function(v) {
- body.push(new ValueSerializer(self.addTagName(self.nsPropertyTagName(p))).build(p, v));
- });
- } else
- if (isReference) {
- forEach(value, function(v) {
- body.push(new ReferenceSerializer(self.addTagName(self.nsPropertyTagName(p))).build(v));
- });
- } else {
- // allow serialization via type
- // rather than element name
- var asType = serializeAsType(p),
- asProperty = serializeAsProperty(p);
- forEach(value, function(v) {
- var serializer;
- if (asType) {
- serializer = new TypeSerializer(self, p);
- } else
- if (asProperty) {
- serializer = new ElementSerializer(self, p);
- } else {
- serializer = new ElementSerializer(self);
- }
- body.push(serializer.build(v));
- });
- }
- });
- };
- ElementSerializer.prototype.getNamespaces = function(local) {
- var namespaces = this.namespaces,
- parent = this.parent,
- parentNamespaces;
- if (!namespaces) {
- parentNamespaces = parent && parent.getNamespaces();
- if (local || !parentNamespaces) {
- this.namespaces = namespaces = new Namespaces(parentNamespaces);
- } else {
- namespaces = parentNamespaces;
- }
- }
- return namespaces;
- };
- ElementSerializer.prototype.logNamespace = function(ns, wellknown, local) {
- var namespaces = this.getNamespaces(local);
- var nsUri = ns.uri,
- nsPrefix = ns.prefix;
- var existing = namespaces.byUri(nsUri);
- if (!existing || local) {
- namespaces.add(ns, wellknown);
- }
- namespaces.mapPrefix(nsPrefix, nsUri);
- return ns;
- };
- ElementSerializer.prototype.logNamespaceUsed = function(ns, local) {
- var element = this.element,
- model = element.$model,
- namespaces = this.getNamespaces(local);
- // ns may be
- //
- // * prefix only
- // * prefix:uri
- // * localName only
- var prefix = ns.prefix,
- uri = ns.uri,
- newPrefix, idx,
- wellknownUri;
- // handle anonymous namespaces (elementForm=unqualified), cf. #23
- if (!prefix && !uri) {
- return { localName: ns.localName };
- }
- wellknownUri = DEFAULT_NS_MAP[prefix] || model && (model.getPackage(prefix) || {}).uri;
- uri = uri || wellknownUri || namespaces.uriByPrefix(prefix);
- if (!uri) {
- throw new Error('no namespace uri given for prefix <' + prefix + '>');
- }
- ns = namespaces.byUri(uri);
- if (!ns) {
- newPrefix = prefix;
- idx = 1;
- // find a prefix that is not mapped yet
- while (namespaces.uriByPrefix(newPrefix)) {
- newPrefix = prefix + '_' + idx++;
- }
- ns = this.logNamespace({ prefix: newPrefix, uri: uri }, wellknownUri === uri);
- }
- if (prefix) {
- namespaces.mapPrefix(prefix, uri);
- }
- return ns;
- };
- ElementSerializer.prototype.parseAttributes = function(properties) {
- var self = this,
- element = this.element;
- forEach(properties, function(p) {
- var value = element.get(p.name);
- if (p.isReference) {
- if (!p.isMany) {
- value = value.id;
- }
- else {
- var values = [];
- forEach(value, function(v) {
- values.push(v.id);
- });
- // IDREFS is a whitespace-separated list of references.
- value = values.join(' ');
- }
- }
- self.addAttribute(self.nsAttributeName(p), value);
- });
- };
- ElementSerializer.prototype.addTagName = function(nsTagName) {
- var actualNs = this.logNamespaceUsed(nsTagName);
- this.getNamespaces().logUsed(actualNs);
- return nsName(nsTagName);
- };
- ElementSerializer.prototype.addAttribute = function(name, value) {
- var attrs = this.attrs;
- if (isString(value)) {
- value = escapeAttr(value);
- }
- attrs.push({ name: name, value: value });
- };
- ElementSerializer.prototype.serializeAttributes = function(writer) {
- var attrs = this.attrs,
- namespaces = this.namespaces;
- if (namespaces) {
- attrs = getNsAttrs(namespaces).concat(attrs);
- }
- forEach(attrs, function(a) {
- writer
- .append(' ')
- .append(nsName(a.name)).append('="').append(a.value).append('"');
- });
- };
- ElementSerializer.prototype.serializeTo = function(writer) {
- var firstBody = this.body[0],
- indent = firstBody && firstBody.constructor !== BodySerializer;
- writer
- .appendIndent()
- .append('<' + this.tagName);
- this.serializeAttributes(writer);
- writer.append(firstBody ? '>' : ' />');
- if (firstBody) {
- if (indent) {
- writer
- .appendNewLine()
- .indent();
- }
- forEach(this.body, function(b) {
- b.serializeTo(writer);
- });
- if (indent) {
- writer
- .unindent()
- .appendIndent();
- }
- writer.append('</' + this.tagName + '>');
- }
- writer.appendNewLine();
- };
- /**
- * A serializer for types that handles serialization of data types
- */
- function TypeSerializer(parent, propertyDescriptor) {
- ElementSerializer.call(this, parent, propertyDescriptor);
- }
- inherits(TypeSerializer, ElementSerializer);
- TypeSerializer.prototype.parseNsAttributes = function(element) {
- // extracted attributes
- var attributes = ElementSerializer.prototype.parseNsAttributes.call(this, element);
- var descriptor = element.$descriptor;
- // only serialize xsi:type if necessary
- if (descriptor.name === this.propertyDescriptor.type) {
- return attributes;
- }
- var typeNs = this.typeNs = this.nsTagName(descriptor);
- this.getNamespaces().logUsed(this.typeNs);
- // add xsi:type attribute to represent the elements
- // actual type
- var pkg = element.$model.getPackage(typeNs.uri),
- typePrefix = (pkg.xml && pkg.xml.typePrefix) || '';
- this.addAttribute(
- this.nsAttributeName(XSI_TYPE$1),
- (typeNs.prefix ? typeNs.prefix + ':' : '') + typePrefix + descriptor.ns.localName
- );
- return attributes;
- };
- TypeSerializer.prototype.isLocalNs = function(ns) {
- return ns.uri === (this.typeNs || this.ns).uri;
- };
- function SavingWriter() {
- this.value = '';
- this.write = function(str) {
- this.value += str;
- };
- }
- function FormatingWriter(out, format) {
- var indent = [''];
- this.append = function(str) {
- out.write(str);
- return this;
- };
- this.appendNewLine = function() {
- if (format) {
- out.write('\n');
- }
- return this;
- };
- this.appendIndent = function() {
- if (format) {
- out.write(indent.join(' '));
- }
- return this;
- };
- this.indent = function() {
- indent.push('');
- return this;
- };
- this.unindent = function() {
- indent.pop();
- return this;
- };
- }
- /**
- * A writer for meta-model backed document trees
- *
- * @param {Object} options output options to pass into the writer
- */
- function Writer(options) {
- options = assign({ format: false, preamble: true }, options || {});
- function toXML(tree, writer) {
- var internalWriter = writer || new SavingWriter();
- var formatingWriter = new FormatingWriter(internalWriter, options.format);
- if (options.preamble) {
- formatingWriter.append(XML_PREAMBLE);
- }
- new ElementSerializer().build(tree).serializeTo(formatingWriter);
- if (!writer) {
- return internalWriter.value;
- }
- }
- return {
- toXML: toXML
- };
- }
- /**
- * A sub class of {@link Moddle} with support for import and export of BPMN 2.0 xml files.
- *
- * @class BpmnModdle
- * @extends Moddle
- *
- * @param {Object|Array} packages to use for instantiating the model
- * @param {Object} [options] additional options to pass over
- */
- function BpmnModdle(packages, options) {
- Moddle.call(this, packages, options);
- }
- BpmnModdle.prototype = Object.create(Moddle.prototype);
- /**
- * Instantiates a BPMN model tree from a given xml string.
- *
- * @param {String} xmlStr
- * @param {String} [typeName='bpmn:Definitions'] name of the root element
- * @param {Object} [options] options to pass to the underlying reader
- * @param {Function} done callback that is invoked with (err, result, parseContext)
- * once the import completes
- */
- BpmnModdle.prototype.fromXML = function(xmlStr, typeName, options, done) {
- if (!isString(typeName)) {
- done = options;
- options = typeName;
- typeName = 'bpmn:Definitions';
- }
- if (isFunction(options)) {
- done = options;
- options = {};
- }
- var reader = new Reader(assign({ model: this, lax: true }, options));
- var rootHandler = reader.handler(typeName);
- reader.fromXML(xmlStr, rootHandler, done);
- };
- /**
- * Serializes a BPMN 2.0 object tree to XML.
- *
- * @param {String} element the root element, typically an instance of `bpmn:Definitions`
- * @param {Object} [options] to pass to the underlying writer
- * @param {Function} done callback invoked with (err, xmlStr) once the import completes
- */
- BpmnModdle.prototype.toXML = function(element, options, done) {
- if (isFunction(options)) {
- done = options;
- options = {};
- }
- var writer = new Writer(options);
- var result;
- var err;
- try {
- result = writer.toXML(element);
- } catch (e) {
- err = e;
- }
- return done(err, result);
- };
- var name = "BPMN20";
- var uri = "http://www.omg.org/spec/BPMN/20100524/MODEL";
- var prefix$1 = "bpmn";
- var associations = [
- ];
- var types$1 = [
- {
- name: "Interface",
- superClass: [
- "RootElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "operations",
- type: "Operation",
- isMany: true
- },
- {
- name: "implementationRef",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "Operation",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "inMessageRef",
- type: "Message",
- isReference: true
- },
- {
- name: "outMessageRef",
- type: "Message",
- isReference: true
- },
- {
- name: "errorRef",
- type: "Error",
- isMany: true,
- isReference: true
- },
- {
- name: "implementationRef",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "EndPoint",
- superClass: [
- "RootElement"
- ]
- },
- {
- name: "Auditing",
- superClass: [
- "BaseElement"
- ]
- },
- {
- name: "GlobalTask",
- superClass: [
- "CallableElement"
- ],
- properties: [
- {
- name: "resources",
- type: "ResourceRole",
- isMany: true
- }
- ]
- },
- {
- name: "Monitoring",
- superClass: [
- "BaseElement"
- ]
- },
- {
- name: "Performer",
- superClass: [
- "ResourceRole"
- ]
- },
- {
- name: "Process",
- superClass: [
- "FlowElementsContainer",
- "CallableElement"
- ],
- properties: [
- {
- name: "processType",
- type: "ProcessType",
- isAttr: true
- },
- {
- name: "isClosed",
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "auditing",
- type: "Auditing"
- },
- {
- name: "monitoring",
- type: "Monitoring"
- },
- {
- name: "properties",
- type: "Property",
- isMany: true
- },
- {
- name: "laneSets",
- isMany: true,
- replaces: "FlowElementsContainer#laneSets",
- type: "LaneSet"
- },
- {
- name: "flowElements",
- isMany: true,
- replaces: "FlowElementsContainer#flowElements",
- type: "FlowElement"
- },
- {
- name: "artifacts",
- type: "Artifact",
- isMany: true
- },
- {
- name: "resources",
- type: "ResourceRole",
- isMany: true
- },
- {
- name: "correlationSubscriptions",
- type: "CorrelationSubscription",
- isMany: true
- },
- {
- name: "supports",
- type: "Process",
- isMany: true,
- isReference: true
- },
- {
- name: "definitionalCollaborationRef",
- type: "Collaboration",
- isAttr: true,
- isReference: true
- },
- {
- name: "isExecutable",
- isAttr: true,
- type: "Boolean"
- }
- ]
- },
- {
- name: "LaneSet",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "lanes",
- type: "Lane",
- isMany: true
- },
- {
- name: "name",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "Lane",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "partitionElementRef",
- type: "BaseElement",
- isAttr: true,
- isReference: true
- },
- {
- name: "partitionElement",
- type: "BaseElement"
- },
- {
- name: "flowNodeRef",
- type: "FlowNode",
- isMany: true,
- isReference: true
- },
- {
- name: "childLaneSet",
- type: "LaneSet",
- xml: {
- serialize: "xsi:type"
- }
- }
- ]
- },
- {
- name: "GlobalManualTask",
- superClass: [
- "GlobalTask"
- ]
- },
- {
- name: "ManualTask",
- superClass: [
- "Task"
- ]
- },
- {
- name: "UserTask",
- superClass: [
- "Task"
- ],
- properties: [
- {
- name: "renderings",
- type: "Rendering",
- isMany: true
- },
- {
- name: "implementation",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "Rendering",
- superClass: [
- "BaseElement"
- ]
- },
- {
- name: "HumanPerformer",
- superClass: [
- "Performer"
- ]
- },
- {
- name: "PotentialOwner",
- superClass: [
- "HumanPerformer"
- ]
- },
- {
- name: "GlobalUserTask",
- superClass: [
- "GlobalTask"
- ],
- properties: [
- {
- name: "implementation",
- isAttr: true,
- type: "String"
- },
- {
- name: "renderings",
- type: "Rendering",
- isMany: true
- }
- ]
- },
- {
- name: "Gateway",
- isAbstract: true,
- superClass: [
- "FlowNode"
- ],
- properties: [
- {
- name: "gatewayDirection",
- type: "GatewayDirection",
- "default": "Unspecified",
- isAttr: true
- }
- ]
- },
- {
- name: "EventBasedGateway",
- superClass: [
- "Gateway"
- ],
- properties: [
- {
- name: "instantiate",
- "default": false,
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "eventGatewayType",
- type: "EventBasedGatewayType",
- isAttr: true,
- "default": "Exclusive"
- }
- ]
- },
- {
- name: "ComplexGateway",
- superClass: [
- "Gateway"
- ],
- properties: [
- {
- name: "activationCondition",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- },
- {
- name: "default",
- type: "SequenceFlow",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "ExclusiveGateway",
- superClass: [
- "Gateway"
- ],
- properties: [
- {
- name: "default",
- type: "SequenceFlow",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "InclusiveGateway",
- superClass: [
- "Gateway"
- ],
- properties: [
- {
- name: "default",
- type: "SequenceFlow",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "ParallelGateway",
- superClass: [
- "Gateway"
- ]
- },
- {
- name: "RootElement",
- isAbstract: true,
- superClass: [
- "BaseElement"
- ]
- },
- {
- name: "Relationship",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "type",
- isAttr: true,
- type: "String"
- },
- {
- name: "direction",
- type: "RelationshipDirection",
- isAttr: true
- },
- {
- name: "source",
- isMany: true,
- isReference: true,
- type: "Element"
- },
- {
- name: "target",
- isMany: true,
- isReference: true,
- type: "Element"
- }
- ]
- },
- {
- name: "BaseElement",
- isAbstract: true,
- properties: [
- {
- name: "id",
- isAttr: true,
- type: "String",
- isId: true
- },
- {
- name: "documentation",
- type: "Documentation",
- isMany: true
- },
- {
- name: "extensionDefinitions",
- type: "ExtensionDefinition",
- isMany: true,
- isReference: true
- },
- {
- name: "extensionElements",
- type: "ExtensionElements"
- }
- ]
- },
- {
- name: "Extension",
- properties: [
- {
- name: "mustUnderstand",
- "default": false,
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "definition",
- type: "ExtensionDefinition",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "ExtensionDefinition",
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "extensionAttributeDefinitions",
- type: "ExtensionAttributeDefinition",
- isMany: true
- }
- ]
- },
- {
- name: "ExtensionAttributeDefinition",
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "type",
- isAttr: true,
- type: "String"
- },
- {
- name: "isReference",
- "default": false,
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "extensionDefinition",
- type: "ExtensionDefinition",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "ExtensionElements",
- properties: [
- {
- name: "valueRef",
- isAttr: true,
- isReference: true,
- type: "Element"
- },
- {
- name: "values",
- type: "Element",
- isMany: true
- },
- {
- name: "extensionAttributeDefinition",
- type: "ExtensionAttributeDefinition",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "Documentation",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "text",
- type: "String",
- isBody: true
- },
- {
- name: "textFormat",
- "default": "text/plain",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "Event",
- isAbstract: true,
- superClass: [
- "FlowNode",
- "InteractionNode"
- ],
- properties: [
- {
- name: "properties",
- type: "Property",
- isMany: true
- }
- ]
- },
- {
- name: "IntermediateCatchEvent",
- superClass: [
- "CatchEvent"
- ]
- },
- {
- name: "IntermediateThrowEvent",
- superClass: [
- "ThrowEvent"
- ]
- },
- {
- name: "EndEvent",
- superClass: [
- "ThrowEvent"
- ]
- },
- {
- name: "StartEvent",
- superClass: [
- "CatchEvent"
- ],
- properties: [
- {
- name: "isInterrupting",
- "default": true,
- isAttr: true,
- type: "Boolean"
- }
- ]
- },
- {
- name: "ThrowEvent",
- isAbstract: true,
- superClass: [
- "Event"
- ],
- properties: [
- {
- name: "dataInputs",
- type: "DataInput",
- isMany: true
- },
- {
- name: "dataInputAssociations",
- type: "DataInputAssociation",
- isMany: true
- },
- {
- name: "inputSet",
- type: "InputSet"
- },
- {
- name: "eventDefinitions",
- type: "EventDefinition",
- isMany: true
- },
- {
- name: "eventDefinitionRef",
- type: "EventDefinition",
- isMany: true,
- isReference: true
- }
- ]
- },
- {
- name: "CatchEvent",
- isAbstract: true,
- superClass: [
- "Event"
- ],
- properties: [
- {
- name: "parallelMultiple",
- isAttr: true,
- type: "Boolean",
- "default": false
- },
- {
- name: "dataOutputs",
- type: "DataOutput",
- isMany: true
- },
- {
- name: "dataOutputAssociations",
- type: "DataOutputAssociation",
- isMany: true
- },
- {
- name: "outputSet",
- type: "OutputSet"
- },
- {
- name: "eventDefinitions",
- type: "EventDefinition",
- isMany: true
- },
- {
- name: "eventDefinitionRef",
- type: "EventDefinition",
- isMany: true,
- isReference: true
- }
- ]
- },
- {
- name: "BoundaryEvent",
- superClass: [
- "CatchEvent"
- ],
- properties: [
- {
- name: "cancelActivity",
- "default": true,
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "attachedToRef",
- type: "Activity",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "EventDefinition",
- isAbstract: true,
- superClass: [
- "RootElement"
- ]
- },
- {
- name: "CancelEventDefinition",
- superClass: [
- "EventDefinition"
- ]
- },
- {
- name: "ErrorEventDefinition",
- superClass: [
- "EventDefinition"
- ],
- properties: [
- {
- name: "errorRef",
- type: "Error",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "TerminateEventDefinition",
- superClass: [
- "EventDefinition"
- ]
- },
- {
- name: "EscalationEventDefinition",
- superClass: [
- "EventDefinition"
- ],
- properties: [
- {
- name: "escalationRef",
- type: "Escalation",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "Escalation",
- properties: [
- {
- name: "structureRef",
- type: "ItemDefinition",
- isAttr: true,
- isReference: true
- },
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "escalationCode",
- isAttr: true,
- type: "String"
- }
- ],
- superClass: [
- "RootElement"
- ]
- },
- {
- name: "CompensateEventDefinition",
- superClass: [
- "EventDefinition"
- ],
- properties: [
- {
- name: "waitForCompletion",
- isAttr: true,
- type: "Boolean",
- "default": true
- },
- {
- name: "activityRef",
- type: "Activity",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "TimerEventDefinition",
- superClass: [
- "EventDefinition"
- ],
- properties: [
- {
- name: "timeDate",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- },
- {
- name: "timeCycle",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- },
- {
- name: "timeDuration",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- }
- ]
- },
- {
- name: "LinkEventDefinition",
- superClass: [
- "EventDefinition"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "target",
- type: "LinkEventDefinition",
- isAttr: true,
- isReference: true
- },
- {
- name: "source",
- type: "LinkEventDefinition",
- isMany: true,
- isReference: true
- }
- ]
- },
- {
- name: "MessageEventDefinition",
- superClass: [
- "EventDefinition"
- ],
- properties: [
- {
- name: "messageRef",
- type: "Message",
- isAttr: true,
- isReference: true
- },
- {
- name: "operationRef",
- type: "Operation",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "ConditionalEventDefinition",
- superClass: [
- "EventDefinition"
- ],
- properties: [
- {
- name: "condition",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- }
- ]
- },
- {
- name: "SignalEventDefinition",
- superClass: [
- "EventDefinition"
- ],
- properties: [
- {
- name: "signalRef",
- type: "Signal",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "Signal",
- superClass: [
- "RootElement"
- ],
- properties: [
- {
- name: "structureRef",
- type: "ItemDefinition",
- isAttr: true,
- isReference: true
- },
- {
- name: "name",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "ImplicitThrowEvent",
- superClass: [
- "ThrowEvent"
- ]
- },
- {
- name: "DataState",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "ItemAwareElement",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "itemSubjectRef",
- type: "ItemDefinition",
- isAttr: true,
- isReference: true
- },
- {
- name: "dataState",
- type: "DataState"
- }
- ]
- },
- {
- name: "DataAssociation",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "sourceRef",
- type: "ItemAwareElement",
- isMany: true,
- isReference: true
- },
- {
- name: "targetRef",
- type: "ItemAwareElement",
- isReference: true
- },
- {
- name: "transformation",
- type: "FormalExpression",
- xml: {
- serialize: "property"
- }
- },
- {
- name: "assignment",
- type: "Assignment",
- isMany: true
- }
- ]
- },
- {
- name: "DataInput",
- superClass: [
- "ItemAwareElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "isCollection",
- "default": false,
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "inputSetRef",
- type: "InputSet",
- isMany: true,
- isVirtual: true,
- isReference: true
- },
- {
- name: "inputSetWithOptional",
- type: "InputSet",
- isMany: true,
- isVirtual: true,
- isReference: true
- },
- {
- name: "inputSetWithWhileExecuting",
- type: "InputSet",
- isMany: true,
- isVirtual: true,
- isReference: true
- }
- ]
- },
- {
- name: "DataOutput",
- superClass: [
- "ItemAwareElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "isCollection",
- "default": false,
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "outputSetRef",
- type: "OutputSet",
- isMany: true,
- isVirtual: true,
- isReference: true
- },
- {
- name: "outputSetWithOptional",
- type: "OutputSet",
- isMany: true,
- isVirtual: true,
- isReference: true
- },
- {
- name: "outputSetWithWhileExecuting",
- type: "OutputSet",
- isMany: true,
- isVirtual: true,
- isReference: true
- }
- ]
- },
- {
- name: "InputSet",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "dataInputRefs",
- type: "DataInput",
- isMany: true,
- isReference: true
- },
- {
- name: "optionalInputRefs",
- type: "DataInput",
- isMany: true,
- isReference: true
- },
- {
- name: "whileExecutingInputRefs",
- type: "DataInput",
- isMany: true,
- isReference: true
- },
- {
- name: "outputSetRefs",
- type: "OutputSet",
- isMany: true,
- isReference: true
- }
- ]
- },
- {
- name: "OutputSet",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "dataOutputRefs",
- type: "DataOutput",
- isMany: true,
- isReference: true
- },
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "inputSetRefs",
- type: "InputSet",
- isMany: true,
- isReference: true
- },
- {
- name: "optionalOutputRefs",
- type: "DataOutput",
- isMany: true,
- isReference: true
- },
- {
- name: "whileExecutingOutputRefs",
- type: "DataOutput",
- isMany: true,
- isReference: true
- }
- ]
- },
- {
- name: "Property",
- superClass: [
- "ItemAwareElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "DataInputAssociation",
- superClass: [
- "DataAssociation"
- ]
- },
- {
- name: "DataOutputAssociation",
- superClass: [
- "DataAssociation"
- ]
- },
- {
- name: "InputOutputSpecification",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "dataInputs",
- type: "DataInput",
- isMany: true
- },
- {
- name: "dataOutputs",
- type: "DataOutput",
- isMany: true
- },
- {
- name: "inputSets",
- type: "InputSet",
- isMany: true
- },
- {
- name: "outputSets",
- type: "OutputSet",
- isMany: true
- }
- ]
- },
- {
- name: "DataObject",
- superClass: [
- "FlowElement",
- "ItemAwareElement"
- ],
- properties: [
- {
- name: "isCollection",
- "default": false,
- isAttr: true,
- type: "Boolean"
- }
- ]
- },
- {
- name: "InputOutputBinding",
- properties: [
- {
- name: "inputDataRef",
- type: "InputSet",
- isAttr: true,
- isReference: true
- },
- {
- name: "outputDataRef",
- type: "OutputSet",
- isAttr: true,
- isReference: true
- },
- {
- name: "operationRef",
- type: "Operation",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "Assignment",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "from",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- },
- {
- name: "to",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- }
- ]
- },
- {
- name: "DataStore",
- superClass: [
- "RootElement",
- "ItemAwareElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "capacity",
- isAttr: true,
- type: "Integer"
- },
- {
- name: "isUnlimited",
- "default": true,
- isAttr: true,
- type: "Boolean"
- }
- ]
- },
- {
- name: "DataStoreReference",
- superClass: [
- "ItemAwareElement",
- "FlowElement"
- ],
- properties: [
- {
- name: "dataStoreRef",
- type: "DataStore",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "DataObjectReference",
- superClass: [
- "ItemAwareElement",
- "FlowElement"
- ],
- properties: [
- {
- name: "dataObjectRef",
- type: "DataObject",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "ConversationLink",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "sourceRef",
- type: "InteractionNode",
- isAttr: true,
- isReference: true
- },
- {
- name: "targetRef",
- type: "InteractionNode",
- isAttr: true,
- isReference: true
- },
- {
- name: "name",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "ConversationAssociation",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "innerConversationNodeRef",
- type: "ConversationNode",
- isAttr: true,
- isReference: true
- },
- {
- name: "outerConversationNodeRef",
- type: "ConversationNode",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "CallConversation",
- superClass: [
- "ConversationNode"
- ],
- properties: [
- {
- name: "calledCollaborationRef",
- type: "Collaboration",
- isAttr: true,
- isReference: true
- },
- {
- name: "participantAssociations",
- type: "ParticipantAssociation",
- isMany: true
- }
- ]
- },
- {
- name: "Conversation",
- superClass: [
- "ConversationNode"
- ]
- },
- {
- name: "SubConversation",
- superClass: [
- "ConversationNode"
- ],
- properties: [
- {
- name: "conversationNodes",
- type: "ConversationNode",
- isMany: true
- }
- ]
- },
- {
- name: "ConversationNode",
- isAbstract: true,
- superClass: [
- "InteractionNode",
- "BaseElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "participantRef",
- type: "Participant",
- isMany: true,
- isReference: true
- },
- {
- name: "messageFlowRefs",
- type: "MessageFlow",
- isMany: true,
- isReference: true
- },
- {
- name: "correlationKeys",
- type: "CorrelationKey",
- isMany: true
- }
- ]
- },
- {
- name: "GlobalConversation",
- superClass: [
- "Collaboration"
- ]
- },
- {
- name: "PartnerEntity",
- superClass: [
- "RootElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "participantRef",
- type: "Participant",
- isMany: true,
- isReference: true
- }
- ]
- },
- {
- name: "PartnerRole",
- superClass: [
- "RootElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "participantRef",
- type: "Participant",
- isMany: true,
- isReference: true
- }
- ]
- },
- {
- name: "CorrelationProperty",
- superClass: [
- "RootElement"
- ],
- properties: [
- {
- name: "correlationPropertyRetrievalExpression",
- type: "CorrelationPropertyRetrievalExpression",
- isMany: true
- },
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "type",
- type: "ItemDefinition",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "Error",
- superClass: [
- "RootElement"
- ],
- properties: [
- {
- name: "structureRef",
- type: "ItemDefinition",
- isAttr: true,
- isReference: true
- },
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "errorCode",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "CorrelationKey",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "correlationPropertyRef",
- type: "CorrelationProperty",
- isMany: true,
- isReference: true
- },
- {
- name: "name",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "Expression",
- superClass: [
- "BaseElement"
- ],
- isAbstract: false,
- properties: [
- {
- name: "body",
- isBody: true,
- type: "String"
- }
- ]
- },
- {
- name: "FormalExpression",
- superClass: [
- "Expression"
- ],
- properties: [
- {
- name: "language",
- isAttr: true,
- type: "String"
- },
- {
- name: "evaluatesToTypeRef",
- type: "ItemDefinition",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "Message",
- superClass: [
- "RootElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "itemRef",
- type: "ItemDefinition",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "ItemDefinition",
- superClass: [
- "RootElement"
- ],
- properties: [
- {
- name: "itemKind",
- type: "ItemKind",
- isAttr: true
- },
- {
- name: "structureRef",
- isAttr: true,
- type: "String"
- },
- {
- name: "isCollection",
- "default": false,
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "import",
- type: "Import",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "FlowElement",
- isAbstract: true,
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "auditing",
- type: "Auditing"
- },
- {
- name: "monitoring",
- type: "Monitoring"
- },
- {
- name: "categoryValueRef",
- type: "CategoryValue",
- isMany: true,
- isReference: true
- }
- ]
- },
- {
- name: "SequenceFlow",
- superClass: [
- "FlowElement"
- ],
- properties: [
- {
- name: "isImmediate",
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "conditionExpression",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- },
- {
- name: "sourceRef",
- type: "FlowNode",
- isAttr: true,
- isReference: true
- },
- {
- name: "targetRef",
- type: "FlowNode",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "FlowElementsContainer",
- isAbstract: true,
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "laneSets",
- type: "LaneSet",
- isMany: true
- },
- {
- name: "flowElements",
- type: "FlowElement",
- isMany: true
- }
- ]
- },
- {
- name: "CallableElement",
- isAbstract: true,
- superClass: [
- "RootElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "ioSpecification",
- type: "InputOutputSpecification",
- xml: {
- serialize: "property"
- }
- },
- {
- name: "supportedInterfaceRef",
- type: "Interface",
- isMany: true,
- isReference: true
- },
- {
- name: "ioBinding",
- type: "InputOutputBinding",
- isMany: true,
- xml: {
- serialize: "property"
- }
- }
- ]
- },
- {
- name: "FlowNode",
- isAbstract: true,
- superClass: [
- "FlowElement"
- ],
- properties: [
- {
- name: "incoming",
- type: "SequenceFlow",
- isMany: true,
- isReference: true
- },
- {
- name: "outgoing",
- type: "SequenceFlow",
- isMany: true,
- isReference: true
- },
- {
- name: "lanes",
- type: "Lane",
- isMany: true,
- isVirtual: true,
- isReference: true
- }
- ]
- },
- {
- name: "CorrelationPropertyRetrievalExpression",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "messagePath",
- type: "FormalExpression"
- },
- {
- name: "messageRef",
- type: "Message",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "CorrelationPropertyBinding",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "dataPath",
- type: "FormalExpression"
- },
- {
- name: "correlationPropertyRef",
- type: "CorrelationProperty",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "Resource",
- superClass: [
- "RootElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "resourceParameters",
- type: "ResourceParameter",
- isMany: true
- }
- ]
- },
- {
- name: "ResourceParameter",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "isRequired",
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "type",
- type: "ItemDefinition",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "CorrelationSubscription",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "correlationKeyRef",
- type: "CorrelationKey",
- isAttr: true,
- isReference: true
- },
- {
- name: "correlationPropertyBinding",
- type: "CorrelationPropertyBinding",
- isMany: true
- }
- ]
- },
- {
- name: "MessageFlow",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "sourceRef",
- type: "InteractionNode",
- isAttr: true,
- isReference: true
- },
- {
- name: "targetRef",
- type: "InteractionNode",
- isAttr: true,
- isReference: true
- },
- {
- name: "messageRef",
- type: "Message",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "MessageFlowAssociation",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "innerMessageFlowRef",
- type: "MessageFlow",
- isAttr: true,
- isReference: true
- },
- {
- name: "outerMessageFlowRef",
- type: "MessageFlow",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "InteractionNode",
- isAbstract: true,
- properties: [
- {
- name: "incomingConversationLinks",
- type: "ConversationLink",
- isMany: true,
- isVirtual: true,
- isReference: true
- },
- {
- name: "outgoingConversationLinks",
- type: "ConversationLink",
- isMany: true,
- isVirtual: true,
- isReference: true
- }
- ]
- },
- {
- name: "Participant",
- superClass: [
- "InteractionNode",
- "BaseElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "interfaceRef",
- type: "Interface",
- isMany: true,
- isReference: true
- },
- {
- name: "participantMultiplicity",
- type: "ParticipantMultiplicity"
- },
- {
- name: "endPointRefs",
- type: "EndPoint",
- isMany: true,
- isReference: true
- },
- {
- name: "processRef",
- type: "Process",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "ParticipantAssociation",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "innerParticipantRef",
- type: "Participant",
- isAttr: true,
- isReference: true
- },
- {
- name: "outerParticipantRef",
- type: "Participant",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "ParticipantMultiplicity",
- properties: [
- {
- name: "minimum",
- "default": 0,
- isAttr: true,
- type: "Integer"
- },
- {
- name: "maximum",
- "default": 1,
- isAttr: true,
- type: "Integer"
- }
- ],
- superClass: [
- "BaseElement"
- ]
- },
- {
- name: "Collaboration",
- superClass: [
- "RootElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "isClosed",
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "participants",
- type: "Participant",
- isMany: true
- },
- {
- name: "messageFlows",
- type: "MessageFlow",
- isMany: true
- },
- {
- name: "artifacts",
- type: "Artifact",
- isMany: true
- },
- {
- name: "conversations",
- type: "ConversationNode",
- isMany: true
- },
- {
- name: "conversationAssociations",
- type: "ConversationAssociation"
- },
- {
- name: "participantAssociations",
- type: "ParticipantAssociation",
- isMany: true
- },
- {
- name: "messageFlowAssociations",
- type: "MessageFlowAssociation",
- isMany: true
- },
- {
- name: "correlationKeys",
- type: "CorrelationKey",
- isMany: true
- },
- {
- name: "choreographyRef",
- type: "Choreography",
- isMany: true,
- isReference: true
- },
- {
- name: "conversationLinks",
- type: "ConversationLink",
- isMany: true
- }
- ]
- },
- {
- name: "ChoreographyActivity",
- isAbstract: true,
- superClass: [
- "FlowNode"
- ],
- properties: [
- {
- name: "participantRef",
- type: "Participant",
- isMany: true,
- isReference: true
- },
- {
- name: "initiatingParticipantRef",
- type: "Participant",
- isAttr: true,
- isReference: true
- },
- {
- name: "correlationKeys",
- type: "CorrelationKey",
- isMany: true
- },
- {
- name: "loopType",
- type: "ChoreographyLoopType",
- "default": "None",
- isAttr: true
- }
- ]
- },
- {
- name: "CallChoreography",
- superClass: [
- "ChoreographyActivity"
- ],
- properties: [
- {
- name: "calledChoreographyRef",
- type: "Choreography",
- isAttr: true,
- isReference: true
- },
- {
- name: "participantAssociations",
- type: "ParticipantAssociation",
- isMany: true
- }
- ]
- },
- {
- name: "SubChoreography",
- superClass: [
- "ChoreographyActivity",
- "FlowElementsContainer"
- ],
- properties: [
- {
- name: "artifacts",
- type: "Artifact",
- isMany: true
- }
- ]
- },
- {
- name: "ChoreographyTask",
- superClass: [
- "ChoreographyActivity"
- ],
- properties: [
- {
- name: "messageFlowRef",
- type: "MessageFlow",
- isMany: true,
- isReference: true
- }
- ]
- },
- {
- name: "Choreography",
- superClass: [
- "Collaboration",
- "FlowElementsContainer"
- ]
- },
- {
- name: "GlobalChoreographyTask",
- superClass: [
- "Choreography"
- ],
- properties: [
- {
- name: "initiatingParticipantRef",
- type: "Participant",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "TextAnnotation",
- superClass: [
- "Artifact"
- ],
- properties: [
- {
- name: "text",
- type: "String"
- },
- {
- name: "textFormat",
- "default": "text/plain",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "Group",
- superClass: [
- "Artifact"
- ],
- properties: [
- {
- name: "categoryValueRef",
- type: "CategoryValue",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "Association",
- superClass: [
- "Artifact"
- ],
- properties: [
- {
- name: "associationDirection",
- type: "AssociationDirection",
- isAttr: true
- },
- {
- name: "sourceRef",
- type: "BaseElement",
- isAttr: true,
- isReference: true
- },
- {
- name: "targetRef",
- type: "BaseElement",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "Category",
- superClass: [
- "RootElement"
- ],
- properties: [
- {
- name: "categoryValue",
- type: "CategoryValue",
- isMany: true
- },
- {
- name: "name",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "Artifact",
- isAbstract: true,
- superClass: [
- "BaseElement"
- ]
- },
- {
- name: "CategoryValue",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "categorizedFlowElements",
- type: "FlowElement",
- isMany: true,
- isVirtual: true,
- isReference: true
- },
- {
- name: "value",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "Activity",
- isAbstract: true,
- superClass: [
- "FlowNode"
- ],
- properties: [
- {
- name: "isForCompensation",
- "default": false,
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "default",
- type: "SequenceFlow",
- isAttr: true,
- isReference: true
- },
- {
- name: "ioSpecification",
- type: "InputOutputSpecification",
- xml: {
- serialize: "property"
- }
- },
- {
- name: "boundaryEventRefs",
- type: "BoundaryEvent",
- isMany: true,
- isReference: true
- },
- {
- name: "properties",
- type: "Property",
- isMany: true
- },
- {
- name: "dataInputAssociations",
- type: "DataInputAssociation",
- isMany: true
- },
- {
- name: "dataOutputAssociations",
- type: "DataOutputAssociation",
- isMany: true
- },
- {
- name: "startQuantity",
- "default": 1,
- isAttr: true,
- type: "Integer"
- },
- {
- name: "resources",
- type: "ResourceRole",
- isMany: true
- },
- {
- name: "completionQuantity",
- "default": 1,
- isAttr: true,
- type: "Integer"
- },
- {
- name: "loopCharacteristics",
- type: "LoopCharacteristics"
- }
- ]
- },
- {
- name: "ServiceTask",
- superClass: [
- "Task"
- ],
- properties: [
- {
- name: "implementation",
- isAttr: true,
- type: "String"
- },
- {
- name: "operationRef",
- type: "Operation",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "SubProcess",
- superClass: [
- "Activity",
- "FlowElementsContainer",
- "InteractionNode"
- ],
- properties: [
- {
- name: "triggeredByEvent",
- "default": false,
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "artifacts",
- type: "Artifact",
- isMany: true
- }
- ]
- },
- {
- name: "LoopCharacteristics",
- isAbstract: true,
- superClass: [
- "BaseElement"
- ]
- },
- {
- name: "MultiInstanceLoopCharacteristics",
- superClass: [
- "LoopCharacteristics"
- ],
- properties: [
- {
- name: "isSequential",
- "default": false,
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "behavior",
- type: "MultiInstanceBehavior",
- "default": "All",
- isAttr: true
- },
- {
- name: "loopCardinality",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- },
- {
- name: "loopDataInputRef",
- type: "ItemAwareElement",
- isReference: true
- },
- {
- name: "loopDataOutputRef",
- type: "ItemAwareElement",
- isReference: true
- },
- {
- name: "inputDataItem",
- type: "DataInput",
- xml: {
- serialize: "property"
- }
- },
- {
- name: "outputDataItem",
- type: "DataOutput",
- xml: {
- serialize: "property"
- }
- },
- {
- name: "complexBehaviorDefinition",
- type: "ComplexBehaviorDefinition",
- isMany: true
- },
- {
- name: "completionCondition",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- },
- {
- name: "oneBehaviorEventRef",
- type: "EventDefinition",
- isAttr: true,
- isReference: true
- },
- {
- name: "noneBehaviorEventRef",
- type: "EventDefinition",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "StandardLoopCharacteristics",
- superClass: [
- "LoopCharacteristics"
- ],
- properties: [
- {
- name: "testBefore",
- "default": false,
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "loopCondition",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- },
- {
- name: "loopMaximum",
- type: "Integer",
- isAttr: true
- }
- ]
- },
- {
- name: "CallActivity",
- superClass: [
- "Activity"
- ],
- properties: [
- {
- name: "calledElement",
- type: "String",
- isAttr: true
- }
- ]
- },
- {
- name: "Task",
- superClass: [
- "Activity",
- "InteractionNode"
- ]
- },
- {
- name: "SendTask",
- superClass: [
- "Task"
- ],
- properties: [
- {
- name: "implementation",
- isAttr: true,
- type: "String"
- },
- {
- name: "operationRef",
- type: "Operation",
- isAttr: true,
- isReference: true
- },
- {
- name: "messageRef",
- type: "Message",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "ReceiveTask",
- superClass: [
- "Task"
- ],
- properties: [
- {
- name: "implementation",
- isAttr: true,
- type: "String"
- },
- {
- name: "instantiate",
- "default": false,
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "operationRef",
- type: "Operation",
- isAttr: true,
- isReference: true
- },
- {
- name: "messageRef",
- type: "Message",
- isAttr: true,
- isReference: true
- }
- ]
- },
- {
- name: "ScriptTask",
- superClass: [
- "Task"
- ],
- properties: [
- {
- name: "scriptFormat",
- isAttr: true,
- type: "String"
- },
- {
- name: "script",
- type: "String"
- }
- ]
- },
- {
- name: "BusinessRuleTask",
- superClass: [
- "Task"
- ],
- properties: [
- {
- name: "implementation",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "AdHocSubProcess",
- superClass: [
- "SubProcess"
- ],
- properties: [
- {
- name: "completionCondition",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- },
- {
- name: "ordering",
- type: "AdHocOrdering",
- isAttr: true
- },
- {
- name: "cancelRemainingInstances",
- "default": true,
- isAttr: true,
- type: "Boolean"
- }
- ]
- },
- {
- name: "Transaction",
- superClass: [
- "SubProcess"
- ],
- properties: [
- {
- name: "protocol",
- isAttr: true,
- type: "String"
- },
- {
- name: "method",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "GlobalScriptTask",
- superClass: [
- "GlobalTask"
- ],
- properties: [
- {
- name: "scriptLanguage",
- isAttr: true,
- type: "String"
- },
- {
- name: "script",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "GlobalBusinessRuleTask",
- superClass: [
- "GlobalTask"
- ],
- properties: [
- {
- name: "implementation",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "ComplexBehaviorDefinition",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "condition",
- type: "FormalExpression"
- },
- {
- name: "event",
- type: "ImplicitThrowEvent"
- }
- ]
- },
- {
- name: "ResourceRole",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "resourceRef",
- type: "Resource",
- isReference: true
- },
- {
- name: "resourceParameterBindings",
- type: "ResourceParameterBinding",
- isMany: true
- },
- {
- name: "resourceAssignmentExpression",
- type: "ResourceAssignmentExpression"
- },
- {
- name: "name",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "ResourceParameterBinding",
- properties: [
- {
- name: "expression",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- },
- {
- name: "parameterRef",
- type: "ResourceParameter",
- isAttr: true,
- isReference: true
- }
- ],
- superClass: [
- "BaseElement"
- ]
- },
- {
- name: "ResourceAssignmentExpression",
- properties: [
- {
- name: "expression",
- type: "Expression",
- xml: {
- serialize: "xsi:type"
- }
- }
- ],
- superClass: [
- "BaseElement"
- ]
- },
- {
- name: "Import",
- properties: [
- {
- name: "importType",
- isAttr: true,
- type: "String"
- },
- {
- name: "location",
- isAttr: true,
- type: "String"
- },
- {
- name: "namespace",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "Definitions",
- superClass: [
- "BaseElement"
- ],
- properties: [
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "targetNamespace",
- isAttr: true,
- type: "String"
- },
- {
- name: "expressionLanguage",
- "default": "http://www.w3.org/1999/XPath",
- isAttr: true,
- type: "String"
- },
- {
- name: "typeLanguage",
- "default": "http://www.w3.org/2001/XMLSchema",
- isAttr: true,
- type: "String"
- },
- {
- name: "imports",
- type: "Import",
- isMany: true
- },
- {
- name: "extensions",
- type: "Extension",
- isMany: true
- },
- {
- name: "rootElements",
- type: "RootElement",
- isMany: true
- },
- {
- name: "diagrams",
- isMany: true,
- type: "bpmndi:BPMNDiagram"
- },
- {
- name: "exporter",
- isAttr: true,
- type: "String"
- },
- {
- name: "relationships",
- type: "Relationship",
- isMany: true
- },
- {
- name: "exporterVersion",
- isAttr: true,
- type: "String"
- }
- ]
- }
- ];
- var enumerations = [
- {
- name: "ProcessType",
- literalValues: [
- {
- name: "None"
- },
- {
- name: "Public"
- },
- {
- name: "Private"
- }
- ]
- },
- {
- name: "GatewayDirection",
- literalValues: [
- {
- name: "Unspecified"
- },
- {
- name: "Converging"
- },
- {
- name: "Diverging"
- },
- {
- name: "Mixed"
- }
- ]
- },
- {
- name: "EventBasedGatewayType",
- literalValues: [
- {
- name: "Parallel"
- },
- {
- name: "Exclusive"
- }
- ]
- },
- {
- name: "RelationshipDirection",
- literalValues: [
- {
- name: "None"
- },
- {
- name: "Forward"
- },
- {
- name: "Backward"
- },
- {
- name: "Both"
- }
- ]
- },
- {
- name: "ItemKind",
- literalValues: [
- {
- name: "Physical"
- },
- {
- name: "Information"
- }
- ]
- },
- {
- name: "ChoreographyLoopType",
- literalValues: [
- {
- name: "None"
- },
- {
- name: "Standard"
- },
- {
- name: "MultiInstanceSequential"
- },
- {
- name: "MultiInstanceParallel"
- }
- ]
- },
- {
- name: "AssociationDirection",
- literalValues: [
- {
- name: "None"
- },
- {
- name: "One"
- },
- {
- name: "Both"
- }
- ]
- },
- {
- name: "MultiInstanceBehavior",
- literalValues: [
- {
- name: "None"
- },
- {
- name: "One"
- },
- {
- name: "All"
- },
- {
- name: "Complex"
- }
- ]
- },
- {
- name: "AdHocOrdering",
- literalValues: [
- {
- name: "Parallel"
- },
- {
- name: "Sequential"
- }
- ]
- }
- ];
- var xml = {
- tagAlias: "lowerCase",
- typePrefix: "t"
- };
- var BpmnPackage = {
- name: name,
- uri: uri,
- prefix: prefix$1,
- associations: associations,
- types: types$1,
- enumerations: enumerations,
- xml: xml
- };
- var name$1 = "BPMNDI";
- var uri$1 = "http://www.omg.org/spec/BPMN/20100524/DI";
- var prefix$1$1 = "bpmndi";
- var types$1$1 = [
- {
- name: "BPMNDiagram",
- properties: [
- {
- name: "plane",
- type: "BPMNPlane",
- redefines: "di:Diagram#rootElement"
- },
- {
- name: "labelStyle",
- type: "BPMNLabelStyle",
- isMany: true
- }
- ],
- superClass: [
- "di:Diagram"
- ]
- },
- {
- name: "BPMNPlane",
- properties: [
- {
- name: "bpmnElement",
- isAttr: true,
- isReference: true,
- type: "bpmn:BaseElement",
- redefines: "di:DiagramElement#modelElement"
- }
- ],
- superClass: [
- "di:Plane"
- ]
- },
- {
- name: "BPMNShape",
- properties: [
- {
- name: "bpmnElement",
- isAttr: true,
- isReference: true,
- type: "bpmn:BaseElement",
- redefines: "di:DiagramElement#modelElement"
- },
- {
- name: "isHorizontal",
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "isExpanded",
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "isMarkerVisible",
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "label",
- type: "BPMNLabel"
- },
- {
- name: "isMessageVisible",
- isAttr: true,
- type: "Boolean"
- },
- {
- name: "participantBandKind",
- type: "ParticipantBandKind",
- isAttr: true
- },
- {
- name: "choreographyActivityShape",
- type: "BPMNShape",
- isAttr: true,
- isReference: true
- }
- ],
- superClass: [
- "di:LabeledShape"
- ]
- },
- {
- name: "BPMNEdge",
- properties: [
- {
- name: "label",
- type: "BPMNLabel"
- },
- {
- name: "bpmnElement",
- isAttr: true,
- isReference: true,
- type: "bpmn:BaseElement",
- redefines: "di:DiagramElement#modelElement"
- },
- {
- name: "sourceElement",
- isAttr: true,
- isReference: true,
- type: "di:DiagramElement",
- redefines: "di:Edge#source"
- },
- {
- name: "targetElement",
- isAttr: true,
- isReference: true,
- type: "di:DiagramElement",
- redefines: "di:Edge#target"
- },
- {
- name: "messageVisibleKind",
- type: "MessageVisibleKind",
- isAttr: true,
- "default": "initiating"
- }
- ],
- superClass: [
- "di:LabeledEdge"
- ]
- },
- {
- name: "BPMNLabel",
- properties: [
- {
- name: "labelStyle",
- type: "BPMNLabelStyle",
- isAttr: true,
- isReference: true,
- redefines: "di:DiagramElement#style"
- }
- ],
- superClass: [
- "di:Label"
- ]
- },
- {
- name: "BPMNLabelStyle",
- properties: [
- {
- name: "font",
- type: "dc:Font"
- }
- ],
- superClass: [
- "di:Style"
- ]
- }
- ];
- var enumerations$1 = [
- {
- name: "ParticipantBandKind",
- literalValues: [
- {
- name: "top_initiating"
- },
- {
- name: "middle_initiating"
- },
- {
- name: "bottom_initiating"
- },
- {
- name: "top_non_initiating"
- },
- {
- name: "middle_non_initiating"
- },
- {
- name: "bottom_non_initiating"
- }
- ]
- },
- {
- name: "MessageVisibleKind",
- literalValues: [
- {
- name: "initiating"
- },
- {
- name: "non_initiating"
- }
- ]
- }
- ];
- var associations$1 = [
- ];
- var BpmnDiPackage = {
- name: name$1,
- uri: uri$1,
- prefix: prefix$1$1,
- types: types$1$1,
- enumerations: enumerations$1,
- associations: associations$1
- };
- var name$2 = "DC";
- var uri$2 = "http://www.omg.org/spec/DD/20100524/DC";
- var prefix$2 = "dc";
- var types$2 = [
- {
- name: "Boolean"
- },
- {
- name: "Integer"
- },
- {
- name: "Real"
- },
- {
- name: "String"
- },
- {
- name: "Font",
- properties: [
- {
- name: "name",
- type: "String",
- isAttr: true
- },
- {
- name: "size",
- type: "Real",
- isAttr: true
- },
- {
- name: "isBold",
- type: "Boolean",
- isAttr: true
- },
- {
- name: "isItalic",
- type: "Boolean",
- isAttr: true
- },
- {
- name: "isUnderline",
- type: "Boolean",
- isAttr: true
- },
- {
- name: "isStrikeThrough",
- type: "Boolean",
- isAttr: true
- }
- ]
- },
- {
- name: "Point",
- properties: [
- {
- name: "x",
- type: "Real",
- "default": "0",
- isAttr: true
- },
- {
- name: "y",
- type: "Real",
- "default": "0",
- isAttr: true
- }
- ]
- },
- {
- name: "Bounds",
- properties: [
- {
- name: "x",
- type: "Real",
- "default": "0",
- isAttr: true
- },
- {
- name: "y",
- type: "Real",
- "default": "0",
- isAttr: true
- },
- {
- name: "width",
- type: "Real",
- isAttr: true
- },
- {
- name: "height",
- type: "Real",
- isAttr: true
- }
- ]
- }
- ];
- var associations$2 = [
- ];
- var DcPackage = {
- name: name$2,
- uri: uri$2,
- prefix: prefix$2,
- types: types$2,
- associations: associations$2
- };
- var name$3 = "DI";
- var uri$3 = "http://www.omg.org/spec/DD/20100524/DI";
- var prefix$3 = "di";
- var types$3 = [
- {
- name: "DiagramElement",
- isAbstract: true,
- properties: [
- {
- name: "id",
- isAttr: true,
- isId: true,
- type: "String"
- },
- {
- name: "extension",
- type: "Extension"
- },
- {
- name: "owningDiagram",
- type: "Diagram",
- isReadOnly: true,
- isVirtual: true,
- isReference: true
- },
- {
- name: "owningElement",
- type: "DiagramElement",
- isReadOnly: true,
- isVirtual: true,
- isReference: true
- },
- {
- name: "modelElement",
- isReadOnly: true,
- isVirtual: true,
- isReference: true,
- type: "Element"
- },
- {
- name: "style",
- type: "Style",
- isReadOnly: true,
- isVirtual: true,
- isReference: true
- },
- {
- name: "ownedElement",
- type: "DiagramElement",
- isReadOnly: true,
- isMany: true,
- isVirtual: true
- }
- ]
- },
- {
- name: "Node",
- isAbstract: true,
- superClass: [
- "DiagramElement"
- ]
- },
- {
- name: "Edge",
- isAbstract: true,
- superClass: [
- "DiagramElement"
- ],
- properties: [
- {
- name: "source",
- type: "DiagramElement",
- isReadOnly: true,
- isVirtual: true,
- isReference: true
- },
- {
- name: "target",
- type: "DiagramElement",
- isReadOnly: true,
- isVirtual: true,
- isReference: true
- },
- {
- name: "waypoint",
- isUnique: false,
- isMany: true,
- type: "dc:Point",
- xml: {
- serialize: "xsi:type"
- }
- }
- ]
- },
- {
- name: "Diagram",
- isAbstract: true,
- properties: [
- {
- name: "id",
- isAttr: true,
- isId: true,
- type: "String"
- },
- {
- name: "rootElement",
- type: "DiagramElement",
- isReadOnly: true,
- isVirtual: true
- },
- {
- name: "name",
- isAttr: true,
- type: "String"
- },
- {
- name: "documentation",
- isAttr: true,
- type: "String"
- },
- {
- name: "resolution",
- isAttr: true,
- type: "Real"
- },
- {
- name: "ownedStyle",
- type: "Style",
- isReadOnly: true,
- isMany: true,
- isVirtual: true
- }
- ]
- },
- {
- name: "Shape",
- isAbstract: true,
- superClass: [
- "Node"
- ],
- properties: [
- {
- name: "bounds",
- type: "dc:Bounds"
- }
- ]
- },
- {
- name: "Plane",
- isAbstract: true,
- superClass: [
- "Node"
- ],
- properties: [
- {
- name: "planeElement",
- type: "DiagramElement",
- subsettedProperty: "DiagramElement-ownedElement",
- isMany: true
- }
- ]
- },
- {
- name: "LabeledEdge",
- isAbstract: true,
- superClass: [
- "Edge"
- ],
- properties: [
- {
- name: "ownedLabel",
- type: "Label",
- isReadOnly: true,
- subsettedProperty: "DiagramElement-ownedElement",
- isMany: true,
- isVirtual: true
- }
- ]
- },
- {
- name: "LabeledShape",
- isAbstract: true,
- superClass: [
- "Shape"
- ],
- properties: [
- {
- name: "ownedLabel",
- type: "Label",
- isReadOnly: true,
- subsettedProperty: "DiagramElement-ownedElement",
- isMany: true,
- isVirtual: true
- }
- ]
- },
- {
- name: "Label",
- isAbstract: true,
- superClass: [
- "Node"
- ],
- properties: [
- {
- name: "bounds",
- type: "dc:Bounds"
- }
- ]
- },
- {
- name: "Style",
- isAbstract: true,
- properties: [
- {
- name: "id",
- isAttr: true,
- isId: true,
- type: "String"
- }
- ]
- },
- {
- name: "Extension",
- properties: [
- {
- name: "values",
- isMany: true,
- type: "Element"
- }
- ]
- }
- ];
- var associations$3 = [
- ];
- var xml$1 = {
- tagAlias: "lowerCase"
- };
- var DiPackage = {
- name: name$3,
- uri: uri$3,
- prefix: prefix$3,
- types: types$3,
- associations: associations$3,
- xml: xml$1
- };
- var name$4 = "bpmn.io colors for BPMN";
- var uri$4 = "http://bpmn.io/schema/bpmn/biocolor/1.0";
- var prefix$4 = "bioc";
- var types$4 = [
- {
- name: "ColoredShape",
- "extends": [
- "bpmndi:BPMNShape"
- ],
- properties: [
- {
- name: "stroke",
- isAttr: true,
- type: "String"
- },
- {
- name: "fill",
- isAttr: true,
- type: "String"
- }
- ]
- },
- {
- name: "ColoredEdge",
- "extends": [
- "bpmndi:BPMNEdge"
- ],
- properties: [
- {
- name: "stroke",
- isAttr: true,
- type: "String"
- },
- {
- name: "fill",
- isAttr: true,
- type: "String"
- }
- ]
- }
- ];
- var enumerations$2 = [
- ];
- var associations$4 = [
- ];
- var BiocPackage = {
- name: name$4,
- uri: uri$4,
- prefix: prefix$4,
- types: types$4,
- enumerations: enumerations$2,
- associations: associations$4
- };
- var packages = {
- bpmn: BpmnPackage,
- bpmndi: BpmnDiPackage,
- dc: DcPackage,
- di: DiPackage,
- bioc: BiocPackage
- };
- function simple(additionalPackages, options) {
- var pks = assign({}, packages, additionalPackages);
- return new BpmnModdle(pks, options);
- }
- var diRefs = new objectRefs(
- { name: 'bpmnElement', enumerable: true },
- { name: 'di', configurable: true }
- );
- /**
- * Returns true if an element has the given meta-model type
- *
- * @param {ModdleElement} element
- * @param {string} type
- *
- * @return {boolean}
- */
- function is$1(element, type) {
- return element.$instanceOf(type);
- }
- /**
- * Find a suitable display candidate for definitions where the DI does not
- * correctly specify one.
- */
- function findDisplayCandidate(definitions) {
- return find(definitions.rootElements, function(e) {
- return is$1(e, 'bpmn:Process') || is$1(e, 'bpmn:Collaboration');
- });
- }
- function BpmnTreeWalker(handler, translate) {
- // list of containers already walked
- var handledElements = {};
- // list of elements to handle deferred to ensure
- // prerequisites are drawn
- var deferred = [];
- // Helpers //////////////////////
- function contextual(fn, ctx) {
- return function(e) {
- fn(e, ctx);
- };
- }
- function handled(element) {
- handledElements[element.id] = element;
- }
- function isHandled(element) {
- return handledElements[element.id];
- }
- function visit(element, ctx) {
- var gfx = element.gfx;
- // avoid multiple rendering of elements
- if (gfx) {
- throw new Error(
- translate('already rendered {element}', { element: elementToString(element) })
- );
- }
- // call handler
- return handler.element(element, ctx);
- }
- function visitRoot(element, diagram) {
- return handler.root(element, diagram);
- }
- function visitIfDi(element, ctx) {
- try {
- var gfx = element.di && visit(element, ctx);
- handled(element);
- return gfx;
- } catch (e) {
- logError(e.message, { element: element, error: e });
- console.error(translate('failed to import {element}', { element: elementToString(element) }));
- console.error(e);
- }
- }
- function logError(message, context) {
- handler.error(message, context);
- }
- // DI handling //////////////////////
- function registerDi(di) {
- var bpmnElement = di.bpmnElement;
- if (bpmnElement) {
- if (bpmnElement.di) {
- logError(
- translate('multiple DI elements defined for {element}', {
- element: elementToString(bpmnElement)
- }),
- { element: bpmnElement }
- );
- } else {
- diRefs.bind(bpmnElement, 'di');
- bpmnElement.di = di;
- }
- } else {
- logError(
- translate('no bpmnElement referenced in {element}', {
- element: elementToString(di)
- }),
- { element: di }
- );
- }
- }
- function handleDiagram(diagram) {
- handlePlane(diagram.plane);
- }
- function handlePlane(plane) {
- registerDi(plane);
- forEach(plane.planeElement, handlePlaneElement);
- }
- function handlePlaneElement(planeElement) {
- registerDi(planeElement);
- }
- // Semantic handling //////////////////////
- /**
- * Handle definitions and return the rendered diagram (if any)
- *
- * @param {ModdleElement} definitions to walk and import
- * @param {ModdleElement} [diagram] specific diagram to import and display
- *
- * @throws {Error} if no diagram to display could be found
- */
- function handleDefinitions(definitions, diagram) {
- // make sure we walk the correct bpmnElement
- var diagrams = definitions.diagrams;
- if (diagram && diagrams.indexOf(diagram) === -1) {
- throw new Error(translate('diagram not part of bpmn:Definitions'));
- }
- if (!diagram && diagrams && diagrams.length) {
- diagram = diagrams[0];
- }
- // no diagram -> nothing to import
- if (!diagram) {
- throw new Error(translate('no diagram to display'));
- }
- // load DI from selected diagram only
- handleDiagram(diagram);
- var plane = diagram.plane;
- if (!plane) {
- throw new Error(translate(
- 'no plane for {element}',
- { element: elementToString(diagram) }
- ));
- }
- var rootElement = plane.bpmnElement;
- // ensure we default to a suitable display candidate (process or collaboration),
- // even if non is specified in DI
- if (!rootElement) {
- rootElement = findDisplayCandidate(definitions);
- if (!rootElement) {
- throw new Error(translate('no process or collaboration to display'));
- } else {
- logError(
- translate('correcting missing bpmnElement on {plane} to {rootElement}', {
- plane: elementToString(plane),
- rootElement: elementToString(rootElement)
- })
- );
- // correct DI on the fly
- plane.bpmnElement = rootElement;
- registerDi(plane);
- }
- }
- var ctx = visitRoot(rootElement, plane);
- if (is$1(rootElement, 'bpmn:Process')) {
- handleProcess(rootElement, ctx);
- } else if (is$1(rootElement, 'bpmn:Collaboration')) {
- handleCollaboration(rootElement);
- // force drawing of everything not yet drawn that is part of the target DI
- handleUnhandledProcesses(definitions.rootElements, ctx);
- } else {
- throw new Error(
- translate('unsupported bpmnElement for {plane}: {rootElement}', {
- plane: elementToString(plane),
- rootElement: elementToString(rootElement)
- })
- );
- }
- // handle all deferred elements
- handleDeferred();
- }
- function handleDeferred() {
- var fn;
- // drain deferred until empty
- while (deferred.length) {
- fn = deferred.shift();
- fn();
- }
- }
- function handleProcess(process, context) {
- handleFlowElementsContainer(process, context);
- handleIoSpecification(process.ioSpecification, context);
- handleArtifacts(process.artifacts, context);
- // log process handled
- handled(process);
- }
- function handleUnhandledProcesses(rootElements, ctx) {
- // walk through all processes that have not yet been drawn and draw them
- // if they contain lanes with DI information.
- // we do this to pass the free-floating lane test cases in the MIWG test suite
- var processes = filter(rootElements, function(e) {
- return !isHandled(e) && is$1(e, 'bpmn:Process') && e.laneSets;
- });
- processes.forEach(contextual(handleProcess, ctx));
- }
- function handleMessageFlow(messageFlow, context) {
- visitIfDi(messageFlow, context);
- }
- function handleMessageFlows(messageFlows, context) {
- forEach(messageFlows, contextual(handleMessageFlow, context));
- }
- function handleDataAssociation(association, context) {
- visitIfDi(association, context);
- }
- function handleDataInput(dataInput, context) {
- visitIfDi(dataInput, context);
- }
- function handleDataOutput(dataOutput, context) {
- visitIfDi(dataOutput, context);
- }
- function handleArtifact(artifact, context) {
- // bpmn:TextAnnotation
- // bpmn:Group
- // bpmn:Association
- visitIfDi(artifact, context);
- }
- function handleArtifacts(artifacts, context) {
- forEach(artifacts, function(e) {
- if (is$1(e, 'bpmn:Association')) {
- deferred.push(function() {
- handleArtifact(e, context);
- });
- } else {
- handleArtifact(e, context);
- }
- });
- }
- function handleIoSpecification(ioSpecification, context) {
- if (!ioSpecification) {
- return;
- }
- forEach(ioSpecification.dataInputs, contextual(handleDataInput, context));
- forEach(ioSpecification.dataOutputs, contextual(handleDataOutput, context));
- }
- function handleSubProcess(subProcess, context) {
- handleFlowElementsContainer(subProcess, context);
- handleArtifacts(subProcess.artifacts, context);
- }
- function handleFlowNode(flowNode, context) {
- var childCtx = visitIfDi(flowNode, context);
- if (is$1(flowNode, 'bpmn:SubProcess')) {
- handleSubProcess(flowNode, childCtx || context);
- }
- if (is$1(flowNode, 'bpmn:Activity')) {
- handleIoSpecification(flowNode.ioSpecification, context);
- }
- // defer handling of associations
- // affected types:
- //
- // * bpmn:Activity
- // * bpmn:ThrowEvent
- // * bpmn:CatchEvent
- //
- deferred.push(function() {
- forEach(flowNode.dataInputAssociations, contextual(handleDataAssociation, context));
- forEach(flowNode.dataOutputAssociations, contextual(handleDataAssociation, context));
- });
- }
- function handleSequenceFlow(sequenceFlow, context) {
- visitIfDi(sequenceFlow, context);
- }
- function handleDataElement(dataObject, context) {
- visitIfDi(dataObject, context);
- }
- function handleLane(lane, context) {
- deferred.push(function() {
- var newContext = visitIfDi(lane, context);
- if (lane.childLaneSet) {
- handleLaneSet(lane.childLaneSet, newContext || context);
- }
- wireFlowNodeRefs(lane);
- });
- }
- function handleLaneSet(laneSet, context) {
- forEach(laneSet.lanes, contextual(handleLane, context));
- }
- function handleLaneSets(laneSets, context) {
- forEach(laneSets, contextual(handleLaneSet, context));
- }
- function handleFlowElementsContainer(container, context) {
- handleFlowElements(container.flowElements, context);
- if (container.laneSets) {
- handleLaneSets(container.laneSets, context);
- }
- }
- function handleFlowElements(flowElements, context) {
- forEach(flowElements, function(e) {
- if (is$1(e, 'bpmn:SequenceFlow')) {
- deferred.push(function() {
- handleSequenceFlow(e, context);
- });
- } else if (is$1(e, 'bpmn:BoundaryEvent')) {
- deferred.unshift(function() {
- handleFlowNode(e, context);
- });
- } else if (is$1(e, 'bpmn:FlowNode')) {
- handleFlowNode(e, context);
- } else if (is$1(e, 'bpmn:DataObject')) ; else if (is$1(e, 'bpmn:DataStoreReference')) {
- handleDataElement(e, context);
- } else if (is$1(e, 'bpmn:DataObjectReference')) {
- handleDataElement(e, context);
- } else {
- logError(
- translate('unrecognized flowElement {element} in context {context}', {
- element: elementToString(e),
- context: (context ? elementToString(context.businessObject) : 'null')
- }),
- { element: e, context: context }
- );
- }
- });
- }
- function handleParticipant(participant, context) {
- var newCtx = visitIfDi(participant, context);
- var process = participant.processRef;
- if (process) {
- handleProcess(process, newCtx || context);
- }
- }
- function handleCollaboration(collaboration) {
- forEach(collaboration.participants, contextual(handleParticipant));
- handleArtifacts(collaboration.artifacts);
- // handle message flows latest in the process
- deferred.push(function() {
- handleMessageFlows(collaboration.messageFlows);
- });
- }
- function wireFlowNodeRefs(lane) {
- // wire the virtual flowNodeRefs <-> relationship
- forEach(lane.flowNodeRef, function(flowNode) {
- var lanes = flowNode.get('lanes');
- if (lanes) {
- lanes.push(lane);
- }
- });
- }
- // API //////////////////////
- return {
- handleDeferred: handleDeferred,
- handleDefinitions: handleDefinitions,
- handleSubProcess: handleSubProcess,
- registerDi: registerDi
- };
- }
- /**
- * Import the definitions into a diagram.
- *
- * Errors and warnings are reported through the specified callback.
- *
- * @param {djs.Diagram} diagram
- * @param {ModdleElement<Definitions>} definitions
- * @param {ModdleElement<BPMNDiagram>} [bpmnDiagram] the diagram to be rendered
- * (if not provided, the first one will be rendered)
- * @param {Function} done the callback, invoked with (err, [ warning ]) once the import is done
- */
- function importBpmnDiagram(diagram, definitions, bpmnDiagram, done) {
- if (isFunction(bpmnDiagram)) {
- done = bpmnDiagram;
- bpmnDiagram = null;
- }
- var importer,
- eventBus,
- translate;
- var error,
- warnings = [];
- /**
- * Walk the diagram semantically, importing (=drawing)
- * all elements you encounter.
- *
- * @param {ModdleElement<Definitions>} definitions
- * @param {ModdleElement<BPMNDiagram>} bpmnDiagram
- */
- function render(definitions, bpmnDiagram) {
- var visitor = {
- root: function(element) {
- return importer.add(element);
- },
- element: function(element, parentShape) {
- return importer.add(element, parentShape);
- },
- error: function(message, context) {
- warnings.push({ message: message, context: context });
- }
- };
- var walker = new BpmnTreeWalker(visitor, translate);
- // traverse BPMN 2.0 document model,
- // starting at definitions
- walker.handleDefinitions(definitions, bpmnDiagram);
- }
- try {
- importer = diagram.get('bpmnImporter');
- eventBus = diagram.get('eventBus');
- translate = diagram.get('translate');
- eventBus.fire('import.render.start', { definitions: definitions });
- render(definitions, bpmnDiagram);
- eventBus.fire('import.render.complete', {
- error: error,
- warnings: warnings
- });
- } catch (e) {
- error = e;
- }
- done(error, warnings);
- }
- /**
- * This file must not be changed or exchanged.
- *
- * @see http://bpmn.io/license for more information.
- */
- // inlined ../../resources/logo.svg
- var BPMNIO_LOGO_SVG = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 960"><path fill="#fff" d="M960 60v839c0 33-27 61-60 61H60c-33 0-60-27-60-60V60C0 27 27 0 60 0h839c34 0 61 27 61 60z"/><path fill="#52b415" d="M217 548a205 205 0 0 0-144 58 202 202 0 0 0-4 286 202 202 0 0 0 285 3 200 200 0 0 0 48-219 203 203 0 0 0-185-128zM752 6a206 206 0 0 0-192 285 206 206 0 0 0 269 111 207 207 0 0 0 111-260A204 204 0 0 0 752 6zM62 0A62 62 0 0 0 0 62v398l60 46a259 259 0 0 1 89-36c5-28 10-57 14-85l99 2 12 85a246 246 0 0 1 88 38l70-52 69 71-52 68c17 30 29 58 35 90l86 14-2 100-86 12a240 240 0 0 1-38 89l43 58h413c37 0 60-27 60-61V407a220 220 0 0 1-44 40l21 85-93 39-45-76a258 258 0 0 1-98 1l-45 76-94-39 22-85a298 298 0 0 1-70-69l-86 22-38-94 76-45a258 258 0 0 1-1-98l-76-45 40-94 85 22a271 271 0 0 1 41-47z"/></svg>';
- var BPMNIO_LOGO_URL = 'data:image/svg+xml,' + encodeURIComponent(BPMNIO_LOGO_SVG);
- var BPMNIO_IMG = '<img width="52" height="52" src="' + BPMNIO_LOGO_URL + '" />';
- function css(attrs) {
- return attrs.join(';');
- }
- var LIGHTBOX_STYLES = css([
- 'z-index: 1001',
- 'position: fixed',
- 'top: 0',
- 'left: 0',
- 'right: 0',
- 'bottom: 0'
- ]);
- var BACKDROP_STYLES = css([
- 'width: 100%',
- 'height: 100%',
- 'background: rgba(0,0,0,0.2)'
- ]);
- var NOTICE_STYLES = css([
- 'position: absolute',
- 'left: 50%',
- 'top: 40%',
- 'margin: 0 -130px',
- 'width: 260px',
- 'padding: 10px',
- 'background: white',
- 'border: solid 1px #AAA',
- 'border-radius: 3px',
- 'font-family: Helvetica, Arial, sans-serif',
- 'font-size: 14px',
- 'line-height: 1.2em'
- ]);
- var LIGHTBOX_MARKUP =
- '<div class="bjs-powered-by-lightbox" style="' + LIGHTBOX_STYLES + '">' +
- '<div class="backdrop" style="' + BACKDROP_STYLES + '"></div>' +
- '<div class="notice" style="' + NOTICE_STYLES + '">' +
- '<a href="http://bpmn.io" target="_blank" style="float: left; margin-right: 10px">' +
- BPMNIO_IMG +
- '</a>' +
- 'Web-based tooling for BPMN, DMN and CMMN diagrams ' +
- 'powered by <a href="http://bpmn.io" target="_blank">bpmn.io</a>.' +
- '</div>' +
- '</div>';
- var lightbox;
- function open() {
- if (!lightbox) {
- lightbox = domify(LIGHTBOX_MARKUP);
- delegateEvents.bind(lightbox, '.backdrop', 'click', function(event) {
- document.body.removeChild(lightbox);
- });
- }
- document.body.appendChild(lightbox);
- }
- /**
- * The code in the <project-logo></project-logo> area
- * must not be changed.
- *
- * @see http://bpmn.io/license for more information.
- */
- /**
- * A base viewer for BPMN 2.0 diagrams.
- *
- * Have a look at {@link Viewer}, {@link NavigatedViewer} or {@link Modeler} for
- * bundles that include actual features.
- *
- * @param {Object} [options] configuration options to pass to the viewer
- * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
- * @param {string|number} [options.width] the width of the viewer
- * @param {string|number} [options.height] the height of the viewer
- * @param {Object} [options.moddleExtensions] extension packages to provide
- * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
- * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
- */
- function BaseViewer(options) {
- options = assign({}, DEFAULT_OPTIONS, options);
- this._moddle = this._createModdle(options);
- this._container = this._createContainer(options);
- /* <project-logo> */
- addProjectLogo(this._container);
- /* </project-logo> */
- this._init(this._container, this._moddle, options);
- }
- inherits_browser(BaseViewer, Diagram);
- /**
- * Parse and render a BPMN 2.0 diagram.
- *
- * Once finished the viewer reports back the result to the
- * provided callback function with (err, warnings).
- *
- * ## Life-Cycle Events
- *
- * During import the viewer will fire life-cycle events:
- *
- * * import.parse.start (about to read model from xml)
- * * import.parse.complete (model read; may have worked or not)
- * * import.render.start (graphical import start)
- * * import.render.complete (graphical import finished)
- * * import.done (everything done)
- *
- * You can use these events to hook into the life-cycle.
- *
- * @param {string} xml the BPMN 2.0 xml
- * @param {ModdleElement<BPMNDiagram>|string} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
- * @param {Function} [done] invoked with (err, warnings=[])
- */
- BaseViewer.prototype.importXML = function(xml, bpmnDiagram, done) {
- if (isFunction(bpmnDiagram)) {
- done = bpmnDiagram;
- bpmnDiagram = null;
- }
- // done is optional
- done = done || function() {};
- var self = this;
- // hook in pre-parse listeners +
- // allow xml manipulation
- xml = this._emit('import.parse.start', { xml: xml }) || xml;
- this._moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) {
- // hook in post parse listeners +
- // allow definitions manipulation
- definitions = self._emit('import.parse.complete', {
- error: err,
- definitions: definitions,
- context: context
- }) || definitions;
- var parseWarnings = context.warnings;
- if (err) {
- err = checkValidationError(err);
- self._emit('import.done', { error: err, warnings: parseWarnings });
- return done(err, parseWarnings);
- }
- self.importDefinitions(definitions, bpmnDiagram, function(err, importWarnings) {
- var allWarnings = [].concat(parseWarnings, importWarnings || []);
- self._emit('import.done', { error: err, warnings: allWarnings });
- done(err, allWarnings);
- });
- });
- };
- /**
- * Import parsed definitions and render a BPMN 2.0 diagram.
- *
- * Once finished the viewer reports back the result to the
- * provided callback function with (err, warnings).
- *
- * ## Life-Cycle Events
- *
- * During import the viewer will fire life-cycle events:
- *
- * * import.render.start (graphical import start)
- * * import.render.complete (graphical import finished)
- *
- * You can use these events to hook into the life-cycle.
- *
- * @param {ModdleElement<Definitions>} definitions parsed BPMN 2.0 definitions
- * @param {ModdleElement<BPMNDiagram>|string} [bpmnDiagram] BPMN diagram or id of diagram to render (if not provided, the first one will be rendered)
- * @param {Function} [done] invoked with (err, warnings=[])
- */
- BaseViewer.prototype.importDefinitions = function(definitions, bpmnDiagram, done) {
- if (isFunction(bpmnDiagram)) {
- done = bpmnDiagram;
- bpmnDiagram = null;
- }
- // done is optional
- done = done || function() {};
- this._setDefinitions(definitions);
- return this.open(bpmnDiagram, done);
- };
- /**
- * Open diagram of previously imported XML.
- *
- * Once finished the viewer reports back the result to the
- * provided callback function with (err, warnings).
- *
- * ## Life-Cycle Events
- *
- * During switch the viewer will fire life-cycle events:
- *
- * * import.render.start (graphical import start)
- * * import.render.complete (graphical import finished)
- *
- * You can use these events to hook into the life-cycle.
- *
- * @param {string|ModdleElement<BPMNDiagram>} [bpmnDiagramOrId] id or the diagram to open
- * @param {Function} [done] invoked with (err, warnings=[])
- */
- BaseViewer.prototype.open = function(bpmnDiagramOrId, done) {
- if (isFunction(bpmnDiagramOrId)) {
- done = bpmnDiagramOrId;
- bpmnDiagramOrId = null;
- }
- var definitions = this._definitions;
- var bpmnDiagram = bpmnDiagramOrId;
- // done is optional
- done = done || function() {};
- if (!definitions) {
- return done(new Error('no XML imported'));
- }
- if (typeof bpmnDiagramOrId === 'string') {
- bpmnDiagram = findBPMNDiagram(definitions, bpmnDiagramOrId);
- if (!bpmnDiagram) {
- return done(new Error('BPMNDiagram <' + bpmnDiagramOrId + '> not found'));
- }
- }
- // clear existing rendered diagram
- // catch synchronous exceptions during #clear()
- try {
- this.clear();
- } catch (error) {
- return done(error);
- }
- // perform graphical import
- return importBpmnDiagram(this, definitions, bpmnDiagram, done);
- };
- /**
- * Export the currently displayed BPMN 2.0 diagram as
- * a BPMN 2.0 XML document.
- *
- * ## Life-Cycle Events
- *
- * During XML saving the viewer will fire life-cycle events:
- *
- * * saveXML.start (before serialization)
- * * saveXML.serialized (after xml generation)
- * * saveXML.done (everything done)
- *
- * You can use these events to hook into the life-cycle.
- *
- * @param {Object} [options] export options
- * @param {boolean} [options.format=false] output formatted XML
- * @param {boolean} [options.preamble=true] output preamble
- *
- * @param {Function} done invoked with (err, xml)
- */
- BaseViewer.prototype.saveXML = function(options, done) {
- if (!done) {
- done = options;
- options = {};
- }
- var self = this;
- var definitions = this._definitions;
- if (!definitions) {
- return done(new Error('no definitions loaded'));
- }
- // allow to fiddle around with definitions
- definitions = this._emit('saveXML.start', {
- definitions: definitions
- }) || definitions;
- this._moddle.toXML(definitions, options, function(err, xml) {
- try {
- xml = self._emit('saveXML.serialized', {
- error: err,
- xml: xml
- }) || xml;
- self._emit('saveXML.done', {
- error: err,
- xml: xml
- });
- } catch (e) {
- console.error('error in saveXML life-cycle listener', e);
- }
- done(err, xml);
- });
- };
- /**
- * Export the currently displayed BPMN 2.0 diagram as
- * an SVG image.
- *
- * ## Life-Cycle Events
- *
- * During SVG saving the viewer will fire life-cycle events:
- *
- * * saveSVG.start (before serialization)
- * * saveSVG.done (everything done)
- *
- * You can use these events to hook into the life-cycle.
- *
- * @param {Object} [options]
- * @param {Function} done invoked with (err, svgStr)
- */
- BaseViewer.prototype.saveSVG = function(options, done) {
- if (!done) {
- done = options;
- options = {};
- }
- this._emit('saveSVG.start');
- var svg, err;
- try {
- var canvas = this.get('canvas');
- var contentNode = canvas.getDefaultLayer(),
- defsNode = query('defs', canvas._svg);
- var contents = innerSVG(contentNode),
- defs = defsNode ? '<defs>' + innerSVG(defsNode) + '</defs>' : '';
- var bbox = contentNode.getBBox();
- svg =
- '<?xml version="1.0" encoding="utf-8"?>\n' +
- '<!-- created with bpmn-js / http://bpmn.io -->\n' +
- '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
- '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +
- 'width="' + bbox.width + '" height="' + bbox.height + '" ' +
- 'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' +
- defs + contents +
- '</svg>';
- } catch (e) {
- err = e;
- }
- this._emit('saveSVG.done', {
- error: err,
- svg: svg
- });
- done(err, svg);
- };
- /**
- * Get a named diagram service.
- *
- * @example
- *
- * var elementRegistry = viewer.get('elementRegistry');
- * var startEventShape = elementRegistry.get('StartEvent_1');
- *
- * @param {string} name
- *
- * @return {Object} diagram service instance
- *
- * @method BaseViewer#get
- */
- /**
- * Invoke a function in the context of this viewer.
- *
- * @example
- *
- * viewer.invoke(function(elementRegistry) {
- * var startEventShape = elementRegistry.get('StartEvent_1');
- * });
- *
- * @param {Function} fn to be invoked
- *
- * @return {Object} the functions return value
- *
- * @method BaseViewer#invoke
- */
- BaseViewer.prototype._setDefinitions = function(definitions) {
- this._definitions = definitions;
- };
- BaseViewer.prototype.getModules = function() {
- return this._modules;
- };
- /**
- * Remove all drawn elements from the viewer.
- *
- * After calling this method the viewer can still
- * be reused for opening another diagram.
- *
- * @method BaseViewer#clear
- */
- BaseViewer.prototype.clear = function() {
- if (!this.getDefinitions()) {
- // no diagram to clear
- return;
- }
- // remove businessObject#di binding
- //
- // this is necessary, as we establish the bindings
- // in the BpmnTreeWalker (and assume none are given
- // on reimport)
- this.get('elementRegistry').forEach(function(element) {
- var bo = element.businessObject;
- if (bo && bo.di) {
- delete bo.di;
- }
- });
- // remove drawn elements
- Diagram.prototype.clear.call(this);
- };
- /**
- * Destroy the viewer instance and remove all its
- * remainders from the document tree.
- */
- BaseViewer.prototype.destroy = function() {
- // diagram destroy
- Diagram.prototype.destroy.call(this);
- // dom detach
- remove$1(this._container);
- };
- /**
- * Register an event listener
- *
- * Remove a previously added listener via {@link #off(event, callback)}.
- *
- * @param {string} event
- * @param {number} [priority]
- * @param {Function} callback
- * @param {Object} [that]
- */
- BaseViewer.prototype.on = function(event, priority, callback, target) {
- return this.get('eventBus').on(event, priority, callback, target);
- };
- /**
- * De-register an event listener
- *
- * @param {string} event
- * @param {Function} callback
- */
- BaseViewer.prototype.off = function(event, callback) {
- this.get('eventBus').off(event, callback);
- };
- BaseViewer.prototype.attachTo = function(parentNode) {
- if (!parentNode) {
- throw new Error('parentNode required');
- }
- // ensure we detach from the
- // previous, old parent
- this.detach();
- // unwrap jQuery if provided
- if (parentNode.get && parentNode.constructor.prototype.jquery) {
- parentNode = parentNode.get(0);
- }
- if (typeof parentNode === 'string') {
- parentNode = query(parentNode);
- }
- parentNode.appendChild(this._container);
- this._emit('attach', {});
- this.get('canvas').resized();
- };
- BaseViewer.prototype.getDefinitions = function() {
- return this._definitions;
- };
- BaseViewer.prototype.detach = function() {
- var container = this._container,
- parentNode = container.parentNode;
- if (!parentNode) {
- return;
- }
- this._emit('detach', {});
- parentNode.removeChild(container);
- };
- BaseViewer.prototype._init = function(container, moddle, options) {
- var baseModules = options.modules || this.getModules(),
- additionalModules = options.additionalModules || [],
- staticModules = [
- {
- bpmnjs: [ 'value', this ],
- moddle: [ 'value', moddle ]
- }
- ];
- var diagramModules = [].concat(staticModules, baseModules, additionalModules);
- var diagramOptions = assign(omit(options, [ 'additionalModules' ]), {
- canvas: assign({}, options.canvas, { container: container }),
- modules: diagramModules
- });
- // invoke diagram constructor
- Diagram.call(this, diagramOptions);
- if (options && options.container) {
- this.attachTo(options.container);
- }
- };
- /**
- * Emit an event on the underlying {@link EventBus}
- *
- * @param {string} type
- * @param {Object} event
- *
- * @return {Object} event processing result (if any)
- */
- BaseViewer.prototype._emit = function(type, event) {
- return this.get('eventBus').fire(type, event);
- };
- BaseViewer.prototype._createContainer = function(options) {
- var container = domify('<div class="bjs-container"></div>');
- assign(container.style, {
- width: ensureUnit(options.width),
- height: ensureUnit(options.height),
- position: options.position
- });
- return container;
- };
- BaseViewer.prototype._createModdle = function(options) {
- var moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
- return new simple(moddleOptions);
- };
- BaseViewer.prototype._modules = [];
- // helpers ///////////////
- function checkValidationError(err) {
- // check if we can help the user by indicating wrong BPMN 2.0 xml
- // (in case he or the exporting tool did not get that right)
- var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/;
- var match = pattern.exec(err.message);
- if (match) {
- err.message =
- 'unparsable content <' + match[1] + '> detected; ' +
- 'this may indicate an invalid BPMN 2.0 diagram file' + match[2];
- }
- return err;
- }
- var DEFAULT_OPTIONS = {
- width: '100%',
- height: '100%',
- position: 'relative'
- };
- /**
- * Ensure the passed argument is a proper unit (defaulting to px)
- */
- function ensureUnit(val) {
- return val + (isNumber(val) ? 'px' : '');
- }
- /**
- * Find BPMNDiagram in definitions by ID
- *
- * @param {ModdleElement<Definitions>} definitions
- * @param {string} diagramId
- *
- * @return {ModdleElement<BPMNDiagram>|null}
- */
- function findBPMNDiagram(definitions, diagramId) {
- if (!diagramId) {
- return null;
- }
- return find(definitions.diagrams, function(element) {
- return element.id === diagramId;
- }) || null;
- }
- /**
- * Adds the project logo to the diagram container as
- * required by the bpmn.io license.
- *
- * @see http://bpmn.io/license
- *
- * @param {Element} container
- */
- function addProjectLogo(container) {
- var img = BPMNIO_IMG;
- var linkMarkup =
- '<a href="http://bpmn.io" ' +
- 'target="_blank" ' +
- 'class="bjs-powered-by" ' +
- 'title="Powered by bpmn.io" ' +
- 'style="position: absolute; bottom: 15px; right: 15px; z-index: 100">' +
- img +
- '</a>';
- var linkElement = domify(linkMarkup);
- container.appendChild(linkElement);
- componentEvent.bind(linkElement, 'click', function(event) {
- open();
- event.preventDefault();
- });
- }
- /* </project-logo> */
- /**
- * A viewer for BPMN 2.0 diagrams.
- *
- * Have a look at {@link NavigatedViewer} or {@link Modeler} for bundles that include
- * additional features.
- *
- *
- * ## Extending the Viewer
- *
- * In order to extend the viewer pass extension modules to bootstrap via the
- * `additionalModules` option. An extension module is an object that exposes
- * named services.
- *
- * The following example depicts the integration of a simple
- * logging component that integrates with interaction events:
- *
- *
- * ```javascript
- *
- * // logging component
- * function InteractionLogger(eventBus) {
- * eventBus.on('element.hover', function(event) {
- * console.log()
- * })
- * }
- *
- * InteractionLogger.$inject = [ 'eventBus' ]; // minification save
- *
- * // extension module
- * var extensionModule = {
- * __init__: [ 'interactionLogger' ],
- * interactionLogger: [ 'type', InteractionLogger ]
- * };
- *
- * // extend the viewer
- * var bpmnViewer = new Viewer({ additionalModules: [ extensionModule ] });
- * bpmnViewer.importXML(...);
- * ```
- *
- * @param {Object} [options] configuration options to pass to the viewer
- * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body.
- * @param {string|number} [options.width] the width of the viewer
- * @param {string|number} [options.height] the height of the viewer
- * @param {Object} [options.moddleExtensions] extension packages to provide
- * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules
- * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules
- */
- function Viewer(options) {
- BaseViewer.call(this, options);
- }
- inherits_browser(Viewer, BaseViewer);
- // modules the viewer is composed of
- Viewer.prototype._modules = [
- CoreModule,
- TranslateModule,
- SelectionModule,
- OverlaysModule
- ];
- // default moddle extensions the viewer is composed of
- Viewer.prototype._moddleExtensions = {};
- return Viewer;
- }));
|